{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "N = 100 # no. of customers\n",
    "C = [[] for i in range(N)] # customer dishes assignment\n",
    "K = 0 # no. of current disches selected\n",
    "dishes = [] # no. of customers sampled with each dish\n",
    "alpha = 1 # Poisson prior"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "for n in range(N):\n",
    "    for k in range(K):\n",
    "        p = dishes[k] / n\n",
    "        z = np.random.binomial(n=1, p=p)\n",
    "        C[n].append(z) # update customer dish assignment\n",
    "        dishes[k] = dishes[k] + 1 # update customer count for dish k\n",
    "        \n",
    "    # Lets try new dishes\n",
    "    new_dishes = np.random.poisson(lam=alpha)\n",
    "    \n",
    "    for k in range(new_dishes):\n",
    "        C[n].append(1)\n",
    "        dishes.append(1)\n",
    "        \n",
    "    # Update the dish count\n",
    "    K += new_dishes"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Convert to binary matrix "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "C_ = np.zeros([N, K])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 1.  0.  0. ...,  0.  0.  0.]\n",
      " [ 1.  0.  0. ...,  0.  0.  0.]\n",
      " [ 1.  1.  1. ...,  0.  0.  0.]\n",
      " ..., \n",
      " [ 1.  1.  1. ...,  0.  0.  0.]\n",
      " [ 1.  1.  1. ...,  1.  0.  0.]\n",
      " [ 1.  1.  1. ...,  0.  1.  1.]]\n"
     ]
    }
   ],
   "source": [
    "for n in range(N):\n",
    "    C_[n, 0:len(C[n])] = np.array(C[n])\n",
    "print(C_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "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.6.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}