geoml.stats

The package generator

One seed governs everything: call set_seed() before the objects are built, and parameter initialization, the training draws and the simulation stream all follow from it. A model’s options draw their own seed from this generator at construction, and a saved model keeps the number it drew, so its simulations replay on reload.

The generator that every random initialization draws from.

Parameters are initialized at random when an object is built — a latent node, a kernel’s transform, an orthonormal matrix — which happens before any model exists to carry options.seed. So the draws come from one generator held here, seeded with set_seed before the objects are built:

import geoml geoml.set_seed(1234)

latent = geoml.latent.BasicGP(data, kernel=kernel) model = geoml.models.VGPNetwork(data, variables, likelihoods, latent)

Building the same objects again after the same call gives the same starting parameters. Left alone, the generator is seeded from the operating system, so each run differs — as it did before.

Training and prediction reach this generator through one more step: a model’s options draw their seed from here when built, and stateless TensorFlow sampling turns that one number into every training draw and simulation. So the call above is the single knob — it fixes the initial parameters, the training trajectory and the simulation stream alike, and a saved model keeps the seed it drew.

geoml.stats.random.set_seed(seed)[source]

Seeds the generator used to initialize parameters.

Parameters:

seed (int) – The seed. None draws a fresh one from the operating system, which is how the generator starts out.

Notes

This must be called before the objects are built, since that is when the initial values are drawn. It replaces the generator, so anything already built keeps the values it was given.

geoml.stats.random.rng()[source]

The generator every random initialization draws from.

Returns:

numpy.random.Generator

geoml.stats.random.sobol_engine(dimension, seed)[source]

A scrambled Sobol engine, however SciPy spells its seed argument.

SciPy is renaming that argument from seed to rng (SPEC 7): the new name works today and the old one is on its way out, so both are tried here and the same call runs either side of the change. The sequence a given SciPy produces is unaffected – the scramble is drawn from the same seed by the same construction under either name.

Parameters:
  • dimension (int) – How many dimensions the points have.

  • seed (int or numpy.random.Generator) – What the scramble is drawn from, so that the rule is fixed rather than random.

Returns:

scipy.stats.qmc.Sobol

Distributions

Custom TensorFlow-Probability distributions, used by the likelihoods and the spline warpings.

class geoml.stats.probability.EpsilonInsensitive(loc, scale, epsilon, validate_args=False, allow_nan_stats=True, name='EpsilonInsensitive')[source]

Bases: Distribution

A custom implementation of the Epsilon Insensitive distribution (Gonçalves et al., 2022).

__init__(loc, scale, epsilon, validate_args=False, allow_nan_stats=True, name='EpsilonInsensitive')[source]

Initialize the distribution.

Args:

loc: The mean (mu) of the distribution. scale: The rate (c) of the distribution. epsilon: The insensitivity parameter.

property loc

Distribution parameter for the mean.

property scale

Distribution parameter for the standard deviation.

property epsilon

Distribution parameter for the insensitivity.

property parameters

Returns a dict of parameters.

class geoml.stats.probability.Huber(loc, scale, epsilon, validate_args=False, allow_nan_stats=True, name='Huber')[source]

Bases: EpsilonInsensitive

Based on the Huber loss.

__init__(loc, scale, epsilon, validate_args=False, allow_nan_stats=True, name='Huber')[source]

Initialize the distribution.

Args:

loc: The mean (mu) of the distribution. scale: The rate (c) of the distribution. epsilon: The insensitivity parameter.

geoml.stats.probability.hazen_plotting_positions(n, dtype=tf.float64)[source]

Generates plotting positions using the Hazen formula. p_i = (i - 0.5) / n for i = 1, …, n

class geoml.stats.probability.SplineBased(x_sorted, prob, validate_args=False, allow_nan_stats=True, name='SplineBased')[source]

Bases: Distribution

A continuous distribution based on a sample ECDF.

The distribution is defined by: - A MonotonicSpline for the body (between min/max samples) - Exponential tails for extrapolation (below min / above max)

The tails are ‘stitched’ to the spline by matching the value and slope at the min/max sample points.

class geoml.stats.probability.SmoothEmpirical(samples, name='SmoothEmpirical')[source]

Bases: SplineBased

A continuous distribution based on a sample ECDF.

The distribution is defined by: - A MonotonicSpline for the body (between min/max samples) - Exponential tails for extrapolation (below min / above max)

The tails are ‘stitched’ to the spline by matching the value and slope at the min/max sample points.

geoml.stats.probability.hazen_binned_plotting_points(samples, num_bins, margin=0.05, pseudo_counts=1, dtype=tf.float64)[source]

Calculates K plotting points based on binned data.

Args:

samples: A 1D tensor of raw data. num_bins: The number of bins (K) to create. margin: The margin to use. pseudo_counts: The number of pseudo counts to use. dtype: The data type to use.

Returns:

(x_prime, p_prime): A tuple of K x-coordinates and K p-coordinates.

class geoml.stats.probability.BinnedEmpirical(samples, num_bins, margin=0.05, pseudo_counts=1, name='BinnedEmpirical')[source]

Bases: SplineBased

class geoml.stats.probability.EmpiricalGaussianMixture(samples, num_knots, batch_size=1000, epochs=None)[source]

Bases: object

Note

The distribution methods every TensorFlow-Probability distribution has – sample, log_prob, quantile and the rest – are left out above: their docstrings come from TFP’s own base class, which copies them into each subclass, and they document TFP rather than geoML. Read them in the TFP reference.