Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
j1c committed Oct 17, 2023
1 parent ebc6f4e commit 11a0ceb
Show file tree
Hide file tree
Showing 2 changed files with 157 additions and 105 deletions.
82 changes: 41 additions & 41 deletions data.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
"metadata": {},
"outputs": [],
"source": [
"from pathlib import Path\n",
"\n",
"import numpy as np\n",
"import scipy as sp\n",
"from pathlib import Path\n",
"\n",
"from hyppo.tools import ts_sim\n",
"\n",
"TS_SIMS = [\n",
Expand All @@ -40,7 +42,7 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 2,
"id": "03d96d14-c068-471b-b7c1-80e17621f73e",
"metadata": {},
"outputs": [],
Expand All @@ -61,12 +63,12 @@
"Y = np.stack([data[1] for data in datas])\n",
"\n",
"savedict = {\n",
" 'X' : X,\n",
" 'Y' : Y,\n",
" \"X\": X,\n",
" \"Y\": Y,\n",
"}\n",
"\n",
"# save to disk\n",
"sp.io.savemat(f'{p}{fname}.mat', savedict, do_compression=True)"
"sp.io.savemat(f\"{p}{fname}.mat\", savedict, do_compression=True)"
]
},
{
Expand All @@ -79,16 +81,16 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 8,
"id": "d6a02659-109a-451f-9d06-773e0726e9b9",
"metadata": {},
"outputs": [],
"source": [
"fname = \"2-independent_ar_phi\"\n",
"\n",
"n = 300\n",
"n = 200\n",
"reps = 300\n",
"phis = np.arange(0.2, 1, 0.025)\n",
"phis = np.arange(0.2, 1, 0.05)\n",
"sigmas = 1 - (phis**2)\n",
"\n",
"np.random.seed(1)\n",
Expand All @@ -97,22 +99,20 @@
"Ys = []\n",
"\n",
"for (phi, sigma) in zip(phis, sigmas):\n",
" datas = [ts_sim(\"indep_ar\", n, phi=float(phi), sigma=float(sigma)) for _ in range(reps)]\n",
" Xs.append(np.hstack([data[0] for data in datas]))\n",
" Ys.append(np.hstack([data[1] for data in datas]))\n",
" datas = [\n",
" ts_sim(\"indep_ar\", n, phi=float(phi), sigma=float(sigma)) for _ in range(reps)\n",
" ]\n",
" Xs.append(np.stack([data[0] for data in datas]))\n",
" Ys.append(np.stack([data[1] for data in datas]))\n",
"\n",
"\n",
"X = np.stack(Xs)\n",
"Y = np.stack(Ys)\n",
"\n",
"savedict = {\n",
" 'X' : X,\n",
" 'Y' : Y,\n",
" 'phi': phis\n",
"}\n",
"savedict = {\"X\": X, \"Y\": Y, \"phi\": phis}\n",
"\n",
"# save to disk\n",
"# sp.io.savemat(f'{p}{fname}.mat', savedict, do_compression=True)"
"sp.io.savemat(f\"{p}{fname}.mat\", savedict, do_compression=True)"
]
},
{
Expand All @@ -139,16 +139,16 @@
"\n",
"datas = [ts_sim(\"cross_corr_ar\", n) for _ in range(reps)]\n",
"\n",
"X = np.hstack([data[0] for data in datas])\n",
"Y = np.hstack([data[1] for data in datas])\n",
"X = np.stack([data[0] for data in datas])\n",
"Y = np.stack([data[1] for data in datas])\n",
"\n",
"savedict = {\n",
" 'X' : X,\n",
" 'Y' : Y,\n",
" \"X\": X,\n",
" \"Y\": Y,\n",
"}\n",
"\n",
"# save to disk\n",
"sp.io.savemat(f'{p}{fname}.mat', savedict, do_compression=True)"
"sp.io.savemat(f\"{p}{fname}.mat\", savedict, do_compression=True)"
]
},
{
Expand All @@ -175,16 +175,16 @@
"\n",
"datas = [ts_sim(\"nonlinear_process\", n) for _ in range(reps)]\n",
"\n",
"X = np.hstack([data[0] for data in datas])\n",
"Y = np.hstack([data[1] for data in datas])\n",
"X = np.stack([data[0] for data in datas])\n",
"Y = np.stack([data[1] for data in datas])\n",
"\n",
"savedict = {\n",
" 'X' : X,\n",
" 'Y' : Y,\n",
" \"X\": X,\n",
" \"Y\": Y,\n",
"}\n",
"\n",
"# save to disk\n",
"sp.io.savemat(f'{p}{fname}.mat', savedict, do_compression=True)"
"sp.io.savemat(f\"{p}{fname}.mat\", savedict, do_compression=True)"
]
},
{
Expand All @@ -211,29 +211,29 @@
"\n",
"datas = [ts_sim(\"extinct_gaussian_process\", n) for _ in range(reps)]\n",
"\n",
"X = np.hstack([data[0] for data in datas])\n",
"Y = np.hstack([data[1] for data in datas])\n",
"X = np.stack([data[0] for data in datas])\n",
"Y = np.stack([data[1] for data in datas])\n",
"\n",
"savedict = {\n",
" 'X' : X,\n",
" 'Y' : Y,\n",
" \"X\": X,\n",
" \"Y\": Y,\n",
"}\n",
"\n",
"# save to disk\n",
"sp.io.savemat(f'{p}{fname}.mat', savedict, do_compression=True)"
"sp.io.savemat(f\"{p}{fname}.mat\", savedict, do_compression=True)"
]
},
{
"cell_type": "markdown",
"id": "98cf8254-3a4e-4421-a272-5a0eb81d2c37",
"metadata": {},
"source": [
"Generate Experiment 6 - Independent Vector AR(1) with increasing sample size\n"
"# Generate Experiment 6 - Independent Vector AR(1) with increasing sample size\n"
]
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 9,
"id": "2899b2f6",
"metadata": {},
"outputs": [],
Expand All @@ -243,8 +243,8 @@
" d : corresponds to dimension of the time series\n",
" \"\"\"\n",
" rng = rng = np.random.default_rng(seed)\n",
" coeff = np.eye(d*2) * phi\n",
" covar = np.eye(d*2) * (1 - (phi ** 2))\n",
" coeff = np.eye(d * 2) * phi\n",
" covar = np.eye(d * 2) * (1 - (phi**2))\n",
" errors = np.random.multivariate_normal(np.zeros(d * 2), covar, n)\n",
"\n",
" Y = np.zeros((n, d * 2))\n",
Expand All @@ -261,7 +261,7 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": null,
"id": "5f28ebc4",
"metadata": {},
"outputs": [],
Expand All @@ -280,12 +280,12 @@
"Y = np.stack([data[1] for data in datas])\n",
"\n",
"savedict = {\n",
" 'X' : X,\n",
" 'Y' : Y,\n",
" \"X\": X,\n",
" \"Y\": Y,\n",
"}\n",
"\n",
"# save to disk\n",
"sp.io.savemat(f'{p}{fname}.mat', savedict, do_compression=True)"
"sp.io.savemat(f\"{p}{fname}.mat\", savedict, do_compression=True)"
]
},
{
Expand Down Expand Up @@ -334,7 +334,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.13"
"version": "3.9.16"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 11a0ceb

Please sign in to comment.