geoml.latent
The nodes a model’s latent network is composed from. A network is built
bottom-up — an input node, one or more GP nodes above it, operations that
combine them — and handed to
VGPNetwork as its latent_network.
The signatures here are unannotated on purpose: everything below the
constructors is tensor code, where a tf.Tensor in and a tf.Tensor out
says nothing about the rank, dtype or axis order that actually goes wrong.
The constructors’ own arguments are documented in their docstrings.
Inputs
- geoml.latent.network.simulation_rule(qmc)[source]
Chooses how the posterior simulations are drawn while active.
- geoml.latent.network.propagation_rule(rule, joint=False)[source]
Chooses how experts propagate their inducing sets, and whether uncertainty travels with its covariance between locations, while active.
- geoml.latent.network.expert_subset(experts)[source]
Computes only the given experts, by index, while active: a sequence for every input, or a mapping from an input node to its experts.
- geoml.latent.network.expert_slots(slots)[source]
Computes only the experts in slots while active: a _Slots for every input, or a mapping from an input node to its own.
- geoml.latent.network.padded_inducing_points(root)[source]
An input’s inducing points stacked over its experts and padded to the largest set, with one padding expert after the last: [n_experts + 1, m, d], and the mask of the real points [n_experts + 1, m]. A padded entry repeats its expert’s first point, so the transform only ever sees places it has seen.
- geoml.latent.network.refresh_cached(network, jitter=1e-06, owner=None)[source]
Refreshes a network once and snapshots it for prediction.
refresh is pure arithmetic over parameters that do not move during prediction, but running it eagerly pays Python overhead for each of the K x K covariance blocks a multi-expert network builds – at 32 experts that is most of a predict call. Tracing it collapses those into one graph call. The trace is kept – on owner, or on the node – so predicting again does not rebuild it, and it reads the parameters live, so it also follows further training.
- Parameters:
network – The output node of a latent network, or a list of its leaves – a model with one leaf per likelihood, whose leaves may share parents or sit on separate trees. Every node is refreshed and snapshotted once whichever way it is reached.
jitter (float) – Small value added to the covariance matrices for numerical stability.
owner – Where to keep the trace. A list of leaves has no single node to hang it on, so the model passes itself.
- exception geoml.latent.network.NodeIncompatibilityError[source]
Bases:
ExceptionException raised for incompatibilities between a node and its parents/children.
- exception geoml.latent.network.BrokenPropagationError[source]
Bases:
NodeIncompatibilityErrorException raised when inducing points can’t be propagated through nodes.
- exception geoml.latent.network.SizeIncompatibilityError[source]
Bases:
NodeIncompatibilityErrorException raised for incompatibilities in the number of latent variables in nodes.
- class geoml.latent.network.BasicInput(inducing_points, transform=None, fix_transform=False, center=False, name=None)[source]
Bases:
_RootLatentVariableBasic input node.
Converts a deterministic input (usually spatial coordinates) into Gaussian latent variables with zero variance, after applying a transform for normalization. Also defines the inducing points that will be propagated to other nodes.
- __init__(inducing_points, transform=None, fix_transform=False, center=False, name=None)[source]
Initializer for BasicInput.
- Parameters:
inducing_points – A PointData object, or a list of these objects.
transform – An object from the transform module for normalization; the identity if left out.
fix_transform (bool) – Whether to fix the transform parameters to prevent them from changing during training.
center (bool) – Whether to center the data, based on the inducing points’ bounding box.
name (str) – A name for this node, shown in the printed network and accepted by get_node. Numbered automatically if omitted.
- refresh(jitter=1e-06)[source]
Updates the model’s internal state.
If called within TensorFlow’s eager mode, will allow inspection of the internal tensors.
- Parameters:
jitter (float) – Small value added to the covariance matrices for numerical stability.
- propagate(x, x_var=None)[source]
Propagates mean and variance to the next node.
Also stamps the node’s sweep state: _explained_var always, and _sim_state wherever the node’s own simulate draws rather than transforms – simulations originate at GP nodes and are carried pathwise by the operation nodes above them, so an operation node’s simulate calls its parents’ instead of reading a stash.
- Parameters:
x (Tensor) – Mean of the input.
x_var (Tensor) – Variance of the input.
- Returns:
_Moments – The mean and the variance of the output, [n, size] each, which unpack as a pair; and, under the expected kernel and where a GP node reads the output, each expert’s chain in experts: the output’s moments as that expert alone gives them, and its covariance with the expert’s inducing points.
- class geoml.latent.network.GaussianInput(inducing_points, transform=None, fix_transform=False, center=False, name=None)[source]
Bases:
BasicInputInput node for uncertain inputs.
Takes each input as a Gaussian – a mean and a variance per coordinate, which is what a GaussianData container holds – and hands the network both, where BasicInput hands it the mean alone. The case it is built for is a high-dimensional input with missing entries: an entry that is not known is given the mean and variance it could have, and the expected kernel the GP nodes carry integrates over it, so the row is used for what it says rather than dropped or imputed. An uncertain location in space is the same mechanism in three coordinates.
The variance is carried through the transform as the diagonal of
J diag(var) J^T: exactly for an affine transform (the ellipsoids, projections, ARD, selections – transform.linear), where the Jacobian is read off one probe point and applied as one matrix product, and to first order through a nonlinear one (Periodic, the faults), where it is measured at every point. Inducing points are exact. Given no variance the node is BasicInput to the last bit.- Parameters:
inducing_points – A PointData object, or a list of these objects.
transform – An object from the transform module for normalization.
fix_transform – Whether to fix the transform parameters to prevent them from changing during training.
center – Whether to center the data, based on the inducing points’ bounding box.
name – A name for this node, shown in the printed network and accepted by get_node. Numbered automatically if omitted.
See also
BasicInputthe deterministic input.
geoml.data.GaussianDatathe container carrying a variance per coordinate.
- propagate(x, x_var=None)[source]
Propagates mean and variance to the next node.
Also stamps the node’s sweep state: _explained_var always, and _sim_state wherever the node’s own simulate draws rather than transforms – simulations originate at GP nodes and are carried pathwise by the operation nodes above them, so an operation node’s simulate calls its parents’ instead of reading a stash.
- Parameters:
x (Tensor) – Mean of the input.
x_var (Tensor) – Variance of the input.
- Returns:
_Moments – The mean and the variance of the output, [n, size] each, which unpack as a pair; and, under the expected kernel and where a GP node reads the output, each expert’s chain in experts: the output’s moments as that expert alone gives them, and its covariance with the expert’s inducing points.
- class geoml.latent.network.Stack(*latent_variables, name=None)[source]
Bases:
_OperationLatent variable stacking.
Consolidates a list of latent variables into a single object.
- propagate(x, x_var=None)[source]
Propagates mean and variance to the next node.
Also stamps the node’s sweep state: _explained_var always, and _sim_state wherever the node’s own simulate draws rather than transforms – simulations originate at GP nodes and are carried pathwise by the operation nodes above them, so an operation node’s simulate calls its parents’ instead of reading a stash.
- Parameters:
x (Tensor) – Mean of the input.
x_var (Tensor) – Variance of the input.
- Returns:
_Moments – The mean and the variance of the output, [n, size] each, which unpack as a pair; and, under the expected kernel and where a GP node reads the output, each expert’s chain in experts: the output’s moments as that expert alone gives them, and its covariance with the expert’s inducing points.
- simulate(n_sim, seed=(0, 0))[source]
Draws from the state the same sweep’s propagate stamped.
- Parameters:
n_sim (int) – Number of simulations to draw.
seed (tuple) – A set of two seeds for the random number generator.
- Returns:
sims – Simulations of shape [size, n_data, n_sim].
- class geoml.latent.network.Concatenate(*latent_variables, name=None)[source]
Bases:
StackLatent variable concatenation.
Consolidates a list of latent variables into a single object. This operation requires all its parent nodes to be able to propagate inducing points.
- class geoml.latent.network.BasicGP(parent, size=1, kernel=None, fix_range=False, isotropic=False, range_prior=2.0, name=None)[source]
Bases:
_GPNodeStandard Gaussian process node.
In this module, GP nodes are able to work with inputs that may be Gaussian, having an associated variance. This variance is integrated by considering it as a squared range and applying the non-stationary covariance.
- __init__(parent, size=1, kernel=None, fix_range=False, isotropic=False, range_prior=2.0, name=None)[source]
Initializer for BasicGP.
- Parameters:
parent – Parent node.
size – Number of output latent variables
kernel – The kernel to use for the covariance matrices. A fresh Gaussian if omitted.
fix_range (bool) – Whether to force a unit range for all input dimensions.
isotropic (bool) – If True, forces the same range for all input dimensions.
range_prior (float, optional) – Strength of the Gamma prior that regularizes the ranges, which stay point estimates – the prior’s log-density joins the training objective. It peaks at 1, the natural scale of the whitened space every node works in, falls hard as a range collapses toward zero and gently as it grows. Larger values hold on tighter; None removes it, leaving the ranges to the data alone as in versions before 0.6.5.
name (str) – A name for this node, shown in the printed network and accepted by get_node. Numbered automatically if omitted.
- refresh(jitter=1e-06)[source]
Updates the model’s internal state.
If called within TensorFlow’s eager mode, will allow inspection of the internal tensors.
- Parameters:
jitter (float) – Small value added to the covariance matrices for numerical stability.
- cache_prediction_state()[source]
Snapshot the propagated state into Variables (see _state_var).
Called once per prediction (after refresh) for every node in the network. Subclasses holding additional prediction state extend this.
- expected_covariance(mean_x, var_x, mean_y, var_y, cov=None, gradient=False)[source]
The covariance between two sets of uncertain inputs under the expected kernel: mean_x […, n, d], mean_y […, m, d], their variances alike or None, and their covariance […, n, m, d] or None. Returns […, n, m], and with gradient its derivative in mean_x, […, n, m, d].
- class geoml.latent.network.AdditiveGP(parent, size=1, kernel=None, fix_range=False, isotropic=False, range_prior=2.0, name=None)[source]
Bases:
BasicGPAdditive GP node.
This node is similar to the BasicGP, with the difference that is covariance matrices are computed separately for each input dimension and then averaged. It makes more sense to use it on high-dimensional non-spatial inputs.
- expected_covariance(mean_x, var_x, mean_y, var_y, cov=None, gradient=False)[source]
The covariance between two sets of uncertain inputs under the expected kernel: mean_x […, n, d], mean_y […, m, d], their variances alike or None, and their covariance […, n, m, d] or None. Returns […, n, m], and with gradient its derivative in mean_x, […, n, m, d].
- class geoml.latent.network.UncertainInputGP(parent, size=1, kernel=None, fix_range=False, isotropic=False, range_prior=2.0, n_nodes=32, name=None)[source]
Bases:
BasicGPGP node that integrates over the uncertainty of its input by quadrature. Deprecated.
Deprecated since 0.9.0, and to be removed: under the expected kernel (GPOptions(propagation=”joint”), the default for a new model) a BasicGP on an uncertain input takes the mixture’s moments in closed form, more closely than this node’s quadrature, and the likelihood integrates what its realizations leave out. Under the old rule BasicGP reads an uncertain input through an inflated covariance – Paciorek’s nonstationary form – and takes its moments as if the input were one point under that kernel, which understates the predictive variance several times over and misplaces the mean once the input variance reaches a tenth of the squared range. This node computes the mixture instead: n_nodes scrambled Sobol points of the input’s Gaussian, the deterministic posterior at each of them, and the mixture’s moments out – the mean of the means, the mean of the variances plus the variance of the means. Each realization is drawn at a node of its own, so the simulations carry the mixture as well. Nothing depends on the kernel.
- Parameters:
parent – The node whose output is the input. Its variance is what is integrated over: a GaussianInput root, or any GP node above.
size – Number of latent variables.
kernel – A kernel object from geoml.kernels.
fix_range – Whether to fix the range parameters.
isotropic – Whether to use a single range for every input dimension.
range_prior – As in BasicGP.
n_nodes – Quadrature points per input. A power of two keeps the Sobol sequence balanced.
name – A name for this node, shown in the printed network and accepted by get_node. Numbered automatically if omitted.
See also
BasicGPthe node this extends.
GaussianInputthe root that supplies an input variance.
Notes
The cost is n_nodes cross-covariances per prediction or training step where BasicGP computes one, and the same factor in memory for them. Given an input with no variance the node is BasicGP.
- class geoml.latent.network.Linear(parent, size=1, unit_norm=True, weight_prior=1.0, name=None)[source]
Bases:
_FunctionalLatentVariableLinear node.
This node outputs one or more linear combinations of the inputs. Its role in a network depends on its position. Close to a root node it induces rotation in the coordinates. At the end it induces correlations between the outputs, and in the middle it can serve as an information bottleneck.
- __init__(parent, size=1, unit_norm=True, weight_prior=1.0, name=None)[source]
Initializer for Linear.
- Parameters:
parent – Parent node
size – Number of output latent variables.
unit_norm (bool) – Whether the weights should form a unit norm vector. If False, the weights are free and regularized by weight_prior.
weight_prior (float, optional) – Standard deviation of the zero-mean Gaussian prior on the free weights (unit_norm=False only – the unit norm is constraint enough on its own). The weights stay point estimates; the prior’s log-density joins the training objective, so a weight grows only while the data pays for it, which matters because this is the parameter whose count scales with the network (parent.size times size) and no KL prices it. The standard deviation of 1 matches the whitened scale the network works in. None removes the prior and restores the hard [-1, 1] walls of versions before 0.6.5.
name (str) – A name for this node.
- refresh(jitter=1e-06)[source]
Updates the model’s internal state.
If called within TensorFlow’s eager mode, will allow inspection of the internal tensors.
- Parameters:
jitter (float) – Small value added to the covariance matrices for numerical stability.
- propagate(x, x_var=None)[source]
Propagates mean and variance to the next node.
Also stamps the node’s sweep state: _explained_var always, and _sim_state wherever the node’s own simulate draws rather than transforms – simulations originate at GP nodes and are carried pathwise by the operation nodes above them, so an operation node’s simulate calls its parents’ instead of reading a stash.
- Parameters:
x (Tensor) – Mean of the input.
x_var (Tensor) – Variance of the input.
- Returns:
_Moments – The mean and the variance of the output, [n, size] each, which unpack as a pair; and, under the expected kernel and where a GP node reads the output, each expert’s chain in experts: the output’s moments as that expert alone gives them, and its covariance with the expert’s inducing points.
- class geoml.latent.network.SelectInput(parent, columns, name=None)[source]
Bases:
_FunctionalLatentVariableVariable selection.
Returns the specified columns of the input, discarding the others.
- __init__(parent, columns, name=None)[source]
Initializer for SelectInput.
- Parameters:
parent – Parent node.
columns (list) – List of indices to retain.
name (str) – A name for this node.
- propagate(x, x_var=None)[source]
Propagates mean and variance to the next node.
Also stamps the node’s sweep state: _explained_var always, and _sim_state wherever the node’s own simulate draws rather than transforms – simulations originate at GP nodes and are carried pathwise by the operation nodes above them, so an operation node’s simulate calls its parents’ instead of reading a stash.
- Parameters:
x (Tensor) – Mean of the input.
x_var (Tensor) – Variance of the input.
- Returns:
_Moments – The mean and the variance of the output, [n, size] each, which unpack as a pair; and, under the expected kernel and where a GP node reads the output, each expert’s chain in experts: the output’s moments as that expert alone gives them, and its covariance with the expert’s inducing points.
- simulate(n_sim, seed=(0, 0))[source]
Draws from the state the same sweep’s propagate stamped.
- Parameters:
n_sim (int) – Number of simulations to draw.
seed (tuple) – A set of two seeds for the random number generator.
- Returns:
sims – Simulations of shape [size, n_data, n_sim].
- class geoml.latent.network.LinearCombination(*latent_variables, unit_variance=True, per_component=False, weight_concentration=2.0, name=None)[source]
Bases:
_OperationLinear combination.
This node combines the inputs linearly with positive weights.
- __init__(*latent_variables, unit_variance=True, per_component=False, weight_concentration=2.0, name=None)[source]
Initializer for LinearCombination.
- Parameters:
latent_variables – Nodes to combine. They must all have the same number of variables.
unit_variance (bool) – If True, constrains the weights to unit sum to control the variance of the output.
per_component (bool) – One set of mixing weights per output component instead of one for the whole node, so each component takes its own share of each parent – one element can lean on a trend that another ignores. Requires unit_variance, and multiplies the weight count by size, which is why the prior below comes with it.
weight_concentration (float, optional) – Concentration of the symmetric Dirichlet prior on each component’s weights (per_component=True only – the shared weights are few enough to need none). The weights stay point estimates; the prior’s log-density joins the training objective, holding each component’s shares near equal until its data argues otherwise. Must exceed 1 for the pull to point at equal shares; None removes it.
name (str) – A name for this node.
- refresh(jitter=1e-06)[source]
Updates the model’s internal state.
If called within TensorFlow’s eager mode, will allow inspection of the internal tensors.
- Parameters:
jitter (float) – Small value added to the covariance matrices for numerical stability.
- propagate(x, x_var=None)[source]
Propagates mean and variance to the next node.
Also stamps the node’s sweep state: _explained_var always, and _sim_state wherever the node’s own simulate draws rather than transforms – simulations originate at GP nodes and are carried pathwise by the operation nodes above them, so an operation node’s simulate calls its parents’ instead of reading a stash.
- Parameters:
x (Tensor) – Mean of the input.
x_var (Tensor) – Variance of the input.
- Returns:
_Moments – The mean and the variance of the output, [n, size] each, which unpack as a pair; and, under the expected kernel and where a GP node reads the output, each expert’s chain in experts: the output’s moments as that expert alone gives them, and its covariance with the expert’s inducing points.
- class geoml.latent.network.ProductOfExperts(*latent_variables, name=None)[source]
Bases:
_OperationProduct of Experts.
The Product of Experts combines latent variables from different nodes with weights inversely proportional to the local variance. It is more useful when combining the outputs of smaller networks with different set of inducing points, allowing each one to focus on a region of space.
This node treats its parents independently. Means and variances will be “stiched” smoothly, but individual simulations may exhibit artifacts.
This node is not capable of propagating inducing points.
- __init__(*latent_variables, name=None)[source]
Initializer for ProductOfExperts.
- Parameters:
latent_variables – Parent nodes to combine.
name (str) – A name for this node.
- refresh(jitter=1e-06)[source]
Updates the model’s internal state.
If called within TensorFlow’s eager mode, will allow inspection of the internal tensors.
- Parameters:
jitter (float) – Small value added to the covariance matrices for numerical stability.
- propagate(x, x_var=None)[source]
Propagates mean and variance to the next node.
Also stamps the node’s sweep state: _explained_var always, and _sim_state wherever the node’s own simulate draws rather than transforms – simulations originate at GP nodes and are carried pathwise by the operation nodes above them, so an operation node’s simulate calls its parents’ instead of reading a stash.
- Parameters:
x (Tensor) – Mean of the input.
x_var (Tensor) – Variance of the input.
- Returns:
_Moments – The mean and the variance of the output, [n, size] each, which unpack as a pair; and, under the expected kernel and where a GP node reads the output, each expert’s chain in experts: the output’s moments as that expert alone gives them, and its covariance with the expert’s inducing points.
- class geoml.latent.network.Exponentiation(parent, name=None)[source]
Bases:
_FunctionalLatentVariableThe exponential of a latent variable: a field that is always positive.
Each output is
exp(sqrt(amp_scale) * f + amp_mean)of its parent’s outputf, the two parameters trained, and its moments are those of the log-normal that makes. Meant as an amplitude multiplied into another branch, so a field’s variability can change from place to place. The output is no longer Gaussian, so no inducing points pass through it and nothing that needs them can sit above it.- Parameters:
parent – The latent variable to exponentiate; the output has its size.
name – The node’s name, numbered within the tree.
- propagate(x, x_var=None)[source]
Propagates mean and variance to the next node.
Also stamps the node’s sweep state: _explained_var always, and _sim_state wherever the node’s own simulate draws rather than transforms – simulations originate at GP nodes and are carried pathwise by the operation nodes above them, so an operation node’s simulate calls its parents’ instead of reading a stash.
- Parameters:
x (Tensor) – Mean of the input.
x_var (Tensor) – Variance of the input.
- Returns:
_Moments – The mean and the variance of the output, [n, size] each, which unpack as a pair; and, under the expected kernel and where a GP node reads the output, each expert’s chain in experts: the output’s moments as that expert alone gives them, and its covariance with the expert’s inducing points.
- class geoml.latent.network.Multiply(*latent_variables, name=None)[source]
Bases:
_OperationThe product of latent variables of one size, output by output.
The mean and variance are those of a product of independent variables, and each realization is the product of the parents’ realizations. The usual use is an amplitude times a field, the amplitude an Exponentiation. A product of Gaussians is not Gaussian, so no inducing points pass through it.
- Parameters:
latent_variables – The latent variables to multiply, all of the same size.
name – The node’s name, numbered within the tree.
- refresh(jitter=1e-06)[source]
Updates the model’s internal state.
If called within TensorFlow’s eager mode, will allow inspection of the internal tensors.
- Parameters:
jitter (float) – Small value added to the covariance matrices for numerical stability.
- propagate(x, x_var=None)[source]
Propagates mean and variance to the next node.
Also stamps the node’s sweep state: _explained_var always, and _sim_state wherever the node’s own simulate draws rather than transforms – simulations originate at GP nodes and are carried pathwise by the operation nodes above them, so an operation node’s simulate calls its parents’ instead of reading a stash.
- Parameters:
x (Tensor) – Mean of the input.
x_var (Tensor) – Variance of the input.
- Returns:
_Moments – The mean and the variance of the output, [n, size] each, which unpack as a pair; and, under the expected kernel and where a GP node reads the output, each expert’s chain in experts: the output’s moments as that expert alone gives them, and its covariance with the expert’s inducing points.
- class geoml.latent.network.GaussianMixture(weights, components, n_nodes=64, name=None)[source]
Bases:
_OperationA mixture of latent variables, weighted by the softmax of others.
weights holds one latent variable per component, in the components’ order: the first latent variable of weights weighs the first component, the second the second, and so on. At every location the softmax of the weights, scaled by a trained amplitude, gives each component its share, and the output is the components’ sum under those shares – a field that follows one component where its weight dominates and passes smoothly to another where the weights change places. The amplitude sets how sharp the passage is: a large one makes each realization nearly one component at a time, a small one blends them.
The mixture is computed realization by realization, from the realizations of the weights and of the components, so it keeps whatever those share through common parents. The output is not Gaussian: a model trains the likelihood of a leaf above this node on its realizations, and no inducing points pass through it.
- Parameters:
weights – A node of one latent variable per component, in the order of components.
components – Two or more nodes of one common size, which is the output’s size. Their order is the order of the weights’ latent variables.
n_nodes – Quadrature points over the weights for the moments. A power of two keeps the Sobol sequence balanced.
name – A name for this node, shown in the printed network and accepted by get_node. Numbered automatically if omitted.
- Raises:
SizeIncompatibilityError – If the weights do not have one latent variable per component, or the components differ in size.
See also
ProductOfExpertscomponents weighted by their own variances.
geoml.likelihood.Mixturea mixture of noise laws, not of fields.
Notes
A component as flexible as the field it blends can fit every regime on its own, and then the weights never switch: give the components a smoother structure than the passage between regimes (a longer range).
The mean and variance take the weights as independent of the components, and each weight as independent of the others: the softmax is averaged over n_nodes scrambled Sobol points of the weights’ marginal Gaussians. Where the weights and the components share a parent the moments miss that correlation; the realizations do not.
- refresh(jitter=1e-06)[source]
Updates the model’s internal state.
If called within TensorFlow’s eager mode, will allow inspection of the internal tensors.
- Parameters:
jitter (float) – Small value added to the covariance matrices for numerical stability.
- propagate(x, x_var=None)[source]
Propagates mean and variance to the next node.
Also stamps the node’s sweep state: _explained_var always, and _sim_state wherever the node’s own simulate draws rather than transforms – simulations originate at GP nodes and are carried pathwise by the operation nodes above them, so an operation node’s simulate calls its parents’ instead of reading a stash.
- Parameters:
x (Tensor) – Mean of the input.
x_var (Tensor) – Variance of the input.
- Returns:
_Moments – The mean and the variance of the output, [n, size] each, which unpack as a pair; and, under the expected kernel and where a GP node reads the output, each expert’s chain in experts: the output’s moments as that expert alone gives them, and its covariance with the expert’s inducing points.
- class geoml.latent.network.Add(*latent_variables, name=None)[source]
Bases:
_OperationThe sum of latent variables of one size, output by output.
Means, variances and realizations add up, the parents taken as independent. Inducing points pass through, summed, when every parent passes its own on and all of them grow from one input, so a GP can sit on the sum – a trend plus a residual, or structures at several scales.
- Parameters:
latent_variables – The latent variables to add, all of the same size.
name – The node’s name, numbered within the tree.
- refresh(jitter=1e-06)[source]
Updates the model’s internal state.
If called within TensorFlow’s eager mode, will allow inspection of the internal tensors.
- Parameters:
jitter (float) – Small value added to the covariance matrices for numerical stability.
- propagate(x, x_var=None)[source]
Propagates mean and variance to the next node.
Also stamps the node’s sweep state: _explained_var always, and _sim_state wherever the node’s own simulate draws rather than transforms – simulations originate at GP nodes and are carried pathwise by the operation nodes above them, so an operation node’s simulate calls its parents’ instead of reading a stash.
- Parameters:
x (Tensor) – Mean of the input.
x_var (Tensor) – Variance of the input.
- Returns:
_Moments – The mean and the variance of the output, [n, size] each, which unpack as a pair; and, under the expected kernel and where a GP node reads the output, each expert’s chain in experts: the output’s moments as that expert alone gives them, and its covariance with the expert’s inducing points.
- class geoml.latent.network.Bias(parent, scale=5, name=None)[source]
Bases:
_FunctionalLatentVariableAdds a deterministic constant to its input.
- refresh(jitter=1e-06)[source]
Updates the model’s internal state.
If called within TensorFlow’s eager mode, will allow inspection of the internal tensors.
- Parameters:
jitter (float) – Small value added to the covariance matrices for numerical stability.
- propagate(x, x_var=None)[source]
Propagates mean and variance to the next node.
Also stamps the node’s sweep state: _explained_var always, and _sim_state wherever the node’s own simulate draws rather than transforms – simulations originate at GP nodes and are carried pathwise by the operation nodes above them, so an operation node’s simulate calls its parents’ instead of reading a stash.
- Parameters:
x (Tensor) – Mean of the input.
x_var (Tensor) – Variance of the input.
- Returns:
_Moments – The mean and the variance of the output, [n, size] each, which unpack as a pair; and, under the expected kernel and where a GP node reads the output, each expert’s chain in experts: the output’s moments as that expert alone gives them, and its covariance with the expert’s inducing points.
- class geoml.latent.network.Scale(parent, name=None)[source]
Bases:
_FunctionalLatentVariableScale.
Multiplies its input by a constant. The variance is multiplied by the square of the same value.
- refresh(jitter=1e-06)[source]
Updates the model’s internal state.
If called within TensorFlow’s eager mode, will allow inspection of the internal tensors.
- Parameters:
jitter (float) – Small value added to the covariance matrices for numerical stability.
- propagate(x, x_var=None)[source]
Propagates mean and variance to the next node.
Also stamps the node’s sweep state: _explained_var always, and _sim_state wherever the node’s own simulate draws rather than transforms – simulations originate at GP nodes and are carried pathwise by the operation nodes above them, so an operation node’s simulate calls its parents’ instead of reading a stash.
- Parameters:
x (Tensor) – Mean of the input.
x_var (Tensor) – Variance of the input.
- Returns:
_Moments – The mean and the variance of the output, [n, size] each, which unpack as a pair; and, under the expected kernel and where a GP node reads the output, each expert’s chain in experts: the output’s moments as that expert alone gives them, and its covariance with the expert’s inducing points.
- class geoml.latent.network.RadialTrend(parent, size=1, name=None)[source]
Bases:
_FunctionalLatentVariableRadial trend.
This node outputs a (hyper)spherical deterministic function, positive on the inside and negative on the outside. It can be made ellipsoidal or with a more complex shape depending on its parent nodes. Its main use is for implicit geological modelling.
It will ignore the variance of its inputs.
- __init__(parent, size=1, name=None)[source]
Initializer for RadialTrend.
- Parameters:
parent – Parent node.
size (int) – Number of output functions to generate.
name (str) – A name for this node.
- refresh(jitter=1e-06)[source]
Updates the model’s internal state.
If called within TensorFlow’s eager mode, will allow inspection of the internal tensors.
- Parameters:
jitter (float) – Small value added to the covariance matrices for numerical stability.
- propagate(x, x_var=None)[source]
Propagates mean and variance to the next node.
Also stamps the node’s sweep state: _explained_var always, and _sim_state wherever the node’s own simulate draws rather than transforms – simulations originate at GP nodes and are carried pathwise by the operation nodes above them, so an operation node’s simulate calls its parents’ instead of reading a stash.
- Parameters:
x (Tensor) – Mean of the input.
x_var (Tensor) – Variance of the input.
- Returns:
_Moments – The mean and the variance of the output, [n, size] each, which unpack as a pair; and, under the expected kernel and where a GP node reads the output, each expert’s chain in experts: the output’s moments as that expert alone gives them, and its covariance with the expert’s inducing points.
- class geoml.latent.network.GPWalk(parent, step=0.01, n_steps=10, name=None)[source]
Bases:
_FunctionalLatentVariableA walk along an uncertain vector field.
This node uses the vector field defined by its parent to move points in space: n_steps steps of step times the field, scaled by a trained amplitude, the field read again where each step lands. It learns non-stationary patterns – a GP above it reads coordinates that the field has stretched and folded – at the cost of the steps.
The node’s parent (a GP) defines the vector field and the parent’s parent contains the coordinates that will be moved. Both must have the same size.
Under the expected kernel (GPOptions(propagation=”joint”), the default since 0.9.0) the field is one random field, the same at every step: a point carries its uncertainty and its covariance with every other point along, the field is read under the expected kernel with the uncertainty accumulated so far – so an uncertain walker reads a weaker field and slows down – and more steps refine the path rather than adding noise. step * n_steps * amp is the walk’s reach. The field’s variance that its inducing points leave unexplained – the whole prior far from them – moves each point on its own, so far from the data a walk is uncertain. Each realization walks a realization of the field. The walk adds no random variable of its own: the field’s KL prices the deformation. Under the marginal rule of the versions before, a KL term prices the inducing points’ displacement against the walk’s spread instead, and precision shrinks the variance at each step; both are deprecated, and ignored here.
Build the GP that reads the walk with isotropic=True. The walk already bends the space, so a range per dimension in its reader is a second way to say the same thing, and training settles the trade on a reader stretched along one axis over a near-certain walk – intervals too narrow on new data. The anisotropy the model starts from belongs in the input’s transform, where it carries what is known beforehand, and the reader’s one range is relative to it.
- __init__(parent, step=0.01, n_steps=10, name=None)[source]
Initializer for GPWalk.
In principle the step argument does not need to be changed, as the underlying GP tends to adjust its amplitude to take larger or smaller steps in practice. A higher n_steps allows the model to have finer control of the points’ trajectories at a higher computational cost. n_steps=5 seems to be the minimum possible for practical purposes.
- Parameters:
parent – Parent node. Must be a GP variant.
step (float) – Size of the step at each iteration.
n_steps (int) – Number of steps.
name (str) – A name for this node.
- cache_prediction_state()[source]
Snapshot the propagated state into Variables (see _state_var).
Called once per prediction (after refresh) for every node in the network. Subclasses holding additional prediction state extend this.
- propagate(x, x_var=None)[source]
Propagates mean and variance to the next node.
Also stamps the node’s sweep state: _explained_var always, and _sim_state wherever the node’s own simulate draws rather than transforms – simulations originate at GP nodes and are carried pathwise by the operation nodes above them, so an operation node’s simulate calls its parents’ instead of reading a stash.
- Parameters:
x (Tensor) – Mean of the input.
x_var (Tensor) – Variance of the input.
- Returns:
_Moments – The mean and the variance of the output, [n, size] each, which unpack as a pair; and, under the expected kernel and where a GP node reads the output, each expert’s chain in experts: the output’s moments as that expert alone gives them, and its covariance with the expert’s inducing points.
- refresh(jitter=1e-06)[source]
Updates the model’s internal state.
If called within TensorFlow’s eager mode, will allow inspection of the internal tensors.
- Parameters:
jitter (float) – Small value added to the covariance matrices for numerical stability.
- expert_kl_terms()[source]
Each active expert’s term of the walk’s KL, in the order of the active experts; under slots a tensor over the slots, to which a padded point adds nothing.
Under the marginal rule, the inducing points’ displacement against the walk’s own spread where they land. Under the expected kernel the walk adds no random variable of its own, so nothing: the field’s KL prices the deformation. The displacement term did that job by a heuristic – calibration 1.97 to 1.26 on the folded section’s first seed, 2.24 on another – and an isotropic GP reading the walk scored -6.1 a new hole on three seeds against its -10.7.
- class geoml.latent.network.MultiStructureGP(parent, size=1, kernel=None, fix_range=False, n_structures=2, weight_concentration='staircase', range_prior=2.0, name=None)[source]
Bases:
BasicGPGaussian process with multiple structures.
A linear combination of multiple kernels with (possibly) different ranges. The difference between using this node and applying a linear combination externally is that here the combination is at the kernel level instead of the latent variable level.
- __init__(parent, size=1, kernel=None, fix_range=False, n_structures=2, weight_concentration='staircase', range_prior=2.0, name=None)[source]
Initializer for MultiStructureGP.
- Parameters:
parent – Parent node.
size (int) – Number of output functions.
kernel – The kernel to use for the covariance matrices. A fresh Gaussian if omitted.
fix_range (bool) – Whether to force a unit range for all input dimensions.
n_structures (int) – Number of kernels to combine (minimum 2).
weight_concentration (str, float, or None) – The Dirichlet prior on the structure weights, which stay point estimates – the prior’s log-density joins the training objective. “staircase” (the default) aligns the prior with the ranges: structure n starts with range 1 / (n + 1), and its weight’s share of the prior’s peak follows the same ordering, so mass sits on the long-range structure until the data moves it to the short ones. The weights themselves still start uniform – initializing them on the staircase was measured and rejected, since training never left that basin. A number gives a symmetric Dirichlet peaking at equal shares (it must exceed 1); None removes the prior, as in versions before 0.6.5.
range_prior (float, optional) – Strength of the Gamma priors on the ranges, one per structure, each peaking at that structure’s own starting range rather than at a common value – a shared peak would fight the staircase the structures exist for. None removes them.
name (str) – A name for this node.
- expected_covariance(mean_x, var_x, mean_y, var_y, cov=None, gradient=False)[source]
The covariance between two sets of uncertain inputs under the expected kernel: mean_x […, n, d], mean_y […, m, d], their variances alike or None, and their covariance […, n, m, d] or None. Returns […, n, m], and with gradient its derivative in mean_x, […, n, m, d].
- class geoml.latent.network.GradientConstrainedInput(inducing_points, directional_data, covariance, size=1, fix_covariance=False, name=None)[source]
Bases:
_RootLatentVariableInputs constrained by structural data.
This node uses a set of directional data to constrain the output’s gradient. The output GP is considered to have zero gradient in the specified directions, flowing only in the orthogonal direction.
- __init__(inducing_points, directional_data, covariance, size=1, fix_covariance=False, name=None)[source]
Initializer for GradientConstrainedInput.
The locations of the provided directional_data will be added to the inducing points set to better constrain the output.
- Parameters:
inducing_points – A PointData object, or a list of these objects.
directional_data – A DirectionalData object, or a list of these objects.
covariance – A covariance object, containing a kernel and transform.
size (int) – Number of output variables.
fix_covariance (bool) – Whether to fix the covariance’s parameters during training.
name (str) – A name for this node.
- refresh(jitter=1e-06)[source]
Updates the model’s internal state.
If called within TensorFlow’s eager mode, will allow inspection of the internal tensors.
- Parameters:
jitter (float) – Small value added to the covariance matrices for numerical stability.
- cache_prediction_state()[source]
Snapshot the propagated state into Variables (see _state_var).
Called once per prediction (after refresh) for every node in the network. Subclasses holding additional prediction state extend this.
- propagate(x, x_var=None)[source]
Propagates mean and variance to the next node.
Also stamps the node’s sweep state: _explained_var always, and _sim_state wherever the node’s own simulate draws rather than transforms – simulations originate at GP nodes and are carried pathwise by the operation nodes above them, so an operation node’s simulate calls its parents’ instead of reading a stash.
- Parameters:
x (Tensor) – Mean of the input.
x_var (Tensor) – Variance of the input.
- Returns:
_Moments – The mean and the variance of the output, [n, size] each, which unpack as a pair; and, under the expected kernel and where a GP node reads the output, each expert’s chain in experts: the output’s moments as that expert alone gives them, and its covariance with the expert’s inducing points.
Gaussian process nodes
- class geoml.latent.network.BasicGP(parent, size=1, kernel=None, fix_range=False, isotropic=False, range_prior=2.0, name=None)[source]
Bases:
_GPNodeStandard Gaussian process node.
In this module, GP nodes are able to work with inputs that may be Gaussian, having an associated variance. This variance is integrated by considering it as a squared range and applying the non-stationary covariance.
- __init__(parent, size=1, kernel=None, fix_range=False, isotropic=False, range_prior=2.0, name=None)[source]
Initializer for BasicGP.
- Parameters:
parent – Parent node.
size – Number of output latent variables
kernel – The kernel to use for the covariance matrices. A fresh Gaussian if omitted.
fix_range (bool) – Whether to force a unit range for all input dimensions.
isotropic (bool) – If True, forces the same range for all input dimensions.
range_prior (float, optional) – Strength of the Gamma prior that regularizes the ranges, which stay point estimates – the prior’s log-density joins the training objective. It peaks at 1, the natural scale of the whitened space every node works in, falls hard as a range collapses toward zero and gently as it grows. Larger values hold on tighter; None removes it, leaving the ranges to the data alone as in versions before 0.6.5.
name (str) – A name for this node, shown in the printed network and accepted by get_node. Numbered automatically if omitted.
- refresh(jitter=1e-06)[source]
Updates the model’s internal state.
If called within TensorFlow’s eager mode, will allow inspection of the internal tensors.
- Parameters:
jitter (float) – Small value added to the covariance matrices for numerical stability.
- cache_prediction_state()[source]
Snapshot the propagated state into Variables (see _state_var).
Called once per prediction (after refresh) for every node in the network. Subclasses holding additional prediction state extend this.
- expected_covariance(mean_x, var_x, mean_y, var_y, cov=None, gradient=False)[source]
The covariance between two sets of uncertain inputs under the expected kernel: mean_x […, n, d], mean_y […, m, d], their variances alike or None, and their covariance […, n, m, d] or None. Returns […, n, m], and with gradient its derivative in mean_x, […, n, m, d].
- class geoml.latent.network.AdditiveGP(parent, size=1, kernel=None, fix_range=False, isotropic=False, range_prior=2.0, name=None)[source]
Bases:
BasicGPAdditive GP node.
This node is similar to the BasicGP, with the difference that is covariance matrices are computed separately for each input dimension and then averaged. It makes more sense to use it on high-dimensional non-spatial inputs.
- expected_covariance(mean_x, var_x, mean_y, var_y, cov=None, gradient=False)[source]
The covariance between two sets of uncertain inputs under the expected kernel: mean_x […, n, d], mean_y […, m, d], their variances alike or None, and their covariance […, n, m, d] or None. Returns […, n, m], and with gradient its derivative in mean_x, […, n, m, d].
- class geoml.latent.network.UncertainInputGP(parent, size=1, kernel=None, fix_range=False, isotropic=False, range_prior=2.0, n_nodes=32, name=None)[source]
Bases:
BasicGPGP node that integrates over the uncertainty of its input by quadrature. Deprecated.
Deprecated since 0.9.0, and to be removed: under the expected kernel (GPOptions(propagation=”joint”), the default for a new model) a BasicGP on an uncertain input takes the mixture’s moments in closed form, more closely than this node’s quadrature, and the likelihood integrates what its realizations leave out. Under the old rule BasicGP reads an uncertain input through an inflated covariance – Paciorek’s nonstationary form – and takes its moments as if the input were one point under that kernel, which understates the predictive variance several times over and misplaces the mean once the input variance reaches a tenth of the squared range. This node computes the mixture instead: n_nodes scrambled Sobol points of the input’s Gaussian, the deterministic posterior at each of them, and the mixture’s moments out – the mean of the means, the mean of the variances plus the variance of the means. Each realization is drawn at a node of its own, so the simulations carry the mixture as well. Nothing depends on the kernel.
- Parameters:
parent – The node whose output is the input. Its variance is what is integrated over: a GaussianInput root, or any GP node above.
size – Number of latent variables.
kernel – A kernel object from geoml.kernels.
fix_range – Whether to fix the range parameters.
isotropic – Whether to use a single range for every input dimension.
range_prior – As in BasicGP.
n_nodes – Quadrature points per input. A power of two keeps the Sobol sequence balanced.
name – A name for this node, shown in the printed network and accepted by get_node. Numbered automatically if omitted.
See also
BasicGPthe node this extends.
GaussianInputthe root that supplies an input variance.
Notes
The cost is n_nodes cross-covariances per prediction or training step where BasicGP computes one, and the same factor in memory for them. Given an input with no variance the node is BasicGP.
- class geoml.latent.network.MultiStructureGP(parent, size=1, kernel=None, fix_range=False, n_structures=2, weight_concentration='staircase', range_prior=2.0, name=None)[source]
Bases:
BasicGPGaussian process with multiple structures.
A linear combination of multiple kernels with (possibly) different ranges. The difference between using this node and applying a linear combination externally is that here the combination is at the kernel level instead of the latent variable level.
- __init__(parent, size=1, kernel=None, fix_range=False, n_structures=2, weight_concentration='staircase', range_prior=2.0, name=None)[source]
Initializer for MultiStructureGP.
- Parameters:
parent – Parent node.
size (int) – Number of output functions.
kernel – The kernel to use for the covariance matrices. A fresh Gaussian if omitted.
fix_range (bool) – Whether to force a unit range for all input dimensions.
n_structures (int) – Number of kernels to combine (minimum 2).
weight_concentration (str, float, or None) – The Dirichlet prior on the structure weights, which stay point estimates – the prior’s log-density joins the training objective. “staircase” (the default) aligns the prior with the ranges: structure n starts with range 1 / (n + 1), and its weight’s share of the prior’s peak follows the same ordering, so mass sits on the long-range structure until the data moves it to the short ones. The weights themselves still start uniform – initializing them on the staircase was measured and rejected, since training never left that basin. A number gives a symmetric Dirichlet peaking at equal shares (it must exceed 1); None removes the prior, as in versions before 0.6.5.
range_prior (float, optional) – Strength of the Gamma priors on the ranges, one per structure, each peaking at that structure’s own starting range rather than at a common value – a shared peak would fight the staircase the structures exist for. None removes them.
name (str) – A name for this node.
- expected_covariance(mean_x, var_x, mean_y, var_y, cov=None, gradient=False)[source]
The covariance between two sets of uncertain inputs under the expected kernel: mean_x […, n, d], mean_y […, m, d], their variances alike or None, and their covariance […, n, m, d] or None. Returns […, n, m], and with gradient its derivative in mean_x, […, n, m, d].
Combining and reshaping
- class geoml.latent.network.Add(*latent_variables, name=None)[source]
Bases:
_OperationThe sum of latent variables of one size, output by output.
Means, variances and realizations add up, the parents taken as independent. Inducing points pass through, summed, when every parent passes its own on and all of them grow from one input, so a GP can sit on the sum – a trend plus a residual, or structures at several scales.
- Parameters:
latent_variables – The latent variables to add, all of the same size.
name – The node’s name, numbered within the tree.
- refresh(jitter=1e-06)[source]
Updates the model’s internal state.
If called within TensorFlow’s eager mode, will allow inspection of the internal tensors.
- Parameters:
jitter (float) – Small value added to the covariance matrices for numerical stability.
- propagate(x, x_var=None)[source]
Propagates mean and variance to the next node.
Also stamps the node’s sweep state: _explained_var always, and _sim_state wherever the node’s own simulate draws rather than transforms – simulations originate at GP nodes and are carried pathwise by the operation nodes above them, so an operation node’s simulate calls its parents’ instead of reading a stash.
- Parameters:
x (Tensor) – Mean of the input.
x_var (Tensor) – Variance of the input.
- Returns:
_Moments – The mean and the variance of the output, [n, size] each, which unpack as a pair; and, under the expected kernel and where a GP node reads the output, each expert’s chain in experts: the output’s moments as that expert alone gives them, and its covariance with the expert’s inducing points.
- class geoml.latent.network.Multiply(*latent_variables, name=None)[source]
Bases:
_OperationThe product of latent variables of one size, output by output.
The mean and variance are those of a product of independent variables, and each realization is the product of the parents’ realizations. The usual use is an amplitude times a field, the amplitude an Exponentiation. A product of Gaussians is not Gaussian, so no inducing points pass through it.
- Parameters:
latent_variables – The latent variables to multiply, all of the same size.
name – The node’s name, numbered within the tree.
- refresh(jitter=1e-06)[source]
Updates the model’s internal state.
If called within TensorFlow’s eager mode, will allow inspection of the internal tensors.
- Parameters:
jitter (float) – Small value added to the covariance matrices for numerical stability.
- propagate(x, x_var=None)[source]
Propagates mean and variance to the next node.
Also stamps the node’s sweep state: _explained_var always, and _sim_state wherever the node’s own simulate draws rather than transforms – simulations originate at GP nodes and are carried pathwise by the operation nodes above them, so an operation node’s simulate calls its parents’ instead of reading a stash.
- Parameters:
x (Tensor) – Mean of the input.
x_var (Tensor) – Variance of the input.
- Returns:
_Moments – The mean and the variance of the output, [n, size] each, which unpack as a pair; and, under the expected kernel and where a GP node reads the output, each expert’s chain in experts: the output’s moments as that expert alone gives them, and its covariance with the expert’s inducing points.
- class geoml.latent.network.LinearCombination(*latent_variables, unit_variance=True, per_component=False, weight_concentration=2.0, name=None)[source]
Bases:
_OperationLinear combination.
This node combines the inputs linearly with positive weights.
- __init__(*latent_variables, unit_variance=True, per_component=False, weight_concentration=2.0, name=None)[source]
Initializer for LinearCombination.
- Parameters:
latent_variables – Nodes to combine. They must all have the same number of variables.
unit_variance (bool) – If True, constrains the weights to unit sum to control the variance of the output.
per_component (bool) – One set of mixing weights per output component instead of one for the whole node, so each component takes its own share of each parent – one element can lean on a trend that another ignores. Requires unit_variance, and multiplies the weight count by size, which is why the prior below comes with it.
weight_concentration (float, optional) – Concentration of the symmetric Dirichlet prior on each component’s weights (per_component=True only – the shared weights are few enough to need none). The weights stay point estimates; the prior’s log-density joins the training objective, holding each component’s shares near equal until its data argues otherwise. Must exceed 1 for the pull to point at equal shares; None removes it.
name (str) – A name for this node.
- refresh(jitter=1e-06)[source]
Updates the model’s internal state.
If called within TensorFlow’s eager mode, will allow inspection of the internal tensors.
- Parameters:
jitter (float) – Small value added to the covariance matrices for numerical stability.
- propagate(x, x_var=None)[source]
Propagates mean and variance to the next node.
Also stamps the node’s sweep state: _explained_var always, and _sim_state wherever the node’s own simulate draws rather than transforms – simulations originate at GP nodes and are carried pathwise by the operation nodes above them, so an operation node’s simulate calls its parents’ instead of reading a stash.
- Parameters:
x (Tensor) – Mean of the input.
x_var (Tensor) – Variance of the input.
- Returns:
_Moments – The mean and the variance of the output, [n, size] each, which unpack as a pair; and, under the expected kernel and where a GP node reads the output, each expert’s chain in experts: the output’s moments as that expert alone gives them, and its covariance with the expert’s inducing points.
- class geoml.latent.network.Linear(parent, size=1, unit_norm=True, weight_prior=1.0, name=None)[source]
Bases:
_FunctionalLatentVariableLinear node.
This node outputs one or more linear combinations of the inputs. Its role in a network depends on its position. Close to a root node it induces rotation in the coordinates. At the end it induces correlations between the outputs, and in the middle it can serve as an information bottleneck.
- __init__(parent, size=1, unit_norm=True, weight_prior=1.0, name=None)[source]
Initializer for Linear.
- Parameters:
parent – Parent node
size – Number of output latent variables.
unit_norm (bool) – Whether the weights should form a unit norm vector. If False, the weights are free and regularized by weight_prior.
weight_prior (float, optional) – Standard deviation of the zero-mean Gaussian prior on the free weights (unit_norm=False only – the unit norm is constraint enough on its own). The weights stay point estimates; the prior’s log-density joins the training objective, so a weight grows only while the data pays for it, which matters because this is the parameter whose count scales with the network (parent.size times size) and no KL prices it. The standard deviation of 1 matches the whitened scale the network works in. None removes the prior and restores the hard [-1, 1] walls of versions before 0.6.5.
name (str) – A name for this node.
- refresh(jitter=1e-06)[source]
Updates the model’s internal state.
If called within TensorFlow’s eager mode, will allow inspection of the internal tensors.
- Parameters:
jitter (float) – Small value added to the covariance matrices for numerical stability.
- propagate(x, x_var=None)[source]
Propagates mean and variance to the next node.
Also stamps the node’s sweep state: _explained_var always, and _sim_state wherever the node’s own simulate draws rather than transforms – simulations originate at GP nodes and are carried pathwise by the operation nodes above them, so an operation node’s simulate calls its parents’ instead of reading a stash.
- Parameters:
x (Tensor) – Mean of the input.
x_var (Tensor) – Variance of the input.
- Returns:
_Moments – The mean and the variance of the output, [n, size] each, which unpack as a pair; and, under the expected kernel and where a GP node reads the output, each expert’s chain in experts: the output’s moments as that expert alone gives them, and its covariance with the expert’s inducing points.
- class geoml.latent.network.ProductOfExperts(*latent_variables, name=None)[source]
Bases:
_OperationProduct of Experts.
The Product of Experts combines latent variables from different nodes with weights inversely proportional to the local variance. It is more useful when combining the outputs of smaller networks with different set of inducing points, allowing each one to focus on a region of space.
This node treats its parents independently. Means and variances will be “stiched” smoothly, but individual simulations may exhibit artifacts.
This node is not capable of propagating inducing points.
- __init__(*latent_variables, name=None)[source]
Initializer for ProductOfExperts.
- Parameters:
latent_variables – Parent nodes to combine.
name (str) – A name for this node.
- refresh(jitter=1e-06)[source]
Updates the model’s internal state.
If called within TensorFlow’s eager mode, will allow inspection of the internal tensors.
- Parameters:
jitter (float) – Small value added to the covariance matrices for numerical stability.
- propagate(x, x_var=None)[source]
Propagates mean and variance to the next node.
Also stamps the node’s sweep state: _explained_var always, and _sim_state wherever the node’s own simulate draws rather than transforms – simulations originate at GP nodes and are carried pathwise by the operation nodes above them, so an operation node’s simulate calls its parents’ instead of reading a stash.
- Parameters:
x (Tensor) – Mean of the input.
x_var (Tensor) – Variance of the input.
- Returns:
_Moments – The mean and the variance of the output, [n, size] each, which unpack as a pair; and, under the expected kernel and where a GP node reads the output, each expert’s chain in experts: the output’s moments as that expert alone gives them, and its covariance with the expert’s inducing points.
- class geoml.latent.network.GaussianMixture(weights, components, n_nodes=64, name=None)[source]
Bases:
_OperationA mixture of latent variables, weighted by the softmax of others.
weights holds one latent variable per component, in the components’ order: the first latent variable of weights weighs the first component, the second the second, and so on. At every location the softmax of the weights, scaled by a trained amplitude, gives each component its share, and the output is the components’ sum under those shares – a field that follows one component where its weight dominates and passes smoothly to another where the weights change places. The amplitude sets how sharp the passage is: a large one makes each realization nearly one component at a time, a small one blends them.
The mixture is computed realization by realization, from the realizations of the weights and of the components, so it keeps whatever those share through common parents. The output is not Gaussian: a model trains the likelihood of a leaf above this node on its realizations, and no inducing points pass through it.
- Parameters:
weights – A node of one latent variable per component, in the order of components.
components – Two or more nodes of one common size, which is the output’s size. Their order is the order of the weights’ latent variables.
n_nodes – Quadrature points over the weights for the moments. A power of two keeps the Sobol sequence balanced.
name – A name for this node, shown in the printed network and accepted by get_node. Numbered automatically if omitted.
- Raises:
SizeIncompatibilityError – If the weights do not have one latent variable per component, or the components differ in size.
See also
ProductOfExpertscomponents weighted by their own variances.
geoml.likelihood.Mixturea mixture of noise laws, not of fields.
Notes
A component as flexible as the field it blends can fit every regime on its own, and then the weights never switch: give the components a smoother structure than the passage between regimes (a longer range).
The mean and variance take the weights as independent of the components, and each weight as independent of the others: the softmax is averaged over n_nodes scrambled Sobol points of the weights’ marginal Gaussians. Where the weights and the components share a parent the moments miss that correlation; the realizations do not.
- refresh(jitter=1e-06)[source]
Updates the model’s internal state.
If called within TensorFlow’s eager mode, will allow inspection of the internal tensors.
- Parameters:
jitter (float) – Small value added to the covariance matrices for numerical stability.
- propagate(x, x_var=None)[source]
Propagates mean and variance to the next node.
Also stamps the node’s sweep state: _explained_var always, and _sim_state wherever the node’s own simulate draws rather than transforms – simulations originate at GP nodes and are carried pathwise by the operation nodes above them, so an operation node’s simulate calls its parents’ instead of reading a stash.
- Parameters:
x (Tensor) – Mean of the input.
x_var (Tensor) – Variance of the input.
- Returns:
_Moments – The mean and the variance of the output, [n, size] each, which unpack as a pair; and, under the expected kernel and where a GP node reads the output, each expert’s chain in experts: the output’s moments as that expert alone gives them, and its covariance with the expert’s inducing points.
- class geoml.latent.network.Stack(*latent_variables, name=None)[source]
Bases:
_OperationLatent variable stacking.
Consolidates a list of latent variables into a single object.
- propagate(x, x_var=None)[source]
Propagates mean and variance to the next node.
Also stamps the node’s sweep state: _explained_var always, and _sim_state wherever the node’s own simulate draws rather than transforms – simulations originate at GP nodes and are carried pathwise by the operation nodes above them, so an operation node’s simulate calls its parents’ instead of reading a stash.
- Parameters:
x (Tensor) – Mean of the input.
x_var (Tensor) – Variance of the input.
- Returns:
_Moments – The mean and the variance of the output, [n, size] each, which unpack as a pair; and, under the expected kernel and where a GP node reads the output, each expert’s chain in experts: the output’s moments as that expert alone gives them, and its covariance with the expert’s inducing points.
- simulate(n_sim, seed=(0, 0))[source]
Draws from the state the same sweep’s propagate stamped.
- Parameters:
n_sim (int) – Number of simulations to draw.
seed (tuple) – A set of two seeds for the random number generator.
- Returns:
sims – Simulations of shape [size, n_data, n_sim].
- class geoml.latent.network.Concatenate(*latent_variables, name=None)[source]
Bases:
StackLatent variable concatenation.
Consolidates a list of latent variables into a single object. This operation requires all its parent nodes to be able to propagate inducing points.
- class geoml.latent.network.SelectInput(parent, columns, name=None)[source]
Bases:
_FunctionalLatentVariableVariable selection.
Returns the specified columns of the input, discarding the others.
- __init__(parent, columns, name=None)[source]
Initializer for SelectInput.
- Parameters:
parent – Parent node.
columns (list) – List of indices to retain.
name (str) – A name for this node.
- propagate(x, x_var=None)[source]
Propagates mean and variance to the next node.
Also stamps the node’s sweep state: _explained_var always, and _sim_state wherever the node’s own simulate draws rather than transforms – simulations originate at GP nodes and are carried pathwise by the operation nodes above them, so an operation node’s simulate calls its parents’ instead of reading a stash.
- Parameters:
x (Tensor) – Mean of the input.
x_var (Tensor) – Variance of the input.
- Returns:
_Moments – The mean and the variance of the output, [n, size] each, which unpack as a pair; and, under the expected kernel and where a GP node reads the output, each expert’s chain in experts: the output’s moments as that expert alone gives them, and its covariance with the expert’s inducing points.
- simulate(n_sim, seed=(0, 0))[source]
Draws from the state the same sweep’s propagate stamped.
- Parameters:
n_sim (int) – Number of simulations to draw.
seed (tuple) – A set of two seeds for the random number generator.
- Returns:
sims – Simulations of shape [size, n_data, n_sim].
Shaping a field
- class geoml.latent.network.Bias(parent, scale=5, name=None)[source]
Bases:
_FunctionalLatentVariableAdds a deterministic constant to its input.
- refresh(jitter=1e-06)[source]
Updates the model’s internal state.
If called within TensorFlow’s eager mode, will allow inspection of the internal tensors.
- Parameters:
jitter (float) – Small value added to the covariance matrices for numerical stability.
- propagate(x, x_var=None)[source]
Propagates mean and variance to the next node.
Also stamps the node’s sweep state: _explained_var always, and _sim_state wherever the node’s own simulate draws rather than transforms – simulations originate at GP nodes and are carried pathwise by the operation nodes above them, so an operation node’s simulate calls its parents’ instead of reading a stash.
- Parameters:
x (Tensor) – Mean of the input.
x_var (Tensor) – Variance of the input.
- Returns:
_Moments – The mean and the variance of the output, [n, size] each, which unpack as a pair; and, under the expected kernel and where a GP node reads the output, each expert’s chain in experts: the output’s moments as that expert alone gives them, and its covariance with the expert’s inducing points.
- class geoml.latent.network.Scale(parent, name=None)[source]
Bases:
_FunctionalLatentVariableScale.
Multiplies its input by a constant. The variance is multiplied by the square of the same value.
- refresh(jitter=1e-06)[source]
Updates the model’s internal state.
If called within TensorFlow’s eager mode, will allow inspection of the internal tensors.
- Parameters:
jitter (float) – Small value added to the covariance matrices for numerical stability.
- propagate(x, x_var=None)[source]
Propagates mean and variance to the next node.
Also stamps the node’s sweep state: _explained_var always, and _sim_state wherever the node’s own simulate draws rather than transforms – simulations originate at GP nodes and are carried pathwise by the operation nodes above them, so an operation node’s simulate calls its parents’ instead of reading a stash.
- Parameters:
x (Tensor) – Mean of the input.
x_var (Tensor) – Variance of the input.
- Returns:
_Moments – The mean and the variance of the output, [n, size] each, which unpack as a pair; and, under the expected kernel and where a GP node reads the output, each expert’s chain in experts: the output’s moments as that expert alone gives them, and its covariance with the expert’s inducing points.
- class geoml.latent.network.Exponentiation(parent, name=None)[source]
Bases:
_FunctionalLatentVariableThe exponential of a latent variable: a field that is always positive.
Each output is
exp(sqrt(amp_scale) * f + amp_mean)of its parent’s outputf, the two parameters trained, and its moments are those of the log-normal that makes. Meant as an amplitude multiplied into another branch, so a field’s variability can change from place to place. The output is no longer Gaussian, so no inducing points pass through it and nothing that needs them can sit above it.- Parameters:
parent – The latent variable to exponentiate; the output has its size.
name – The node’s name, numbered within the tree.
- propagate(x, x_var=None)[source]
Propagates mean and variance to the next node.
Also stamps the node’s sweep state: _explained_var always, and _sim_state wherever the node’s own simulate draws rather than transforms – simulations originate at GP nodes and are carried pathwise by the operation nodes above them, so an operation node’s simulate calls its parents’ instead of reading a stash.
- Parameters:
x (Tensor) – Mean of the input.
x_var (Tensor) – Variance of the input.
- Returns:
_Moments – The mean and the variance of the output, [n, size] each, which unpack as a pair; and, under the expected kernel and where a GP node reads the output, each expert’s chain in experts: the output’s moments as that expert alone gives them, and its covariance with the expert’s inducing points.
- class geoml.latent.network.RadialTrend(parent, size=1, name=None)[source]
Bases:
_FunctionalLatentVariableRadial trend.
This node outputs a (hyper)spherical deterministic function, positive on the inside and negative on the outside. It can be made ellipsoidal or with a more complex shape depending on its parent nodes. Its main use is for implicit geological modelling.
It will ignore the variance of its inputs.
- __init__(parent, size=1, name=None)[source]
Initializer for RadialTrend.
- Parameters:
parent – Parent node.
size (int) – Number of output functions to generate.
name (str) – A name for this node.
- refresh(jitter=1e-06)[source]
Updates the model’s internal state.
If called within TensorFlow’s eager mode, will allow inspection of the internal tensors.
- Parameters:
jitter (float) – Small value added to the covariance matrices for numerical stability.
- propagate(x, x_var=None)[source]
Propagates mean and variance to the next node.
Also stamps the node’s sweep state: _explained_var always, and _sim_state wherever the node’s own simulate draws rather than transforms – simulations originate at GP nodes and are carried pathwise by the operation nodes above them, so an operation node’s simulate calls its parents’ instead of reading a stash.
- Parameters:
x (Tensor) – Mean of the input.
x_var (Tensor) – Variance of the input.
- Returns:
_Moments – The mean and the variance of the output, [n, size] each, which unpack as a pair; and, under the expected kernel and where a GP node reads the output, each expert’s chain in experts: the output’s moments as that expert alone gives them, and its covariance with the expert’s inducing points.
- class geoml.latent.network.GPWalk(parent, step=0.01, n_steps=10, name=None)[source]
Bases:
_FunctionalLatentVariableA walk along an uncertain vector field.
This node uses the vector field defined by its parent to move points in space: n_steps steps of step times the field, scaled by a trained amplitude, the field read again where each step lands. It learns non-stationary patterns – a GP above it reads coordinates that the field has stretched and folded – at the cost of the steps.
The node’s parent (a GP) defines the vector field and the parent’s parent contains the coordinates that will be moved. Both must have the same size.
Under the expected kernel (GPOptions(propagation=”joint”), the default since 0.9.0) the field is one random field, the same at every step: a point carries its uncertainty and its covariance with every other point along, the field is read under the expected kernel with the uncertainty accumulated so far – so an uncertain walker reads a weaker field and slows down – and more steps refine the path rather than adding noise. step * n_steps * amp is the walk’s reach. The field’s variance that its inducing points leave unexplained – the whole prior far from them – moves each point on its own, so far from the data a walk is uncertain. Each realization walks a realization of the field. The walk adds no random variable of its own: the field’s KL prices the deformation. Under the marginal rule of the versions before, a KL term prices the inducing points’ displacement against the walk’s spread instead, and precision shrinks the variance at each step; both are deprecated, and ignored here.
Build the GP that reads the walk with isotropic=True. The walk already bends the space, so a range per dimension in its reader is a second way to say the same thing, and training settles the trade on a reader stretched along one axis over a near-certain walk – intervals too narrow on new data. The anisotropy the model starts from belongs in the input’s transform, where it carries what is known beforehand, and the reader’s one range is relative to it.
- __init__(parent, step=0.01, n_steps=10, name=None)[source]
Initializer for GPWalk.
In principle the step argument does not need to be changed, as the underlying GP tends to adjust its amplitude to take larger or smaller steps in practice. A higher n_steps allows the model to have finer control of the points’ trajectories at a higher computational cost. n_steps=5 seems to be the minimum possible for practical purposes.
- Parameters:
parent – Parent node. Must be a GP variant.
step (float) – Size of the step at each iteration.
n_steps (int) – Number of steps.
name (str) – A name for this node.
- cache_prediction_state()[source]
Snapshot the propagated state into Variables (see _state_var).
Called once per prediction (after refresh) for every node in the network. Subclasses holding additional prediction state extend this.
- propagate(x, x_var=None)[source]
Propagates mean and variance to the next node.
Also stamps the node’s sweep state: _explained_var always, and _sim_state wherever the node’s own simulate draws rather than transforms – simulations originate at GP nodes and are carried pathwise by the operation nodes above them, so an operation node’s simulate calls its parents’ instead of reading a stash.
- Parameters:
x (Tensor) – Mean of the input.
x_var (Tensor) – Variance of the input.
- Returns:
_Moments – The mean and the variance of the output, [n, size] each, which unpack as a pair; and, under the expected kernel and where a GP node reads the output, each expert’s chain in experts: the output’s moments as that expert alone gives them, and its covariance with the expert’s inducing points.
- refresh(jitter=1e-06)[source]
Updates the model’s internal state.
If called within TensorFlow’s eager mode, will allow inspection of the internal tensors.
- Parameters:
jitter (float) – Small value added to the covariance matrices for numerical stability.
- expert_kl_terms()[source]
Each active expert’s term of the walk’s KL, in the order of the active experts; under slots a tensor over the slots, to which a padded point adds nothing.
Under the marginal rule, the inducing points’ displacement against the walk’s own spread where they land. Under the expected kernel the walk adds no random variable of its own, so nothing: the field’s KL prices the deformation. The displacement term did that job by a heuristic – calibration 1.97 to 1.26 on the folded section’s first seed, 2.24 on another – and an isotropic GP reading the walk scored -6.1 a new hole on three seeds against its -10.7.
When nodes do not fit together
- exception geoml.latent.network.NodeIncompatibilityError[source]
Bases:
ExceptionException raised for incompatibilities between a node and its parents/children.
- exception geoml.latent.network.BrokenPropagationError[source]
Bases:
NodeIncompatibilityErrorException raised when inducing points can’t be propagated through nodes.
- exception geoml.latent.network.SizeIncompatibilityError[source]
Bases:
NodeIncompatibilityErrorException raised for incompatibilities in the number of latent variables in nodes.