Expand source code
import numpy as np
from ..model import Model
from ..samplers.sampler import Sampler
from ..sigma import Sigma
class SigmaSampler(Sampler):
def step(self, model: Model, sigma: Sigma) -> float:
sample_value = self.sample(model, sigma)
sigma.set_value(sample_value)
return sample_value
@staticmethod
def sample(model: Model, sigma: Sigma) -> float:
posterior_alpha = sigma.alpha + (model.data.X.n_obsv / 2.)
posterior_beta = sigma.beta + (0.5 * (np.sum(np.square(model.residuals()))))
draw = np.power(np.random.gamma(posterior_alpha, 1./posterior_beta), -0.5)
return draw
Classes
class SigmaSampler
-
Helper class that provides a standard way to create an ABC using inheritance.
Expand source code
class SigmaSampler(Sampler): def step(self, model: Model, sigma: Sigma) -> float: sample_value = self.sample(model, sigma) sigma.set_value(sample_value) return sample_value @staticmethod def sample(model: Model, sigma: Sigma) -> float: posterior_alpha = sigma.alpha + (model.data.X.n_obsv / 2.) posterior_beta = sigma.beta + (0.5 * (np.sum(np.square(model.residuals())))) draw = np.power(np.random.gamma(posterior_alpha, 1./posterior_beta), -0.5) return draw
Ancestors
- Sampler
- abc.ABC
Static methods
def sample(model: Model, sigma: Sigma) ‑> float
-
Expand source code
@staticmethod def sample(model: Model, sigma: Sigma) -> float: posterior_alpha = sigma.alpha + (model.data.X.n_obsv / 2.) posterior_beta = sigma.beta + (0.5 * (np.sum(np.square(model.residuals())))) draw = np.power(np.random.gamma(posterior_alpha, 1./posterior_beta), -0.5) return draw
Methods
def step(self, model: Model, sigma: Sigma) ‑> float
-
Expand source code
def step(self, model: Model, sigma: Sigma) -> float: sample_value = self.sample(model, sigma) sigma.set_value(sample_value) return sample_value