Rust works!
This commit is contained in:
parent
c334bf2aac
commit
5b526ecc13
File diff suppressed because one or more lines are too long
68
tools/calc-fd.py
Normal file
68
tools/calc-fd.py
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
from pathlib import Path
|
||||||
|
import pandas as pd
|
||||||
|
import numpy as np
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import scipy
|
||||||
|
from glob import glob
|
||||||
|
|
||||||
|
|
||||||
|
def read_xy(path: str):
|
||||||
|
df = pd.read_csv(path, skipinitialspace=True)
|
||||||
|
df['N'] = df.index + 1
|
||||||
|
df['r'] = (df.x ** 2 + df.y ** 2) ** 0.5
|
||||||
|
df['cr'] = df.r.cummax()
|
||||||
|
df['fd'] = np.log(df.N) / np.log(df.cr)
|
||||||
|
|
||||||
|
return df
|
||||||
|
|
||||||
|
|
||||||
|
def read_all(load_dir: str):
|
||||||
|
paths = glob(f'{load_dir}/*.csv')
|
||||||
|
return [read_xy(path) for path in paths]
|
||||||
|
|
||||||
|
|
||||||
|
def stick_prob_from_load_dir(load_dir: str):
|
||||||
|
return float(Path(load_dir).name)
|
||||||
|
|
||||||
|
|
||||||
|
def read_sp_dir(load_dir: str):
|
||||||
|
return stick_prob_from_load_dir(load_dir), read_all(load_dir)
|
||||||
|
|
||||||
|
|
||||||
|
def read_sp_full(probabilities_dir: str):
|
||||||
|
a = [read_sp_dir(load_dir) for load_dir in glob(f'{probabilities_dir}/*')]
|
||||||
|
b = [fd_of_dfs(dfs) for (p, dfs) in a]
|
||||||
|
ps = [p for (p, dfs) in a]
|
||||||
|
means, stds = list(zip(*b))
|
||||||
|
c = pd.DataFrame(zip(ps, means, stds), columns=['p', 'fd_mean', 'fd_std'])
|
||||||
|
c.sort_values(by='p', inplace=True)
|
||||||
|
return c
|
||||||
|
|
||||||
|
|
||||||
|
def convergent_tail_index(series, tol):
|
||||||
|
diffs = np.abs(np.ediff1d(series))
|
||||||
|
for i in range(0, len(diffs)):
|
||||||
|
if np.max(diffs[i:]) <= tol:
|
||||||
|
return i
|
||||||
|
|
||||||
|
# No convergence found
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def mean_of_tail(series, tol=0.05):
|
||||||
|
tail_index = convergent_tail_index(series, tol)
|
||||||
|
return np.mean(series[tail_index:])
|
||||||
|
|
||||||
|
|
||||||
|
def fd_of_dfs(dfs):
|
||||||
|
fds = [mean_of_tail(df.fd, 0.001) for df in dfs]
|
||||||
|
fds_clean = [f for f in fds if f < np.inf]
|
||||||
|
return np.mean(fds_clean), np.std(fds_clean)
|
||||||
|
|
||||||
|
|
||||||
|
import sys
|
||||||
|
print(sys.argv)
|
||||||
|
np.seterr(divide='ignore')
|
||||||
|
|
||||||
|
argv_ = sys.argv[1]
|
||||||
|
print(read_sp_full(argv_))
|
||||||
4
tools/copy-run.bash
Executable file
4
tools/copy-run.bash
Executable file
@ -0,0 +1,4 @@
|
|||||||
|
REF=$(cd "/Users/joshuacoles/Developer/checkouts/jc3091/CompB DLA/rust-codebase/" && git rev-parse --short HEAD && cargo build --release)
|
||||||
|
cp "/Users/joshuacoles/Developer/checkouts/jc3091/CompB DLA/rust-codebase/target/release/model" ./model-$REF
|
||||||
|
#./tools/sp-harness.bash ./model-$REF rust-sp-$REF $(seq 0.2 0.4 1)
|
||||||
|
echo ./model-$REF created
|
||||||
@ -21,4 +21,4 @@ done
|
|||||||
|
|
||||||
MAX_PARTICLES="${MAX_PARTICLES:=2000}"
|
MAX_PARTICLES="${MAX_PARTICLES:=2000}"
|
||||||
|
|
||||||
parallel "'$MODEL'" '{1}' $MAX_PARTICLES '{2}' "$ROOT/{2}/{1}.csv" ::: {1..100} ::: $PROBABILITIES
|
RUST_BACKTRACE=1 parallel "'$MODEL'" '{1}' $MAX_PARTICLES '{2}' "$ROOT/{2}/{1}.csv" ::: {1..100} ::: $PROBABILITIES
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user