### Author Topic: Calculating Defensive EV spreads  (Read 3921 times)

#### Aphid « on: December 08, 2014, 02:58:27 PM »
I see fairly often that guides feature suboptimal defensive EV spreads.

The purpose of defensive EVs is often one of the following three goals, in order of how common they are:

1) Maximize defenses against a chosen type of attack.
2) Maximize defenses against a mixed 'barrage' of attack.
3) Maximize defense against an opponent that picks the most effective type.

In order to understand defensive EVs, let's first consider the attack damage formula. Effectively, this formula says the damage percentage from an attack is 100 * A * P * C * R/ (D * H), where A is the attacking puppet's attack stat, while D is your defense stat. P is the move's power, C is a certain constant, and R varies between 0.85 and 1 randomly. (Both puppets are assumed to be level 100). Since only 'D' and 'H' here is within our control we can observe a simple fact:

EHP = D * H * C

Where EHP is your `effective` health. The higher this number, the more attacks a puppet can withstand. Now EV's raise the 'H' and 'D' statistics by exactly one point per 4 EVs.

Goal <1>

When D > H, it is obvious raising 'H' by one point will provide you with more EHP than raising 'D' by one point, so it is best to spend your EVs in the lower of the two values. There is some 'optimal' amount of EVs to invest in either attack or hp before reaching the cutoff point. Let h be your HP stat, and d be your defense stat. The cutoff point is at d = h + 52.5.

Suppose d < h + 52.5. Then we need more defense. So first invest (h  - d) * 8 + 420 EV's into defense, then split equally.
If h < d - 52.5, then we need more HP. First invest (d - h) * 8 - 420 EV's into HP, then split equally.

Let's do an example: We have a puppet with the following stats:

HP: 80
DEF: 140

And we want to maximize physical defense, having 240 EV's available for this in our build. In order to do so, notice how h < d - 52.5. (d - h) * 8 - 420 = 60, so first invest 60 EV's into HP, then split equally. Then you get the following EV spread:

HP: 150
DEF: 90

Because EV's are rounded in multiples of 4, we can optimize for rounding by using this instead:

HP: 152
DEF: 92

Now, suppose we have a +def nature. By using that spread, the actual value ends in a '9' before nature (339 HP, 339 def). So we can win an extra +1 defense point by investing 4 extra EV's into this, which is very much worth the investment. So the final EVs become:

HP: 148
DEF: 96

Remark:

For the more 'complicated' goals mathematically it can be very useful to convert base stats into actual real stats, as we can work with real stat points instead of having to work with base stats, which makes the formulas much more complicated, introducing a lot of extra terms. Convert a base stat into a real stat like this:

HP: H = h * 2 + 141
Others: X = x * 2 + 35

Goal <2>

In order to satisfy goal <2> we want to maximize the following, letting HP = H, Defense = D, Special Defense = S:

H / (1 / D + 1 / S)

Under this condition, we can express H = h0 + Eh, D = d0 + Ed, S = s0 + Es, where h0 = 8 * h + 564, and d0 = 8 * d + 144, similar for s0. The formula becomes:

(h0 + Eh)(d0 + Ed)(s0 + Es) / (d0 + Ed + s0 + Es).

This formula can be solved using the method of Lagrange Multipliers, but this is quite more complicated than strictly necessary. First, observe that if d = s or D=S, we have a simple case. At this point, we want to invest in HP as long as 2 * H < D = S, in other words, the turning point is now at:

d = h / 2 + 17.5

So, when:

d < h / 2 + 17.5
D < H / 2

Invest into defenses until this formula is no longer satisfied, then invest 2 EV's into HP for every 1 EV into defenses.

And, when:

d > h / 2 + 17.5
D > H / 2

Invest into health until this formula is no longer satisfied, then invest 2 EV's into HP for every 1 EV into defenses.

Now we turn to the more complicated case. What if D < S (the opposite case is a mirror, so we may assume that 'defense' is the lower of the two defenses).

Solving for H we get:

H = D*D / S + D

And for D:
D = 0.5 * (-S + sqrt(S^2 + 4 * H * S))

If H > D*D / S + D invest EV's into Defense
If H < D*D / S + D invest EV's into Health.

Note that S here is the special defense 'before' any nature benefits.
At this point, natures do matter. Because the sequence of application of EVs does 'not' matter we want the 'most' EHP (if we pick a defense nature) out of it as possible. We can do so by checking whether the 'low' or the 'high' defense stat is a better pick. This involves solving the formula (1 / (1/(ax) + 1/b)) / (1 / (1/a + 1/(bx))) > 1, for which the conclusion is that the 'high' stat is the better pick (not really a weird conclusion there). However, as for the valuation of the low stat and the distribution of EVs, it stays of course the case that nature should be ignored due to the way it works (as a multiplier)  for optimal results, which results in an eventual stat spread of (given enough EVs to work out the kinks in the natural spread) 2:1.1:1, where the 1.1 is in the higher starting def. However, in most cases the natural deviations from the ideal spread are big enough that we can only approach it, and the way most effective to do so as a procedure is best illustrated with examples.

Let's do an example now for case <2>. Suppose we have a 'mon with the following stats:

300 EVs to invest in defenses.
HP: 150
DEF: 100
SDEF: 150

This yields the following 'base real stats':

H: 441
D: 235
S: 335

So we calculate our target HP for the given Defense and Special defense:

H = D^2 / S + D = 235^2/335 + 235 = 400

So we are basically overspent on HP and investing in 'def' is the more efficient choice. So apply the reverse formula:

D =  0.5 * (-S + sqrt(S^2 + 4 * H * S)) = 252

This means the first 68 EV's should be spent in 'Defense'. After this, we have the following stat spread:

H: 441
D: 252
S: 335

Now in order to maximize gains we have to divide EV's between defense and HP in a peculiar way, namely to follow the curve H = D^2 / S + D. At this point we have to solve for both H and D given the constraints. Our constraints are:

S = 335
D = 252 + 1/4x
H = 441 + 1/4v - 1/4x
Subject to:
H = D^2 / S + D

Where v is the total remainder EV we want to invest, and x is the amount of defense ev's. The amount of HP ev's then obviously is x - v. Note that S > D + 63, so we're never going to reach the point where investing in special defense is worthwhile. The solution for the eq. is:

x = 2 sqrt(335) sqrt(v + 4112) - 2348) = 64.666

Rounding down to a multiple of 4 we get 64 extra defense EV's, and 232 - 64 = 168 HP EV's. 64 + 68 = 132, so our final spread is:

HP: 168
DEF: 132
SDEF: 0
Nature: +SDEF

This spread will give you the most effective health against a 50/50 mix of damage given the provided stats.

Remark:

If defense and special defense are 'close together' you will need to see if you have enough EV's that defense = special defense when following the quadratic formula obtained as a solution to the problem. At this point HP will be 2* defense as well (due to the way the formula was derived). If this is true, then we can simply forego any further calculations, and start from that point using the 'simple' solution (for def = sdef).

Remark #2:

It is possible to solve the system directly. In this case, we have:

Maximize:
H*D*S / (D*S)
Under the constraints:
D = D0 + 1/4d
S = S0 + 1/4s
H = H0 + 1/4h
d+s+h = v
d >= 0
s >= 0
h >= 0
0 <= v <= 512

But since we've covered all possible sensible cases, the only reason to bother with lagrange techniques here is as a math curiosity.

Edit: Changed notation. Now using capitals for all final stats and small letters for ev's and base stats.

Case <3>

An observant reader will notice a similarity between this and case <1>. Simply pretend the higher defense stat does not exist and treat it as case <1>. Are the defense stats close enough that investing your allotted EV's will balance them out? Then split the remainder as per the simple case <2>. There is one exception which we will come to later.

Let's do a simple example for this special scenario:

HP: 130
DEF: 80
SDEF: 70
EV to spend: 500

This yields the following stats:
HP: 401
DEF: 195
SDEF: 175

First, we equalize the defenses. so spend 80 to SDEF. Then we need an additional 6 points in both defenses, and 1 in HP to get the 2:1:1 distribution, spending an additional 24 in both defenses, and 4 in HP. This yields:

4 HP
24 DEF
104 SDEF
Total spent: 132.

There are now 368 points left. 368 / 4 = 92, so spend another:
184 in HP
92 in DEF
92 in SDEF

For a total of:
188 HP
116 DEF
196 SDEF

Which means stats of:
448 HP
224 DEF
224 SDEF

Now comes the exception, which is 'natures'. This is rather a bit annoying as you see, we can't simply ignore nature here. If we use a boosting nature, then it makes the most sense to boost the lowest defense if they are far apart (for it is impossible to equate the defenses using EVs). However, once it becomes possible to equate the defenses with EV's there's a certain 'tipping point' where you will want the higher def to be chosen for the nature, and then a second tipping point where it won't matter which one you choose. When there's a boosting nature, equalize the defenses after applying the nature.

In order to get 11 defense and 11 special defense, we need to spend 21 points. In other words, we get a 22/21 deal here (22 points for 21). So the ideal distribution 'WITH' a nature for balanced defenses is 21:11:11 if we're behind the second 'tipping point'. Before the first 'tipping point' the ideal distribution is 2:1.1 (the higher def stat doesn't matter).

Finding the first 'tipping point' is quite simple: As soon as the lower defense stat exceeds the higher with both nature and EV's we are in trouble. The same with the second 'tipping point': if we can't equate the lower nature to the higher with a nature applied using EV's, we are in trouble.

Tipping point 1:
1.1 * D + Ed > S

Tipping point 2:
D + Ed' < S * 1.1

Where Ed is obtained using part '1' technique and Ed' is obtained using part '2' technique

In between (when both equations are true), the answer is quite complex.

« Last Edit: December 13, 2014, 01:57:37 AM by Aphid »

#### joshcja ##### Re: Calculating Defensive EV spreads
« Reply #1 on: December 08, 2014, 08:31:14 PM »
Sticky imo.

Also ya my spreads are probably awful since I generaly don't give a damn outside of the one or 2 super specific things they're eved for. Sooooo ya, if you feel like fixing those go right ahead xD

It'd be great if you could fit in a mention of odd hp and why it matters alongside a modified version of this formula that allows for lefties numbers as well useful person.
« Last Edit: December 08, 2014, 09:13:44 PM by joshcja » #### ZXNova ##### Re: Calculating Defensive EV spreads
« Reply #2 on: December 08, 2014, 08:46:08 PM »
The example is confusing. What do you mean by split equally? I think you should be more specific, or simplify it in a more understandable way. The example is when I get confused.

#### ZXNova ##### Re: Calculating Defensive EV spreads
« Reply #3 on: December 11, 2014, 05:48:46 AM »
Sorry about the double post, but I do have to ask what this 'certain constant' is? I can't solve the Effective HP problem unless I know what C is supposed to be.

Also how to calculate Ed, and Es. You never said how to calculate those either.

Also how did you get from 400 EVs to "368 'points'" left in case three when you spent 132 EVs?

I really think you should put the formula above the example equation so that people here can know what's going on.

EDIT

While I'm able to understand most of what's going on now, I do wonder what you would do if you got into a case where HP and Def are close together. Now for example, Defense Meiling has base HP of 110 and base defense of 120. Now by the formula, she's technically h > d, but the problem is you could never equalize Defense and HP with her, even with a +def nature due to how much HP she has. And what if you wanted her to be a sort of mixed wall? Her bulk is 110/120/80 which isn't bad at all. How exactly would you calculate that?
« Last Edit: December 11, 2014, 08:08:17 PM by ZXNova »

#### DoctorShanks

• :coolguys:
• A Member group
•     • • Posts: 188
• . ##### Re: Calculating Defensive EV spreads
« Reply #4 on: December 12, 2014, 05:58:24 PM »
Before I post here, I'd like to start off with this link in case someone may find it useful. <--- This is a calculator that should help players with Defensive EV spreads.

I haven't actually read the OP, but it's true that customized EV spreads are the way to go. It's also true that a lot of them need to be redone, however, by the time I learned about how to efficiently EV something myself, most of the move-sets were already posted, and I didn't actually look twice.

No one asked for my opinion, but here it is: 252/252/4 is always a great place to start; copying an EV spread for a puppet built for another team and/or to take certain hits may or may not be actually useful for one's team. As you play more games, you can edit the above 252/252/4 according to your own needs. A simple damage calculator can help with this. To simplify what this thread doesn't simplify, unless your puppet is named "Kaguya" or "Orange," you're probably going to want to pump HP more-so than defenses.

Moved over to General Metagame. I'll have more to say once I make a better effort to understand the numbers in the OP.

#### Aphid ##### Re: Calculating Defensive EV spreads
« Reply #5 on: December 13, 2014, 02:42:50 AM »
Sorry about the double post, but I do have to ask what this 'certain constant' is? I can't solve the Effective HP problem unless I know what C is supposed to be.

Also how to calculate Ed, and Es. You never said how to calculate those either.

Also how did you get from 400 EVs to "368 'points'" left in case three when you spent 132 EVs?

I really think you should put the formula above the example equation so that people here can know what's going on.

EDIT

While I'm able to understand most of what's going on now, I do wonder what you would do if you got into a case where HP and Def are close together. Now for example, Defense Meiling has base HP of 110 and base defense of 120. Now by the formula, she's technically h > d, but the problem is you could never equalize Defense and HP with her, even with a +def nature due to how much HP she has. And what if you wanted her to be a sort of mixed wall? Her bulk is 110/120/80 which isn't bad at all. How exactly would you calculate that?

Let me answer the points one by one:

First, it does not really matter what C is, that is the entire point. It is a simple multiplier that the game tuned to some constant factor to all attacks. We can't really modify this. C is certainly low enough that attacks don't generally one-shot things, and generally high enough that attacks do enough damage to matter over other more passive sources of damage (poison, leech seed) or healing (such as leftovers) in a way that makes them relevant, without making defenses irrelevant. No matter what the value of C is though it will not affect the 'relative' balance of defense and HP. The optimal mix for your situation remains the same (unless you are looking to ensure survivability against something really specific).

Ed, Es are basically 'EVs spent into defense and special defense', those are the two variables we 'want to know', but don't know yet. There's some assumptions (maximize a certain numerical quantity, assume they are between 0 and 512), and under those assumptions, I built a rudimentary mathematical model that results in a valid answer that satisfies all of them. It's most certainly not a full rigorous answer, but that would not really serve much of a purpose to make it easy to calculate optimal EV's.

The 400-368 thing is a good catch, it's supposed to be 500. I changed it to a more realistic number when I figured out that even at 500 I would get all of the interesting scenario's without bumping into 252-limits. (Where you basically have to put the rest of the defense EV's into suboptimal places). Edited original post.

Now to understand "split equally", let's see it this way:

Say I do 10000 special, 10000 physical damage, you get 100/100 defenses, and C = 1. Then I do 200 points of damage. If I allowed you to spend X points and distribute them between def and sdef, what is optimal?
Define d the defense points, and s = X - d is special def points.

Damage you take is 10000 / (100 + D) + 10000 / (100 + X - D). Take the first derivative towards D, equate to 0, solve, and your answer will be D = 0.5X to be a critical point. Some visual inspection of the function (try putting it into wolfram alpha for some sensible values of X such as say 20) shows you that this critical point is a maximum. It makes a lot of sense too. The lower your defense is, the more damage block you gain from a single point of it. Raising defense from 40 to 100 (like say Chansey does) is very effective at stopping physical damage, it makes her twice as good against this form of damage. But investing special defense from 400 to 460 yields less. The same logic holds for HP and defense when you want to look at only one form of defense. So the optimum thing to do (before natures are taken into account) is to balance the two equally. For the problem with three variables (adding HP ev's into the problem as well) you need Lagrange multipliers to fully solve, and I solved some simplified corner cases with additional assumptions in the main post that should cover most of your needs. A full solution is probably going to need some sort of script to do the math for you because that can get a bit tedious otherwise.

The three scenario's should cover most of your basic EV spread needs. What the data shows though is that the actual optimization is a bit less straightforward than just maxing HP. First, you should take a look at the stats for your puppet. Most puppets will have skewed stat distributions. Then you should ask what you want to build for. One type of attack in particular, a balance, or cover weaknesses? There's some tradeoff being made. E.g. equating DEF to HP point for point gives you the best physical defense, but not the best general defense (unless special defense is stupidly high). The other important parts are those 'critical points', where the optimal strategy to distribute further points changes.

I would also like you to more carefully consider the puppet list before dumping HP. The separating line is narrower than you might think. For example, in order to have 'Excess HP' hp stat needs to be above 'twice'  your defense stat. That's not as much as you think because of the 100 base bonus hp that everyone gets that helps this stat along. Here's some puppets that may want to forego HP for more defense (apart from orange, kaguya, and d.Satori):

- Eirin
- Namazu
- Kogasa
- Sara
- and many more

For example, with a HP stat of 140, that's 421 base HP before EV's. You will need defense stats of at least 210 before investing in hp becomes sensible at all over your defense stat(s) of choice, which is 88 base defense / special defense. There's actually quite a few puppets with more hp/less defense than this. Here's a list of values where you get that 2:1 distribution (for mixed walls).
Code: [Select]
`HP   DEF  NWD160 | 98 | 114150 | 93 | 109140 | 88 | 104130 | 83 | 99120 | 78 | 94110 | 73 | 89100 | 68 | 84 90 | 63 | 79 80 | 58 | 74 70 | 53 | 69 60 | 48 | 64 50 | 43 | 59 40 | 38 | 54 30 | 33 | 49`
Read the table as follows: This table is for mixed walls. When your puppet's HP is the indicated number, look at its defense stats. If they're above the second number (so say 68 for a 100 HP puppet) then HP is the most efficient stat initially. If defenses are above the third number, then even at 252 HP Ev's you would still value the 253rd HP EV above a defense EV. If defenses are in between, you will need some kind of mix (refer to the first post).

There's actually quite a few puppets where the following is true:
- HP is more or Defenses are both less than the indicated stat.
In that case defenses trump HP. It's not just orange and kaguya.

« Last Edit: December 13, 2014, 02:51:22 AM by Aphid »