I don't understand how to implement the log-uniform probability distribution in Scipy. According to the comments of this post, it is possible to do so by defining only _pdf
. Also, I know from this source the actual derivation for the pdf.
However, I can't figure out where to put the a
and b
parameters and how to set a
such that a>0
. Also, please note that I want a
and b
to be the actual minimum and maximum values of the range. Please also note that, in the end, I really just want to be able to use the .rvs()
method so any trick with the uniform distribution is acceptable.
Here is my curent (non-working) code:
from scipy.stats import rv_continuous
import numpy as np
class log_uniform_gen(rv_continuous):
"Log-uniform distribution"
def _pdf(self, x):
if np.exp(self.a) <= x <= np.exp(self.b):
temp = x / (self.b - self.a)
else:
temp = 0.
return temp
log_uniform = log_uniform_gen(a=0.1, b=1.0, name='log-uniform')