kinisi.diffusion#
Calculate the diffusion coefficient.
- class kinisi.diffusion.Diffusion(dg)#
Bases:
objectThe class for the calcualtion of the self-diffusion coefficient.
- Parameters:
dg (
DataGroup) – Ascipp.DataGroupobject containing the relevant mean-squared displacement data and number of independent samples.
- property covariance_matrix: Variable#
- Returns:
The covariance matrix as a
scippobject, 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 is1e16.recondition (
bool) – Whether to recondition the covariance matrix. Optional, default isFalse.fit_intercept (
bool) – Whether to fit an intercept. Optional, default isTrue.n_samples (
int) – The number of MCMC samples to take. Optional, default is1000.n_walkers (
int) – The number of walkers to use in the MCMC. Optional, default is32.n_burn (
int) – The number of burn-in samples to discard. Optional, default is500.n_thin (
int) – The thinning factor for the MCMC samples. Optional, default is10.progress (
bool) – Whether to show the progress bar. Optional, default isTrue.random_state (
RandomState) – The random state to use for the MCMC. Optional, default isNone.
- compute_covariance_matrix()#
Compute the covariance matrix for the diffusion coefficient calculation.
- Return type:
- Returns:
A
scippobject 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 is256.progress (
bool) – Show tqdm progress for sampling. Optional, default isTrue.
- Return type:
- 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_maxbased 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 distributionlambda – lambda parameter
sigma (
float) – standard deviation of the distribution
- Return type:
ndarray