Sunday 15 October 2017

An in-depth look at Gym Decay

Hey there Trainers!

The other day I was wondering about gym decay rate, and was surprised to find that no one had figured out the exact formula yet. Granted, gym decay is somewhat unimportant in the current metagame, as expending any mental effort on defending is a waste of time. But despite numerous posts like these, there still wasn't a finite Gym decay rate algorithm out there.

Since I was last writing, the game has changed significantly, and so have I. For one thing, I live on the other side of the world, and with the change to gym mechanics, my gym motivation decayed significantly as well. But my current location gives me a great group of local gyms that are either high-turnover or hold for up to 4 days undisturbed. So I decided I would test Pokemon over a wide range of CP to determine exactly how gym decay changes with CP.

You can find this calculator, my 250-1299 calculator, and my 2321+ calculator on the Let's GO Decay Rate Calculator page, but I've pasted in the 1300-2321CP calculator here for folks to see.


Let's be honest, this is like... the only thing you care about in this article. Find the 2322+ calculator on the Let's GO Decay Rate calculator page here! I'll be updating the calculator page with calculators for below 1300 CP as well when more data becomes available. Unfortunately I suck at code and so I haven't yet figured out how to merge all three calculators into one.

Disclaimer: In testing this calculator against my recorded data, there was no difference in predicted CP/h greater than 0.30, and no difference in predicted %CP/h greater than 0.01% within the bounds of 1300-2321 CP.

But to see how I've come up with this calculator, read on! Note that the calculator only applies between 1300 and 2321 at the moment. Above ~2321, decay rate is 10% of the Initial CP, and so you can just use the formula (Initial CP)*(0.1) to find your CP/h decay rate, and any %CP/h or "Time until" numbers are the same as CP = 2321.

Summary of findings

  • There may be three formulae for decay rate, depending on the initial CP of a Pokemon, where decay rate becomes a flat 10% around 2321 CP.
  • I confirmed previous findings that decay rate is constant over the whole range of a Pokemon's CP decay.
  • I confirmed that decay rate freezes upon a Raid Egg appearing, and while a Raid Pokemon is in the gym, but only if the Pokemon was in the gym prior to the Raid Egg appearing. A Pokemon added to the gym after a Raid Egg appears will decay normally. Feeding a frozen Pokemon a berry re-starts the CP decay. I do not know how this affects coin-earning.
  • Pokemon are knocked out a gym if they are defeated while their CP is below 36% of their initial CP. This probably isn't a new finding, but I haven't seen anyone explicitly state this. You can see this in gyms because the Pokemon's CP text colour shifts from white to red.
  • A Pokemon's CP may be rounded to the nearest whole number

Methods


My methods were largely similar to HalfPastLunchTime's from GamePress, though I was able to take advantage of his pilot data to improve my efficiency. There were rumours that decay rate shifted as Pokemon CP changed. Thankfully, since HalfPast found that decay rate was constant, I was able to look at the decay of Pokemon at two timepoints, and get a good idea of the decay rate per hour using the average of the decay rates calculated at both timepoints. So my data should match pretty closely to the actual decay rate, but there is of course room for error (see Sources of Error below). I also looked at decay rates for a select few samples over a 3rd or 4th time point to verify that decay was indeed constant over the entire range of a Pokemon's CP; most of my data was collected within 1-2 hours of dropping the Pokemon, but I checked decay for a few Pokemon at late time points by feeding a Pokemon a berry up to about mid-CP and then taking decay rate data from that time point on.

Results and Discussion


What is the decay rate in CP/h for a Pokemon with _____ CP?

Figure 1: The three boundaries for decay rate in green, blue,
and red. My data are lacking in the range of 1073 to 1216.

Surprisingly, I found that there are three formulae for the raw CP/h decay rate, that apply to three different boundaries. Given the work of others, I entered assuming that ~2% was the minimum decay rate, and that any observations otherwise were due to error introduced by raids due to the long periods of time required to collect good data. But I've found that instead, there may be a linear relationship between decay rate from 10 CP to ~1300 CP, though the data aren't as reliable in this range. This is followed by an exponential decay rate from ~1300 CP to ~2321 CP.  After that, decay rate goes back to being linear.

Figure 2: Decay rate in %CP/h. Green represents the fairly
linear decay rate between 10 CP and 1073 CP. Blue represents 
the exponential decay rate between 1216 CP and 2314 CP. 
Red represents the decay rate for CP above 2321; at 2337 CP, 
found the decay rate to be ~10.0%.


When converted to %CP/h,  the shift from relatively linear to exponential rates becomes a bit more obvious (Figure 2). This leads to the following boundaries: a fairly linear decay rate from ~1.0% to 3.0% from initial CPs of 10 to ~1300 CP. Then an exponentially increasing decay rate from 3.0% to 10.0% for ~1300 CP to ~2321 CP, followed by a flat rate of 10% decay for Pokemon above ~2321 CP.

That's cool and all, but can I use this for anything?


Ah... hmm... yes I see your point. The competitive game IS completely bunk right now, so there isn't much motivation to plan out anything. A competent player will be able to reduce a gym to nothing in minutes, no matter how strong it is. But if there is a use for this data, it's in warding off the casuals, and those without lots of time to take down the gym; for instance, people who are just battling the gym because they're bored and waiting for their bus. I pass by numerous gyms en route to work every morning, battling them as I pass to earn Gym points; gotta get my Gold badges somehow!

So if you place Pokemon that don't decay too quickly, then people like me won't knock them out passively. And since there's no preventing someone from knocking a Pokemon out actively, preventing passive KOs is the best you can really prepare for!

Hours until decayed to the point that one battle is a KO

Figure 3: Hours before a Pokemon decays to its minimum CP (20% of its
Initial CP). The calculator also includes hours until 36% and 64%!

Essentially, if your Pokemon doesn't decay to the point where someone like me can knock it out in one battle (36% its initial CP), then it won't get knocked out passively by one random player. Since your Pokemon earns you 1 coin every 10 minutes it's in a gym, it takes 500 minutes (8h20m) to earn a full 50 coins. So if you can avoid decaying past 36% before 8h20m are up (see Figure 3), you'll hold on for the full 50 coins, even if someone gets into a battle while on the bus/train.

Additionally, your Pokemon decays ~28% CP when an attacker defeats your defender. So if you can stay above 36% + 28% = 64%, then it'll take an attacker TWO battles to knock your Pokemon out of the gym! 

Now... that said Blissey is absolutely the best defender in the game, and it's not worth reducing its Initial CP just to keep it from decaying. If a 3000 Blissey decays 1200 in 4 hours, it was still tougher to beat than an 1799 Blissey that entire time. And a massive Blissey CAN still effectively wall casual players for the first couple hours; taking down a 3000+ Blissey can be near impossible for players Level 25 and below, even with Machamp raids available.

So by no means am I advising that you should avoid putting top-tier defenders into gyms because they'll decay. A few berries patches that problem up just fine. But if the gym already has a Blissey, Snorlax, and Chansey, then you can take advantage of that core and say "I want my Pokemon to deter attackers until 8h20m are up, maybe I'll put in a lower-CP defender like Umbreon or Steelix. It's also interesting to note that a 2300 CP Lapras will decay to 20% pretty much just as fast as a 3500 Dragonite, so I would say that whatever Pokemon forces a switch better is the better defender, not the one with the higher HP (given that both decay extremely quickly).

Significant findings


Prior to this study, little data existed on at what CP a Pokemon's decay rate became 10%. HalfPastLunchTime wrote a good exploratory post on Gamepress, which used a 2588 Snorlax, and some folks on Reddit had pinned it down a little lower I think. But as far as I'm aware, this is the first report that shows as low as 2337 CP decays at a rate of 10%, and my formula predicts the turnover point to be 2321 CP; again, take this with a grain of salt, but it should be very very close.

Additionally, prior to this study, a couple folks proposed the decay rate to be fairly constant below 1000 CP at 2%. I found that there may be three distinct ranges of decay, governed by three separate formulae: a linear decay where my data go as low as 0.94% for a 44 CP Pokemon, up to 3.0% for a 1073 CP Pokemon, followed by exponential decay between (presumably) 1073 and ~2321, and then a flat decay rate of 10% above 2321. I extrapolate that the decay rate can be as low as 1.0% because that makes the numbers pretty, but the accuracy of my data is poor at this range.

Niantic has presumably coded their CP decay rate formula as an "if then" function, where below some CP (e.g. 1300) it applies a fairly linear equation, between a CP range (e.g. between 1300 and 2321) it applies a polynomial to determine decay rate, and if above some CP (e.g. 2321) it applies a flat rate. For instance:

if (CP < 1301) then: y = mx + b
else if (1300 < CP < 2322) then: y = m1x^3 - m2x^2 + m3x - b
else if (CP > 2321) then: y = 0.1
... can you tell I'm not a programmer?
Figure 4: Example curves for 1st, 2nd, 3rd, and 4th order 
polynomials. I somewhat doubt Niantic is using a 4th order
polynomial  (purple) because... that's seems unnecessarily 
intense.
I think the likelihood of a second or third order polynomial is good for the formula. To remind everyone of their Junior High / High School math, the shape of a curve changes with increasing exponential order (Figure 4).

I think that Niantic would probably want a curve that declines towards y=0.01 (decay rate of 1.0%) with decreasing x (initial CP), which is most simply performed by a second order polynomial (x^2). But my data don't really fit an x^2 parabola very well, which leads me to believe that a third order polynomial (x^3) is more likely. But maybe my sources of error are just throwing the calculations off. It's also difficult to calculate properly without an intimate knowledge of the exact point at which the formula stops applying: that is to say, at what CP the formula used to calculate decay changes from exponential to linear.

Raids are really annoying for data
collection... :\

Sources of Error


To be clear, my data are sparse at the very lowest end of initial CPs; the lowest I have is a 44 CP 'mon with an observed decay rate of 0.94%. At 1073 CP, I get a decay rate of 2.50%. You can see the data points in green in Figure 1 aren't perfect, but collecting good data from such low decay rates is difficult; 0.9% from a 44 CP Pokemon requires 3 hours to see a drop of 1 CP (note: see section on Rounding and the FLOOR function). Raids (which freeze decay rate) are very likely to disrupt data collection at these low initial CPs. I also confirmed that decay rate freezes for a Pokemon only if that Pokemon was in the Gym prior to the Raid Egg appearing. If you add a Pokemon after the Raid Egg has appeared, it will decay as per normal. Feeding a berry to a Pokemon with a frozen decay rate re-starts the decay. I do not know if the Raid Egg hatching re-freezes the decay. Indeed, it may be unintended that the Raid Egg appearing freezes decay at all #NianticCoding.

The actual point at which decay rate shifts to a flat 10% is likely not exactly 2321, but I observed a decay rate of 9.89% at 2314, and 9.99% at 2337, 10.03% at 2358 and 10.01% at 2464. The formula predicts decay rate shifts to 10% at 2321. I suspect the 9.99% is just error, and not the actual CP value at which decay rate shifts from exponential to flat, just like how I recorded 10.03% at 2358 CP, but chock this up to error and assume the true value is actually 10.00%. I'll be updating the calculator as I collect additional data in these sensitive transition ranges (1070-1300 and 2310-2350) to better reflect decay rates at a wider range of CPs. However, for now, the calculator should work very accurately for CPs between 1300-2300.

Rounding and the Floor Function are likely major contributors of error, especially for low CP Pokemon. This really threw me off at the start of my data collection.

In testing the decay rate during Raid conditions, I realized something was a bit off about CP decay at early time points. One example: I placed a 2868 Snorlax (decay rate 10%/h) in a gym with an egg that had 26 minutes left. I collected three time points on my way to work: 5 minutes, 9 minutes, and 14 minutes. The CP at each time point was 2844, 2825, and 2801 respectively. Converted to CP/h, the independent decay rates of each time point were: 288.0, 286.7, and 287.1 CP/h. The theoretical decay rate at 10% should be 2868*0.1 = 286.8. As you can see, the two later time points are close, which makes sense as they're an average over a longer time period.

Figure 5: A) A 44CP Farfetch'd after 1h0m. B) A 44CP Farfetch'd having 
decayed 4 CP after 9h12m. C) A 44CP Farfetch'd having decayed 5 CP 
shortly after the time point turned to 9h12m. The 9h12m transpired overnight,
so I didn't actually watch for raids during this time... but raids are almost 
non-existant here at night, and I woke up at 7:26am to see no raid (meaning
no raid occurred after 5:26am).
Notably, I was intrigued by the elevated decay rate of the first time point (5 minutes). I'd had similar inconsistencies for lower CP Pokemon (a 44 CP and 111CP Pokemon to be specific). I found that the 111CP Pokemon lost its first CP point after 33m, but then failed to lose a second CP point even after 1h10m. My 44CP Pokemon didn't lose a single CP point in one hour, but lost its 5th CP point after 9h12m; I caught this 5th CP point drop in action making the data at that time point very precise. Losing 5 CP over 9h12m is a rate of 0.54 CP/h or 1.22%. Yet after an additional 11h, it had lost only 3 more CP, and after 13h only 4 total. This difference was likely due to raids, but the numbers still felt off to me. At a rate of 0.54 CP/h you'd expect a loss of 7.6 CP over 13h, but I observed only 4 CP lost (a rate of 0.31 CP/h or 0.70%). Either the gym had 3 Raids during the ~11 hours (possible, but unlikely?) I wasn't watching, or something was off with my assumptions.

Rounding and the Floor function


I came to realize that this discrepancy could be explained by rounding, and/or contributions of the FLOOR function.

In brief: the FLOOR function rounds a Pokemon's CP down to the nearest whole number. Your Pokemon's CP is calculated by a formula using its stats and level. If the output of that formula is a CP of 2500.99, your Pokemon's CP will be 2500. If it's 2500.01, your Pokemon's CP will be 2500.
Essentially, the first CP point your Pokemon loses after being placed in a Gym likely occurs at a faster rate than the rate of decay for the rest of its CP. I don't know exactly after how many decimal places Niantic's FLOOR function rounds, but this hypothesis would fit with my observations. I'm happy to pass the torch to someone else on this one. I'd recommend catching the first CP point lost in action, and then calculating decay rate from that point onward. I think you'll find that the rate of loss for the first CP point is always greater than subsequent CP points.

If it's a rounding issue, that would make sense. If your Pokemon's CP starts at 1000.0, the displayed CP will be 1000. If, then, you decay to 999.49, you might get rounded down to 999. But above 999.5, you display as 1000 CP. This makes sense, but is at odds with Niantic's application of the FLOOR function to CP calculations. In such a system, dropping the first CP point would take only 0.5 CP's worth of decline (e.g. 1000.00->999.49), while dropping the next CP point would take a full 1.0 CP's worth of decline (e.g. 999.49->998.49).

Figure 6: Farfetch'd dropped an additional 4CP over the next 11h (A) to 13h
(B). At a decay rate of 1.0%, it would make sense if one or two Raids occurred
at the  Gym during the time I wasn't watching (~9h unobserved), and the drop
to 35CP happened around 11h or 13h respectively.
I watched my 44 CP Pokemon for a full 1 hour without a drop in CP, and witnessed the 5th CP point lost at 9h12m. These two values are at odds with each other. If the true rate is 0.54 CP/h, and the rounding occurs as soon as the calculated CP drops below 43.5, then I should have seen a drop in CP before 1 hour was up. One alternative is that Niantic rounds up to the nearest whole number, rather than down; this would be completely antithetical to their rounding in every other situation in the game. I would have expected the Floor function to be used for rounding CP, but my observed decay rates are too rapid to explain my data using rounding by the Floor function (any drop below 1000.0 would result in a loss of 1 CP).

Unfortunately, I realized this very late in my data collection, so I haven't censored much of the data for this source of error. I re-evaluated and censored some of my lowest CP Pokemon data (e.g. I do not include my 111CP mon in my calculations), however, it matters far less for high-CP Pokemon (case in-point, 2868 Snorlax whose average over the first two time points was 287.35, pretty close to the theoretical 286.8).

Back of the napkin calculation suggesting that Niantic rounds to the nearest whole CP


At a maximum rate, assuming the 1st CP point dropped at 1h8m, the rate over that first CP point would be 0.869CP/h, or 1.98%CP/h. If you assume this, then the true rate of decay would be half that, or 0.435CP/h (0.99%). If you apply this rate (0.435CP/h) over the next 8h4m (leading to my time point of 9h12m), you'd expect a loss of 3.507CP. This would result in 1+3.507 = 4.507 CP lost over 9h12m. I saw the 5th CP point lost, suggesting that a rate of 0.435CP/h could be close to correct if Niantic rounds to the nearest whole number. This would be approximately 1.00%, my hypothetical minimum CP decay rate for a Pokemon, applied to a 44CP mon.

This data shouldn't be too tough to collect. I just need to drop that 44CP 'mon again and watch for its first CP point drop to occur around 1h8m. I'll be updating the article with a more refined CP calculation formula for CP between ~1075CP to 1300 CP, and when I do, I'll let you know what I've found regarding this first CP point drop. But if a 44CP 'mon really does have a decay rate of 1%, either that means that decay rate hits 1.0% before reaching 10CP, or decay rate can actually go below 1%. Either way, I'll need a fair bit more time to collect enough data around this range, given that CP decays are so slow and Raids are very likely to disrupt my data collection.

That's probably enough for now...


So there you have it! I've written this article to announce our new CP decay rate calculator, and explain where the data come from. I'll be updating it when I've got the time to re-approach this problem (might be tomorrow, might be next week), but felt like I had enough to publish what I've got right now.

I also don't really know Java very well... so I got the calculator working for 1300-2321 CP, but when it comes time to switch formulae to the linear rates above 2321 CP or below 1073 CP, I'll need to up my game to get the calculator to handle that properly. If someone wants to point me in the right direction for if-else clauses in Java, that'd be great :) I tried looking it up briefly, but I don't understand Java syntax enough to understand what I'm doing wrong when I try to apply if-else clauses.

Let's GO!

5 comments:

  1. This is an amazing post!!! Thanks a LOT for your research!

    But... care to share the exact formula you've found out and fed to the calculator? I could not find the constants you're using even after reading every word of your reseach

    ReplyDelete
    Replies
    1. Thanks! Glad to share :) Added a reply with the details in the calculator page.

      As an aside, my data following up on this (which I haven't looked at in ages) made me think that maybe it is just a sort of 3rd-order polynomial that applies all the way from 10CP-2321CP, but that it just looks linear for the first ~1300CP. I think my data that got me thinking there were three separate decay rates may be biased by collection errors, and so I'm over-estimating the true rate of decay for some of those low-CP samples.

      But I don't think I want to spend too much more time on the data collection front, since it's not a hugely important issue and the current formulae I have are very good approximations.

      Delete
  2. I love your blog. It is very informative. You have given a fresh outlook to the topic. I would definitely share this on other platforms as well.

    If you are have been planning on hitting the fitness center in jaipur, try Fit O’ Clock. It is the best gym in Jaipur. It is equipped with advanced machines (not found elsewhere in Jaipur) and has the best trainers for gym-goers.

    ReplyDelete
  3. It is very informative. You have given a fresh outlook on the topic. I would definitely share this on other platforms as well.
    If you are have been planning on hitting the gym in Jaipur,
    try Fit O’ Clock. It is the best gym in Jaipur. It is equipped with advanced machines
    (not found elsewhere in Jaipur) and has the best trainers for gym-goers.

    ReplyDelete