Taweret.core namespace

Submodules

class Taweret.core.base_mixer.BaseMixer[source]

Bases: ABC

abstract evaluate()[source]

Calculate a point estimate for mixing model

evaluationfloat

point estimate from mixing model

Global linear mixing:

\[f_\mathrm{mixed} = \sum_{i=1}^N w_i \mathcal M_i(\theta_i)\]
class MyMixer(BaseMixer):
    @property
    def models(self):
        return self._model_list
    @models.setter
    def models(self, model_list):
        self._model_list = model_list
    def evaluate(self, weights, model_parameters):
        value = 0
        for i in range(len(self._model_list)):
            value += self._model_list[i](
                x, model_parameters[i]
            ) * weight[i]
        return value
abstract evaluate_weights()[source]

Calculate or sample a point estimate for model weights

weightsnp.ndarray

array of the evaluations or samples of weights

Global linear mixing:

import scipy
class MyMixer(BaseMixer):
    # . . .
    def evaluate_weights(self, dirichlet_params):
        return scipy.stats.dirichlet.rvs(dirichlet_params)
    # . . .
abstract property map

Stores the MAP values for the posterior distributions and is set during the self.train step

abstract property posterior

Stores the most recent posteriors from running self.train function

_posteriornp.ndarray

posterior from learning the weights

abstract predict()[source]

Evaluate posterior to make prediction at test points.

evaluated_posteriornp.ndarray

array of posterior predictive distribution evaluated at provided test points

meannp.ndarray

average mixed model value at each provided test points

credible_intervalsnp.ndarray

intervals corresponding for 60%, 90% credible intervals

std_devnp.ndarray

sample standard deviation of mixed model output at provided test points

Global liner mixing:

class MyMixer(BaseMixer):
    # . . .
    def predict(self, x_test):
        # work to calculate everything
        # . . .
        return posterior, means, credible_intervals, std_dev
abstract predict_weights()[source]

Calculate posterior predictive distribution for model weights

evaluated_posteriornp.ndarray

array of posterior predictive distribution evaluated at provided test points

meannp.ndarray

average mixed model value at each provided test points

credible_intervalsnp.ndarray

intervals corresponding for 60%, 90% credible intervals

std_devnp.ndarray

sample standard deviation of mixed model output at provided test points

Global liner mixing:

class MyMixer(BaseMixer):
    # . . .
    def predict_weights(self, x_test):
        # work to calculate everything
        # . . .
        return posterior, means, credible_intervals, std_dev
abstract property prior

Dictionary of prior distributions. Format should be compatible with sampler.

_priorDict[str, Any]

Underlying prior object(s)

Please consult BaseMixer.set_prior for an example

abstract prior_predict()[source]

Get prior predictive distribution and prior distribution samples

evaluated_priornp.ndarray

array of prior predictive distribution evaluated at provided test points

meannp.ndarray

average mixed model value at each provided test points

credible_intervalsnp.ndarray

intervals corresponding for 60%, 90% credible intervals

std_devnp.ndarray

sample standard deviation of mixed model output at provided test points

Global liner mixing:

class MyMixer(BaseMixer):
    # . . .
    def prior_predict(self, x_test):
        # work to calculate everything
        # . . .
        return prior, means, credible_intervals, std_dev
abstract set_prior()[source]

User must provide function that sets a member varibale called _prior. Dictionary of prior distributions. Format should be compatible with sampler.

class MyMixer(BaseMixer):
    # . . .
    def set_prior(self, prior_dict):
        self._prior = prior_dict
    # . . .
# creating a bilby prior dict
priors = dict()
priors['a'] = bilby.core.prior.MultivariateGaussian(mvg, 'a')
priors['b'] = bilby.core.prior.MultivariateGaussian(mvg, 'b')
m = MyMixer()
m.set_prior(prior_dict=priors)
abstract train()[source]

Run sampler to learn parameters. Method should also create class members that store the posterior and other diagnostic quantities import for plotting MAP values should also caluclate and set as member variable of class

_posteriornp.ndarray

the mcmc chain return from sampler

class Taweret.core.base_model.BaseModel[source]

Bases: ABC

abstract evaluate()[source]

Calculate a point estimate for mixing model

evaluationfloat

point estimate for model

Example

class MyModel(BaseModel):
    @property
    def model(self):
        return self._model

    @models.setter
    def model(self, the_model):
        self._model = the_model

    def evaluate(self, model_parameters):
        return self._model(model_parameters)
    # . . .
abstract log_likelihood_elementwise()[source]

Calculate log_likelihood for array of points given, and return with array with same shape[0]

log_likelisnp.ndarray

an array of length as shape[0] of the input evaluation points

class MyModel(BaseModel):
    def log_likelihood_elementwise(
        self, y_exp, y_err, model_params
    ):
        # Assuming a normal distribution for error
        y = self.evaluate(model_params)
        # If y_exp, y_err, y are numpy arrays of same length
        return np.exp(-(y - y_exp) **2 / (2 * y_err ** 2)) \
            / np.sqrt(2 * np.pi * y_err ** 2))
abstract set_prior()[source]

User must provide function that sets a member varibale called _prior. Dictionary of prior distributions. Format should be compatible with sampler.

class MyModel(BaseMixer):
    # . . .
    def set_prior(self, prior_dict):
        self._prior = prior_dict
    # . . .

Name: trees_setup.py Author: John Yannotty (yannotty.1@osu.edu) Desc: Setups up working environment for mixing classes

Start Date: 11/28/22 Version: 1.0

Taweret.core.trees_setup.trees_setup()[source]