kinisi.diffusion#

Calculate the diffusion coefficient.

class kinisi.diffusion.Diffusion(dg)#

Bases: object

The class for the calcualtion of the self-diffusion coefficient.

Parameters:

dg (DataGroup) – A scipp.DataGroup object containing the relevant mean-squared displacement data and number of independent samples.

property covariance_matrix: Variable#
Returns:

The covariance matrix as a scipp object, with dimensions of time_interval1 and time_interval2.

bayesian_regression(start_dt, cond_max=1e+16, recondition=False, fit_intercept=True, n_samples=1000, n_walkers=32, n_burn=500, n_thin=10, progress=True, random_state=None)#

Perform the Bayesian regression with a linear model against the observed data.

Parameters:
  • start_dt (Variable) – The time at which the diffusion regime begins.

  • cond_max (float) – The maximum condition number of the covariance matrix. Optional, default is 1e16.

  • recondition (bool) – Whether to recondition the covariance matrix. Optional, default is False.

  • fit_intercept (bool) – Whether to fit an intercept. Optional, default is True.

  • n_samples (int) – The number of MCMC samples to take. Optional, default is 1000.

  • n_walkers (int) – The number of walkers to use in the MCMC. Optional, default is 32.

  • n_burn (int) – The number of burn-in samples to discard. Optional, default is 500.

  • n_thin (int) – The thinning factor for the MCMC samples. Optional, default is 10.

  • progress (bool) – Whether to show the progress bar. Optional, default is True.

  • random_state (RandomState) – The random state to use for the MCMC. Optional, default is None.

property D: Variable#
Returns:

The diffusion coefficient as a scipp object.

property D_J: Variable#
Returns:

The jump diffusion coefficient as a scipp object.

property sigma: Variable#
Returns:

The conductivity as a scipp object.

compute_covariance_matrix()#

Compute the covariance matrix for the diffusion coefficient calculation.

Return type:

Variable

Returns:

A scipp object containing the covariance matrix.

posterior_predictive(n_posterior_samples=None, n_predictive_samples=256, progress=True)#

Sample the posterior predictive distribution. The shape of the resulting array will be (n_posterior_samples * n_predictive_samples, start_dt).

Parameters:
  • n_posterior_samples (int) – Number of samples from the posterior distribution. Optional, default is the number of posterior samples.

  • n_predictive_samples (int) – Number of random samples per sample from the posterior distribution. Optional, default is 256.

  • progress (bool) – Show tqdm progress for sampling. Optional, default is True.

Return type:

Variable

Returns:

Samples from the posterior predictive distribution.

kinisi.diffusion.minimum_eigenvalue_method(cov, cond_max=1e+16)#

Implementation of the matrix reconditioning method known as the minimum eigenvalue method, as outlined in doi:10.1080/16000870.2019.1696646. This should produce a matrix with a condition number of cond_max based on the eigenvalues and eigenvectors of the input matrix.

Parameters:
  • matrix – Matrix to recondition.

  • cond_max – Expected condition number of output matrix. Optional, default is 1e16.

Return type:

ndarray

Returns:

Reconditioned matrix.

kinisi.diffusion.eigenvalue_clipping(cov)#

Eigenvalue clipping method for matrix reconditioning.

Parameters:

cov (ndarray) – Covariance matrix to recondition.

Return type:

ndarray

Returns:

Reconditioned covariance matrix.

kinisi.diffusion.marchenkopastur(x, lambda_, sigma)#

Marchenko-Pastur distribution

Parameters:
  • x (ndarray) – points at which to evaluate the distribution

  • lambda – lambda parameter

  • sigma (float) – standard deviation of the distribution

Return type:

ndarray