Dear all,
I am coding with python. I created a very simple model and run it with python. The Stan model object (sm) gets created by pystan. However, when I want to sample, then it gets deleted.
While debugging I see that after (LOCATION 1) I have the sm-Object.
If I continue to (LOCATION 2) then, after that step, the sm-Object disappeared AND the process jumps/stops again at the breakpoint at (LOCATION 1); this allthough there is no loop.
I would be gratefull to learn more what I made wrong to understand this unexpected behavior.
Thanx in advance
PYTHON CODE:
import numpy as np
import matplotlib.pyplot as plt
from scipy import stats
#########################################################
investigation 01: beta distribution
############################################################
simulate x. beta distributed
n_sim = 1000
alpha = 5
beta = 5
x = stats.beta.rvs( alpha, beta,size=n_sim)
cdf = np.linspace( 0, 1, len(x))
plt.figure(1)
plt.plot( np.sort(x), cdf )
############################################################
build stan model
my_data={} # create data dictionary
my_data[“data_n”] = n_sim
my_data[“X”] = x
print(“compile stan model”)
fname = “scr_82_model.stan”
LOCATION 1
sm = pystan.StanModel(file=fname) # build stan model
############################################################
fit with stan model
print(“fit with stan”)
LOCATION 2
fit = sm.sampling( data = my_data)
alpha = fit[“alpha”]
beta = fit[“beta”]
STAN MODEL:
// MODEL 82
// check beta distribution
data {
int data_n; // number of values
vector[data_n] X; // data values
}
parameters {
real <lower= 1e-15> alpha;
real <lower= 1e-15> beta;
}
model {
// priors
alpha ~ normal(5, 2);
beta ~ normal(5, 2);
// likelihood
X ~ beta( alpha, beta );
}