def get_prior():
     prior_dict = {
         'log_eta': dists.LogD(dists.Gamma(a=.1, b=.1)),
         'logit_sigma': dists.LogitD(dists.Beta(a=1., b=1.)),
         'log_c': dists.LogD(dists.Gamma(a=.1, b=.1))
     }
     return dists.StructDist(prior_dict)
Exemplo n.º 2
0
 def get_prior():
     prior_dict = {
         'lam': dists.Normal(loc=0., scale=1.),#W
         'log_alpha': dists.LogD(dists.Gamma(a=.1, b=.1)),#W
         'log_delta': dists.LogD(dists.Gamma(a=.1, b=.1)),
     }
     return dists.StructDist(prior_dict)
Exemplo n.º 3
0
 def get_prior():
     prior_dict = {
         'log_eta': dists.LogD(dists.Gamma(a=.1, b=.1)),  #W
         'log_tau_minus_one': dists.LogD(dists.Uniform(a=0., b=4.)),  #W
         'logit_sigma': dists.LogitD(dists.Beta(a=1., b=1.)),
         'log_c': dists.LogD(dists.Gamma(a=.1, b=.1))  #W
     }
     return dists.StructDist(prior_dict)
 def get_prior():
     prior_dict = {
         'log_eta': dists.LogD(dists.Gamma(a=0.1, b=0.1)),
         'log_tau_minus_one': dists.LogD(dists.Gamma(a=1.0, b=1.0)),
         'log_c': dists.LogD(dists.Gamma(a=0.1, b=0.1)),
         'log_lam': dists.LogD(dists.Gamma(a=0.1, b=0.1))
     }
     #prior_dict = {
     #        'log_eta':dists.LogD(dists.Gamma(a=1.0, b=1.0)),
     #        'log_tau_minus_one':dists.LogD(dists.Gamma(a=1.0, b=1.0)),
     #        'log_c':dists.LogD(dists.Gamma(a=1.0, b=1.0)),
     #        'log_lam':dists.LogD(dists.Gamma(a=1.0, b=1.0))}
     return dists.StructDist(prior_dict)
Exemplo n.º 5
0
        self.sigmaY = 1. / np.sqrt(self.precY)


ssm_cls = ThetaLogisticReparametrised

# data
data = np.loadtxt('../../datasets/nutria.txt')

# prior
dict_prior = OrderedDict()
dict_prior['tau0'] = dists.TruncNormal(b=3.)
dict_prior['tau1'] = dists.TruncNormal(b=3.)
dict_prior['tau2'] = dists.TruncNormal(b=3.)
dict_prior['precX'] = dists.Gamma(a=2., b=1.)
dict_prior['precY'] = dists.Gamma(a=2., b=1.)
prior = dists.StructDist(dict_prior)


# Particle Gibbs
class PGibbs(mcmc.ParticleGibbs):
    def update_theta(self, theta, x):
        new_theta = theta.copy()
        ax = np.array(x)
        dax = np.diff(ax)
        ay = np.array(data).flatten()
        tau0 = theta['tau0']
        tau1 = theta['tau1']
        tau2 = theta['tau2']

        # update precisions
        deltaX = dax - tau0 + tau1 * np.exp(tau2 * ax[:-1])
Exemplo n.º 6
0
if dataset_name == 'sonar':
    N = 10**4
    Ms = [10, 20, 30, 40, 50, 60]
    typM = 50
elif dataset_name == 'pima':
    N = 10**3
    Ms = [1, 3, 5]
    typM = 3
elif dataset_name == 'eeg':
    N = 10**3
    Ms = [1, 3, 5, 7, 10, 15, 20]
    typM = 5

# prior & model
prior = dists.StructDist({'beta': dists.MvNormal(scale=5., cov=np.eye(p))})


class LogisticRegression(smc_samplers.StaticModel):
    def logpyt(self, theta, t):
        # log-likelihood factor t, for given theta
        lin = np.matmul(theta['beta'], data[t, :])
        return -np.logaddexp(0., -lin)


# algorithms
# N and values of M set above according to dataset
ESSrmin = 0.5
nruns = 16
results = []
Exemplo n.º 7
0
        sigma, rho = 0.2, 0.95  # fixed values
        xlag = np.array(x[1:] + [
            0.,
        ])
        dx = (x - rho * xlag) / (1. - rho)
        s = sigma / (1. - rho)**2
        new_theta['mu'] = self.prior.laws['mu'].posterior(dx, sigma=s).rvs()
        return new_theta


prior_dict = {
    'mu': dists.Normal(scale=2.),
    'rho': dists.Uniform(a=-1., b=1.),
    'sigma': dists.Gamma()
}
my_prior = dists.StructDist(prior_dict)

# real data
raw_data = np.loadtxt('data.txt', skiprows=2, usecols=(3, ), comments='(C)')
full_data = np.diff(np.log(raw_data))
data = full_data[:50]

pg = PGStochVol(ssm_cls=StochVol,
                data=data,
                prior=my_prior,
                Nx=200,
                niter=1000)
pg.run()  # may take several seconds...

# plt.plot(pg.chain.theta['mu'])
# plt.xlabel('iter')
Exemplo n.º 8
0
 def get_prior():
     prior_dict = {
         'log_alpha': dists.LogD(dists.Gamma(a=.1, b=.1)),
         'log_lambda': dists.LogD(dists.Gamma(a=.1, b=.1))
     }
     return dists.StructDist(prior_dict)
Exemplo n.º 9
0
 def get_prior():
     prior_dict = {
         'log_half_nu_minus_one': dists.LogD(dists.Gamma(a=1., b=1.)),
         'log_sigma': dists.LogD(dists.Gamma(a=.1, b=.1))
     }
     return dists.StructDist(prior_dict)
Exemplo n.º 10
0
 def get_prior():
     prior_dict = {
             'log_eta':dists.LogD(dists.Gamma(a=0.1, b=0.1)),
             'log_c':dists.LogD(dists.Gamma(a=0.1, b=0.1)),
             'log_lam':dists.LogD(dists.Gamma(a=0.1, b=0.1))}
     return dists.StructDist(prior_dict)
Exemplo n.º 11
0
import warnings

warnings.simplefilter('ignore')  # hide warnings

from matplotlib import pyplot as plt
import numpy as np

from particles import distributions as dists

prior_dict = {
    'mu': dists.Normal(scale=2.),
    'rho': dists.Uniform(a=-1., b=1.),
    'sigma': dists.Gamma()
}
my_prior = dists.StructDist(prior_dict)

theta = my_prior.rvs(size=500)  # sample 500 theta-parameters

plt.style.use('ggplot')
plt.hist(theta['sigma'], 30)
plt.xlabel('sigma')

plt.figure()
z = my_prior.logpdf(theta)
plt.hist(z, 30)
plt.xlabel('log-pdf')

plt.figure()
another_prior_dict = {
    'rho': dists.Uniform(a=-1., b=1.),
    'log_sigma': dists.LogD(dists.Gamma())