{
  "nbformat_minor": 0, 
  "nbformat": 4, 
  "cells": [
    {
      "execution_count": null, 
      "cell_type": "code", 
      "source": [
        "%matplotlib inline"
      ], 
      "outputs": [], 
      "metadata": {
        "collapsed": false
      }
    }, 
    {
      "source": [
        "\n# Using the missing_inds function to label interpolated values\n\n\nIf you have data with missing values, Hypertools will try to interpolate them\nusing PPCA.  To visualize how well its doing, you can use the missing_inds\nfunction and then highlight the values that were interpolated.  Here, we\ngenerated some synthetic data, removed some values, and then plotted the\noriginal data, data with missing values and highlighted the missing datapoints\nwith stars.\n\n"
      ], 
      "cell_type": "markdown", 
      "metadata": {}
    }, 
    {
      "execution_count": null, 
      "cell_type": "code", 
      "source": [
        "# Code source: Andrew Heusser\n# License: MIT\n\n# import\nfrom scipy.linalg import toeplitz\nimport numpy as np\nfrom copy import copy\nimport hypertools as hyp\n\n# simulate data\nK = 10 - toeplitz(np.arange(10))\ndata1 = np.cumsum(np.random.multivariate_normal(np.zeros(10), K, 250), axis=0)\ndata2 = copy(data1)\n\n# randomly remove 5% of the data\nmissing = .01\ninds = [(i,j) for i in range(data1.shape[0]) for j in range(data1.shape[1])]\nmissing_data = [inds[i] for i in np.random.choice(int(len(inds)), int(len(inds)*missing))]\nfor i,j in missing_data:\n    data2[i,j]=np.nan\n\n# reduce the data\ndata1_r,data2_r = hyp.reduce([data1, data2], ndims=3)\n\n# pull out missing inds\nmissing_inds = hyp.tools.missing_inds(data2)\nmissing_data = data2_r[missing_inds, :]\n\n# plot\nhyp.plot([data1_r, data2_r, missing_data], ['-', '--', '*'],\n         legend=['Full', 'Missing', 'Missing Points'])"
      ], 
      "outputs": [], 
      "metadata": {
        "collapsed": false
      }
    }
  ], 
  "metadata": {
    "kernelspec": {
      "display_name": "Python 2", 
      "name": "python2", 
      "language": "python"
    }, 
    "language_info": {
      "mimetype": "text/x-python", 
      "nbconvert_exporter": "python", 
      "name": "python", 
      "file_extension": ".py", 
      "version": "2.7.11", 
      "pygments_lexer": "ipython2", 
      "codemirror_mode": {
        "version": 2, 
        "name": "ipython"
      }
    }
  }
}