inferpy.inferences package¶
Submodules¶
inferpy.inferences.inference module¶
Module with the functionality related to inference methods.
-
inferpy.inferences.inference.
INF_METHODS
= ['KLpq', 'KLqp', 'Laplace', 'ReparameterizationEntropyKLqp', 'ReparameterizationKLKLqp', 'ReparameterizationKLqp', 'ScoreEntropyKLqp', 'ScoreKLKLqp', 'ScoreKLqp', 'ScoreRBKLqp', 'WakeSleep', 'MetropolisHastings']¶ List with all the alowed implemented inference methods
-
inferpy.inferences.inference.
INF_METHODS_ALIAS
= {'Variational': 'KLqp', 'MCMC': 'MetropolisHastings'}¶ Aliases for some of the inference methods
inferpy.inferences.qmodel module¶
Module with the required functionality for implementing the Q-models and Q-distributions used by some inference algorithms.
-
class
inferpy.inferences.qmodel.
Qmodel
(varlist)[source]¶ Bases:
object
Class implementing a Q model
A Q model approximates the posterior distribution of a probabilistic model P . In the ‘Q’ model we should include a q distribution for every non observed variable in the ‘P’ model. Otherwise, an error will be raised during model compilation.
An example of use:
import edward as ed import inferpy as inf #### learning a 2 parameters of 1-dim from 2-dim data N = 50 sampling_mean = [30., 10.] sess = ed.util.get_session() with inf.ProbModel() as m: theta1 = inf.models.Normal(loc=0., scale=1., dim=1) theta2 = inf.models.Normal(loc=0., scale=1., dim=1) with inf.replicate(size=N): x = inf.models.Normal(loc=[theta1, theta2], scale=1., observed=True) # define the Qmodel # define with any type q_theta1 = inf.Qmodel.Uniform(theta1) q_theta2 = inf.Qmodel.new_qvar(theta2) qmodel = inf.Qmodel([q_theta1, q_theta2]) inf.Qmodel.Normal(theta1) m.compile(Q=qmodel) x_train = inf.models.Normal(loc=sampling_mean, scale=1.).sample(N) data = {x.name : x_train} m.fit(data) m.posterior(theta1).base_object m.posterior(theta2)
-
classmethod
Bernoulli
(v, initializer='ones')¶ Creates a new q-variable of type Bernoulli
Parameters: - v – Inferpy p-variable
- initializer (str) – indicates how the new variable should be initialized. Possible values: ‘ones’ , ‘zeroes’.
-
classmethod
Beta
(v, initializer='ones')¶ Creates a new q-variable of type Beta
Parameters: - v – Inferpy p-variable
- initializer (str) – indicates how the new variable should be initialized. Possible values: ‘ones’ , ‘zeroes’.
-
classmethod
Categorical
(v, initializer='ones')¶ Creates a new q-variable of type Categorical
Parameters: - v – Inferpy p-variable
- initializer (str) – indicates how the new variable should be initialized. Possible values: ‘ones’ , ‘zeroes’.
-
classmethod
Deterministic
(v, initializer='ones')¶ Creates a new q-variable of type Deterministic
Parameters: - v – Inferpy p-variable
- initializer (str) – indicates how the new variable should be initialized. Possible values: ‘ones’ , ‘zeroes’.
-
classmethod
Dirichlet
(v, initializer='ones')¶ Creates a new q-variable of type Dirichlet
Parameters: - v – Inferpy p-variable
- initializer (str) – indicates how the new variable should be initialized. Possible values: ‘ones’ , ‘zeroes’.
-
classmethod
Exponential
(v, initializer='ones')¶ Creates a new q-variable of type Exponential
Parameters: - v – Inferpy p-variable
- initializer (str) – indicates how the new variable should be initialized. Possible values: ‘ones’ , ‘zeroes’.
-
classmethod
Gamma
(v, initializer='ones')¶ Creates a new q-variable of type Gamma
Parameters: - v – Inferpy p-variable
- initializer (str) – indicates how the new variable should be initialized. Possible values: ‘ones’ , ‘zeroes’.
-
classmethod
InverseGamma
(v, initializer='ones')¶ Creates a new q-variable of type InverseGamma
Parameters: - v – Inferpy p-variable
- initializer (str) – indicates how the new variable should be initialized. Possible values: ‘ones’ , ‘zeroes’.
-
classmethod
Laplace
(v, initializer='ones')¶ Creates a new q-variable of type Laplace
Parameters: - v – Inferpy p-variable
- initializer (str) – indicates how the new variable should be initialized. Possible values: ‘ones’ , ‘zeroes’.
-
classmethod
Multinomial
(v, initializer='ones')¶ Creates a new q-variable of type Multinomial
Parameters: - v – Inferpy p-variable
- initializer (str) – indicates how the new variable should be initialized. Possible values: ‘ones’ , ‘zeroes’.
-
classmethod
MultivariateNormalDiag
(v, initializer='ones')¶ Creates a new q-variable of type MultivariateNormalDiag
Parameters: - v – Inferpy p-variable
- initializer (str) – indicates how the new variable should be initialized. Possible values: ‘ones’ , ‘zeroes’.
-
classmethod
Normal
(v, initializer='ones')¶ Creates a new q-variable of type Normal
Parameters: - v – Inferpy p-variable
- initializer (str) – indicates how the new variable should be initialized. Possible values: ‘ones’ , ‘zeroes’.
-
classmethod
Poisson
(v, initializer='ones')¶ Creates a new q-variable of type Poisson
Parameters: - v – Inferpy p-variable
- initializer (str) – indicates how the new variable should be initialized. Possible values: ‘ones’ , ‘zeroes’.
-
classmethod
Uniform
(v, initializer='ones')¶ Creates a new q-variable of type Uniform
Parameters: - v – Inferpy p-variable
- initializer (str) – indicates how the new variable should be initialized. Possible values: ‘ones’ , ‘zeroes’.
-
static
build_from_pmodel
(p, empirical=False)[source]¶ Initializes a Q model from a P model.
Parameters: - p – P model of type inferpy.ProbModel.
- empirical – determines if q distributions will be empirical or of the same type than each p distribution.
-
dict
¶ Dictionary where the keys and values are the p and q distributions respectively.
-
static
new_qvar
(v, initializer='ones', qvar_inf_module=None, qvar_inf_type=None, qvar_ed_type=None, check_observed=True, name='qvar')[source]¶ Builds an Inferpy q-variable for a p-variable.
Parameters: - v – Inferpy variable to be approximated.
- initializer (str) – indicates how the new variable should be initialized. Possible values: “ones” , “zeroes”.
- qvar_inf_module (str) – module of the new Inferpy variable.
- qvar_inf_type (str) – name of the new Inferpy variable.
- qvar_ed_type (str) – full name of the encapsulated Edward variable type.
- check_observed (bool) – To check if p-variable is observed.
Returns: Inferpy variable approximating in input variable.
-
static
new_qvar_empirical
(v, n_post_samples, initializer='ones', check_observed=True, name='qvar')[source]¶ Builds an empirical Inferpy q-variable for a p-variable.
Parameters: - v – Inferpy variable to be approximated.
- n_post_samples – number of posterior samples.
- initializer (str) – indicates how the new variable should be initialized. Possible values: “ones” , “zeroes”.
- check_observed (bool) – To check if p-variable is observed.
Returns: Inferpy variable approximating in input variable. The InferPy type will be Deterministic while the encapsulated Edward variable will be of type Empirical.
-
varlist
¶ list of q variables of Inferpy type
-
classmethod