-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
711 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,7 +38,7 @@ We then perform Bayesian regression to sample the distribution of linear models | |
<a href="https://orcid.org/0000-0001-9722-5676">Samuel W. Coles</a> | ||
and | ||
<a href="https://orcid.org/0000-0002-3056-8233">Benjamin J. Morgan</a>†<br> | ||
*<a href="mailto:[email protected]">andrew.mccluskey@ess.eu</a>/†<a href="mailto:[email protected]">[email protected]</a> | ||
*<a href="mailto:[email protected]">andrew.mccluskey@bristol.ac.uk</a>/†<a href="mailto:[email protected]">[email protected]</a> | ||
</p> | ||
|
||
--- | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Copyright (c) Andrew R. McCluskey | ||
# Distributed under the terms of the MIT License | ||
# author: Andrew R. McCluskey (arm61) | ||
|
||
import numpy as np | ||
from scipy.stats import linregress | ||
from scipy.linalg import pinvh | ||
from emcee import EnsembleSampler | ||
from scipy.optimize import minimize | ||
from kinisi.matrix import find_nearest_positive_definite | ||
from kinisi.diffusion import _straight_line | ||
|
||
np.random.seed(1) | ||
|
||
start_diff = snakemake.params['start_diff'] | ||
|
||
timestep = np.load(f'src/data/llzo/diffusion_0_{start_diff}.npz')['dt'][0, 0] | ||
no = np.load(f'src/data/llzo/diffusion_0_{start_diff}.npz')['no'][0, 0] | ||
d = np.zeros((16, 8, 1, timestep.size)) | ||
for i in range(0, 16, 1): | ||
d[i] = np.load(f'src/data/llzo/diffusion_{i}_{start_diff}.npz')['msd_true'] | ||
|
||
max_ngp = np.argwhere(timestep > start_diff)[0][0] | ||
true_msd = d.reshape(-1, d.shape[-1])[:, max_ngp:] | ||
true_cov = np.cov(true_msd.T) | ||
timestep = timestep[max_ngp:] | ||
|
||
y = true_msd.T | ||
A = np.array([timestep, np.ones(timestep.size)]).T | ||
W = true_cov | ||
V = np.diag(true_cov.diagonal()) | ||
|
||
g1 = np.matmul(np.linalg.inv(np.matmul(A.T, np.matmul(np.linalg.pinv(W), A))), | ||
np.matmul(A.T, np.matmul(np.linalg.pinv(W), y)))[0] / 6 | ||
c1 = np.sqrt(np.linalg.inv(np.matmul(A.T, np.matmul(np.linalg.pinv(W), A)))[0][0]) / 6 | ||
g2 = np.matmul(np.linalg.inv(np.matmul(A.T, np.matmul(np.linalg.pinv(V), A))), | ||
np.matmul(A.T, np.matmul(np.linalg.pinv(V), y)))[0] / 6 | ||
c2 = np.sqrt(np.linalg.inv(np.matmul(A.T, np.matmul(np.linalg.pinv(V), A)))[0][0]) / 6 | ||
g3 = np.matmul(np.linalg.inv(np.matmul(A.T, A)), np.matmul(A.T, y))[0] / 6 | ||
|
||
c3 = [] | ||
for i in true_msd: | ||
c3.append(linregress(timestep, i).stderr / 6) | ||
|
||
np.savez(f'src/data/llzo/glswlsols_{start_diff}.npz', | ||
gls_pop=g1, | ||
wls_pop=g2, | ||
ols_pop=g3, | ||
gls_est=c1, | ||
wls_est=c2, | ||
ols_est=np.mean(c3)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Copyright (c) Andrew R. McCluskey | ||
# Distributed under the terms of the MIT License | ||
# author: Andrew R. McCluskey (arm61) | ||
|
||
import numpy as np | ||
from kinisi.diffusion import MSDBootstrap | ||
from tqdm import tqdm | ||
from random_walk import get_disp3d, walk | ||
|
||
jump = snakemake.params['jump'] | ||
atoms = snakemake.params['atoms'] | ||
length = int(snakemake.params['length']) | ||
size = int(snakemake.params['n']) | ||
|
||
timestep = np.arange(1, length + 1, 1, dtype=int) | ||
data = np.zeros((size, timestep.size, 4)) | ||
covariance = np.zeros((size, timestep.size - 4, timestep.size - 4)) | ||
npd_covariance = np.zeros((size, timestep.size - 4, timestep.size - 4)) | ||
n_o = np.zeros((size, timestep.size)) | ||
diff_c = np.zeros((size, 3200)) | ||
intercept = np.zeros((size, 3200)) | ||
|
||
for seed in tqdm(range(size)): | ||
rng = np.random.RandomState(seed) | ||
np.random.seed(seed) | ||
disp_3d, n_samples = get_disp3d(walk, length, atoms, jump_size=jump, seed=rng) | ||
|
||
diff = MSDBootstrap(timestep, disp_3d, n_samples, random_state=rng, progress=False, block=True) | ||
diff.diffusion(5, model=False, random_state=rng, progress=False) | ||
diff_c[seed] = diff.gradient.samples / 6 | ||
intercept[seed] = diff.intercept.samples | ||
data[seed, :, 0] = diff.dt | ||
data[seed, :, 1] = diff.n | ||
data[seed, :, 2] = diff.s | ||
data[seed, 4:, 3] = diff._model_v | ||
npd_covariance[seed] = diff._npd_covariance_matrix | ||
covariance[seed] = diff.covariance_matrix | ||
n_o[seed] = diff._n_o | ||
|
||
np.savez(f'src/data/random_walks/pyblock_modelfree/rw_1_{atoms}_{length}_s{size}.npz', | ||
diff_c=diff_c, | ||
intercept=intercept, | ||
data=data, | ||
covariance=covariance, | ||
npd_covariance=npd_covariance, | ||
n_o=n_o) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Copyright (c) Andrew R. McCluskey | ||
# Distributed under the terms of the MIT License | ||
# author: Andrew R. McCluskey (arm61) | ||
|
||
import numpy as np | ||
from kinisi.diffusion import MSDBootstrap | ||
from tqdm import tqdm | ||
from random_walk import get_disp3d, walk | ||
|
||
jump = snakemake.params['jump'] | ||
atoms = snakemake.params['atoms'] | ||
length = int(snakemake.params['length']) | ||
size = int(snakemake.params['n']) | ||
|
||
timestep = np.arange(1, length + 1, 1, dtype=int) | ||
data = np.zeros((size, timestep.size, 4)) | ||
covariance = np.zeros((size, timestep.size - 4, timestep.size - 4)) | ||
npd_covariance = np.zeros((size, timestep.size - 4, timestep.size - 4)) | ||
n_o = np.zeros((size, timestep.size)) | ||
diff_c = np.zeros((size, 3200)) | ||
intercept = np.zeros((size, 3200)) | ||
|
||
for seed in tqdm(range(size)): | ||
rng = np.random.RandomState(seed) | ||
np.random.seed(seed) | ||
disp_3d, n_samples = get_disp3d(walk, length, atoms, jump_size=jump, seed=rng) | ||
|
||
diff = MSDBootstrap(timestep, disp_3d, n_samples, random_state=rng, progress=False, block=True) | ||
diff.diffusion(5, random_state=rng, progress=False) | ||
diff_c[seed] = diff.gradient.samples / 6 | ||
intercept[seed] = diff.intercept.samples | ||
data[seed, :, 0] = diff.dt | ||
data[seed, :, 1] = diff.n | ||
data[seed, :, 2] = diff.s | ||
data[seed, 4:, 3] = diff._model_v | ||
npd_covariance[seed] = diff._npd_covariance_matrix | ||
covariance[seed] = diff.covariance_matrix | ||
n_o[seed] = diff._n_o | ||
|
||
np.savez(f'src/data/random_walks/pyblock/rw_1_{atoms}_{length}_s{size}.npz', | ||
diff_c=diff_c, | ||
intercept=intercept, | ||
data=data, | ||
covariance=covariance, | ||
npd_covariance=npd_covariance, | ||
n_o=n_o) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.