MAP estimation converges to maximum of prior distribution

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:

First, it looks like optimization is not converging. You might try tweaking optimization

optimizer = ClippedAdam({"lr=0.01"})  # gradient clipping helps with Gammas
elbo = Trace_ELBO(num_particles=10, vectorize_particles=True)

Second, maybe I’m missing something, but I don’t see where raw_photon_count is sampled in the guide. Are you additionally conditioning on that? You might try an AutoDelta guide instead.

Thanks for the advise, I will def try your suggestions. For now I also found a problem with my custom distribution, which I have to fix first. You are right, ‘raw_photon_count’ should not be in the sample call but just stored in a variable to be used in the obs_photon_count! I will let you know the result using the optimization tweeks!

Thanks again!