I am new to PyMC, and I am attempting to estimate the parameters of a Generalized Extreme Value distribution for my dataset. My data has been truncated artificially, and so I would like to use a truncated version of this distribution. I am able to estimate parameters for the GEV distribution for my data without truncation, but I am having trouble making the distribution truncated.
The following DOES work, without truncation:
data = read_in_data() # a numpy array of floats
basic_model = pm.Model()
with basic_model:
# Priors
mu = pm.Uniform("mu", lower = 1300, upper = 1500)
sigma = pm.Uniform("sigma", lower = 90, upper = 150)
xi = pm.TruncatedNormal("chi", mu=0, sigma=0.4, lower=-0.7, upper=0.7)
# Estimation
gev = pmx.GenExtreme("gev", mu=mu, sigma=sigma, xi=xi, observed=data)
gev_idata = pm.sample()
However, I believe my data comes from a truncated GEV distribution. My attempt to use a truncated GEV distribution, after reading the documentation here is as follows:
data = read_in_data() # a numpy array of floats
basic_model = pm.Model()
with basic_model:
# Priors
mu = pm.Uniform("mu", lower = 1300, upper = 1500)
sigma = pm.Uniform("sigma", lower = 90, upper = 150)
xi = pm.TruncatedNormal("xi", mu=0, sigma=0.4, lower=-0.7, upper=0.7)
# Estimation
gev_full = pmx.GenExtreme.dist(mu=mu, sigma=sigma, xi=xi)
gev = pm.Truncated("gev", gev_full, upper=2000, lower = None, observed=z_ions)
gev_idata = pm.sample()
I get the error:
SamplingError: Initial evaluation of model at starting point failed!
Starting values:
{'mu_interval__': array(-0.53549444), 'sigma_interval__': array(-0.41259799), 'xi_interval__': array(0.48288129)}
Logp initial evaluation results:
{'mu': -1.46, 'sigma': -1.43, 'xi': -1.18, 'gev': -inf}
You can call `model.debug()` for more details.
I’ve got this error many times before, without using the truncated distribution, and never understood why it was trying to evaluate starting values of the parameters outside the distributions I specified. I see that it’s giving an infinite value of the gev
distribution which is why it is erroring out, but I don’t understand why. In the past, just playing around with the priors for some reason fixed this error, but I can’t seem to find a set of priors that works in this case.
I assume I’m making a rookie mistake in implementing the truncated distribution.
How can I implement a truncated GEV distribution? Thank you so much in advance!