diff --git a/time_series_analysis/cp_pelt.ipynb b/time_series_analysis/cp_pelt.ipynb index ebff7fe..b9d6b56 100644 --- a/time_series_analysis/cp_pelt.ipynb +++ b/time_series_analysis/cp_pelt.ipynb @@ -13,8 +13,10 @@ }, { "cell_type": "code", - "execution_count": 1, - "metadata": {}, + "execution_count": 25, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "y = [\n", @@ -45,13 +47,15 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "We wish to look for changes in the mean, which is selected using the following `ctype` value in the NAG routine" + "We wish to look for changes in the mean, assuming the data comes from Normal distributions, which is selected by setting the `ctype` parameter of the `cp_pelt` routine to `1`. Other values for `ctype` can be used for different distributions and properties of the data, but the plot in this notebook assumes `ctype = 1`." ] }, { "cell_type": "code", - "execution_count": 2, - "metadata": {}, + "execution_count": 26, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "ctype = 1" @@ -66,8 +70,10 @@ }, { "cell_type": "code", - "execution_count": 3, - "metadata": {}, + "execution_count": 46, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "param = [0.2]" @@ -82,8 +88,10 @@ }, { "cell_type": "code", - "execution_count": 4, - "metadata": {}, + "execution_count": 47, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "from naginterfaces.library import tsa\n", @@ -101,7 +109,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 48, "metadata": {}, "outputs": [ { @@ -138,7 +146,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 49, "metadata": {}, "outputs": [ { @@ -223,7 +231,7 @@ " };\n", "\n", " this.imageObj.onunload = function() {\n", - " fig.ws.close();\n", + " this.ws.close();\n", " }\n", "\n", " this.ws.onmessage = this._make_on_message_function(this);\n", @@ -698,7 +706,7 @@ "mpl.figure.prototype.toolbar_button_onmouseover = function(tooltip) {\n", " this.message.textContent = tooltip;\n", "};\n", - "mpl.toolbar_items = [[\"Home\", \"Reset original view\", \"fa fa-home icon-home\", \"home\"], [\"Back\", \"Back to previous view\", \"fa fa-arrow-left icon-arrow-left\", \"back\"], [\"Forward\", \"Forward to next view\", \"fa fa-arrow-right icon-arrow-right\", \"forward\"], [\"\", \"\", \"\", \"\"], [\"Pan\", \"Pan axes with left mouse, zoom with right\", \"fa fa-arrows icon-move\", \"pan\"], [\"Zoom\", \"Zoom to rectangle\", \"fa fa-square-o icon-check-empty\", \"zoom\"], [\"\", \"\", \"\", \"\"], [\"Download\", \"Download plot\", \"fa fa-floppy-o icon-save\", \"download\"]];\n", + "mpl.toolbar_items = [[\"Home\", \"Reset original view\", \"fa fa-home icon-home\", \"home\"], [\"Back\", \"Back to previous view\", \"fa fa-arrow-left icon-arrow-left\", \"back\"], [\"Forward\", \"Forward to next view\", \"fa fa-arrow-right icon-arrow-right\", \"forward\"], [\"\", \"\", \"\", \"\"], [\"Pan\", \"Pan axes with left mouse, zoom with right\", \"fa fa-arrows icon-move\", \"pan\"], [\"Zoom\", \"Zoom to rectangle\", \"fa fa-square-o icon-check-empty\", \"zoom\"], [\"\", \"\", \"\", \"\"], [\"Download\", \"Download plot\", \"fa fa-floppy-o icon-save\", \"download\"]];\n", "\n", "mpl.extensions = [\"eps\", \"pdf\", \"png\", \"ps\", \"raw\", \"svg\"];\n", "\n", @@ -718,7 +726,7 @@ " // Register the callback with on_msg.\n", " comm.on_msg(function(msg) {\n", " //console.log('receiving', msg['content']['data'], msg);\n", - " // Pass the mpl event to the overridden (by mpl) onmessage function.\n", + " // Pass the mpl event to the overriden (by mpl) onmessage function.\n", " ws.onmessage(msg['content']['data'])\n", " });\n", " return ws;\n", @@ -870,12 +878,9 @@ " // Check for shift+enter\n", " if (event.shiftKey && event.which == 13) {\n", " this.canvas_div.blur();\n", - " event.shiftKey = false;\n", - " // Send a \"J\" for go to next cell\n", - " event.which = 74;\n", - " event.keyCode = 74;\n", - " manager.command_mode();\n", - " manager.handle_keydown(event);\n", + " // select the cell after this one\n", + " var index = IPython.notebook.find_cell_index(this.cell_info[0]);\n", + " IPython.notebook.select(index + 1);\n", " }\n", "}\n", "\n", @@ -950,7 +955,7 @@ " last_cp = tau_val\n", "plt.xlim((1, len(y)))\n", "t11 = ['1999 Initiation of Euro', '2008 Financial Crisis', '2016 UK EU Referendum']\n", - "t12 = (0, soln.tau[1]-4, soln.tau[3]-4)\n", + "t12 = [0, 9*12, 17*12]\n", "plt.xticks(t12, t11, size='small')\n", "plt.xlabel('Time - January 1999 to December 2018')\n", "plt.ylabel('Euros per Pound')\n", @@ -961,11 +966,21 @@ "plt.legend(handles=[vl, hl], loc='upper right')\n", "plt.show()" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] } ], "metadata": { + "anaconda-cloud": {}, "kernelspec": { - "display_name": "Python 3", + "display_name": "Python [default]", "language": "python", "name": "python3" }, diff --git a/time_series_analysis/ts_data.txt b/time_series_analysis/ts_data.txt new file mode 100644 index 0000000..0f74771 --- /dev/null +++ b/time_series_analysis/ts_data.txt @@ -0,0 +1 @@ +[1.41, 1.47, 1.49, 1.49, 1.54, 1.56, 1.54, 1.52, 1.54, 1.56, 1.59, 1.61, 1.61, 1.67, 1.64, 1.69, 1.72, 1.61, 1.61, 1.64, 1.64, 1.69, 1.69, 1.67, 1.59, 1.59, 1.59, 1.61, 1.61, 1.69, 1.69, 1.64, 1.64, 1.64, 1.64, 1.61, 1.61, 1.67, 1.67, 1.64, 1.64, 1.56, 1.56, 1.61, 1.59, 1.61, 1.59, 1.59, 1.56, 1.54, 1.47, 1.45, 1.45, 1.41, 1.45, 1.45, 1.47, 1.43, 1.47, 1.45, 1.43, 1.47, 1.52, 1.52, 1.49, 1.52, 1.52, 1.54, 1.49, 1.45, 1.45, 1.47, 1.43, 1.45, 1.47, 1.47, 1.49, 1.49, 1.49, 1.47, 1.47, 1.49, 1.47, 1.49, 1.47, 1.49, 1.47, 1.45, 1.47, 1.47, 1.45, 1.47, 1.49, 1.49, 1.52, 1.49, 1.49, 1.52, 1.49, 1.49, 1.47, 1.49, 1.49, 1.49, 1.49, 1.45, 1.45, 1.43, 1.35, 1.33, 1.32, 1.27, 1.28, 1.28, 1.27, 1.28, 1.23, 1.27, 1.27, 1.19, 1.05, 1.12, 1.12, 1.1, 1.14, 1.16, 1.18, 1.18, 1.15, 1.1, 1.11, 1.11, 1.12, 1.15, 1.11, 1.14, 1.16, 1.2, 1.22, 1.22, 1.22, 1.15, 1.16, 1.19, 1.16, 1.18, 1.19, 1.14, 1.12, 1.15, 1.11, 1.15, 1.14, 1.18, 1.18, 1.18, 1.2, 1.2, 1.2, 1.2, 1.23, 1.25, 1.25, 1.28, 1.27, 1.27, 1.25, 1.23, 1.23, 1.16, 1.16, 1.19, 1.19, 1.18, 1.18, 1.15, 1.19, 1.2, 1.19, 1.22, 1.2, 1.22, 1.22, 1.22, 1.22, 1.23, 1.27, 1.27, 1.27, 1.3, 1.28, 1.27, 1.28, 1.33, 1.39, 1.39, 1.37, 1.41, 1.43, 1.43, 1.37, 1.37, 1.41, 1.43, 1.37, 1.33, 1.3, 1.25, 1.28, 1.3, 1.2, 1.19, 1.19, 1.15, 1.11, 1.19, 1.18, 1.18, 1.18, 1.18, 1.19, 1.15, 1.15, 1.12, 1.1, 1.14, 1.15, 1.14, 1.14, 1.15, 1.12, 1.15, 1.14, 1.15, 1.14, 1.14, 1.12, 1.14, 1.15, 1.13] \ No newline at end of file