Skip to content

Commit

Permalink
add example to instruct.ipynb
Browse files Browse the repository at this point in the history
  • Loading branch information
chenxinye committed Jun 23, 2024
1 parent e07dc5b commit c8ca6a3
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions instruct.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,42 @@
"reconst_same_shape[1, 1, 2:]"
]
},
{
"cell_type": "markdown",
"id": "81888e95-6fbe-4375-8ecc-ae52a1133aec",
"metadata": {},
"source": [
"### for out-of-sample data transform and shape recasting"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b938b5e1-a9c9-44b2-b082-fa56a15ebd4a",
"metadata": {},
"outputs": [],
"source": [
"mts = np.random.randn(130, 100, 10)\n",
"test = mts[120:]\n",
"mts = mts[:120]\n",
"\n",
"qabba = JABBA(tol=0.01, init=\"agg\", alpha=0.001, verbose=0)\n",
"\n",
"strings = qabba.fit_transform(mts) \n",
"inverse_ts = qabba.inverse_transform(strings)\n",
"inverse_ts = qabba.recast_shape(inverse_ts)\n",
"np.sum(np.abs(mts - inverse_ts)**2)\n",
"\n",
"\n",
"import matplotlib.pyplot as plt\n",
"symbols_test, params_test = qabba.transform(test)\n",
"inverse_ts = qabba.inverse_transform(symbols_test, params_test)\n",
"inverse_ts = qabba.recast_shape(inverse_ts)\n",
"plt.plot(test[3], c='r', label='original')\n",
"plt.plot(inverse_ts[3], c='g', label='inverse')\n",
"plt.legend()"
]
},
{
"cell_type": "markdown",
"id": "f6bd7b2d-233f-4e1c-a1bd-08d9661ba66e",
Expand Down

0 comments on commit c8ca6a3

Please sign in to comment.