Esempio n. 1
0
 def __init__(self, mean=0, sigma=1, name='', model=None):
     super().__init__(name, model)
     self.Var('v1', Normal.dist(mu=mean, sigma=sigma))
     Normal('v2', mu=mean, sigma=sigma)
     Normal('v3', mu=mean, sigma=HalfCauchy('sd', beta=10, testval=1.))
     Deterministic('v3_sq', self.v3 ** 2)
     Potential('p1', tt.constant(1))
Esempio n. 2
0
 def __init__(self, mean=0, sigma=1, name="", model=None):
     super().__init__(name, model)
     self.Var("v1", Normal.dist(mu=mean, sigma=sigma))
     Normal("v2", mu=mean, sigma=sigma)
     Normal("v3", mu=mean, sigma=HalfCauchy("sd", beta=10, testval=1.0))
     Deterministic("v3_sq", self.v3 ** 2)
     Potential("p1", aet.constant(1))
Esempio n. 3
0
    def fit(self, n_steps=30000):
        """
        Creates a Bayesian Estimation model for replicate measurements of
        treatment(s) vs. control.

        Parameters
        ----------
        n_steps : int
            The number of steps to run ADVI.
        """

        sample_names = set(self.data[self.sample_col].values)
        sample_names.remove(self.baseline_name)

        with Model() as model:
            # Hyperpriors
            upper = Exponential('upper', lam=0.05)
            nu = Exponential('nu_minus_one', 1 / 29.) + 1

            # "fold", which is the estimated fold change.
            fold = Uniform('fold',
                           lower=1E-10,
                           upper=upper,
                           shape=len(sample_names))

            # Assume that data have heteroskedastic (i.e. variable) error but
            # are drawn from the same HalfCauchy distribution.
            sigma = HalfCauchy('sigma', beta=1, shape=len(sample_names))

            # Model prediction
            mu = fold[self.data['indices']]
            sig = sigma[self.data['indices']]

            # Data likelihood
            like = StudentT('like',
                            nu=nu,
                            mu=mu,
                            sd=sig**-2,
                            observed=self.data[self.output_col])

        self.model = model

        with model:
            params = advi(n=n_steps)
            trace = sample_vp(params, draws=2000)

        self.trace = trace