pyrolite.util.distributions

pyrolite.util.distributions.get_scaler(*fs)[source]

Generate a function which will transform columns of an array based on input functions (e.g. np.log will log-transform the x values, None, np.log will log-transform the y values but not the x).

Parameters

fs – A series of functions to apply to subsequent axes of an array.

pyrolite.util.distributions.sample_kde(data, samples, renorm=False, transform=<function <lambda>>, bw_method=None)[source]

Sample a Kernel Density Estimate at points or a grid defined.

Parameters
  • data (numpy.ndarray) – Source data to estimate the kernel density estimate; observations should be in rows (npoints, ndim).

  • samples (numpy.ndarray) – Coordinates to sample the KDE estimate at (npoints, ndim).

  • transform – Transformation used prior to kernel density estimate.

  • bw_method (str, float, callable) – Method used to calculate the estimator bandwidth. See scipy.stats.gaussian_kde().

Return type

numpy.ndarray

pyrolite.util.distributions.sample_ternary_kde(data, samples, transform=<function ILR>)[source]

Sample a Kernel Density Estimate in ternary space points or a grid defined by samples.

Parameters
  • data (numpy.ndarray) – Source data to estimate the kernel density estimate (npoints, ndim).

  • samples (numpy.ndarray) – Coordinates to sample the KDE estimate at (npoints, ndim)..

  • transform – Log-transformation used prior to kernel density estimate.

Return type

numpy.ndarray

pyrolite.util.distributions.lognorm_to_norm(mu, s)[source]

Calculate mean and variance for a normal random variable from the lognormal parameters mu and s.

Parameters
  • mu (float) – Parameter mu for the lognormal distribution.

  • s (float) – sigma for the lognormal distribution.

Returns

  • mean (float) – Mean of the normal distribution.

  • sigma (float) – Variance of the normal distribution.

pyrolite.util.distributions.norm_to_lognorm(mean, sigma, exp=True)[source]

Calculate mu and sigma parameters for a lognormal random variable with a given mean and variance. Lognormal with parameters mean and sigma.

Parameters
  • mean (float) – Mean of the normal distribution.

  • sigma (float) – sigma of the normal distribution.

  • exp (bool) – If using the scipy.stats parameterisation; this uses scale = np.exp(mu).

Returns

  • mu (float) – Parameter mu for the lognormal distribution.

  • s (float) – sigma of the lognormal distribution.