Hello everyone,
I still in the process of fiddling with MAP estimation using pyro. I have tried some simple model which all seem to work very nice, but I am encountering a weird problem when applying MAP estimation to a custom distribution. When I try to run MAP estimation using delta distribution for my custom distribution it seems the MAP estimate converges to the maximum of the prior distribution which I choose for the parameter. It might be that this problem is due to the custom distribution, but I suspect there is something else going on here. The custom distribution is basically a power law (x^-gamma) which is smoothly glued to a normal distribution for small x, such that the divergence around zero is cutoff.
def model_1d():
# want to find the MAP estimator of gamma which is assumed to have prior
# ~ gamma
gamma = pyro.sample('gamma', dist.Gamma(torch.tensor(1.), torch.tensor(.5)))
raw_photon_count = pyro.sample('raw_photon_count', InverseTransformSampling(
LogProbNormalTruncatedPowerDist(gamma), # custom distribution
xgrid
)).expand(torch.Size([1000])) # 1d image of raw photon count
return pyro.sample( # slightly noised photoncount
'obs_photon_count', dist.Normal(raw_photon_count, torch.tensor(0.01))
)
def guide():
gamma_av = pyro.param('param_gamma', torch.tensor(3.2), constraint=positive)
return pyro.sample('gamma', dist.Delta(gamma_av))
def load_data(gamma=torch.tensor(2.334432)):
raw = InverseTransformSampling(
LogProbNormalTruncatedPowerDist(gamma),
xgrid
).expand(torch.Size([1000])).sample()
return dist.Normal(raw, torch.tensor(0.01)).sample()
conditioned_model = pyro.condition(model_1d, data={"obs_photon_count": load_data()})
optimizer = Adam({"lr": 0.01})
svi = pyro.infer.SVI(model=conditioned_model,
guide=guide,#
optim=optimizer,
loss=Trace_ELBO())
run optimization.. etc etc
Any ideas why this might happen?
loss:
gamma_param: