hello, I am new to pyro. I would like to use HMC for pre-sampling. Here is the code for the model.
def model():
params = pyro.sample('params', dist.Uniform(0, 1).expand([13]).to_event(1)).to(device)
data = eval_objective_DrProb(params).unsqueeze(-1)
# Custom likelihood function to enforce the constraint
def likelihood_fn(x):
if x > -0.0001:
return torch.tensor(1.0) # Satisfied constraint
else:
return torch.tensor(0.0) # Constraint not satisfied
return pyro.sample('obs', dist.Bernoulli(probs=likelihood_fn(data)), obs=torch.tensor(1.0))
I use the function eval_objective_DrProb to calculate the results, and I would like to take only those samples with results less than 0.0001.
# Initialize your MCMC sampler with the NUTS kernel
nuts_kernel = NUTS(model)
# Run the MCMC sampler
mcmc = MCMC(nuts_kernel, num_samples=1000, warmup_steps=200)
mcmc.run()
# Get the samples
samples = mcmc.get_samples()
The final result did not meet my requirements and the maximum value of the sample result was -0.0133.