How to write a decay function in Python

At my exercise of reinforcement learning, I needed to write a decay function for Ɛ-greedy strategy. The mathematical function should look something like:

 f(x) = decay^x

But in the algorithm, I don’t have access to the iterator value (x in the above formula), only the current epsilon (Ɛ) and the decay factor I defined.

It turns out it is not necessary to use x to obtain the same value. If `x` is the current step in the iteration, all that is needed to do is:

Ɛ = Ɛ * decay

It would translate to

Ɛ = Ɛ * decay ^ X

Where `X` would be the total amount of steps in the iteration. In python, the code would look like:

 self.epsilon = self.epsilon * self.decay

Although simple, it took me some time to visualize both functions are equal but written in different forms.

About The Author

Thiago Ricieri

I’m software engineer at Pluto TV, working on iOS, Android and Roku platforms. Personally interested in machine learning, algorithms, data science and tech industry. I travel a lot and take good pictures.

Add a comment

*Please complete all fields correctly

Related Posts

Understanding Expectation Maximization and Soft Clustering
This powerful algorithm will give you, for each data point you have, a vector of probabilities. Each probability will refer to each cluster you are trying to assign the data...
K-Means Clustering: A very simple overview
A quick draft about K-Means Clustering, what it is, what it does and how to get started with it using SKLearn.