{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Multimodality and Resampling" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This notebook tests the robustness of modified Liu-West (MLW) resampling to multimodality in the posterior distribution. We use as a test the familiar model\n", "$$\n", " \\Pr(0 | \\omega, t) = \\cos^2(\\omega t),\n", "$$\n", "exploiting that the likelihood function is *even* in $\\omega$ to produce posteriors that always have exactly two modes. Because this structure is not explicitly added to the resampling, but is easy to reason about analytically, it serves as a nice test case." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Preamble" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "As usual, we start by configuring division and enabling plotting support." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from __future__ import division, print_function\n", "%matplotlib inline" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import numpy as np\n", "import matplotlib.pyplot as plt\n", "try: plt.style.use('ggplot')\n", "except: pass" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In order to view the incredibly verbose output from resampler debugging, it is helpful to point Python's logging functionality at a file instead of printing it inside the notebook. We use tempfile to pick a directory in a cross-platform way." ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Logging to C:\\Users\\Chris\\AppData\\Local\\Temp\\multimodal_testing.log.\n" ] } ], "source": [ "import os, tempfile\n", "logfile = os.path.join(tempfile.gettempdir(), 'multimodal_testing.log')\n", "print(\"Logging to {}.\".format(logfile))\n", "\n", "import logging\n", "logging.basicConfig(level=logging.DEBUG, filename=logfile)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Next, we import all the functionality from **QInfer** that we will need." ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "C:\\Anaconda3\\lib\\site-packages\\IPython\\parallel.py:13: ShimWarning: The IPython.parallel package has been deprecated. You should import from ipyparallel instead.\n", " \"You should import from ipyparallel instead.\", ShimWarning)\n", "c:\\users\\chris\\dropbox\\software-projects\\python-qinfer\\src\\qinfer\\parallel.py:52: UserWarning: Could not import IPython parallel. Parallelization support will be disabled.\n", " \"Could not import IPython parallel. \"\n" ] } ], "source": [ "import qinfer as qi" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Model and Prior Definition" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We want the simple precession model $\\cos^2(\\omega t)$ to now extend over $\\omega \\in [-1, 1]$, so we redefine the are_models_valid method to allow for negative $\\omega$." ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [], "source": [ "class NotQuiteSoSimplePrecessionModel(qi.SimplePrecessionModel):\n", " @staticmethod\n", " def are_models_valid(modelparams):\n", " return (np.abs(modelparams) <= 1)[:, 0]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Having done so, we now set a prior that explicitly includes the degeneracy in the likelihood." ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [], "source": [ "model = NotQuiteSoSimplePrecessionModel()\n", "prior = qi.UniformDistribution([-1, 1])" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false }, "outputs": [], "source": [ "def trial(a=0.98, h=None, track=True):\n", " true_params = prior.sample()\n", " updater = qi.SMCUpdater(model, 1000, prior, resampler=qi.LiuWestResampler(a=a, h=h, debug=True), track_resampling_divergence=track, debug_resampling=True)\n", " \n", " for idx_exp in range(100):\n", " exp = np.array([(9/8)**idx_exp], dtype=model.expparams_dtype)\n", " datum = model.simulate_experiment(true_params, exp)\n", " \n", " updater.update(datum, exp)\n", " \n", " # Since this model is always degenerate about the origin, take the mean\n", " # not of the original particles, but of the absolute value of the particles.\n", " updater.particle_locations = np.abs(updater.particle_locations)\n", " \n", " if track:\n", " return [true_params, updater.est_mean()], np.mean(updater.resampling_divergences)\n", " else:\n", " return [true_params, updater.est_mean()]" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false }, "outputs": [], "source": [ "def corr(a=0.98, h=None, track=True, n_trials=100):\n", " trues = np.zeros((n_trials,))\n", " ests = np.zeros((n_trials,))\n", " \n", " if track:\n", " divs = np.zeros((n_trials, ))\n", " \n", " for idx_trial in range(n_trials):\n", " if track:\n", " print(idx_trial, end=' ')\n", " (true, est), div = trial(a, h, track)\n", " else:\n", " true, est = trial(a, h, track)\n", " trues[idx_trial] = true\n", " ests[idx_trial] = est\n", " if track:\n", " divs[idx_trial] = div\n", " \n", " if track:\n", " return trues, ests, divs\n", " else:\n", " return trues, ests" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false }, "outputs": [], "source": [ "trues, ests = corr(1, 0.02, False, 100)" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0.00697411114983 0.0123620858504\n" ] } ], "source": [ "bias = np.mean(np.abs(trues) - np.abs(ests))\n", "risk = np.mean(np.abs(np.abs(trues) - np.abs(ests)))\n", "print(bias, risk)" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "(0, 1)" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" }, { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAY8AAAEWCAYAAACe8xtsAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3X9Q0/f9B/BnIPxQiUoQihKslQBxbBMK/qh2X4uyXruu\nArXLdXXeaa11Tr12XbtWqFgd6tnqzVbnj7ZYrLXduDKKd6vtWTurcu0NB2wtyo+gtgJixfiDiL+S\nfL5/uHySQJBPIL/zfNz1lg/5JHnxOpaX798yQRAEEBEROSHE2wEQEZH/YfEgIiKnsXgQEZHTWDyI\niMhpLB5EROQ0Fg8iInKa3FMftH37dtTU1GDEiBHYuHGjw3t27d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k629PY+tPZ2YmNGzdCJpOJP5PL5bh8+TKio6PdER6RS7F4EA2A7Ze+IxEREbh586Z4\nbTabceXKFfF61KhRWLJkCVJSUtwWI5E7sduKaABGjhyJc+fOAXB8rO3o0aNx8+ZN1NbWwmQyoby8\nHEajUXw+JycHH374oXja3ZUrV3Ds2DHPBE/kAmx5EA1AXl4edu3ahffffx+PPfZYr+eHDh2Kp59+\nGjt27IDZbEZubq5dt9YvfvELAEBxcTEuXryIESNGYNq0aQF5wiEFJk7VJSIip7HbioiInMbiQURE\nTmPxICIip7F4EBGR01g8iIjIaSweRETkNBYPIiJyGosHERE5jcWDiIic9v8OoNIDoElgtQAAAABJ\nRU5ErkJggg==\n", "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "plt.plot(np.abs(trues), ests, 'k.')\n", "plt.xlabel('true')\n", "plt.ylabel('estimated')\n", "plt.xlim((0, 1))\n", "plt.ylim((0, 1))" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0.19281919156\n" ] } ], "source": [ "trues, ests = corr(0.98, None, False, 100)\n", "bias = np.mean(np.abs(trues) - np.abs(ests))\n", "print(bias)" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "(0, 1)" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" }, { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAY8AAAEWCAYAAACe8xtsAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3X9Qk/cdB/B3IAJVghJEEYK1JSCWrWLFH1M7q9KuXdeK\npcu5s73VUWetdnVbuxWtWDys15u91eq0v7A4+2Pjylq8XVuPs7OtzK5YyNaiAQFtRYwVU5WIoiTP\n/rAkBELyPPnx5Nf7deddQp4kn3yE55Pvz0chCIIAIiIiCaICHQAREYUeFg8iIpKMx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ain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "plt.plot(np.abs(trues), ests, 'k.')\n", "plt.xlabel('true')\n", "plt.ylabel('estimated')\n", "plt.xlim((0, 1))\n", "plt.ylim((0, 1))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## WIP: Mutliparameter Models" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We also want to try with a multicos model, since that model admits a degeneracy between parameters that is broken by experimental variety. To arrive at a good estimate, then, a resampler must preserve unusual posterior structures that arise in the approach to a unimodal final posterior.\n", "\n", "It's worth noting here that the traditional LW parameters work quite well for a better experimental protocol (choosing lots of varied experiments), but that this protocol may not always be available. Thus, MLW is a resource here to compensate for experimental restrictions." ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "collapsed": false }, "outputs": [], "source": [ "class MultiCosModel(qi.FiniteOutcomeModel):\n", " \n", " def __init__(self, n_terms=2):\n", " self._n_terms = n_terms\n", " super(MultiCosModel, self).__init__()\n", " \n", " @property\n", " def n_modelparams(self):\n", " return self._n_terms\n", " \n", " @property\n", " def is_n_outcomes_constant(self):\n", " return True\n", " def n_outcomes(self, expparams):\n", " return 2\n", " \n", " def are_models_valid(self, modelparams):\n", " return np.all(np.logical_and(modelparams > 0, modelparams <= 1), axis=1)\n", " \n", " @property\n", " def expparams_dtype(self):\n", " return [('ts', '{}float'.format(self._n_terms))]\n", " \n", " def likelihood(self, outcomes, modelparams, expparams):\n", " # We first call the superclass method, which basically\n", " # just makes sure that call count diagnostics are properly\n", " # logged.\n", " super(MultiCosModel, self).likelihood(outcomes, modelparams, expparams)\n", " \n", " # Next, since we have a two-outcome model, everything is defined by\n", " # Pr(0 | modelparams; expparams), so we find the probability of 0\n", " # for each model and each experiment.\n", " #\n", " # We do so by taking a product along the modelparam index (len 2,\n", " # indicating omega_1 or omega_2), then squaring the result.\n", " pr0 = np.prod(\n", " np.cos(\n", " # shape (n_models, 1, 2)\n", " modelparams[:, np.newaxis, :] *\n", " # shape (n_experiments, 2)\n", " expparams['ts']\n", " ), # <- broadcasts to shape (n_models, n_experiments, 2).\n", " axis=2 # <- product over the final index (len 2)\n", " ) ** 2 # square each element\n", " \n", " # Now we use pr0_to_likelihood_array to turn this two index array\n", " # above into the form expected by SMCUpdater and other consumers\n", " # of likelihood().\n", " return qi.FiniteOutcomeModel.pr0_to_likelihood_array(outcomes, pr0)" ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "collapsed": false }, "outputs": [], "source": [ "mp_model = qi.BinomialModel(MultiCosModel(3))\n", "mp_prior = qi.UniformDistribution([[0, 1]]*3)" ] }, { "cell_type": "code", "execution_count": 16, "metadata": { "collapsed": false }, "outputs": [], "source": [ "def multicos_trial(a, h, n_exps=200):\n", " true = mp_prior.sample()\n", " mp_updater = qi.SMCUpdater(mp_model, 2000, mp_prior,\n", " resampler=qi.LiuWestResampler(a=a, h=h, debug=True),\n", " debug_resampling=True\n", " )\n", " \n", " while True:\n", " exp = np.array([(20 * np.pi * np.random.random(3), 40)], dtype=mp_model.expparams_dtype)\n", " # To test the resampler, we take data according to one experiment design until it has to resample, then switch.\n", " # Since the MLW resampler works quite well, we need to set an upper limit.\n", " for idx in range(500):\n", " datum = mp_model.simulate_experiment(true, exp)\n", " mp_updater.update(datum, exp)\n", " \n", " if len(mp_updater.data_record) >= n_exps:\n", " return true, mp_updater.est_mean()\n", " \n", " if mp_updater.just_resampled and idx >= 100:\n", " break\n", " " ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "collapsed": false }, "outputs": [], "source": [ "def nanmean(arr):\n", " return np.nansum(arr) / np.sum(np.isfinite(arr))" ] }, { "cell_type": "code", "execution_count": 18, "metadata": { "collapsed": false }, "outputs": [], "source": [ "def mp_risk(a, h, n_trials=10, n_exps=200):\n", " mp_errors = np.empty((n_trials,))\n", " for idx_trial in range(n_trials):\n", " true, est = multicos_trial(a, h, n_exps)\n", " mp_errors[idx_trial] = np.sum((true - est)**2)\n", " \n", " n_nan = np.sum(np.isnan(mp_errors))\n", " if n_nan > 0:\n", " print(\"{} NaNs observed.\".format(n_nan))\n", " \n", " return nanmean(mp_errors)" ] } ], "metadata": { "kernelspec": { "display_name": "Python [default]", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.5.2" }, "widgets": { "state": {}, "version": "1.1.1" } }, "nbformat": 4, "nbformat_minor": 0 }