pymc.Approximation#
- class pymc.Approximation(groups, model=None)[source]#
Wrapper for grouped approximations.
Wraps list of groups, creates an Approximation instance that collects sampled variables from all the groups, also collects logQ needed for explicit Variational Inference.
- Parameters:
- groups: list[Group]
List of
Groupinstances. They should have all model variables- model: Model
See also
Notes
Some shortcuts for single group approximations are available:
Methods
Approximation.__init__(groups[, model])Approximation.collect(item)Dev - optimizations for logP.
Approximation.make_size_and_deterministic_replacements(s, d)Dev - create correct replacements for initial depending on sample size and deterministic flag.
Approximation.rslice(name)Dev - vectorized sampling for named random variable without call to pytensor.scan.
Approximation.sample([draws, random_seed, ...])Draw samples from variational posterior.
Approximation.sample_node(node[, size, ...])Sample given node or nodes over shared posterior.
Dev - after node is sampled via
symbolic_sample_over_posterior()orsymbolic_single_sample()new random generator can be allocated and applied to node.Dev - perform sampling of node applying independent samples from posterior each time.
Approximation.symbolic_single_sample(node[, ...])Dev - perform sampling of node applying single sample from posterior.
Approximation.to_flat_input(node[, ...])Dev - replace vars with flattened view stored in self.inputs.
Attributes
all_histogramsany_histogramsdatalogpDev - computes \(E_{q}(data term)\) from model via pytensor.scan that can be optimized later.
datalogp_normDev - normalized \(E_{q}(data term)\).
ddimhas_logqinputsjoint_histogramlogpDev - computes \(E_{q}(logP)\) from model via pytensor.scan that can be optimized later.
logp_normDev - normalized \(E_{q}(logP)\).
logqDev - collects logQ for all groups.
logq_normDev - collects logQ for all groups and normalizes it.
ndimparamsreplacementsDev - all replacements from groups to replace PyMC random variables with approximation.
sample_dict_fnscale_cost_to_minibatchDev - Property to control scaling cost to minibatch.
single_symbolic_datalogpDev - for single MC sample estimate of \(E_{q}(data term)\) pytensor.scan is not needed and code can be optimized.
single_symbolic_logpDev - for single MC sample estimate of \(E_{q}(logP)\) pytensor.scan is not needed and code can be optimized.
single_symbolic_varlogpDev - for single MC sample estimate of \(E_{q}(prior term)\) pytensor.scan is not needed and code can be optimized.
sized_symbolic_datalogpDev - computes sampled data term from model via pytensor.scan.
sized_symbolic_logpDev - computes sampled logP from model via pytensor.scan.
sized_symbolic_varlogpDev - computes sampled prior term from model via pytensor.scan.
symbolic_logqDev - collects symbolic_logq for all groups.
symbolic_normalizing_constantDev - normalizing constant for self.logq, scales it to minibatch_size instead of total_size.
symbolic_randomsymbolic_randomsvarlogpDev - computes \(E_{q}(prior term)\) from model via pytensor.scan that can be optimized later.
varlogp_normDev - normalized \(E_{q}(prior term)\).