Esempio n. 1
0
    def __init__(self,
                 name='',
                 display_name=None,
                 mu=0.0,
                 sigma=1.0,
                 alpha=1.0,
                 beta=1.0,
                 nchains=1):
        self.name = name

        if display_name is None:
            display_name = self.name
        self.display_name = display_name

        # save the priors
        self._mu = mu
        self._sigma = sigma
        self._alpha = alpha
        self._beta = beta

        # save number of chains
        self._nchains = nchains

        # set initial values
        self._mean = normal(mu, sigma).rvs(nchains)
        self._std = np.sqrt(invgamma(alpha, beta).rvs(nchains))
Esempio n. 2
0
 def _update_std(self, posts):
     """
     Update the current std.
     """
     if len(posts) != self._nchains:
         raise ValueError("You must update all %d chains simultaneously." % self._nchains)
     for i in range(self._nchains):
         # update.sigma=function(x,use.core,use.mu,prior){
         #     require(MCMCpack)
         #     X=use.core[x,]
         X = np.array(posts[i]).flatten()
         #     n=length(X)
         n = len(X)
         #     alpha=prior$alpha
         alpha = self._alpha
         #     beta=prior$beta
         beta = self._beta
         #     mu=use.mu[x]
         mu = self._mean[i]
         #     a=alpha+n/2
         a = alpha + n / 2.0
         #     b=beta+sum((X-mu)**2)/2
         b = beta + ((X - mu) ** 2).sum() / 2.0
         #     sqrt(rinvgamma(1,a,b))
         self._std[i] = np.sqrt(invgamma(a, b).rvs())
     return self._std
Esempio n. 3
0
 def _update_std(self, posts):
     """
     Update the current std.
     """
     if len(posts) != self._nchains:
         raise ValueError("You must update all %d chains simultaneously." %
                          self._nchains)
     for i in range(self._nchains):
         # update.sigma=function(x,use.core,use.mu,prior){
         #     require(MCMCpack)
         #     X=use.core[x,]
         X = np.array(posts[i]).flatten()
         #     n=length(X)
         n = len(X)
         #     alpha=prior$alpha
         alpha = self._alpha
         #     beta=prior$beta
         beta = self._beta
         #     mu=use.mu[x]
         mu = self._mean[i]
         #     a=alpha+n/2
         a = alpha + n / 2.
         #     b=beta+sum((X-mu)**2)/2
         b = beta + ((X - mu)**2).sum() / 2.
         #     sqrt(rinvgamma(1,a,b))
         self._std[i] = np.sqrt(invgamma(a, b).rvs())
     return self._std
Esempio n. 4
0
    def __init__(self, name="", display_name=None, mu=0.0, sigma=1.0, alpha=1.0, beta=1.0, nchains=1):
        self.name = name

        if display_name is None:
            display_name = self.name
        self.display_name = display_name

        # save the priors
        self._mu = mu
        self._sigma = sigma
        self._alpha = alpha
        self._beta = beta

        # save number of chains
        self._nchains = nchains

        # set initial values
        self._mean = normal(mu, sigma).rvs(nchains)
        self._std = np.sqrt(invgamma(alpha, beta).rvs(nchains))