Trying to understand rust divergence

This commit is contained in:
2023-03-03 16:02:44 +00:00
parent 582ff5488f
commit c334bf2aac
13 changed files with 58580 additions and 33 deletions
+29077
View File
File diff suppressed because it is too large Load Diff
Executable
BIN
View File
Binary file not shown.
Executable
BIN
View File
Binary file not shown.
Executable
BIN
View File
Binary file not shown.
Executable
BIN
View File
Binary file not shown.
Executable
BIN
View File
Binary file not shown.
+219
View File
@@ -0,0 +1,219 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 3,
"outputs": [],
"source": [
"import pandas as pd\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import scipy\n",
"from glob import glob\n"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def read_xy(path: str):\n",
" df = pd.read_csv(path)\n",
" df['N'] = df.index + 1\n",
" df['r'] = (df.x ** 2 + df.y ** 2) ** 0.5\n",
" df['cr'] = df.r.cummax()\n",
" df['fd'] = np.log(df.N) / np.log(df.cr)\n",
"\n",
" return df\n",
"\n",
"\n",
"def convergent_tail_index(series, tol):\n",
" diffs = np.abs(np.ediff1d(series))\n",
" for i in range(0, len(diffs)):\n",
" if np.max(diffs[i:]) <= tol:\n",
" return i\n",
"\n",
" # No convergence found\n",
" return None\n",
"\n",
"\n",
"def mean_of_tail(series, tol=0.05):\n",
" tail_index = convergent_tail_index(series, tol)\n",
" return np.mean(series[tail_index:])"
]
},
{
"cell_type": "code",
"execution_count": 19,
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/joshuacoles/Library/Caches/pypoetry/virtualenvs/data-analysis-B4Au_hWl-py3.10/lib/python3.10/site-packages/pandas/core/arraylike.py:402: RuntimeWarning: divide by zero encountered in log\n",
" result = getattr(ufunc, method)(*inputs, **kwargs)\n",
"/Users/joshuacoles/Library/Caches/pypoetry/virtualenvs/data-analysis-B4Au_hWl-py3.10/lib/python3.10/site-packages/pandas/core/arraylike.py:402: RuntimeWarning: divide by zero encountered in log\n",
" result = getattr(ufunc, method)(*inputs, **kwargs)\n",
"/Users/joshuacoles/Library/Caches/pypoetry/virtualenvs/data-analysis-B4Au_hWl-py3.10/lib/python3.10/site-packages/pandas/core/arraylike.py:402: RuntimeWarning: divide by zero encountered in log\n",
" result = getattr(ufunc, method)(*inputs, **kwargs)\n",
"/Users/joshuacoles/Library/Caches/pypoetry/virtualenvs/data-analysis-B4Au_hWl-py3.10/lib/python3.10/site-packages/pandas/core/arraylike.py:402: RuntimeWarning: divide by zero encountered in log\n",
" result = getattr(ufunc, method)(*inputs, **kwargs)\n"
]
}
],
"source": [
"a = read_xy(\"/Users/joshuacoles/Developer/checkouts/jc3091/CompB DLA/c-codebase/a.csv\")\n",
"b = read_xy(\"/Users/joshuacoles/Developer/checkouts/jc3091/CompB DLA/c-codebase/b.csv\")\n",
"c = read_xy(\"/Users/joshuacoles/Developer/checkouts/jc3091/CompB DLA/c-codebase/c.csv\")\n",
"d = read_xy(\"/Users/joshuacoles/Developer/checkouts/jc3091/CompB DLA/c-codebase/d.csv\")"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": 16,
"outputs": [
{
"data": {
"text/plain": "1.7271570214996996"
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mean_of_tail(a.fd)"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": 17,
"outputs": [
{
"data": {
"text/plain": "1.7271570214996996"
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mean_of_tail(b.fd)"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": 18,
"outputs": [
{
"data": {
"text/plain": "1.7634427392486482"
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mean_of_tail(c.fd)"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": 20,
"outputs": [
{
"data": {
"text/plain": "1.7634427392486482"
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mean_of_tail(d.fd)"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": 31,
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/joshuacoles/Library/Caches/pypoetry/virtualenvs/data-analysis-B4Au_hWl-py3.10/lib/python3.10/site-packages/pandas/core/arraylike.py:402: RuntimeWarning: divide by zero encountered in log\n",
" result = getattr(ufunc, method)(*inputs, **kwargs)\n"
]
},
{
"data": {
"text/plain": "20769"
},
"execution_count": 31,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"convergent_tail_index(read_xy(\"../fucking_massive.csv\").fd, 0.001)"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [],
"metadata": {
"collapsed": false
}
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
File diff suppressed because one or more lines are too long
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
+16
View File
@@ -0,0 +1,16 @@
#!/usr/bin/env bash
# NOTE: Requires GNU parallel
MODEL="models/rust-sp"
#MODEL=echo
mkdir -p data/rust-sp
PROBABILITIES=$@
for i in $PROBABILITIES; do
mkdir data/rust-sp/"$i"
done
MAX_PARTICLES=2000
parallel "$MODEL" '{1}' $MAX_PARTICLES '{2}' 'data/rust-sp/{2}/{1}.csv' ::: {1..100} ::: $PROBABILITIES
+24
View File
@@ -0,0 +1,24 @@
#!/usr/bin/env bash
# NOTE: Requires GNU parallel
# USAGE: MAX_PARTICLES=... sp-harness.bash <model> <run_id> <probabilities...>
# Run ID
MODEL="$1"
ID="$2"
shift
shift
ROOT="data/$ID"
mkdir -p "$ROOT"
PROBABILITIES=$@
for i in $PROBABILITIES; do
mkdir -p "$ROOT/$i"
done
MAX_PARTICLES="${MAX_PARTICLES:=2000}"
parallel "'$MODEL'" '{1}' $MAX_PARTICLES '{2}' "$ROOT/{2}/{1}.csv" ::: {1..100} ::: $PROBABILITIES