{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import tensorflow as tf\n",
    "import array\n",
    "import gzip\n",
    "import random\n",
    "from tensorflow.keras import Model\n",
    "from collections import defaultdict"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "def parse(path):\n",
    "    g = gzip.open(path, 'r')\n",
    "    for l in g:\n",
    "        yield eval(l)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "userIDs = {}\n",
    "itemIDs = {}\n",
    "interactions = []\n",
    "\n",
    "for d in parse(\"goodreads_reviews_comics_graphic.json.gz\"):\n",
    "    u = d['user_id']\n",
    "    i = d['book_id']\n",
    "    r = d['rating']\n",
    "    if not u in userIDs: userIDs[u] = len(userIDs)\n",
    "    if not i in itemIDs: itemIDs[i] = len(itemIDs)\n",
    "    interactions.append((u,i,r))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "542338"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(interactions)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "mu = sum([x[2] for x in interactions]) / len(interactions)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "optimizer = tf.keras.optimizers.Adam(0.01)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "class LatentFactorModel(tf.keras.Model):\n",
    "    def __init__(self, mu, K, lamb):\n",
    "        super(LatentFactorModel, self).__init__()\n",
    "        self.alpha = tf.Variable(mu)\n",
    "        self.betaU = tf.Variable(tf.random.normal([len(userIDs)],stddev=0.001))\n",
    "        self.betaI = tf.Variable(tf.random.normal([len(itemIDs)],stddev=0.001))\n",
    "        self.gammaU = tf.Variable(tf.random.normal([len(userIDs),K],stddev=0.001))\n",
    "        self.gammaI = tf.Variable(tf.random.normal([len(itemIDs),K],stddev=0.001))\n",
    "        self.lamb = lamb\n",
    "\n",
    "    def predict(self, u, i):\n",
    "        p = self.alpha + self.betaU[u] + self.betaI[i] +\\\n",
    "            tf.tensordot(self.gammaU[u], self.gammaI[i], 1)\n",
    "        return p\n",
    "\n",
    "    def reg(self):\n",
    "        return self.lamb * (tf.reduce_sum(self.betaU**2) +\\\n",
    "                            tf.reduce_sum(self.betaI**2) +\\\n",
    "                            tf.reduce_sum(self.gammaU**2) +\\\n",
    "                            tf.reduce_sum(self.gammaI**2))\n",
    "\n",
    "    def call(self, u, i, r):\n",
    "        return (self.predict(u,i) - r)**2\n",
    "\n",
    "model = LatentFactorModel(mu, 5, 0.00001)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "def trainingStep(interactions):\n",
    "    with tf.GradientTape() as tape:\n",
    "        sample = random.sample(interactions, 100)\n",
    "        losses = [model(userIDs[u],itemIDs[i],r) for (u,i,r) in sample]\n",
    "        losses.append(model.reg())\n",
    "    gradients = tape.gradient(losses, model.trainable_variables)\n",
    "    optimizer.apply_gradients((grad, var) for\n",
    "                              (grad, var) in zip(gradients, model.trainable_variables)\n",
    "                              if grad is not None)\n",
    "    losses = [l.numpy().flatten()[0] for l in losses]\n",
    "    return sum(losses)/len(losses)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "iteration 0, objective = 1.003250898922434\n",
      "3.7940786\n",
      "iteration 1, objective = 2.055088543794164\n",
      "3.8151507\n",
      "iteration 2, objective = 1.8758883254707055\n",
      "3.8375888\n",
      "iteration 3, objective = 2.1403769497704315\n",
      "3.8535335\n",
      "iteration 4, objective = 2.1997593027327467\n",
      "3.8594613\n",
      "iteration 5, objective = 2.0430366800530897\n",
      "3.8684816\n",
      "iteration 6, objective = 2.0631628962215713\n",
      "3.8631065\n",
      "iteration 7, objective = 2.1383294237524444\n",
      "3.852622\n",
      "iteration 8, objective = 2.113640423009133\n",
      "3.8396275\n",
      "iteration 9, objective = 2.078660896708405\n",
      "3.8254569\n",
      "iteration 10, objective = 2.0437873573317824\n",
      "3.8107479\n",
      "iteration 11, objective = 2.059274099758563\n",
      "3.794509\n",
      "iteration 12, objective = 2.055733612745033\n",
      "3.7745717\n",
      "iteration 13, objective = 2.025617622854768\n",
      "3.7527993\n",
      "iteration 14, objective = 2.0009010525046182\n",
      "3.7372653\n",
      "iteration 15, objective = 1.9791319826125178\n",
      "3.7267566\n",
      "iteration 16, objective = 1.9444395438136142\n",
      "3.7219098\n",
      "iteration 17, objective = 1.9472874784609127\n",
      "3.716126\n",
      "iteration 18, objective = 1.9251154267317545\n",
      "3.7171922\n",
      "iteration 19, objective = 1.9175847847085195\n",
      "3.7165096\n",
      "iteration 20, objective = 1.8915846549208102\n",
      "3.719298\n",
      "iteration 21, objective = 1.8755508497558544\n",
      "3.716357\n",
      "iteration 22, objective = 1.862973529629603\n",
      "3.716226\n",
      "iteration 23, objective = 1.8503678263499357\n",
      "3.7204533\n",
      "iteration 24, objective = 1.8464343695090293\n",
      "3.725771\n",
      "iteration 25, objective = 1.8413233317514455\n",
      "3.7284305\n",
      "iteration 26, objective = 1.8338220364119298\n",
      "3.7287042\n",
      "iteration 27, objective = 1.8305295546807732\n",
      "3.7304442\n",
      "iteration 28, objective = 1.8173108950150267\n",
      "3.73387\n",
      "iteration 29, objective = 1.7992263700412365\n",
      "3.7410955\n",
      "iteration 30, objective = 1.787204615459906\n",
      "3.7492929\n",
      "iteration 31, objective = 1.7767980067330995\n",
      "3.7532325\n",
      "iteration 32, objective = 1.7583024333102626\n",
      "3.7560413\n",
      "iteration 33, objective = 1.740756074473952\n",
      "3.7635467\n",
      "iteration 34, objective = 1.7232113907693445\n",
      "3.7714498\n",
      "iteration 35, objective = 1.7146527001899325\n",
      "3.779834\n",
      "iteration 36, objective = 1.7102909910619555\n",
      "3.7879317\n",
      "iteration 37, objective = 1.7026374637543136\n",
      "3.7952247\n",
      "iteration 38, objective = 1.6924465929368868\n",
      "3.800264\n",
      "iteration 39, objective = 1.679280166622371\n",
      "3.8056254\n",
      "iteration 40, objective = 1.669396050302124\n",
      "3.8095539\n",
      "iteration 41, objective = 1.6705639483700079\n",
      "3.8095996\n",
      "iteration 42, objective = 1.6610061425512936\n",
      "3.8117738\n",
      "iteration 43, objective = 1.6538189803754129\n",
      "3.8165424\n",
      "iteration 44, objective = 1.6474223826678436\n",
      "3.8166308\n",
      "iteration 45, objective = 1.639817937647128\n",
      "3.8167732\n",
      "iteration 46, objective = 1.626529281658221\n",
      "3.8178637\n",
      "iteration 47, objective = 1.6199135309955712\n",
      "3.8185556\n",
      "iteration 48, objective = 1.6165834657978975\n",
      "3.8169231\n",
      "iteration 49, objective = 1.6053519671963803\n",
      "3.8165064\n",
      "iteration 50, objective = 1.6001122126976146\n",
      "3.8128717\n",
      "iteration 51, objective = 1.5962126831599934\n",
      "3.808097\n",
      "iteration 52, objective = 1.5895991851208982\n",
      "3.8047082\n",
      "iteration 53, objective = 1.5967505561988686\n",
      "3.7957447\n",
      "iteration 54, objective = 1.590056422468079\n",
      "3.7881572\n",
      "iteration 55, objective = 1.5854082195886579\n",
      "3.7793767\n",
      "iteration 56, objective = 1.5811930222095592\n",
      "3.7709484\n",
      "iteration 57, objective = 1.5679663353593232\n",
      "3.7673035\n",
      "iteration 58, objective = 1.5621179098930316\n",
      "3.763359\n",
      "iteration 59, objective = 1.5588279883755265\n",
      "3.7603655\n",
      "iteration 60, objective = 1.5532026989808696\n",
      "3.7571669\n",
      "iteration 61, objective = 1.5510115537649505\n",
      "3.756382\n",
      "iteration 62, objective = 1.5464027528651958\n",
      "3.7566833\n",
      "iteration 63, objective = 1.5374791648510409\n",
      "3.7587845\n",
      "iteration 64, objective = 1.5390736455549323\n",
      "3.7603862\n",
      "iteration 65, objective = 1.5402082881037547\n",
      "3.7585897\n",
      "iteration 66, objective = 1.5412985836372055\n",
      "3.7566326\n",
      "iteration 67, objective = 1.5388461668766085\n",
      "3.7546713\n",
      "iteration 68, objective = 1.5369681548816518\n",
      "3.751323\n",
      "iteration 69, objective = 1.534757966364322\n",
      "3.7465234\n",
      "iteration 70, objective = 1.5346183582103508\n",
      "3.7422273\n",
      "iteration 71, objective = 1.533021452027567\n",
      "3.7400026\n",
      "iteration 72, objective = 1.5281768704436436\n",
      "3.7419813\n",
      "iteration 73, objective = 1.5252403041981915\n",
      "3.742877\n",
      "iteration 74, objective = 1.5260838792644393\n",
      "3.7403653\n",
      "iteration 75, objective = 1.5202550800199839\n",
      "3.7423608\n",
      "iteration 76, objective = 1.5167706191481838\n",
      "3.744864\n",
      "iteration 77, objective = 1.5092696529042375\n",
      "3.7520628\n",
      "iteration 78, objective = 1.5087814466741658\n",
      "3.7579317\n",
      "iteration 79, objective = 1.5090901507842778\n",
      "3.762563\n",
      "iteration 80, objective = 1.5054996684378423\n",
      "3.7668967\n",
      "iteration 81, objective = 1.5042677538339266\n",
      "3.769727\n",
      "iteration 82, objective = 1.4977207545072393\n",
      "3.774652\n",
      "iteration 83, objective = 1.4976308324311185\n",
      "3.7761037\n",
      "iteration 84, objective = 1.4964565832627352\n",
      "3.777988\n",
      "iteration 85, objective = 1.4956038302264125\n",
      "3.780792\n",
      "iteration 86, objective = 1.4958459840073448\n",
      "3.7815642\n",
      "iteration 87, objective = 1.4922957374663524\n",
      "3.7825403\n",
      "iteration 88, objective = 1.4920019876510193\n",
      "3.782092\n",
      "iteration 89, objective = 1.4899339954205655\n",
      "3.7834356\n",
      "iteration 90, objective = 1.4922812864248094\n",
      "3.7815223\n",
      "iteration 91, objective = 1.491062304929267\n",
      "3.7767992\n",
      "iteration 92, objective = 1.4935056490325458\n",
      "3.7699838\n",
      "iteration 93, objective = 1.4944270153649701\n",
      "3.763561\n",
      "iteration 94, objective = 1.4940832245468605\n",
      "3.7552013\n",
      "iteration 95, objective = 1.490943756815849\n",
      "3.7482965\n",
      "iteration 96, objective = 1.489358208446273\n",
      "3.7418509\n",
      "iteration 97, objective = 1.4886627298488317\n",
      "3.7361283\n",
      "iteration 98, objective = 1.4870931812283077\n",
      "3.7321405\n",
      "iteration 99, objective = 1.483268274873276\n",
      "3.7306972\n",
      "iteration 100, objective = 1.483117396004056\n",
      "3.7277956\n",
      "iteration 101, objective = 1.4827823994971567\n",
      "3.7262762\n",
      "iteration 102, objective = 1.4808318381559982\n",
      "3.7265403\n",
      "iteration 103, objective = 1.4770719494356777\n",
      "3.7256525\n",
      "iteration 104, objective = 1.4764209687858392\n",
      "3.724015\n",
      "iteration 105, objective = 1.4751112851624282\n",
      "3.7226536\n",
      "iteration 106, objective = 1.4699890699226765\n",
      "3.7238154\n",
      "iteration 107, objective = 1.470104384478914\n",
      "3.723395\n",
      "iteration 108, objective = 1.4659606157596135\n",
      "3.7240825\n",
      "iteration 109, objective = 1.4634083679011705\n",
      "3.7260263\n",
      "iteration 110, objective = 1.4632652860177564\n",
      "3.7257\n",
      "iteration 111, objective = 1.4606958397469911\n",
      "3.725089\n",
      "iteration 112, objective = 1.45732326391641\n",
      "3.723994\n",
      "iteration 113, objective = 1.4540668543805242\n",
      "3.7240825\n",
      "iteration 114, objective = 1.454320151239924\n",
      "3.7220538\n",
      "iteration 115, objective = 1.4559424917909876\n",
      "3.7173584\n",
      "iteration 116, objective = 1.452053529858694\n",
      "3.7171483\n",
      "iteration 117, objective = 1.453578107346193\n",
      "3.7151773\n",
      "iteration 118, objective = 1.454055881775745\n",
      "3.7127478\n",
      "iteration 119, objective = 1.4518405222338762\n",
      "3.7101192\n",
      "iteration 120, objective = 1.4537773077722937\n",
      "3.7079904\n",
      "iteration 121, objective = 1.4496616739200907\n",
      "3.706253\n",
      "iteration 122, objective = 1.445347795013887\n",
      "3.709144\n",
      "iteration 123, objective = 1.443300973376991\n",
      "3.713333\n",
      "iteration 124, objective = 1.4434719379224397\n",
      "3.7186844\n",
      "iteration 125, objective = 1.4408787965709364\n",
      "3.726045\n",
      "iteration 126, objective = 1.4400868780751774\n",
      "3.7328575\n",
      "iteration 127, objective = 1.4372592271095133\n",
      "3.7399292\n",
      "iteration 128, objective = 1.4341098815947428\n",
      "3.749006\n",
      "iteration 129, objective = 1.4327727127193288\n",
      "3.7549655\n",
      "iteration 130, objective = 1.4323974202028216\n",
      "3.7620416\n",
      "iteration 131, objective = 1.4334642944915352\n",
      "3.7668903\n",
      "iteration 132, objective = 1.431687235840196\n",
      "3.7714517\n",
      "iteration 133, objective = 1.4279286593865639\n",
      "3.7740653\n",
      "iteration 134, objective = 1.4259149768240056\n",
      "3.7755096\n",
      "iteration 135, objective = 1.4280856961556103\n",
      "3.7748258\n",
      "iteration 136, objective = 1.4265539892929806\n",
      "3.7775424\n",
      "iteration 137, objective = 1.423403387823058\n",
      "3.7797756\n",
      "iteration 138, objective = 1.4228289385495805\n",
      "3.7804515\n",
      "iteration 139, objective = 1.4211453006026808\n",
      "3.7817729\n",
      "iteration 140, objective = 1.4202949831953458\n",
      "3.7828689\n",
      "iteration 141, objective = 1.4199270744600077\n",
      "3.784014\n",
      "iteration 142, objective = 1.421041354675548\n",
      "3.7825751\n",
      "iteration 143, objective = 1.4222686864463236\n",
      "3.7800689\n",
      "iteration 144, objective = 1.422552781983847\n",
      "3.776313\n",
      "iteration 145, objective = 1.4208241262790098\n",
      "3.7739818\n",
      "iteration 146, objective = 1.419886385870006\n",
      "3.7717147\n",
      "iteration 147, objective = 1.420508163580795\n",
      "3.7694626\n",
      "iteration 148, objective = 1.417101613240188\n",
      "3.7682447\n",
      "iteration 149, objective = 1.4151708781147276\n",
      "3.7668548\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "iteration 150, objective = 1.4150482742201083\n",
      "3.7645822\n",
      "iteration 151, objective = 1.4154148576223007\n",
      "3.7638109\n",
      "iteration 152, objective = 1.4127523474998613\n",
      "3.7647285\n",
      "iteration 153, objective = 1.4136084231699233\n",
      "3.767915\n",
      "iteration 154, objective = 1.414316532300552\n",
      "3.7697465\n",
      "iteration 155, objective = 1.4125326648768397\n",
      "3.7727113\n",
      "iteration 156, objective = 1.4128852587213705\n",
      "3.7728772\n",
      "iteration 157, objective = 1.4129021817928487\n",
      "3.7709951\n",
      "iteration 158, objective = 1.4132266935647284\n",
      "3.7683084\n",
      "iteration 159, objective = 1.410647669429374\n",
      "3.7649\n",
      "iteration 160, objective = 1.4089151267802802\n",
      "3.7624018\n",
      "iteration 161, objective = 1.4061388342413836\n",
      "3.7594604\n",
      "iteration 162, objective = 1.4097138627308476\n",
      "3.7553616\n",
      "iteration 163, objective = 1.408845798057241\n",
      "3.7513986\n",
      "iteration 164, objective = 1.4060089357558403\n",
      "3.7477355\n",
      "iteration 165, objective = 1.407102442855054\n",
      "3.743871\n",
      "iteration 166, objective = 1.4083993205117018\n",
      "3.7382247\n",
      "iteration 167, objective = 1.4079719812658882\n",
      "3.733392\n",
      "iteration 168, objective = 1.409549728150001\n",
      "3.7262642\n",
      "iteration 169, objective = 1.4078224323696564\n",
      "3.7208078\n",
      "iteration 170, objective = 1.4083533300269948\n",
      "3.7148852\n",
      "iteration 171, objective = 1.4088679685741152\n",
      "3.7096782\n",
      "iteration 172, objective = 1.4067224435758363\n",
      "3.704926\n",
      "iteration 173, objective = 1.4054412996302659\n",
      "3.700089\n",
      "iteration 174, objective = 1.4034668902349228\n",
      "3.697791\n",
      "iteration 175, objective = 1.4038736380837447\n",
      "3.6966355\n",
      "iteration 176, objective = 1.4049319209961235\n",
      "3.6942937\n",
      "iteration 177, objective = 1.4038648752766465\n",
      "3.6960516\n",
      "iteration 178, objective = 1.4037688954227445\n",
      "3.6967363\n",
      "iteration 179, objective = 1.4038272588574852\n",
      "3.696308\n",
      "iteration 180, objective = 1.4029046224140498\n",
      "3.696913\n",
      "iteration 181, objective = 1.402480471741983\n",
      "3.6976728\n",
      "iteration 182, objective = 1.4041766220380276\n",
      "3.6976893\n",
      "iteration 183, objective = 1.405254270952253\n",
      "3.6984599\n",
      "iteration 184, objective = 1.4057651173038401\n",
      "3.6991088\n",
      "iteration 185, objective = 1.406110043276805\n",
      "3.6996977\n",
      "iteration 186, objective = 1.407680498089589\n",
      "3.698315\n",
      "iteration 187, objective = 1.4068972005374332\n",
      "3.697276\n",
      "iteration 188, objective = 1.4066039351876782\n",
      "3.6978488\n",
      "iteration 189, objective = 1.407086001333501\n",
      "3.6963391\n",
      "iteration 190, objective = 1.4063483799831524\n",
      "3.695303\n",
      "iteration 191, objective = 1.40538713738659\n",
      "3.6965234\n",
      "iteration 192, objective = 1.404327429236826\n",
      "3.6998858\n",
      "iteration 193, objective = 1.4055016227788264\n",
      "3.7015278\n",
      "iteration 194, objective = 1.4045800387474665\n",
      "3.704483\n",
      "iteration 195, objective = 1.4044507072328687\n",
      "3.7066221\n",
      "iteration 196, objective = 1.4053748297583488\n",
      "3.7066755\n",
      "iteration 197, objective = 1.4048323910628409\n",
      "3.7071466\n",
      "iteration 198, objective = 1.4048138078402506\n",
      "3.7089818\n",
      "iteration 199, objective = 1.4031467157390214\n",
      "3.71207\n",
      "iteration 200, objective = 1.4014482382577307\n",
      "3.713398\n",
      "iteration 201, objective = 1.402158260079718\n",
      "3.7142665\n",
      "iteration 202, objective = 1.4013822318956395\n",
      "3.714479\n",
      "iteration 203, objective = 1.40125365128357\n",
      "3.713038\n",
      "iteration 204, objective = 1.3996274130018478\n",
      "3.7134647\n",
      "iteration 205, objective = 1.3989316300502546\n",
      "3.7143764\n",
      "iteration 206, objective = 1.3971896767201435\n",
      "3.714928\n",
      "iteration 207, objective = 1.398972977792923\n",
      "3.7133892\n",
      "iteration 208, objective = 1.3984891125666805\n",
      "3.7121484\n",
      "iteration 209, objective = 1.3993144626954757\n",
      "3.7109075\n",
      "iteration 210, objective = 1.3982023720695624\n",
      "3.7090538\n",
      "iteration 211, objective = 1.3981582113062598\n",
      "3.7086957\n",
      "iteration 212, objective = 1.397409737339074\n",
      "3.7074986\n",
      "iteration 213, objective = 1.3974821540972744\n",
      "3.7074988\n",
      "iteration 214, objective = 1.396176981440125\n",
      "3.709886\n",
      "iteration 215, objective = 1.394987900406572\n",
      "3.7110252\n",
      "iteration 216, objective = 1.394659732122541\n",
      "3.7116146\n",
      "iteration 217, objective = 1.3934716207220474\n",
      "3.7131922\n",
      "iteration 218, objective = 1.3924629246576665\n",
      "3.7152076\n",
      "iteration 219, objective = 1.3922002202866264\n",
      "3.7170246\n",
      "iteration 220, objective = 1.3898122122094232\n",
      "3.719993\n",
      "iteration 221, objective = 1.388783368804882\n",
      "3.723361\n",
      "iteration 222, objective = 1.3878561645131833\n",
      "3.7266068\n",
      "iteration 223, objective = 1.3887466069473688\n",
      "3.727975\n",
      "iteration 224, objective = 1.389086394488717\n",
      "3.7302167\n",
      "iteration 225, objective = 1.388081494929084\n",
      "3.7336783\n",
      "iteration 226, objective = 1.3874603084289883\n",
      "3.7386353\n",
      "iteration 227, objective = 1.386436795094308\n",
      "3.744917\n",
      "iteration 228, objective = 1.3854726749762647\n",
      "3.7508628\n",
      "iteration 229, objective = 1.3842783016481797\n",
      "3.7582846\n",
      "iteration 230, objective = 1.3845976960684359\n",
      "3.764814\n",
      "iteration 231, objective = 1.3858858746578606\n",
      "3.7693386\n",
      "iteration 232, objective = 1.3847418177407163\n",
      "3.7739875\n",
      "iteration 233, objective = 1.3830423585854776\n",
      "3.7776892\n",
      "iteration 234, objective = 1.3832489677753343\n",
      "3.7808506\n",
      "iteration 235, objective = 1.3827356945653722\n",
      "3.7823412\n",
      "iteration 236, objective = 1.3818733665253302\n",
      "3.7854333\n",
      "iteration 237, objective = 1.3804223796181874\n",
      "3.7882535\n",
      "iteration 238, objective = 1.3814392556465311\n",
      "3.789321\n",
      "iteration 239, objective = 1.3809066025670664\n",
      "3.7912784\n",
      "iteration 240, objective = 1.37977781112272\n",
      "3.7932396\n",
      "iteration 241, objective = 1.377914894128576\n",
      "3.7950568\n",
      "iteration 242, objective = 1.3779203523768826\n",
      "3.7947857\n",
      "iteration 243, objective = 1.3779104048159325\n",
      "3.7938926\n",
      "iteration 244, objective = 1.3766771583955508\n",
      "3.7923412\n",
      "iteration 245, objective = 1.374462648599373\n",
      "3.790041\n",
      "iteration 246, objective = 1.3742689473544014\n",
      "3.7853184\n",
      "iteration 247, objective = 1.3736337153496219\n",
      "3.7800713\n",
      "iteration 248, objective = 1.3725020968893584\n",
      "3.776325\n",
      "iteration 249, objective = 1.3725178082291924\n",
      "3.7732656\n",
      "iteration 250, objective = 1.3719791809646125\n",
      "3.7706149\n",
      "iteration 251, objective = 1.3700494922051025\n",
      "3.7706966\n",
      "iteration 252, objective = 1.368746625674012\n",
      "3.770325\n",
      "iteration 253, objective = 1.3681828386618466\n",
      "3.770813\n",
      "iteration 254, objective = 1.3679969738974844\n",
      "3.7713134\n",
      "iteration 255, objective = 1.3690095925799943\n",
      "3.771582\n",
      "iteration 256, objective = 1.3676336932155835\n",
      "3.7698\n",
      "iteration 257, objective = 1.367164340222398\n",
      "3.7686996\n",
      "iteration 258, objective = 1.366607925494351\n",
      "3.7671587\n",
      "iteration 259, objective = 1.3645891365395486\n",
      "3.7665596\n",
      "iteration 260, objective = 1.3631444189674673\n",
      "3.7653818\n",
      "iteration 261, objective = 1.3624283302737838\n",
      "3.7645745\n",
      "iteration 262, objective = 1.3628992420910577\n",
      "3.7639666\n",
      "iteration 263, objective = 1.3626418978791255\n",
      "3.7642078\n",
      "iteration 264, objective = 1.3631724752124954\n",
      "3.7648208\n",
      "iteration 265, objective = 1.3640499854075385\n",
      "3.76371\n",
      "iteration 266, objective = 1.3640913482985995\n",
      "3.7628324\n",
      "iteration 267, objective = 1.362734729874294\n",
      "3.7619567\n",
      "iteration 268, objective = 1.3631142962544656\n",
      "3.760883\n",
      "iteration 269, objective = 1.3630745963706576\n",
      "3.759479\n",
      "iteration 270, objective = 1.3643177691228994\n",
      "3.7573702\n",
      "iteration 271, objective = 1.3630286478652562\n",
      "3.7577012\n",
      "iteration 272, objective = 1.3627235735650682\n",
      "3.7581663\n",
      "iteration 273, objective = 1.3613765450538151\n",
      "3.7577093\n",
      "iteration 274, objective = 1.3609861163297896\n",
      "3.7581482\n",
      "iteration 275, objective = 1.3613428467070083\n",
      "3.7571766\n",
      "iteration 276, objective = 1.3594532637121268\n",
      "3.757409\n",
      "iteration 277, objective = 1.3595385051868192\n",
      "3.7550817\n",
      "iteration 278, objective = 1.3587105451770796\n",
      "3.754785\n",
      "iteration 279, objective = 1.3589942238571946\n",
      "3.7531152\n",
      "iteration 280, objective = 1.357855019384868\n",
      "3.7534924\n",
      "iteration 281, objective = 1.356714920431533\n",
      "3.7547705\n",
      "iteration 282, objective = 1.3558477776491393\n",
      "3.756471\n",
      "iteration 283, objective = 1.354425782985699\n",
      "3.7588148\n",
      "iteration 284, objective = 1.3540160002748298\n",
      "3.7599428\n",
      "iteration 285, objective = 1.3543951710771638\n",
      "3.7597952\n",
      "iteration 286, objective = 1.3558377019996681\n",
      "3.7574484\n",
      "iteration 287, objective = 1.3559931350975647\n",
      "3.755953\n",
      "iteration 288, objective = 1.3553370145607553\n",
      "3.7561522\n",
      "iteration 289, objective = 1.3547192481094552\n",
      "3.7585282\n",
      "iteration 290, objective = 1.355503535966335\n",
      "3.7574575\n",
      "iteration 291, objective = 1.354478691303619\n",
      "3.757198\n",
      "iteration 292, objective = 1.3532448600030367\n",
      "3.7580605\n",
      "iteration 293, objective = 1.3523939949560908\n",
      "3.7611837\n",
      "iteration 294, objective = 1.3523957890750151\n",
      "3.7640705\n",
      "iteration 295, objective = 1.351944960412898\n",
      "3.7658243\n",
      "iteration 296, objective = 1.3521868234658598\n",
      "3.7677917\n",
      "iteration 297, objective = 1.3519256605400305\n",
      "3.7691967\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "iteration 298, objective = 1.3522016066064748\n",
      "3.7702725\n",
      "iteration 299, objective = 1.3504486320618359\n",
      "3.7737272\n",
      "iteration 300, objective = 1.350393455392476\n",
      "3.7758937\n",
      "iteration 301, objective = 1.3509451301024924\n",
      "3.7761354\n",
      "iteration 302, objective = 1.351005346170859\n",
      "3.775481\n",
      "iteration 303, objective = 1.3502056558827882\n",
      "3.7745407\n",
      "iteration 304, objective = 1.3496622107124245\n",
      "3.7729957\n",
      "iteration 305, objective = 1.3484338435818142\n",
      "3.7721703\n",
      "iteration 306, objective = 1.3500135863083065\n",
      "3.7689643\n",
      "iteration 307, objective = 1.350519568354838\n",
      "3.7658803\n",
      "iteration 308, objective = 1.350320685385172\n",
      "3.7620099\n",
      "iteration 309, objective = 1.3500136954724768\n",
      "3.758393\n",
      "iteration 310, objective = 1.3503972102331152\n",
      "3.754117\n",
      "iteration 311, objective = 1.3499803933251686\n",
      "3.7513924\n",
      "iteration 312, objective = 1.3497800257757657\n",
      "3.7465246\n",
      "iteration 313, objective = 1.3496025219197305\n",
      "3.7417133\n",
      "iteration 314, objective = 1.3486299372854365\n",
      "3.737756\n",
      "iteration 315, objective = 1.3497263458282631\n",
      "3.733349\n",
      "iteration 316, objective = 1.3488103389583357\n",
      "3.7293184\n",
      "iteration 317, objective = 1.3480162853815372\n",
      "3.7254486\n",
      "iteration 318, objective = 1.348315916101116\n",
      "3.7208185\n",
      "iteration 319, objective = 1.3474861402980667\n",
      "3.7182355\n",
      "iteration 320, objective = 1.3470207830729464\n",
      "3.7172601\n",
      "iteration 321, objective = 1.3476306969368026\n",
      "3.715809\n",
      "iteration 322, objective = 1.3465706216533293\n",
      "3.7150462\n",
      "iteration 323, objective = 1.3467004075996496\n",
      "3.7157602\n",
      "iteration 324, objective = 1.3458515429801474\n",
      "3.7168078\n",
      "iteration 325, objective = 1.3467178056477074\n",
      "3.717649\n",
      "iteration 326, objective = 1.3460674327712194\n",
      "3.7186441\n",
      "iteration 327, objective = 1.3460961249132122\n",
      "3.7203007\n",
      "iteration 328, objective = 1.3466634417996732\n",
      "3.7201478\n",
      "iteration 329, objective = 1.3473847604130438\n",
      "3.718601\n",
      "iteration 330, objective = 1.346763827020393\n",
      "3.7188776\n",
      "iteration 331, objective = 1.3451807695678049\n",
      "3.7211308\n",
      "iteration 332, objective = 1.344432106434474\n",
      "3.7247806\n",
      "iteration 333, objective = 1.3445291787422466\n",
      "3.726338\n",
      "iteration 334, objective = 1.3442794523883559\n",
      "3.7283506\n",
      "iteration 335, objective = 1.3437353815504667\n",
      "3.731899\n",
      "iteration 336, objective = 1.3432584206025744\n",
      "3.736452\n",
      "iteration 337, objective = 1.343928497699069\n",
      "3.7416015\n",
      "iteration 338, objective = 1.3430590979610375\n",
      "3.748486\n",
      "iteration 339, objective = 1.3428835829759067\n",
      "3.754307\n",
      "iteration 340, objective = 1.3419730891635528\n",
      "3.7604642\n",
      "iteration 341, objective = 1.341496901079637\n",
      "3.76502\n",
      "iteration 342, objective = 1.3395430507525565\n",
      "3.7702544\n",
      "iteration 343, objective = 1.3399121416962578\n",
      "3.773984\n",
      "iteration 344, objective = 1.3395819452871043\n",
      "3.7772534\n",
      "iteration 345, objective = 1.33904449946161\n",
      "3.780053\n",
      "iteration 346, objective = 1.3395293898262486\n",
      "3.7814963\n",
      "iteration 347, objective = 1.3384223637243573\n",
      "3.7837691\n",
      "iteration 348, objective = 1.3379261129242968\n",
      "3.785528\n",
      "iteration 349, objective = 1.3372564193180572\n",
      "3.7878687\n",
      "iteration 350, objective = 1.33649332375435\n",
      "3.7913482\n",
      "iteration 351, objective = 1.3360546477324382\n",
      "3.794535\n",
      "iteration 352, objective = 1.3347555990295876\n",
      "3.796788\n",
      "iteration 353, objective = 1.3348068688108847\n",
      "3.7974877\n",
      "iteration 354, objective = 1.3335882991342334\n",
      "3.800455\n",
      "iteration 355, objective = 1.333346933616584\n",
      "3.8002107\n",
      "iteration 356, objective = 1.3323860793872442\n",
      "3.800594\n",
      "iteration 357, objective = 1.3322474437318337\n",
      "3.799576\n",
      "iteration 358, objective = 1.3321702768944448\n",
      "3.7989507\n",
      "iteration 359, objective = 1.3310678482108196\n",
      "3.7976866\n",
      "iteration 360, objective = 1.3310551023906754\n",
      "3.7971997\n",
      "iteration 361, objective = 1.3301038245756276\n",
      "3.7961473\n",
      "iteration 362, objective = 1.3292175502391503\n",
      "3.7953696\n",
      "iteration 363, objective = 1.329457985985231\n",
      "3.7932847\n",
      "iteration 364, objective = 1.328637547110921\n",
      "3.7892666\n",
      "iteration 365, objective = 1.328334325706703\n",
      "3.7856882\n",
      "iteration 366, objective = 1.3277647603688567\n",
      "3.7808263\n",
      "iteration 367, objective = 1.3284402986893173\n",
      "3.774128\n",
      "iteration 368, objective = 1.3272840666452363\n",
      "3.7681832\n",
      "iteration 369, objective = 1.3273770610570066\n",
      "3.7622097\n",
      "iteration 370, objective = 1.3276083139552084\n",
      "3.7567627\n",
      "iteration 371, objective = 1.3268216392072438\n",
      "3.751547\n",
      "iteration 372, objective = 1.3261063337802468\n",
      "3.7473361\n",
      "iteration 373, objective = 1.3269291620592163\n",
      "3.7434347\n",
      "iteration 374, objective = 1.326162468155147\n",
      "3.7399235\n",
      "iteration 375, objective = 1.3260826118559248\n",
      "3.738438\n",
      "iteration 376, objective = 1.3260132752523837\n",
      "3.7396479\n",
      "iteration 377, objective = 1.3256825538406392\n",
      "3.7407227\n",
      "iteration 378, objective = 1.3247218332081812\n",
      "3.7422137\n",
      "iteration 379, objective = 1.3245110613275581\n",
      "3.7428298\n",
      "iteration 380, objective = 1.3238483654162305\n",
      "3.7438593\n",
      "iteration 381, objective = 1.3243570359436452\n",
      "3.7461793\n",
      "iteration 382, objective = 1.32398325588434\n",
      "3.7479322\n",
      "iteration 383, objective = 1.3240171875507365\n",
      "3.749037\n",
      "iteration 384, objective = 1.3243048173159078\n",
      "3.7484016\n",
      "iteration 385, objective = 1.3251471285401049\n",
      "3.748849\n",
      "iteration 386, objective = 1.3246899066087572\n",
      "3.7491736\n",
      "iteration 387, objective = 1.323649567113131\n",
      "3.751906\n",
      "iteration 388, objective = 1.3232371980700595\n",
      "3.7564943\n",
      "iteration 389, objective = 1.3226710867739448\n",
      "3.7616036\n",
      "iteration 390, objective = 1.3228071771275858\n",
      "3.7650223\n",
      "iteration 391, objective = 1.3221845238117478\n",
      "3.769303\n",
      "iteration 392, objective = 1.3220177141128446\n",
      "3.7728448\n",
      "iteration 393, objective = 1.3220369063276387\n",
      "3.775441\n",
      "iteration 394, objective = 1.3221198239986558\n",
      "3.7759287\n",
      "iteration 395, objective = 1.3208921462557843\n",
      "3.777649\n",
      "iteration 396, objective = 1.321818552917129\n",
      "3.776909\n",
      "iteration 397, objective = 1.3213287607833737\n",
      "3.7756214\n",
      "iteration 398, objective = 1.3216104271775164\n",
      "3.7739322\n",
      "iteration 399, objective = 1.3212242476167733\n",
      "3.7710679\n",
      "iteration 400, objective = 1.3211279374875804\n",
      "3.76842\n",
      "iteration 401, objective = 1.3209812482393584\n",
      "3.7654397\n",
      "iteration 402, objective = 1.3201910405184873\n",
      "3.7638032\n",
      "iteration 403, objective = 1.3202057264567169\n",
      "3.7632296\n",
      "iteration 404, objective = 1.319657242546336\n",
      "3.7635818\n",
      "iteration 405, objective = 1.3194570079547978\n",
      "3.7635622\n",
      "iteration 406, objective = 1.3192693707711736\n",
      "3.7632966\n",
      "iteration 407, objective = 1.3184977872404908\n",
      "3.7633948\n",
      "iteration 408, objective = 1.3180479575959618\n",
      "3.764594\n",
      "iteration 409, objective = 1.318167694235618\n",
      "3.764752\n",
      "iteration 410, objective = 1.3176128028379042\n",
      "3.766015\n",
      "iteration 411, objective = 1.3175289301893376\n",
      "3.7659159\n",
      "iteration 412, objective = 1.3165401241776478\n",
      "3.7678702\n",
      "iteration 413, objective = 1.3160781525321426\n",
      "3.770679\n",
      "iteration 414, objective = 1.3165874921652685\n",
      "3.7720401\n",
      "iteration 415, objective = 1.3159113058753533\n",
      "3.7724714\n",
      "iteration 416, objective = 1.3153835369809472\n",
      "3.7724173\n",
      "iteration 417, objective = 1.314378812979224\n",
      "3.7726688\n",
      "iteration 418, objective = 1.313734253543974\n",
      "3.7738547\n",
      "iteration 419, objective = 1.3142256668761885\n",
      "3.7738812\n",
      "iteration 420, objective = 1.3139441368081664\n",
      "3.7728858\n",
      "iteration 421, objective = 1.313612536728131\n",
      "3.7741578\n",
      "iteration 422, objective = 1.3125740569262676\n",
      "3.774814\n",
      "iteration 423, objective = 1.3132122724577595\n",
      "3.774092\n",
      "iteration 424, objective = 1.3127621195392976\n",
      "3.7733371\n",
      "iteration 425, objective = 1.312020308920482\n",
      "3.7726827\n",
      "iteration 426, objective = 1.3118309139343312\n",
      "3.7714205\n",
      "iteration 427, objective = 1.312010429269069\n",
      "3.770132\n",
      "iteration 428, objective = 1.3120953473827048\n",
      "3.767027\n",
      "iteration 429, objective = 1.311890070882335\n",
      "3.7647538\n",
      "iteration 430, objective = 1.3119397520093246\n",
      "3.7630432\n",
      "iteration 431, objective = 1.3112621335349108\n",
      "3.7611074\n",
      "iteration 432, objective = 1.3108295468678692\n",
      "3.7609267\n",
      "iteration 433, objective = 1.3102086286855488\n",
      "3.760374\n",
      "iteration 434, objective = 1.3095256130463626\n",
      "3.7618294\n",
      "iteration 435, objective = 1.3088110966521396\n",
      "3.7630563\n",
      "iteration 436, objective = 1.3090209124680758\n",
      "3.7649791\n",
      "iteration 437, objective = 1.3083977180312878\n",
      "3.768537\n",
      "iteration 438, objective = 1.3080633027945887\n",
      "3.7710314\n",
      "iteration 439, objective = 1.3073348542971863\n",
      "3.773881\n",
      "iteration 440, objective = 1.3072075858885592\n",
      "3.775466\n",
      "iteration 441, objective = 1.3073734039357843\n",
      "3.7749863\n",
      "iteration 442, objective = 1.3078211289824264\n",
      "3.7756877\n",
      "iteration 443, objective = 1.3072218322627351\n",
      "3.7769833\n",
      "iteration 444, objective = 1.307343917775545\n",
      "3.7775052\n",
      "iteration 445, objective = 1.3066185922668963\n",
      "3.7785308\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "iteration 446, objective = 1.3056423069800285\n",
      "3.7800105\n",
      "iteration 447, objective = 1.3056572527688164\n",
      "3.7808833\n",
      "iteration 448, objective = 1.3055527181409303\n",
      "3.7804873\n",
      "iteration 449, objective = 1.3059075729610674\n",
      "3.7799745\n",
      "iteration 450, objective = 1.3063236693932554\n",
      "3.7779114\n",
      "iteration 451, objective = 1.3057216663195004\n",
      "3.7754338\n",
      "iteration 452, objective = 1.3059977294204628\n",
      "3.7711096\n",
      "iteration 453, objective = 1.3056849112223763\n",
      "3.765772\n",
      "iteration 454, objective = 1.30517438174241\n",
      "3.761315\n",
      "iteration 455, objective = 1.3056622501468218\n",
      "3.7563918\n",
      "iteration 456, objective = 1.3053447165032002\n",
      "3.7512774\n",
      "iteration 457, objective = 1.3060866193260898\n",
      "3.7461534\n",
      "iteration 458, objective = 1.3051958612477932\n",
      "3.7409594\n",
      "iteration 459, objective = 1.3048602566052834\n",
      "3.7367036\n",
      "iteration 460, objective = 1.3049826709925298\n",
      "3.7332904\n",
      "iteration 461, objective = 1.3058921314021532\n",
      "3.7296994\n",
      "iteration 462, objective = 1.304745268703903\n",
      "3.7290516\n",
      "iteration 463, objective = 1.3050405959506404\n",
      "3.7271404\n",
      "iteration 464, objective = 1.3047401910298293\n",
      "3.725167\n",
      "iteration 465, objective = 1.3041860898905395\n",
      "3.723924\n",
      "iteration 466, objective = 1.304404447010304\n",
      "3.7227654\n",
      "iteration 467, objective = 1.304397267927048\n",
      "3.7213445\n",
      "iteration 468, objective = 1.304825178067492\n",
      "3.719358\n",
      "iteration 469, objective = 1.3041203392592573\n",
      "3.7185106\n",
      "iteration 470, objective = 1.3046053351546572\n",
      "3.717848\n",
      "iteration 471, objective = 1.304132008656569\n",
      "3.7185178\n",
      "iteration 472, objective = 1.3036574878732818\n",
      "3.719637\n",
      "iteration 473, objective = 1.3031613900543852\n",
      "3.721468\n",
      "iteration 474, objective = 1.3028100292950209\n",
      "3.7232368\n",
      "iteration 475, objective = 1.3024398492429277\n",
      "3.7250676\n",
      "iteration 476, objective = 1.302507023793604\n",
      "3.7272644\n",
      "iteration 477, objective = 1.301645527199312\n",
      "3.7313924\n",
      "iteration 478, objective = 1.3014901086728867\n",
      "3.7356107\n",
      "iteration 479, objective = 1.3015467713842115\n",
      "3.7387664\n",
      "iteration 480, objective = 1.3020991540880342\n",
      "3.7413943\n",
      "iteration 481, objective = 1.3015989508912247\n",
      "3.7443657\n",
      "iteration 482, objective = 1.3017411380913482\n",
      "3.746174\n",
      "iteration 483, objective = 1.3012713389564297\n",
      "3.7482808\n",
      "iteration 484, objective = 1.3011658606846235\n",
      "3.750121\n",
      "iteration 485, objective = 1.3014273532683214\n",
      "3.7520444\n",
      "iteration 486, objective = 1.3012419871382312\n",
      "3.7532728\n",
      "iteration 487, objective = 1.3023315925145\n",
      "3.7520607\n",
      "iteration 488, objective = 1.3020072211899232\n",
      "3.7521818\n",
      "iteration 489, objective = 1.3028026690052332\n",
      "3.7513485\n",
      "iteration 490, objective = 1.302852262489555\n",
      "3.7517047\n",
      "iteration 491, objective = 1.3026959630989374\n",
      "3.7522764\n",
      "iteration 492, objective = 1.3026286120990287\n",
      "3.75269\n",
      "iteration 493, objective = 1.3029518310835304\n",
      "3.7531984\n",
      "iteration 494, objective = 1.3027322090374485\n",
      "3.7543516\n",
      "iteration 495, objective = 1.3017352696659343\n",
      "3.7560425\n",
      "iteration 496, objective = 1.3013294689426578\n",
      "3.7580173\n",
      "iteration 497, objective = 1.3007331623265268\n",
      "3.7607348\n",
      "iteration 498, objective = 1.300521663794829\n",
      "3.762931\n",
      "iteration 499, objective = 1.3000959432468815\n",
      "3.763339\n",
      "iteration 500, objective = 1.2997714515805079\n",
      "3.7643814\n",
      "iteration 501, objective = 1.2998383085039853\n",
      "3.7635353\n",
      "iteration 502, objective = 1.3001264757677045\n",
      "3.7624679\n",
      "iteration 503, objective = 1.3003870957771813\n",
      "3.762144\n",
      "iteration 504, objective = 1.3008623174848204\n",
      "3.7611434\n",
      "iteration 505, objective = 1.3001625100329204\n",
      "3.7615113\n",
      "iteration 506, objective = 1.2999331594584642\n",
      "3.7626042\n",
      "iteration 507, objective = 1.2996921986178613\n",
      "3.7639215\n",
      "iteration 508, objective = 1.2994461786761677\n",
      "3.7640984\n",
      "iteration 509, objective = 1.299208488531793\n",
      "3.7647026\n",
      "iteration 510, objective = 1.2985578238730362\n",
      "3.7659378\n",
      "iteration 511, objective = 1.2980937845772345\n",
      "3.7682097\n",
      "iteration 512, objective = 1.2980047737308842\n",
      "3.7700987\n",
      "iteration 513, objective = 1.2985179184465079\n",
      "3.770348\n",
      "iteration 514, objective = 1.2987412548829524\n",
      "3.771195\n",
      "iteration 515, objective = 1.2989840279708724\n",
      "3.7707145\n",
      "iteration 516, objective = 1.298855097749276\n",
      "3.7702396\n",
      "iteration 517, objective = 1.2987200068618812\n",
      "3.7706776\n",
      "iteration 518, objective = 1.2981988554936343\n",
      "3.7699614\n",
      "iteration 519, objective = 1.2978541014486027\n",
      "3.7703555\n",
      "iteration 520, objective = 1.2967366208164475\n",
      "3.7719152\n",
      "iteration 521, objective = 1.2963418952189967\n",
      "3.7731981\n",
      "iteration 522, objective = 1.2955163232318252\n",
      "3.7742822\n",
      "iteration 523, objective = 1.2955371380740026\n",
      "3.7774587\n",
      "iteration 524, objective = 1.2950494638282963\n",
      "3.77983\n",
      "iteration 525, objective = 1.2950770416449513\n",
      "3.7820783\n",
      "iteration 526, objective = 1.295368013086354\n",
      "3.7833614\n",
      "iteration 527, objective = 1.2952817448054181\n",
      "3.7835362\n",
      "iteration 528, objective = 1.29487530772649\n",
      "3.7843397\n",
      "iteration 529, objective = 1.2944986673099081\n",
      "3.7857125\n",
      "iteration 530, objective = 1.2948855796532825\n",
      "3.7844071\n",
      "iteration 531, objective = 1.295189593449428\n",
      "3.7801855\n",
      "iteration 532, objective = 1.2945666675985226\n",
      "3.7762673\n",
      "iteration 533, objective = 1.2948347007833259\n",
      "3.7720203\n",
      "iteration 534, objective = 1.2947425797480754\n",
      "3.7682295\n",
      "iteration 535, objective = 1.2952166130890634\n",
      "3.7644455\n",
      "iteration 536, objective = 1.2950015158437331\n",
      "3.7609453\n",
      "iteration 537, objective = 1.2952455302492347\n",
      "3.7583797\n",
      "iteration 538, objective = 1.2948653980282971\n",
      "3.755205\n",
      "iteration 539, objective = 1.2947962213097342\n",
      "3.753377\n",
      "iteration 540, objective = 1.2946568401166934\n",
      "3.7534566\n",
      "iteration 541, objective = 1.2943942748569615\n",
      "3.752717\n",
      "iteration 542, objective = 1.294905049018097\n",
      "3.7507868\n",
      "iteration 543, objective = 1.2956424201269507\n",
      "3.748022\n",
      "iteration 544, objective = 1.295231470380383\n",
      "3.7471147\n",
      "iteration 545, objective = 1.2949554668967393\n",
      "3.7468286\n",
      "iteration 546, objective = 1.2943222071574736\n",
      "3.7461364\n",
      "iteration 547, objective = 1.2939272426330963\n",
      "3.7454684\n",
      "iteration 548, objective = 1.2936297747009609\n",
      "3.7452624\n",
      "iteration 549, objective = 1.2933091074786025\n",
      "3.7449927\n",
      "iteration 550, objective = 1.292930743508932\n",
      "3.7458987\n",
      "iteration 551, objective = 1.2920765508432157\n",
      "3.747086\n",
      "iteration 552, objective = 1.2923605991204088\n",
      "3.7471175\n",
      "iteration 553, objective = 1.2926075442020435\n",
      "3.7471457\n",
      "iteration 554, objective = 1.2921003370197066\n",
      "3.7478173\n",
      "iteration 555, objective = 1.293102394145923\n",
      "3.745788\n",
      "iteration 556, objective = 1.293534091962533\n",
      "3.7430348\n",
      "iteration 557, objective = 1.2938664179664898\n",
      "3.7398825\n",
      "iteration 558, objective = 1.2934066433441647\n",
      "3.7376156\n",
      "iteration 559, objective = 1.2939084006550459\n",
      "3.735712\n",
      "iteration 560, objective = 1.295237802918383\n",
      "3.7307315\n",
      "iteration 561, objective = 1.2952759303591188\n",
      "3.7255409\n",
      "iteration 562, objective = 1.2951346973633378\n",
      "3.7211468\n",
      "iteration 563, objective = 1.2953695881086078\n",
      "3.7154467\n",
      "iteration 564, objective = 1.2953176634040784\n",
      "3.7114518\n",
      "iteration 565, objective = 1.2945584076069185\n",
      "3.7095764\n",
      "iteration 566, objective = 1.2943570121462\n",
      "3.7085443\n",
      "iteration 567, objective = 1.2944317621350574\n",
      "3.707814\n",
      "iteration 568, objective = 1.2942357458289688\n",
      "3.706517\n",
      "iteration 569, objective = 1.2942742200338548\n",
      "3.7040737\n",
      "iteration 570, objective = 1.2944093310074032\n",
      "3.7013564\n",
      "iteration 571, objective = 1.2936380209797989\n",
      "3.7014265\n",
      "iteration 572, objective = 1.2934063777938614\n",
      "3.7016776\n",
      "iteration 573, objective = 1.2932357939102133\n",
      "3.7044375\n",
      "iteration 574, objective = 1.2936442934064183\n",
      "3.7060905\n",
      "iteration 575, objective = 1.2941797349545334\n",
      "3.7063866\n",
      "iteration 576, objective = 1.2934292968927599\n",
      "3.708493\n",
      "iteration 577, objective = 1.2935401519496954\n",
      "3.7109184\n",
      "iteration 578, objective = 1.2936581624576042\n",
      "3.7125351\n",
      "iteration 579, objective = 1.2934768425683212\n",
      "3.7138832\n",
      "iteration 580, objective = 1.2932838037276906\n",
      "3.7164629\n",
      "iteration 581, objective = 1.2923385419674231\n",
      "3.7209017\n",
      "iteration 582, objective = 1.2917853805280977\n",
      "3.7263343\n",
      "iteration 583, objective = 1.2915281105275087\n",
      "3.730709\n",
      "iteration 584, objective = 1.292282610506069\n",
      "3.732003\n",
      "iteration 585, objective = 1.2920941343670922\n",
      "3.7344558\n",
      "iteration 586, objective = 1.291857764378004\n",
      "3.7359776\n",
      "iteration 587, objective = 1.2915370893547276\n",
      "3.738485\n",
      "iteration 588, objective = 1.2914831450290867\n",
      "3.740229\n",
      "iteration 589, objective = 1.2909912648507935\n",
      "3.742208\n",
      "iteration 590, objective = 1.290983965211171\n",
      "3.7440271\n",
      "iteration 591, objective = 1.2906344613156593\n",
      "3.7479618\n",
      "iteration 592, objective = 1.2911133016154281\n",
      "3.751717\n",
      "iteration 593, objective = 1.2916124711412877\n",
      "3.753709\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "iteration 594, objective = 1.2915079231374413\n",
      "3.7558043\n",
      "iteration 595, objective = 1.291041558251931\n",
      "3.7589898\n",
      "iteration 596, objective = 1.2905296390117973\n",
      "3.7630537\n",
      "iteration 597, objective = 1.2904673645345024\n",
      "3.7658243\n",
      "iteration 598, objective = 1.2899994922981664\n",
      "3.7682242\n",
      "iteration 599, objective = 1.2903694025013854\n",
      "3.770429\n",
      "iteration 600, objective = 1.2902029401199402\n",
      "3.771947\n",
      "iteration 601, objective = 1.2900071042299082\n",
      "3.774975\n",
      "iteration 602, objective = 1.2899358823201468\n",
      "3.7771087\n",
      "iteration 603, objective = 1.2899060890761023\n",
      "3.777769\n",
      "iteration 604, objective = 1.2899528591604386\n",
      "3.7781823\n",
      "iteration 605, objective = 1.2904631881811939\n",
      "3.777797\n",
      "iteration 606, objective = 1.2897236231177924\n",
      "3.777022\n",
      "iteration 607, objective = 1.2895879709743745\n",
      "3.7769647\n",
      "iteration 608, objective = 1.2890712726708167\n",
      "3.776644\n",
      "iteration 609, objective = 1.2897058725945276\n",
      "3.7741342\n",
      "iteration 610, objective = 1.2892640752585753\n",
      "3.772463\n",
      "iteration 611, objective = 1.2888857260733846\n",
      "3.7710104\n",
      "iteration 612, objective = 1.2886225264464994\n",
      "3.7711487\n",
      "iteration 613, objective = 1.2883828140871794\n",
      "3.772122\n",
      "iteration 614, objective = 1.2884864264458336\n",
      "3.7729833\n",
      "iteration 615, objective = 1.2882976524833254\n",
      "3.7742898\n",
      "iteration 616, objective = 1.287996123032855\n",
      "3.7762241\n",
      "iteration 617, objective = 1.2878871895586161\n",
      "3.7784472\n",
      "iteration 618, objective = 1.2876122363530997\n",
      "3.7806652\n",
      "iteration 619, objective = 1.287647096767362\n",
      "3.781374\n",
      "iteration 620, objective = 1.2872557393514603\n",
      "3.7819567\n",
      "iteration 621, objective = 1.2872669991683534\n",
      "3.781227\n",
      "iteration 622, objective = 1.2871901356868665\n",
      "3.7790258\n",
      "iteration 623, objective = 1.2875036023478965\n",
      "3.776089\n",
      "iteration 624, objective = 1.2873383518411587\n",
      "3.7744277\n",
      "iteration 625, objective = 1.2867375162107995\n",
      "3.7741349\n",
      "iteration 626, objective = 1.2861476596034203\n",
      "3.7749572\n",
      "iteration 627, objective = 1.2864872649953867\n",
      "3.7736912\n",
      "iteration 628, objective = 1.2861831001250394\n",
      "3.7728546\n",
      "iteration 629, objective = 1.2864305573462969\n",
      "3.772612\n",
      "iteration 630, objective = 1.2863079005127138\n",
      "3.7717326\n",
      "iteration 631, objective = 1.2871907434931422\n",
      "3.768751\n",
      "iteration 632, objective = 1.2869010800659055\n",
      "3.7671976\n",
      "iteration 633, objective = 1.2872194835993702\n",
      "3.7643445\n",
      "iteration 634, objective = 1.287161281466702\n",
      "3.7623327\n",
      "iteration 635, objective = 1.2866941514529275\n",
      "3.7618418\n",
      "iteration 636, objective = 1.2869092912987412\n",
      "3.7597547\n",
      "iteration 637, objective = 1.2869999366819536\n",
      "3.756448\n",
      "iteration 638, objective = 1.2870020522111871\n",
      "3.7540092\n",
      "iteration 639, objective = 1.2878028689285965\n",
      "3.749041\n",
      "iteration 640, objective = 1.2878938262273345\n",
      "3.7425435\n",
      "iteration 641, objective = 1.2877600986364413\n",
      "3.7369146\n",
      "iteration 642, objective = 1.2873776453832435\n",
      "3.733695\n",
      "iteration 643, objective = 1.2867557088055044\n",
      "3.730047\n",
      "iteration 644, objective = 1.2864199533355054\n",
      "3.7274761\n",
      "iteration 645, objective = 1.2867174559245276\n",
      "3.7243924\n",
      "iteration 646, objective = 1.2866870675470852\n",
      "3.7203777\n",
      "iteration 647, objective = 1.2864404094822448\n",
      "3.7164805\n",
      "iteration 648, objective = 1.2860976532028725\n",
      "3.7131648\n",
      "iteration 649, objective = 1.2863748462552855\n",
      "3.7107043\n",
      "iteration 650, objective = 1.286577742307362\n",
      "3.7068791\n",
      "iteration 651, objective = 1.2861283395110734\n",
      "3.703488\n",
      "iteration 652, objective = 1.285935524582737\n",
      "3.700099\n",
      "iteration 653, objective = 1.2864434249942083\n",
      "3.6966696\n",
      "iteration 654, objective = 1.2862426210041955\n",
      "3.6951847\n",
      "iteration 655, objective = 1.2857917976542568\n",
      "3.6953654\n",
      "iteration 656, objective = 1.2854544550408855\n",
      "3.6973543\n",
      "iteration 657, objective = 1.2853938940991378\n",
      "3.6997569\n",
      "iteration 658, objective = 1.2848513750923893\n",
      "3.7038033\n",
      "iteration 659, objective = 1.2849779919762676\n",
      "3.7072031\n",
      "iteration 660, objective = 1.2848948224634107\n",
      "3.7108765\n",
      "iteration 661, objective = 1.2850349615078847\n",
      "3.714651\n",
      "iteration 662, objective = 1.2850669735648073\n",
      "3.7183359\n",
      "iteration 663, objective = 1.2843232303915937\n",
      "3.7223942\n",
      "iteration 664, objective = 1.2838142481482255\n",
      "3.7285576\n",
      "iteration 665, objective = 1.2843778600953777\n",
      "3.7329056\n",
      "iteration 666, objective = 1.2843964373900396\n",
      "3.7373838\n",
      "iteration 667, objective = 1.2842662795549673\n",
      "3.7411284\n",
      "iteration 668, objective = 1.2842378591292058\n",
      "3.7450795\n",
      "iteration 669, objective = 1.2839952681596516\n",
      "3.749208\n",
      "iteration 670, objective = 1.2839255807958638\n",
      "3.7528403\n",
      "iteration 671, objective = 1.2840889865141618\n",
      "3.7563064\n",
      "iteration 672, objective = 1.2836427481988026\n",
      "3.7589295\n",
      "iteration 673, objective = 1.2833271301139753\n",
      "3.7614636\n",
      "iteration 674, objective = 1.2833963376909943\n",
      "3.7631855\n",
      "iteration 675, objective = 1.2836583815822549\n",
      "3.7622964\n",
      "iteration 676, objective = 1.2830886256511018\n",
      "3.7635202\n",
      "iteration 677, objective = 1.2830294812397078\n",
      "3.7654395\n",
      "iteration 678, objective = 1.2827274280414624\n",
      "3.7683284\n",
      "iteration 679, objective = 1.2830295812080323\n",
      "3.7686086\n",
      "iteration 680, objective = 1.2830344956950168\n",
      "3.76741\n",
      "iteration 681, objective = 1.2826711855482775\n",
      "3.766699\n",
      "iteration 682, objective = 1.282362765453767\n",
      "3.765862\n",
      "iteration 683, objective = 1.2823358522671269\n",
      "3.7645764\n",
      "iteration 684, objective = 1.282243894083422\n",
      "3.76196\n",
      "iteration 685, objective = 1.2822270841462338\n",
      "3.7596507\n",
      "iteration 686, objective = 1.2818824486523597\n",
      "3.758647\n",
      "iteration 687, objective = 1.2823580988925674\n",
      "3.7551956\n",
      "iteration 688, objective = 1.2818798574066244\n",
      "3.7529376\n",
      "iteration 689, objective = 1.2820674630887086\n",
      "3.750901\n",
      "iteration 690, objective = 1.2814448643710021\n",
      "3.7507043\n",
      "iteration 691, objective = 1.2814021786202885\n",
      "3.7493882\n",
      "iteration 692, objective = 1.281295536134781\n",
      "3.7481055\n",
      "iteration 693, objective = 1.2809947613891122\n",
      "3.7455957\n",
      "iteration 694, objective = 1.2813938738374142\n",
      "3.7432172\n",
      "iteration 695, objective = 1.2813742783757804\n",
      "3.7416341\n",
      "iteration 696, objective = 1.2807298917778571\n",
      "3.7426457\n",
      "iteration 697, objective = 1.2803329239359738\n",
      "3.7434478\n",
      "iteration 698, objective = 1.2798798882992781\n",
      "3.7460706\n",
      "iteration 699, objective = 1.2796984292926759\n",
      "3.7490468\n",
      "iteration 700, objective = 1.279597394694223\n",
      "3.7506938\n",
      "iteration 701, objective = 1.2798400313075764\n",
      "3.751393\n",
      "iteration 702, objective = 1.2799837989677185\n",
      "3.7524648\n",
      "iteration 703, objective = 1.2798223434076232\n",
      "3.7537181\n",
      "iteration 704, objective = 1.279780949061335\n",
      "3.7529292\n",
      "iteration 705, objective = 1.279726439257482\n",
      "3.752282\n",
      "iteration 706, objective = 1.2795429480164027\n",
      "3.7505763\n",
      "iteration 707, objective = 1.2798584747000583\n",
      "3.7489932\n",
      "iteration 708, objective = 1.2791374129759219\n",
      "3.7485058\n",
      "iteration 709, objective = 1.2792377215336215\n",
      "3.748144\n",
      "iteration 710, objective = 1.2788210604103805\n",
      "3.7493079\n",
      "iteration 711, objective = 1.2795511085396132\n",
      "3.7493231\n",
      "iteration 712, objective = 1.2795454046212658\n",
      "3.7474868\n",
      "iteration 713, objective = 1.2793312168219724\n",
      "3.7462692\n",
      "iteration 714, objective = 1.2797260414893916\n",
      "3.7452817\n",
      "iteration 715, objective = 1.2796385765731488\n",
      "3.7444954\n",
      "iteration 716, objective = 1.2791258605748035\n",
      "3.7447877\n",
      "iteration 717, objective = 1.2786619400364507\n",
      "3.7457235\n",
      "iteration 718, objective = 1.2783636251964385\n",
      "3.7456324\n",
      "iteration 719, objective = 1.278073002421011\n",
      "3.7466197\n",
      "iteration 720, objective = 1.278069159831693\n",
      "3.748277\n",
      "iteration 721, objective = 1.2777743030968918\n",
      "3.750304\n",
      "iteration 722, objective = 1.2774638487534176\n",
      "3.752472\n",
      "iteration 723, objective = 1.277406551948933\n",
      "3.7524533\n",
      "iteration 724, objective = 1.2769956752467175\n",
      "3.7541468\n",
      "iteration 725, objective = 1.2771214091700631\n",
      "3.7543693\n",
      "iteration 726, objective = 1.2769995885161471\n",
      "3.7551484\n",
      "iteration 727, objective = 1.2764726288282728\n",
      "3.7568886\n",
      "iteration 728, objective = 1.2765167633155703\n",
      "3.757137\n",
      "iteration 729, objective = 1.2764821415800593\n",
      "3.757517\n",
      "iteration 730, objective = 1.2767865368531663\n",
      "3.7586632\n",
      "iteration 731, objective = 1.2763971134926637\n",
      "3.7594645\n",
      "iteration 732, objective = 1.276030722769737\n",
      "3.760815\n",
      "iteration 733, objective = 1.2755266888435\n",
      "3.7612433\n",
      "iteration 734, objective = 1.2759096880392717\n",
      "3.75997\n",
      "iteration 735, objective = 1.2763037612971013\n",
      "3.7577114\n",
      "iteration 736, objective = 1.2759252986401681\n",
      "3.7563918\n",
      "iteration 737, objective = 1.2762561027313024\n",
      "3.7546403\n",
      "iteration 738, objective = 1.2764166362115033\n",
      "3.7529004\n",
      "iteration 739, objective = 1.2761397839457447\n",
      "3.7524884\n",
      "iteration 740, objective = 1.275668561677492\n",
      "3.7524564\n",
      "iteration 741, objective = 1.2754100842850045\n",
      "3.7499993\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "iteration 742, objective = 1.2753668285224409\n",
      "3.748106\n",
      "iteration 743, objective = 1.2751447243813698\n",
      "3.7479045\n",
      "iteration 744, objective = 1.27484575922927\n",
      "3.7456875\n",
      "iteration 745, objective = 1.2745898907026183\n",
      "3.7443192\n",
      "iteration 746, objective = 1.2743683025271484\n",
      "3.7437875\n",
      "iteration 747, objective = 1.2738996586849844\n",
      "3.7443259\n",
      "iteration 748, objective = 1.2741109187263866\n",
      "3.7434142\n",
      "iteration 749, objective = 1.2739261015816512\n",
      "3.7433681\n",
      "iteration 750, objective = 1.2739212416635044\n",
      "3.7429318\n",
      "iteration 751, objective = 1.274392684048807\n",
      "3.7413688\n",
      "iteration 752, objective = 1.2742405864601867\n",
      "3.7384121\n",
      "iteration 753, objective = 1.2740080778452\n",
      "3.7380583\n",
      "iteration 754, objective = 1.2740096957210814\n",
      "3.7380648\n",
      "iteration 755, objective = 1.2742383212921478\n",
      "3.7377214\n",
      "iteration 756, objective = 1.2750098278226265\n",
      "3.7356584\n",
      "iteration 757, objective = 1.274578807027535\n",
      "3.7336261\n",
      "iteration 758, objective = 1.2745686859065435\n",
      "3.7316034\n",
      "iteration 759, objective = 1.2744157496149962\n",
      "3.7294385\n",
      "iteration 760, objective = 1.2742005462252952\n",
      "3.727346\n",
      "iteration 761, objective = 1.2743766502450848\n",
      "3.7255356\n",
      "iteration 762, objective = 1.2739950282753967\n",
      "3.7256532\n",
      "iteration 763, objective = 1.274056246300171\n",
      "3.7252593\n",
      "iteration 764, objective = 1.2737592460794644\n",
      "3.7257924\n",
      "iteration 765, objective = 1.2737384873508313\n",
      "3.7259188\n",
      "iteration 766, objective = 1.2735707636165556\n",
      "3.7271683\n",
      "iteration 767, objective = 1.2735476569043924\n",
      "3.727594\n",
      "iteration 768, objective = 1.2731758123372672\n",
      "3.7284555\n",
      "iteration 769, objective = 1.2733960648342444\n",
      "3.7295666\n",
      "iteration 770, objective = 1.2730710535433407\n",
      "3.7313282\n",
      "iteration 771, objective = 1.2729158839053192\n",
      "3.7332637\n",
      "iteration 772, objective = 1.2727333314178932\n",
      "3.7355292\n",
      "iteration 773, objective = 1.2727893031736555\n",
      "3.7379284\n",
      "iteration 774, objective = 1.272289011254183\n",
      "3.7402837\n",
      "iteration 775, objective = 1.2721566724702371\n",
      "3.7422502\n",
      "iteration 776, objective = 1.2720395035471403\n",
      "3.744269\n",
      "iteration 777, objective = 1.2718623046678483\n",
      "3.7460299\n",
      "iteration 778, objective = 1.2715374736809626\n",
      "3.7482457\n",
      "iteration 779, objective = 1.2713412507833417\n",
      "3.75003\n",
      "iteration 780, objective = 1.2713425447244346\n",
      "3.7511346\n",
      "iteration 781, objective = 1.2708946038955344\n",
      "3.7511127\n",
      "iteration 782, objective = 1.2712763965439031\n",
      "3.74916\n",
      "iteration 783, objective = 1.2711521948746645\n",
      "3.7474487\n",
      "iteration 784, objective = 1.2711418787616635\n",
      "3.746838\n",
      "iteration 785, objective = 1.2709536139928683\n",
      "3.7455792\n",
      "iteration 786, objective = 1.270458212603602\n",
      "3.745213\n",
      "iteration 787, objective = 1.2699544402241592\n",
      "3.7476656\n",
      "iteration 788, objective = 1.26978379242568\n",
      "3.750092\n",
      "iteration 789, objective = 1.269725856971475\n",
      "3.7517214\n",
      "iteration 790, objective = 1.269405968833776\n",
      "3.7544773\n",
      "iteration 791, objective = 1.2697034884136236\n",
      "3.7557952\n",
      "iteration 792, objective = 1.2694848921450774\n",
      "3.7572136\n",
      "iteration 793, objective = 1.2692473908773947\n",
      "3.7592208\n",
      "iteration 794, objective = 1.2687766914890244\n",
      "3.7624257\n",
      "iteration 795, objective = 1.2685457974643237\n",
      "3.7654936\n",
      "iteration 796, objective = 1.2680352171073757\n",
      "3.7695074\n",
      "iteration 797, objective = 1.2676462478822532\n",
      "3.773946\n",
      "iteration 798, objective = 1.2676399786733104\n",
      "3.7781885\n",
      "iteration 799, objective = 1.267365445966122\n",
      "3.7835543\n",
      "iteration 800, objective = 1.2674384728349868\n",
      "3.7895827\n",
      "iteration 801, objective = 1.2674062269299868\n",
      "3.7944047\n",
      "iteration 802, objective = 1.2674663620815405\n",
      "3.7965133\n",
      "iteration 803, objective = 1.267230731546656\n",
      "3.7979748\n",
      "iteration 804, objective = 1.2669975541192515\n",
      "3.7999208\n",
      "iteration 805, objective = 1.2664375510406327\n",
      "3.8030763\n",
      "iteration 806, objective = 1.2663390436730055\n",
      "3.804391\n",
      "iteration 807, objective = 1.2660710273557294\n",
      "3.8069782\n",
      "iteration 808, objective = 1.2663384735508156\n",
      "3.806917\n",
      "iteration 809, objective = 1.2663347132366711\n",
      "3.8061173\n",
      "iteration 810, objective = 1.2657125246294514\n",
      "3.807177\n",
      "iteration 811, objective = 1.2659164817498862\n",
      "3.806913\n",
      "iteration 812, objective = 1.2658039029836698\n",
      "3.8051126\n",
      "iteration 813, objective = 1.2652346995593908\n",
      "3.8038802\n",
      "iteration 814, objective = 1.2654768069616367\n",
      "3.8005893\n",
      "iteration 815, objective = 1.265277724225989\n",
      "3.7980812\n",
      "iteration 816, objective = 1.2650185369429983\n",
      "3.7965026\n",
      "iteration 817, objective = 1.2652640687263788\n",
      "3.7925215\n",
      "iteration 818, objective = 1.2656872514539284\n",
      "3.786157\n",
      "iteration 819, objective = 1.2655396967956387\n",
      "3.7804403\n",
      "iteration 820, objective = 1.2650787012467912\n",
      "3.7765362\n",
      "iteration 821, objective = 1.2650678884757016\n",
      "3.771676\n",
      "iteration 822, objective = 1.2649695808167376\n",
      "3.7679071\n",
      "iteration 823, objective = 1.2652315277991333\n",
      "3.7631466\n",
      "iteration 824, objective = 1.265042443071459\n",
      "3.7582757\n",
      "iteration 825, objective = 1.26498769960053\n",
      "3.7532215\n",
      "iteration 826, objective = 1.2650573995008025\n",
      "3.7486572\n",
      "iteration 827, objective = 1.264860623851332\n",
      "3.744909\n",
      "iteration 828, objective = 1.2646694071335085\n",
      "3.7421556\n",
      "iteration 829, objective = 1.2644764965898265\n",
      "3.7392995\n",
      "iteration 830, objective = 1.2643199729610524\n",
      "3.737\n",
      "iteration 831, objective = 1.2642759394470984\n",
      "3.7350156\n",
      "iteration 832, objective = 1.2643563910813052\n",
      "3.7339149\n",
      "iteration 833, objective = 1.26407159328506\n",
      "3.7334313\n",
      "iteration 834, objective = 1.263892360890521\n",
      "3.7331865\n",
      "iteration 835, objective = 1.2640431008999529\n",
      "3.732185\n",
      "iteration 836, objective = 1.2637663197214288\n",
      "3.7310536\n",
      "iteration 837, objective = 1.2638974810185304\n",
      "3.7296896\n",
      "iteration 838, objective = 1.2635289133292864\n",
      "3.7291481\n",
      "iteration 839, objective = 1.2631878768605207\n",
      "3.7293985\n",
      "iteration 840, objective = 1.2634056868568326\n",
      "3.727645\n",
      "iteration 841, objective = 1.2631842476994202\n",
      "3.7252402\n",
      "iteration 842, objective = 1.263241735865004\n",
      "3.7229877\n",
      "iteration 843, objective = 1.2637705047400603\n",
      "3.7191517\n",
      "iteration 844, objective = 1.2638913738440154\n",
      "3.715332\n",
      "iteration 845, objective = 1.2634941617326645\n",
      "3.7119353\n",
      "iteration 846, objective = 1.2634683428659024\n",
      "3.7087522\n",
      "iteration 847, objective = 1.2637582093494235\n",
      "3.7065105\n",
      "iteration 848, objective = 1.2636033512295943\n",
      "3.7058759\n",
      "iteration 849, objective = 1.2633101838266698\n",
      "3.706479\n",
      "iteration 850, objective = 1.262832970902205\n",
      "3.7083187\n",
      "iteration 851, objective = 1.2627603352975816\n",
      "3.7085073\n",
      "iteration 852, objective = 1.2627157477612512\n",
      "3.7087412\n",
      "iteration 853, objective = 1.2629067366650069\n",
      "3.707501\n",
      "iteration 854, objective = 1.2622141958096345\n",
      "3.7076676\n",
      "iteration 855, objective = 1.2620437332161643\n",
      "3.7081041\n",
      "iteration 856, objective = 1.261942891261455\n",
      "3.709484\n",
      "iteration 857, objective = 1.2619526390203608\n",
      "3.7121973\n",
      "iteration 858, objective = 1.261509727745525\n",
      "3.7163568\n",
      "iteration 859, objective = 1.261669364616303\n",
      "3.7193472\n",
      "iteration 860, objective = 1.261738570663494\n",
      "3.7213202\n",
      "iteration 861, objective = 1.2616330134486018\n",
      "3.7234337\n",
      "iteration 862, objective = 1.261469982967098\n",
      "3.725124\n",
      "iteration 863, objective = 1.2614186282394693\n",
      "3.7272842\n",
      "iteration 864, objective = 1.261199285809225\n",
      "3.729234\n",
      "iteration 865, objective = 1.2610515495220707\n",
      "3.7305648\n",
      "iteration 866, objective = 1.2606595681067945\n",
      "3.7334173\n",
      "iteration 867, objective = 1.2606890025447262\n",
      "3.7363741\n",
      "iteration 868, objective = 1.2603488523703708\n",
      "3.73853\n",
      "iteration 869, objective = 1.260157975490485\n",
      "3.7405677\n",
      "iteration 870, objective = 1.26025143903704\n",
      "3.7415051\n",
      "iteration 871, objective = 1.2600184143540374\n",
      "3.7431262\n",
      "iteration 872, objective = 1.260130088735762\n",
      "3.7431836\n",
      "iteration 873, objective = 1.2602561537613517\n",
      "3.742465\n",
      "iteration 874, objective = 1.2601485746304708\n",
      "3.7420967\n",
      "iteration 875, objective = 1.2603169286080689\n",
      "3.7413979\n",
      "iteration 876, objective = 1.2603116134146632\n",
      "3.7428746\n",
      "iteration 877, objective = 1.2601778369226924\n",
      "3.7439563\n",
      "iteration 878, objective = 1.2598682019744818\n",
      "3.7457292\n",
      "iteration 879, objective = 1.260048036517143\n",
      "3.7451053\n",
      "iteration 880, objective = 1.2599267169820394\n",
      "3.7442424\n",
      "iteration 881, objective = 1.2599526020510032\n",
      "3.74404\n",
      "iteration 882, objective = 1.259699676901314\n",
      "3.742973\n",
      "iteration 883, objective = 1.2596161525209486\n",
      "3.7438185\n",
      "iteration 884, objective = 1.2596760791664743\n",
      "3.7448528\n",
      "iteration 885, objective = 1.259877148929194\n",
      "3.745057\n",
      "iteration 886, objective = 1.2597990267051862\n",
      "3.7453947\n",
      "iteration 887, objective = 1.2599235300893101\n",
      "3.7461927\n",
      "iteration 888, objective = 1.2598710416215282\n",
      "3.7460868\n",
      "iteration 889, objective = 1.2598698425544894\n",
      "3.745543\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "iteration 890, objective = 1.2595535624118706\n",
      "3.7441835\n",
      "iteration 891, objective = 1.2592213697534262\n",
      "3.7430763\n",
      "iteration 892, objective = 1.2591632422280257\n",
      "3.7413917\n",
      "iteration 893, objective = 1.2587268885331737\n",
      "3.74068\n",
      "iteration 894, objective = 1.2584304758375502\n",
      "3.7409186\n",
      "iteration 895, objective = 1.2581262446982266\n",
      "3.7413266\n",
      "iteration 896, objective = 1.2580346099178077\n",
      "3.7402658\n",
      "iteration 897, objective = 1.258054777114098\n",
      "3.7393212\n",
      "iteration 898, objective = 1.2577916758411318\n",
      "3.7378972\n",
      "iteration 899, objective = 1.2573688918266548\n",
      "3.7361486\n",
      "iteration 900, objective = 1.2575592290192654\n",
      "3.7354565\n",
      "iteration 901, objective = 1.2573879147555844\n",
      "3.7355146\n",
      "iteration 902, objective = 1.2572924397268528\n",
      "3.7371595\n",
      "iteration 903, objective = 1.257434691679297\n",
      "3.7387784\n",
      "iteration 904, objective = 1.2573862941216503\n",
      "3.7415478\n",
      "iteration 905, objective = 1.2575194708736732\n",
      "3.7439125\n",
      "iteration 906, objective = 1.257595535567464\n",
      "3.745909\n",
      "iteration 907, objective = 1.257487849486552\n",
      "3.748412\n",
      "iteration 908, objective = 1.2569926925663562\n",
      "3.7508962\n",
      "iteration 909, objective = 1.256673181939389\n",
      "3.7532344\n",
      "iteration 910, objective = 1.2566683907305924\n",
      "3.7543476\n",
      "iteration 911, objective = 1.256146196437347\n",
      "3.7564688\n",
      "iteration 912, objective = 1.2560611959896981\n",
      "3.7592735\n",
      "iteration 913, objective = 1.2560884159456793\n",
      "3.7607443\n",
      "iteration 914, objective = 1.2561054152885835\n",
      "3.7610238\n",
      "iteration 915, objective = 1.2559998419859482\n",
      "3.7619357\n",
      "iteration 916, objective = 1.256441317991353\n",
      "3.761038\n",
      "iteration 917, objective = 1.2564212333411238\n",
      "3.7596896\n",
      "iteration 918, objective = 1.256237949590067\n",
      "3.7591515\n",
      "iteration 919, objective = 1.2561026852538224\n",
      "3.7589653\n",
      "iteration 920, objective = 1.255873713249104\n",
      "3.7598953\n",
      "iteration 921, objective = 1.2558012395926563\n",
      "3.762327\n",
      "iteration 922, objective = 1.255784979954847\n",
      "3.764078\n",
      "iteration 923, objective = 1.2560287199123008\n",
      "3.7651763\n",
      "iteration 924, objective = 1.2556269038476409\n",
      "3.7674875\n",
      "iteration 925, objective = 1.2553856803916195\n",
      "3.7703626\n",
      "iteration 926, objective = 1.2548854456145464\n",
      "3.77394\n",
      "iteration 927, objective = 1.2546053760477562\n",
      "3.777759\n",
      "iteration 928, objective = 1.2545385428735272\n",
      "3.7820563\n",
      "iteration 929, objective = 1.254192718066944\n",
      "3.7866225\n",
      "iteration 930, objective = 1.254047386313612\n",
      "3.791398\n",
      "iteration 931, objective = 1.253837004992208\n",
      "3.7963414\n",
      "iteration 932, objective = 1.2535763086425704\n",
      "3.8000379\n",
      "iteration 933, objective = 1.2532903873233823\n",
      "3.80357\n",
      "iteration 934, objective = 1.2527799781552145\n",
      "3.8080587\n",
      "iteration 935, objective = 1.2524531001372552\n",
      "3.8135731\n",
      "iteration 936, objective = 1.2523790835033994\n",
      "3.8188868\n",
      "iteration 937, objective = 1.2526382993149752\n",
      "3.8215508\n",
      "iteration 938, objective = 1.2528346132167911\n",
      "3.82201\n",
      "iteration 939, objective = 1.2527402045988343\n",
      "3.8220043\n",
      "iteration 940, objective = 1.2522357049885047\n",
      "3.823302\n",
      "iteration 941, objective = 1.2520062767854017\n",
      "3.824993\n",
      "iteration 942, objective = 1.2520388928735502\n",
      "3.8264065\n",
      "iteration 943, objective = 1.2524499993288398\n",
      "3.8251905\n",
      "iteration 944, objective = 1.2523838418651416\n",
      "3.8220234\n",
      "iteration 945, objective = 1.252169999356306\n",
      "3.8190546\n",
      "iteration 946, objective = 1.2520985183307942\n",
      "3.8135266\n",
      "iteration 947, objective = 1.2520027154031723\n",
      "3.807311\n",
      "iteration 948, objective = 1.251823598473544\n",
      "3.8012476\n",
      "iteration 949, objective = 1.252096793183371\n",
      "3.794091\n",
      "iteration 950, objective = 1.2521445014699206\n",
      "3.787001\n",
      "iteration 951, objective = 1.2524701878814468\n",
      "3.77858\n",
      "iteration 952, objective = 1.2526092611918676\n",
      "3.7702985\n",
      "iteration 953, objective = 1.252596529837445\n",
      "3.76316\n",
      "iteration 954, objective = 1.252815253916143\n",
      "3.7553947\n",
      "iteration 955, objective = 1.2530055922312004\n",
      "3.7474134\n",
      "iteration 956, objective = 1.2526006877630627\n",
      "3.7414756\n",
      "iteration 957, objective = 1.2526483945134503\n",
      "3.734376\n",
      "iteration 958, objective = 1.2522860308440333\n",
      "3.7278104\n",
      "iteration 959, objective = 1.2522935320126691\n",
      "3.7207994\n",
      "iteration 960, objective = 1.2519973794735408\n",
      "3.7155507\n",
      "iteration 961, objective = 1.2520041702803677\n",
      "3.7093914\n",
      "iteration 962, objective = 1.2518494491352736\n",
      "3.7038174\n",
      "iteration 963, objective = 1.2515016242519261\n",
      "3.7009394\n",
      "iteration 964, objective = 1.2518448179769746\n",
      "3.6983614\n",
      "iteration 965, objective = 1.25176053918973\n",
      "3.6960301\n",
      "iteration 966, objective = 1.2516311181771909\n",
      "3.693562\n",
      "iteration 967, objective = 1.2518950421257127\n",
      "3.6923099\n",
      "iteration 968, objective = 1.251903006509982\n",
      "3.6925623\n",
      "iteration 969, objective = 1.2516118216712502\n",
      "3.6935418\n",
      "iteration 970, objective = 1.2514832313118287\n",
      "3.6950572\n",
      "iteration 971, objective = 1.2512264641138362\n",
      "3.6975036\n",
      "iteration 972, objective = 1.2509741108243873\n",
      "3.7005363\n",
      "iteration 973, objective = 1.251080308088484\n",
      "3.703916\n",
      "iteration 974, objective = 1.2511509004869497\n",
      "3.7072814\n",
      "iteration 975, objective = 1.2511261674437768\n",
      "3.7108128\n",
      "iteration 976, objective = 1.251069267629533\n",
      "3.713459\n",
      "iteration 977, objective = 1.2507337406446952\n",
      "3.7159781\n",
      "iteration 978, objective = 1.2507796473543293\n",
      "3.7183073\n",
      "iteration 979, objective = 1.2510590653470266\n",
      "3.7206118\n",
      "iteration 980, objective = 1.2510287341912347\n",
      "3.723603\n",
      "iteration 981, objective = 1.2510930423808577\n",
      "3.725617\n",
      "iteration 982, objective = 1.2509874973573516\n",
      "3.727997\n",
      "iteration 983, objective = 1.2509121247823216\n",
      "3.7296016\n",
      "iteration 984, objective = 1.2513493618693512\n",
      "3.7284534\n",
      "iteration 985, objective = 1.2512829294549073\n",
      "3.7284112\n",
      "iteration 986, objective = 1.2509818518308071\n",
      "3.729135\n",
      "iteration 987, objective = 1.2508955462716096\n",
      "3.729076\n",
      "iteration 988, objective = 1.2507494918750321\n",
      "3.7297537\n",
      "iteration 989, objective = 1.250673477037066\n",
      "3.7310617\n",
      "iteration 990, objective = 1.250348211685217\n",
      "3.7338333\n",
      "iteration 991, objective = 1.2501120944774136\n",
      "3.7353673\n",
      "iteration 992, objective = 1.2498409807020596\n",
      "3.7378986\n",
      "iteration 993, objective = 1.2497551725411202\n",
      "3.7405736\n",
      "iteration 994, objective = 1.2493887120526637\n",
      "3.7419324\n",
      "iteration 995, objective = 1.2490633314028161\n",
      "3.7441692\n",
      "iteration 996, objective = 1.2488901152093705\n",
      "3.7457995\n",
      "iteration 997, objective = 1.2487503435451328\n",
      "3.7474277\n",
      "iteration 998, objective = 1.2486971129915079\n",
      "3.747118\n",
      "iteration 999, objective = 1.2484195618762277\n",
      "3.7471755\n",
      "iteration 1000, objective = 1.248424053101743\n",
      "3.7468266\n",
      "iteration 1001, objective = 1.246514265030843\n",
      "3.7457016\n",
      "iteration 1002, objective = 1.2462873437025108\n",
      "3.7451985\n",
      "iteration 1003, objective = 1.2443390134930759\n",
      "3.7449183\n",
      "iteration 1004, objective = 1.2429997566998612\n",
      "3.7449732\n",
      "iteration 1005, objective = 1.2430118565457204\n",
      "3.7431715\n",
      "iteration 1006, objective = 1.241876741926661\n",
      "3.7412305\n",
      "iteration 1007, objective = 1.240293769188915\n",
      "3.7404625\n",
      "iteration 1008, objective = 1.2394285373955634\n",
      "3.7412586\n",
      "iteration 1009, objective = 1.238668515736937\n",
      "3.742595\n",
      "iteration 1010, objective = 1.2382162919378936\n",
      "3.7441168\n",
      "iteration 1011, objective = 1.2371304101218485\n",
      "3.745852\n",
      "iteration 1012, objective = 1.2360640779858214\n",
      "3.7474349\n",
      "iteration 1013, objective = 1.2357250192159046\n",
      "3.7487226\n",
      "iteration 1014, objective = 1.2352760576994433\n",
      "3.7500496\n",
      "iteration 1015, objective = 1.2350723277052624\n",
      "3.7499194\n",
      "iteration 1016, objective = 1.2349140877374831\n",
      "3.7493968\n",
      "iteration 1017, objective = 1.2338336062674233\n",
      "3.748946\n",
      "iteration 1018, objective = 1.2331518683774745\n",
      "3.7488415\n",
      "iteration 1019, objective = 1.2324639634058663\n",
      "3.7491224\n",
      "iteration 1020, objective = 1.232136873712021\n",
      "3.7491772\n",
      "iteration 1021, objective = 1.2314635699233194\n",
      "3.7496529\n",
      "iteration 1022, objective = 1.230817461842233\n",
      "3.7504709\n",
      "iteration 1023, objective = 1.2302618900319235\n",
      "3.7504792\n",
      "iteration 1024, objective = 1.2294733842831518\n",
      "3.750901\n",
      "iteration 1025, objective = 1.228820732575956\n",
      "3.751465\n",
      "iteration 1026, objective = 1.2281142430770524\n",
      "3.753598\n",
      "iteration 1027, objective = 1.2273593746795661\n",
      "3.7561903\n",
      "iteration 1028, objective = 1.2271676225915664\n",
      "3.7565825\n",
      "iteration 1029, objective = 1.2272362458839527\n",
      "3.7567182\n",
      "iteration 1030, objective = 1.2267193663017548\n",
      "3.7579415\n",
      "iteration 1031, objective = 1.2265744249540111\n",
      "3.7580006\n",
      "iteration 1032, objective = 1.2264893548997784\n",
      "3.757951\n",
      "iteration 1033, objective = 1.226697875813285\n",
      "3.7565503\n",
      "iteration 1034, objective = 1.2266690535861227\n",
      "3.755206\n",
      "iteration 1035, objective = 1.2265017899524067\n",
      "3.754842\n",
      "iteration 1036, objective = 1.2262025092490776\n",
      "3.7534447\n",
      "iteration 1037, objective = 1.2257803344452116\n",
      "3.7538545\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "iteration 1038, objective = 1.225463041619735\n",
      "3.7545044\n",
      "iteration 1039, objective = 1.2253621190413921\n",
      "3.7537766\n",
      "iteration 1040, objective = 1.2253322081662235\n",
      "3.7540662\n",
      "iteration 1041, objective = 1.224391102878735\n",
      "3.7548227\n",
      "iteration 1042, objective = 1.2243521102830284\n",
      "3.754313\n",
      "iteration 1043, objective = 1.2242035895859813\n",
      "3.7533846\n",
      "iteration 1044, objective = 1.223959977462445\n",
      "3.7528331\n",
      "iteration 1045, objective = 1.2240117952053848\n",
      "3.751444\n",
      "iteration 1046, objective = 1.224338860995699\n",
      "3.7492363\n",
      "iteration 1047, objective = 1.2241830062915573\n",
      "3.7465627\n",
      "iteration 1048, objective = 1.223741862681315\n",
      "3.7442484\n",
      "iteration 1049, objective = 1.2234718532053288\n",
      "3.742861\n",
      "iteration 1050, objective = 1.2232457260897047\n",
      "3.7409785\n",
      "iteration 1051, objective = 1.2230453618230843\n",
      "3.7397342\n",
      "iteration 1052, objective = 1.2227864809494817\n",
      "3.7372327\n",
      "iteration 1053, objective = 1.22195038303909\n",
      "3.735678\n",
      "iteration 1054, objective = 1.2220321201805167\n",
      "3.733782\n",
      "iteration 1055, objective = 1.2216233464656292\n",
      "3.732019\n",
      "iteration 1056, objective = 1.221728834395896\n",
      "3.7285397\n",
      "iteration 1057, objective = 1.221839616578832\n",
      "3.7256787\n",
      "iteration 1058, objective = 1.2218361742340789\n",
      "3.7227588\n",
      "iteration 1059, objective = 1.2215853774064203\n",
      "3.721503\n",
      "iteration 1060, objective = 1.2214648189317192\n",
      "3.7210257\n",
      "iteration 1061, objective = 1.2212489179983508\n",
      "3.7201514\n",
      "iteration 1062, objective = 1.2211124348004334\n",
      "3.7195723\n",
      "iteration 1063, objective = 1.2214871384758443\n",
      "3.7196653\n",
      "iteration 1064, objective = 1.2208181680384924\n",
      "3.721578\n",
      "iteration 1065, objective = 1.2202750773290796\n",
      "3.7244241\n",
      "iteration 1066, objective = 1.2198895252549478\n",
      "3.727029\n",
      "iteration 1067, objective = 1.2194592739575458\n",
      "3.7293305\n",
      "iteration 1068, objective = 1.2192387733040821\n",
      "3.731009\n",
      "iteration 1069, objective = 1.2189401871530465\n",
      "3.732689\n",
      "iteration 1070, objective = 1.2188859377310097\n",
      "3.733835\n",
      "iteration 1071, objective = 1.2184307722760765\n",
      "3.735169\n",
      "iteration 1072, objective = 1.2188396500801\n",
      "3.7338448\n",
      "iteration 1073, objective = 1.2188816577429078\n",
      "3.731318\n",
      "iteration 1074, objective = 1.2187075043334037\n",
      "3.7272916\n",
      "iteration 1075, objective = 1.2187858423234341\n",
      "3.7245324\n",
      "iteration 1076, objective = 1.2185899137220515\n",
      "3.7228785\n",
      "iteration 1077, objective = 1.218846564844223\n",
      "3.7219937\n",
      "iteration 1078, objective = 1.2188081735272258\n",
      "3.71992\n",
      "iteration 1079, objective = 1.2184707528744465\n",
      "3.718045\n",
      "iteration 1080, objective = 1.2189552670007269\n",
      "3.7142487\n",
      "iteration 1081, objective = 1.2185376598507296\n",
      "3.7130826\n",
      "iteration 1082, objective = 1.2184505481110486\n",
      "3.7130768\n",
      "iteration 1083, objective = 1.218091989586994\n",
      "3.7134507\n",
      "iteration 1084, objective = 1.2177094139764046\n",
      "3.714372\n",
      "iteration 1085, objective = 1.217393875315799\n",
      "3.7156348\n",
      "iteration 1086, objective = 1.2170881835407381\n",
      "3.7161527\n",
      "iteration 1087, objective = 1.216971208776355\n",
      "3.7171254\n",
      "iteration 1088, objective = 1.2167991627887955\n",
      "3.7173336\n",
      "iteration 1089, objective = 1.216271191590075\n",
      "3.7182624\n",
      "iteration 1090, objective = 1.2156380088837633\n",
      "3.7190301\n",
      "iteration 1091, objective = 1.2154302194251088\n",
      "3.7202587\n",
      "iteration 1092, objective = 1.2148527642956854\n",
      "3.7226703\n",
      "iteration 1093, objective = 1.21443395231407\n",
      "3.7242696\n",
      "iteration 1094, objective = 1.2138752868608471\n",
      "3.7272577\n",
      "iteration 1095, objective = 1.2136922649205975\n",
      "3.7305968\n",
      "iteration 1096, objective = 1.2135850051795192\n",
      "3.733249\n",
      "iteration 1097, objective = 1.2132716240715067\n",
      "3.7365882\n",
      "iteration 1098, objective = 1.2130577450699318\n",
      "3.7396622\n",
      "iteration 1099, objective = 1.2129278391403218\n",
      "3.743716\n",
      "iteration 1100, objective = 1.2125497597981274\n",
      "3.746458\n",
      "iteration 1101, objective = 1.21210818771554\n",
      "3.7481804\n",
      "iteration 1102, objective = 1.211941315143198\n",
      "3.7493708\n",
      "iteration 1103, objective = 1.2122078523333806\n",
      "3.7495701\n",
      "iteration 1104, objective = 1.2118302718884193\n",
      "3.7505744\n",
      "iteration 1105, objective = 1.2115737298326903\n",
      "3.752084\n",
      "iteration 1106, objective = 1.2116898098581805\n",
      "3.7547786\n",
      "iteration 1107, objective = 1.2114694179872358\n",
      "3.756555\n",
      "iteration 1108, objective = 1.2118598790670003\n",
      "3.757172\n",
      "iteration 1109, objective = 1.2116218236953513\n",
      "3.7581275\n",
      "iteration 1110, objective = 1.2115864225680724\n",
      "3.7582138\n",
      "iteration 1111, objective = 1.2113682944729125\n",
      "3.7594876\n",
      "iteration 1112, objective = 1.2116018476883428\n",
      "3.760488\n",
      "iteration 1113, objective = 1.2113396502412848\n",
      "3.7631853\n",
      "iteration 1114, objective = 1.21123288094027\n",
      "3.76579\n",
      "iteration 1115, objective = 1.21076815779264\n",
      "3.7660255\n",
      "iteration 1116, objective = 1.2108364919211725\n",
      "3.7665968\n",
      "iteration 1117, objective = 1.2103268974748873\n",
      "3.767167\n",
      "iteration 1118, objective = 1.2101862112707653\n",
      "3.766812\n",
      "iteration 1119, objective = 1.210178374836705\n",
      "3.7650201\n",
      "iteration 1120, objective = 1.2101591739331086\n",
      "3.7606587\n",
      "iteration 1121, objective = 1.2102217993591504\n",
      "3.7575943\n",
      "iteration 1122, objective = 1.2105430323887683\n",
      "3.7568564\n",
      "iteration 1123, objective = 1.2107904497078954\n",
      "3.7573802\n",
      "iteration 1124, objective = 1.2107215685895214\n",
      "3.757054\n",
      "iteration 1125, objective = 1.2108374820312824\n",
      "3.756822\n",
      "iteration 1126, objective = 1.21045012569851\n",
      "3.7562747\n",
      "iteration 1127, objective = 1.2106735670390416\n",
      "3.7564974\n",
      "iteration 1128, objective = 1.2108780568120194\n",
      "3.7565293\n",
      "iteration 1129, objective = 1.2108044630481865\n",
      "3.7551677\n",
      "iteration 1130, objective = 1.2105466972849388\n",
      "3.7543828\n",
      "iteration 1131, objective = 1.2104908392461522\n",
      "3.7535348\n",
      "iteration 1132, objective = 1.2108647252994889\n",
      "3.7516382\n",
      "iteration 1133, objective = 1.2107194443742553\n",
      "3.7506304\n",
      "iteration 1134, objective = 1.2103988880598933\n",
      "3.7519197\n",
      "iteration 1135, objective = 1.2094515025262622\n",
      "3.7545335\n",
      "iteration 1136, objective = 1.209164104603187\n",
      "3.7568035\n",
      "iteration 1137, objective = 1.2092259541993644\n",
      "3.758492\n",
      "iteration 1138, objective = 1.2088838140977831\n",
      "3.7607834\n",
      "iteration 1139, objective = 1.2087863604122413\n",
      "3.7636647\n",
      "iteration 1140, objective = 1.2084607422019533\n",
      "3.7650132\n",
      "iteration 1141, objective = 1.2084479642448394\n",
      "3.7647927\n",
      "iteration 1142, objective = 1.2079058316516191\n",
      "3.7643733\n",
      "iteration 1143, objective = 1.2074491533850182\n",
      "3.7664797\n",
      "iteration 1144, objective = 1.207175732524067\n",
      "3.7682316\n",
      "iteration 1145, objective = 1.20727143478842\n",
      "3.7674186\n",
      "iteration 1146, objective = 1.2070288321220422\n",
      "3.7660546\n",
      "iteration 1147, objective = 1.2066086981402493\n",
      "3.763885\n",
      "iteration 1148, objective = 1.2066175760300764\n",
      "3.7637002\n",
      "iteration 1149, objective = 1.2067629184400457\n",
      "3.7638638\n",
      "iteration 1150, objective = 1.2065399988302974\n",
      "3.7630959\n",
      "iteration 1151, objective = 1.2061105137688357\n",
      "3.7617788\n",
      "iteration 1152, objective = 1.2064314325273364\n",
      "3.7607284\n",
      "iteration 1153, objective = 1.2061301915302731\n",
      "3.7593353\n",
      "iteration 1154, objective = 1.2063289046506525\n",
      "3.7555037\n",
      "iteration 1155, objective = 1.2060506539285236\n",
      "3.7515292\n",
      "iteration 1156, objective = 1.205408410969936\n",
      "3.7487812\n",
      "iteration 1157, objective = 1.2047693181838985\n",
      "3.7485287\n",
      "iteration 1158, objective = 1.20444209334214\n",
      "3.7470355\n",
      "iteration 1159, objective = 1.2050296428490823\n",
      "3.744116\n",
      "iteration 1160, objective = 1.2047585087891561\n",
      "3.7419536\n",
      "iteration 1161, objective = 1.2050773624009923\n",
      "3.7407691\n",
      "iteration 1162, objective = 1.2041142330782777\n",
      "3.7417803\n",
      "iteration 1163, objective = 1.2041610147084443\n",
      "3.7435658\n",
      "iteration 1164, objective = 1.20418770372745\n",
      "3.7456708\n",
      "iteration 1165, objective = 1.2037451963892478\n",
      "3.7476244\n",
      "iteration 1166, objective = 1.2031515256737557\n",
      "3.7504644\n",
      "iteration 1167, objective = 1.2036995459185933\n",
      "3.7520561\n",
      "iteration 1168, objective = 1.2033654820948823\n",
      "3.7541716\n",
      "iteration 1169, objective = 1.2031351223866575\n",
      "3.7562232\n",
      "iteration 1170, objective = 1.2029744981237256\n",
      "3.7568529\n",
      "iteration 1171, objective = 1.2025515086815286\n",
      "3.7570317\n",
      "iteration 1172, objective = 1.2027769712477867\n",
      "3.7571442\n",
      "iteration 1173, objective = 1.2024889013929814\n",
      "3.7572825\n",
      "iteration 1174, objective = 1.202128280920095\n",
      "3.7572515\n",
      "iteration 1175, objective = 1.201934405160788\n",
      "3.7566607\n",
      "iteration 1176, objective = 1.2013842249777857\n",
      "3.7551987\n",
      "iteration 1177, objective = 1.2013199733169082\n",
      "3.7548404\n",
      "iteration 1178, objective = 1.201074236392369\n",
      "3.754013\n",
      "iteration 1179, objective = 1.2007533134330302\n",
      "3.751883\n",
      "iteration 1180, objective = 1.2006921105207788\n",
      "3.750064\n",
      "iteration 1181, objective = 1.2007125377220336\n",
      "3.7480574\n",
      "iteration 1182, objective = 1.2002679727212975\n",
      "3.7463439\n",
      "iteration 1183, objective = 1.1993088614396545\n",
      "3.744923\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "iteration 1184, objective = 1.1989513912351621\n",
      "3.7439973\n",
      "iteration 1185, objective = 1.1984366561470532\n",
      "3.7441835\n",
      "iteration 1186, objective = 1.1983162718546971\n",
      "3.7426395\n",
      "iteration 1187, objective = 1.198244254969386\n",
      "3.7440882\n",
      "iteration 1188, objective = 1.198125105057269\n",
      "3.7455277\n",
      "iteration 1189, objective = 1.1978058538415224\n",
      "3.7474446\n",
      "iteration 1190, objective = 1.1976470041804623\n",
      "3.7477384\n",
      "iteration 1191, objective = 1.1974371807385498\n",
      "3.7487528\n",
      "iteration 1192, objective = 1.1972303502401989\n",
      "3.7497745\n",
      "iteration 1193, objective = 1.1968900799882785\n",
      "3.7506711\n",
      "iteration 1194, objective = 1.1971403939976248\n",
      "3.751248\n",
      "iteration 1195, objective = 1.1967331039837432\n",
      "3.752569\n",
      "iteration 1196, objective = 1.1963222012591228\n",
      "3.7548392\n",
      "iteration 1197, objective = 1.1960622091439252\n",
      "3.7577136\n",
      "iteration 1198, objective = 1.1956592348867816\n",
      "3.7597723\n",
      "iteration 1199, objective = 1.1959199488453505\n",
      "3.7612102\n",
      "iteration 1200, objective = 1.1961278293289916\n",
      "3.76226\n",
      "iteration 1201, objective = 1.195778651038865\n",
      "3.762577\n",
      "iteration 1202, objective = 1.195595541623024\n",
      "3.7615628\n",
      "iteration 1203, objective = 1.1956099284799586\n",
      "3.7604265\n",
      "iteration 1204, objective = 1.1956511884715586\n",
      "3.7593896\n",
      "iteration 1205, objective = 1.1952457910847267\n",
      "3.7594807\n",
      "iteration 1206, objective = 1.1955399151519677\n",
      "3.7590861\n",
      "iteration 1207, objective = 1.1950850670386228\n",
      "3.758109\n",
      "iteration 1208, objective = 1.1946874722652734\n",
      "3.7583911\n",
      "iteration 1209, objective = 1.1945615937081462\n",
      "3.7572377\n",
      "iteration 1210, objective = 1.1945465206833894\n",
      "3.7576683\n",
      "iteration 1211, objective = 1.1941871564609934\n",
      "3.7592657\n",
      "iteration 1212, objective = 1.1937962666071684\n",
      "3.7598472\n",
      "iteration 1213, objective = 1.193659472137536\n",
      "3.7594318\n",
      "iteration 1214, objective = 1.1936625582633738\n",
      "3.759394\n",
      "iteration 1215, objective = 1.1936252524533293\n",
      "3.75909\n",
      "iteration 1216, objective = 1.193536848298964\n",
      "3.7580724\n",
      "iteration 1217, objective = 1.193483657834275\n",
      "3.7554605\n",
      "iteration 1218, objective = 1.1932468788476491\n",
      "3.7537303\n",
      "iteration 1219, objective = 1.1929650819937436\n",
      "3.752116\n",
      "iteration 1220, objective = 1.193304481012653\n",
      "3.7500312\n",
      "iteration 1221, objective = 1.1931865359583596\n",
      "3.7484436\n",
      "iteration 1222, objective = 1.1931049781167402\n",
      "3.746898\n",
      "iteration 1223, objective = 1.1929090629783548\n",
      "3.7444491\n",
      "iteration 1224, objective = 1.192644062893528\n",
      "3.7412047\n",
      "iteration 1225, objective = 1.1932907411606077\n",
      "3.7386234\n",
      "iteration 1226, objective = 1.1933934882390111\n",
      "3.7352483\n",
      "iteration 1227, objective = 1.1934274619956498\n",
      "3.7321124\n",
      "iteration 1228, objective = 1.1933876040540423\n",
      "3.7312644\n",
      "iteration 1229, objective = 1.193607345603864\n",
      "3.7290354\n",
      "iteration 1230, objective = 1.193486224843702\n",
      "3.7246845\n",
      "iteration 1231, objective = 1.1926782404779281\n",
      "3.7223222\n",
      "iteration 1232, objective = 1.1925352662904414\n",
      "3.721147\n",
      "iteration 1233, objective = 1.192800818431534\n",
      "3.7198544\n",
      "iteration 1234, objective = 1.192460918335444\n",
      "3.7191129\n",
      "iteration 1235, objective = 1.1929470401701807\n",
      "3.718778\n",
      "iteration 1236, objective = 1.1929162907621582\n",
      "3.7198436\n",
      "iteration 1237, objective = 1.193207006846579\n",
      "3.7224107\n",
      "iteration 1238, objective = 1.1926221319266785\n",
      "3.7237368\n",
      "iteration 1239, objective = 1.1923631024830914\n",
      "3.7257957\n",
      "iteration 1240, objective = 1.1925433855418257\n",
      "3.7274783\n",
      "iteration 1241, objective = 1.1927430546286664\n",
      "3.729429\n",
      "iteration 1242, objective = 1.1925460837492674\n",
      "3.730839\n",
      "iteration 1243, objective = 1.1926307991674723\n",
      "3.7318223\n",
      "iteration 1244, objective = 1.1926772131068346\n",
      "3.733742\n",
      "iteration 1245, objective = 1.1929778190350828\n",
      "3.7366142\n",
      "iteration 1246, objective = 1.1929701574785216\n",
      "3.7398105\n",
      "iteration 1247, objective = 1.1926340280011527\n",
      "3.7433085\n",
      "iteration 1248, objective = 1.1928371291715796\n",
      "3.7447581\n",
      "iteration 1249, objective = 1.1926720854318626\n",
      "3.7458599\n",
      "iteration 1250, objective = 1.192294413063786\n",
      "3.7460341\n",
      "iteration 1251, objective = 1.19264039129975\n",
      "3.746871\n",
      "iteration 1252, objective = 1.1929017116752334\n",
      "3.747698\n",
      "iteration 1253, objective = 1.192826188976285\n",
      "3.7482228\n",
      "iteration 1254, objective = 1.1928823949978715\n",
      "3.7485185\n",
      "iteration 1255, objective = 1.1926248979021583\n",
      "3.7482798\n",
      "iteration 1256, objective = 1.192741690352473\n",
      "3.7475522\n",
      "iteration 1257, objective = 1.1927266717161973\n",
      "3.7458704\n",
      "iteration 1258, objective = 1.1926049897245268\n",
      "3.7449896\n",
      "iteration 1259, objective = 1.1931281658862347\n",
      "3.7437572\n",
      "iteration 1260, objective = 1.193007251791989\n",
      "3.7424433\n",
      "iteration 1261, objective = 1.1932003111276648\n",
      "3.7401652\n",
      "iteration 1262, objective = 1.19297877947337\n",
      "3.73856\n",
      "iteration 1263, objective = 1.1928174593812433\n",
      "3.7365255\n",
      "iteration 1264, objective = 1.1922218932878677\n",
      "3.735183\n",
      "iteration 1265, objective = 1.1917316306546453\n",
      "3.7334132\n",
      "iteration 1266, objective = 1.191620952791327\n",
      "3.7305553\n",
      "iteration 1267, objective = 1.1919690470455653\n",
      "3.7278805\n",
      "iteration 1268, objective = 1.1920672495048585\n",
      "3.724198\n",
      "iteration 1269, objective = 1.1919891229866917\n",
      "3.7207432\n",
      "iteration 1270, objective = 1.191565787185775\n",
      "3.7170339\n",
      "iteration 1271, objective = 1.1915395901998933\n",
      "3.7134893\n",
      "iteration 1272, objective = 1.191592154054512\n",
      "3.7097204\n",
      "iteration 1273, objective = 1.191453661512622\n",
      "3.7077851\n",
      "iteration 1274, objective = 1.1912961999885945\n",
      "3.706092\n",
      "iteration 1275, objective = 1.1907664756375371\n",
      "3.7059116\n",
      "iteration 1276, objective = 1.1912567741207138\n",
      "3.7035334\n",
      "iteration 1277, objective = 1.1907699364932556\n",
      "3.702199\n",
      "iteration 1278, objective = 1.1905783259870326\n",
      "3.7017694\n",
      "iteration 1279, objective = 1.190157244162771\n",
      "3.702594\n",
      "iteration 1280, objective = 1.1907086880311546\n",
      "3.7040427\n",
      "iteration 1281, objective = 1.1906030700056\n",
      "3.7054222\n",
      "iteration 1282, objective = 1.190400545756645\n",
      "3.7064462\n",
      "iteration 1283, objective = 1.190667578446457\n",
      "3.7078605\n",
      "iteration 1284, objective = 1.1905864729901856\n",
      "3.7093105\n",
      "iteration 1285, objective = 1.189964723508591\n",
      "3.7125132\n",
      "iteration 1286, objective = 1.1891223873326817\n",
      "3.7155194\n",
      "iteration 1287, objective = 1.1893279623579538\n",
      "3.7163334\n",
      "iteration 1288, objective = 1.1892682966655685\n",
      "3.7169404\n",
      "iteration 1289, objective = 1.1895827566226163\n",
      "3.7157645\n",
      "iteration 1290, objective = 1.189060355294309\n",
      "3.7143004\n",
      "iteration 1291, objective = 1.1890007492657457\n",
      "3.7145677\n",
      "iteration 1292, objective = 1.1895145803539884\n",
      "3.714881\n",
      "iteration 1293, objective = 1.189587043932003\n",
      "3.716093\n",
      "iteration 1294, objective = 1.1893818637457414\n",
      "3.7175984\n",
      "iteration 1295, objective = 1.1894648761482791\n",
      "3.7196925\n",
      "iteration 1296, objective = 1.1889638022129432\n",
      "3.7212358\n",
      "iteration 1297, objective = 1.1889096090157214\n",
      "3.7234936\n",
      "iteration 1298, objective = 1.1886158785057308\n",
      "3.7259474\n",
      "iteration 1299, objective = 1.1892421089067953\n",
      "3.7273796\n",
      "iteration 1300, objective = 1.1891973268605687\n",
      "3.7291844\n",
      "iteration 1301, objective = 1.1887807315658276\n",
      "3.7325165\n",
      "iteration 1302, objective = 1.1888764345829896\n",
      "3.7342408\n",
      "iteration 1303, objective = 1.1890701000407902\n",
      "3.7353973\n",
      "iteration 1304, objective = 1.1888909165386075\n",
      "3.7363634\n",
      "iteration 1305, objective = 1.1890301514901056\n",
      "3.7376375\n",
      "iteration 1306, objective = 1.187978529790501\n",
      "3.739193\n",
      "iteration 1307, objective = 1.187701640125993\n",
      "3.7406998\n",
      "iteration 1308, objective = 1.1873682055487325\n",
      "3.7418342\n",
      "iteration 1309, objective = 1.18729654389435\n",
      "3.742836\n",
      "iteration 1310, objective = 1.1866160013499605\n",
      "3.744491\n",
      "iteration 1311, objective = 1.1866640546079394\n",
      "3.746874\n",
      "iteration 1312, objective = 1.186563655093043\n",
      "3.7489927\n",
      "iteration 1313, objective = 1.1862182287004808\n",
      "3.7505891\n",
      "iteration 1314, objective = 1.1865150084198255\n",
      "3.7521095\n",
      "iteration 1315, objective = 1.1857465970709762\n",
      "3.7545323\n",
      "iteration 1316, objective = 1.185891409970668\n",
      "3.7557487\n",
      "iteration 1317, objective = 1.186084912147849\n",
      "3.7558472\n",
      "iteration 1318, objective = 1.1860994165438927\n",
      "3.7537656\n",
      "iteration 1319, objective = 1.1862583217916338\n",
      "3.7509668\n",
      "iteration 1320, objective = 1.1859566632769096\n",
      "3.7491477\n",
      "iteration 1321, objective = 1.1857560548653907\n",
      "3.7469308\n",
      "iteration 1322, objective = 1.1859225835256735\n",
      "3.7453792\n",
      "iteration 1323, objective = 1.1856478542582989\n",
      "3.7432716\n",
      "iteration 1324, objective = 1.1853648489152826\n",
      "3.74364\n",
      "iteration 1325, objective = 1.1846754364501033\n",
      "3.744304\n",
      "iteration 1326, objective = 1.1845841267690709\n",
      "3.745582\n",
      "iteration 1327, objective = 1.184667586737251\n",
      "3.7464821\n",
      "iteration 1328, objective = 1.1843592365915858\n",
      "3.7491415\n",
      "iteration 1329, objective = 1.1839001312542774\n",
      "3.7518647\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "iteration 1330, objective = 1.1839261702675814\n",
      "3.7555618\n",
      "iteration 1331, objective = 1.1839501779888348\n",
      "3.7583847\n",
      "iteration 1332, objective = 1.1840200744067448\n",
      "3.7605968\n",
      "iteration 1333, objective = 1.1835999584559636\n",
      "3.7632258\n",
      "iteration 1334, objective = 1.1835114759128134\n",
      "3.7646217\n",
      "iteration 1335, objective = 1.183434080897142\n",
      "3.7666078\n",
      "iteration 1336, objective = 1.1833080466812973\n",
      "3.768668\n",
      "iteration 1337, objective = 1.182661656626074\n",
      "3.7705493\n",
      "iteration 1338, objective = 1.1825597607250173\n",
      "3.773652\n",
      "iteration 1339, objective = 1.1825077181545578\n",
      "3.7780204\n",
      "iteration 1340, objective = 1.1825443146261845\n",
      "3.7824907\n",
      "iteration 1341, objective = 1.1822078390663104\n",
      "3.7879608\n",
      "iteration 1342, objective = 1.1824726590075474\n",
      "3.7926266\n",
      "iteration 1343, objective = 1.1824552915230984\n",
      "3.7959526\n",
      "iteration 1344, objective = 1.1823031721242363\n",
      "3.798866\n",
      "iteration 1345, objective = 1.1820972153392215\n",
      "3.8018808\n",
      "iteration 1346, objective = 1.1817708059087808\n",
      "3.8044662\n",
      "iteration 1347, objective = 1.1821001605536392\n",
      "3.8062046\n",
      "iteration 1348, objective = 1.1821154680689288\n",
      "3.8067825\n",
      "iteration 1349, objective = 1.182102136716974\n",
      "3.8058903\n",
      "iteration 1350, objective = 1.1825234204066668\n",
      "3.8039763\n",
      "iteration 1351, objective = 1.1824344063460215\n",
      "3.8025753\n",
      "iteration 1352, objective = 1.182464664195105\n",
      "3.8016336\n",
      "iteration 1353, objective = 1.1822069248648346\n",
      "3.7998989\n",
      "iteration 1354, objective = 1.1824790654209092\n",
      "3.7988424\n",
      "iteration 1355, objective = 1.182550897397124\n",
      "3.7963755\n",
      "iteration 1356, objective = 1.1826130404067798\n",
      "3.793058\n",
      "iteration 1357, objective = 1.1825222132757773\n",
      "3.7889588\n",
      "iteration 1358, objective = 1.1822582240482775\n",
      "3.786299\n",
      "iteration 1359, objective = 1.1826965425650788\n",
      "3.783846\n",
      "iteration 1360, objective = 1.1825783649406953\n",
      "3.7808776\n",
      "iteration 1361, objective = 1.182271047782907\n",
      "3.7783005\n",
      "iteration 1362, objective = 1.1822999755848902\n",
      "3.7754514\n",
      "iteration 1363, objective = 1.1819288175247806\n",
      "3.7737033\n",
      "iteration 1364, objective = 1.1822758798584532\n",
      "3.7713172\n"
     ]
    },
    {
     "ename": "KeyboardInterrupt",
     "evalue": "",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mIndexError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[0;32m/usr/local/lib/python3.5/dist-packages/tensorflow_core/python/distribute/distribution_strategy_context.py\u001b[0m in \u001b[0;36m_get_per_thread_mode\u001b[0;34m()\u001b[0m\n\u001b[1;32m     79\u001b[0m   \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 80\u001b[0;31m     \u001b[0;32mreturn\u001b[0m \u001b[0mops\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_default_graph\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_distribution_strategy_stack\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m]\u001b[0m  \u001b[0;31m# pylint: disable=protected-access\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     81\u001b[0m   \u001b[0;32mexcept\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mAttributeError\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mIndexError\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mIndexError\u001b[0m: list index out of range",
      "\nDuring handling of the above exception, another exception occurred:\n",
      "\u001b[0;31mKeyboardInterrupt\u001b[0m                         Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-23-f2aefe1645c5>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m      1\u001b[0m \u001b[0mlosses\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      2\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mi\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m1000000\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m     \u001b[0mobj\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtrainingStep\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minteractions\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m      4\u001b[0m     \u001b[0mlosses\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mlosses\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0mobj\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0;36m1000\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      5\u001b[0m     print(\"iteration \" + str(i) + \", objective = \" +\n",
      "\u001b[0;32m<ipython-input-22-54421b2dc2b7>\u001b[0m in \u001b[0;36mtrainingStep\u001b[0;34m(interactions)\u001b[0m\n\u001b[1;32m      2\u001b[0m     \u001b[0;32mwith\u001b[0m \u001b[0mtf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mGradientTape\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mtape\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      3\u001b[0m         \u001b[0msample\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mrandom\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msample\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minteractions\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m100\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 4\u001b[0;31m         \u001b[0mlosses\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0mmodel\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0muserIDs\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mu\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mitemIDs\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mr\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mu\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mr\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32min\u001b[0m \u001b[0msample\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m      5\u001b[0m         \u001b[0mlosses\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmodel\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mreg\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      6\u001b[0m     \u001b[0mgradients\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtape\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgradient\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlosses\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmodel\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtrainable_variables\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m<ipython-input-22-54421b2dc2b7>\u001b[0m in \u001b[0;36m<listcomp>\u001b[0;34m(.0)\u001b[0m\n\u001b[1;32m      2\u001b[0m     \u001b[0;32mwith\u001b[0m \u001b[0mtf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mGradientTape\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mtape\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      3\u001b[0m         \u001b[0msample\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mrandom\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msample\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minteractions\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m100\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 4\u001b[0;31m         \u001b[0mlosses\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0mmodel\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0muserIDs\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mu\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mitemIDs\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mr\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mu\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mr\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32min\u001b[0m \u001b[0msample\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m      5\u001b[0m         \u001b[0mlosses\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmodel\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mreg\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      6\u001b[0m     \u001b[0mgradients\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtape\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgradient\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlosses\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmodel\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtrainable_variables\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/lib/python3.5/dist-packages/tensorflow_core/python/keras/engine/base_layer.py\u001b[0m in \u001b[0;36m__call__\u001b[0;34m(self, inputs, *args, **kwargs)\u001b[0m\n\u001b[1;32m    820\u001b[0m           with base_layer_utils.autocast_context_manager(\n\u001b[1;32m    821\u001b[0m               self._compute_dtype):\n\u001b[0;32m--> 822\u001b[0;31m             \u001b[0moutputs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcall\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcast_inputs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    823\u001b[0m           \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_handle_activity_regularization\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minputs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0moutputs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    824\u001b[0m           \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_set_mask_metadata\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minputs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0moutputs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0minput_masks\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m<ipython-input-21-4202a7dbb439>\u001b[0m in \u001b[0;36mcall\u001b[0;34m(self, u, i, r)\u001b[0m\n\u001b[1;32m     17\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     18\u001b[0m     \u001b[0;32mdef\u001b[0m \u001b[0mcall\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mu\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mi\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mr\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 19\u001b[0;31m         \u001b[0;32mreturn\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpredict\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mu\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m-\u001b[0m \u001b[0mr\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m**\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     20\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     21\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m<ipython-input-21-4202a7dbb439>\u001b[0m in \u001b[0;36mpredict\u001b[0;34m(self, u, i)\u001b[0m\n\u001b[1;32m     10\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     11\u001b[0m     \u001b[0;32mdef\u001b[0m \u001b[0mpredict\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mu\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mi\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 12\u001b[0;31m         \u001b[0mp\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0malpha\u001b[0m \u001b[0;34m+\u001b[0m            \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mbetaU\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mu\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m+\u001b[0m            \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mbetaI\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m+\u001b[0m            \u001b[0mtf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtensordot\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgammaU\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mu\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgammaI\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     13\u001b[0m         \u001b[0;32mreturn\u001b[0m \u001b[0mp\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     14\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/lib/python3.5/dist-packages/tensorflow_core/python/ops/array_ops.py\u001b[0m in \u001b[0;36m_SliceHelperVar\u001b[0;34m(var, slice_spec)\u001b[0m\n\u001b[1;32m   1136\u001b[0m   \"\"\"\n\u001b[1;32m   1137\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1138\u001b[0;31m   \u001b[0;32mreturn\u001b[0m \u001b[0m_slice_helper\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mvar\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvalue\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mslice_spec\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mvar\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m   1139\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1140\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/lib/python3.5/dist-packages/tensorflow_core/python/ops/resource_variable_ops.py\u001b[0m in \u001b[0;36mvalue\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m    527\u001b[0m       \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_cached_value\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    528\u001b[0m     \u001b[0;32mwith\u001b[0m \u001b[0mops\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcolocate_with\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mignore_existing\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 529\u001b[0;31m       \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_read_variable_op\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    530\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    531\u001b[0m   \u001b[0;32mdef\u001b[0m \u001b[0m_as_graph_element\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/lib/python3.5/dist-packages/tensorflow_core/python/ops/resource_variable_ops.py\u001b[0m in \u001b[0;36m_read_variable_op\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m    609\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    610\u001b[0m   \u001b[0;32mdef\u001b[0m \u001b[0m_read_variable_op\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 611\u001b[0;31m     \u001b[0mvariable_accessed\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    612\u001b[0m     result = gen_resource_variable_ops.read_variable_op(self._handle,\n\u001b[1;32m    613\u001b[0m                                                         self._dtype)\n",
      "\u001b[0;32m/usr/local/lib/python3.5/dist-packages/tensorflow_core/python/ops/resource_variable_ops.py\u001b[0m in \u001b[0;36mvariable_accessed\u001b[0;34m(variable)\u001b[0m\n\u001b[1;32m    318\u001b[0m     \u001b[0mops\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_default_graph\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwatch_variable\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mvariable\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    319\u001b[0m   \u001b[0;32mif\u001b[0m \u001b[0mvariable\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtrainable\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 320\u001b[0;31m     \u001b[0mtape\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvariable_accessed\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mvariable\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    321\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    322\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/lib/python3.5/dist-packages/tensorflow_core/python/eager/tape.py\u001b[0m in \u001b[0;36mvariable_accessed\u001b[0;34m(variable)\u001b[0m\n\u001b[1;32m     79\u001b[0m   \"\"\"\n\u001b[1;32m     80\u001b[0m   strategy, context = (\n\u001b[0;32m---> 81\u001b[0;31m       distribution_strategy_context.get_strategy_and_replica_context())\n\u001b[0m\u001b[1;32m     82\u001b[0m   \u001b[0;32mif\u001b[0m \u001b[0mcontext\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     83\u001b[0m     \u001b[0mvariables\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0mstrategy\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mextended\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvalue_container\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mvariable\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/lib/python3.5/dist-packages/tensorflow_core/python/distribute/distribution_strategy_context.py\u001b[0m in \u001b[0;36mget_strategy_and_replica_context\u001b[0;34m()\u001b[0m\n\u001b[1;32m    214\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    215\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mget_strategy_and_replica_context\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 216\u001b[0;31m   \u001b[0mper_thread_mode\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_get_per_thread_mode\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    217\u001b[0m   \u001b[0;32mreturn\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mper_thread_mode\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstrategy\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mper_thread_mode\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mreplica_context\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    218\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/lib/python3.5/dist-packages/tensorflow_core/python/distribute/distribution_strategy_context.py\u001b[0m in \u001b[0;36m_get_per_thread_mode\u001b[0;34m()\u001b[0m\n\u001b[1;32m     78\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m_get_per_thread_mode\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     79\u001b[0m   \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 80\u001b[0;31m     \u001b[0;32mreturn\u001b[0m \u001b[0mops\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_default_graph\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_distribution_strategy_stack\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m]\u001b[0m  \u001b[0;31m# pylint: disable=protected-access\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     81\u001b[0m   \u001b[0;32mexcept\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mAttributeError\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mIndexError\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     82\u001b[0m     \u001b[0;32mreturn\u001b[0m \u001b[0m_get_default_replica_mode\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mKeyboardInterrupt\u001b[0m: "
     ]
    }
   ],
   "source": [
    "losses = []\n",
    "for i in range(1000000):\n",
    "    obj = trainingStep(interactions)\n",
    "    losses = (losses + [obj])[-1000:]\n",
    "    print(\"iteration \" + str(i) + \", objective = \" +\n",
    "          str(sum(losses) / len(losses)))\n",
    "    print(model.alpha.numpy())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "itemsPerUser = defaultdict(set)\n",
    "for u,i,_ in interactions:\n",
    "    itemsPerUser[u].add(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "items = list(itemIDs.keys())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "metadata": {},
   "outputs": [],
   "source": [
    "optimizer = tf.keras.optimizers.Adam(0.01)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "metadata": {},
   "outputs": [],
   "source": [
    "class BPR(tf.keras.Model):\n",
    "    def __init__(self, K, lamb):\n",
    "        super(BPR, self).__init__()\n",
    "        self.betaI = tf.Variable(tf.random.normal([len(itemIDs)],stddev=0.001))\n",
    "        self.gammaU = tf.Variable(tf.random.normal([len(userIDs),K],stddev=0.001))\n",
    "        self.gammaI = tf.Variable(tf.random.normal([len(itemIDs),K],stddev=0.001))\n",
    "        self.lamb = lamb\n",
    "\n",
    "    def predict(self, u, i):\n",
    "        p = self.betaI[i] + tf.tensordot(self.gammaU[u], self.gammaI[i], 1)\n",
    "        return p\n",
    "\n",
    "    def reg(self):\n",
    "        return self.lamb * (tf.reduce_sum(self.betaI**2) +\\\n",
    "                            tf.reduce_sum(self.gammaU**2) +\\\n",
    "                            tf.reduce_sum(self.gammaI**2))\n",
    "\n",
    "    def call(self, u, i, j):\n",
    "        return -tf.math.log(tf.math.sigmoid(self.predict(u,i) - self.predict(u,j)))\n",
    "\n",
    "model = BPR(5, 0.00001)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 96,
   "metadata": {},
   "outputs": [],
   "source": [
    "def trainingStep(interactions):\n",
    "    with tf.GradientTape() as tape:\n",
    "        sample = []\n",
    "        for _ in range(100):\n",
    "            u,i,_ = random.choice(interactions) # positive sample\n",
    "            j = random.choice(items) # negative sample\n",
    "            while j in itemsPerUser[u]:\n",
    "                j = random.choice(items)\n",
    "            sample.append((u,i,j))\n",
    "        loss = tf.reduce_mean([model(userIDs[u],itemIDs[i],itemIDs[j]) for (u,i,j) in sample])\n",
    "        loss += model.reg()\n",
    "    gradients = tape.gradient(loss, model.trainable_variables)\n",
    "    optimizer.apply_gradients((grad, var) for\n",
    "                              (grad, var) in zip(gradients, model.trainable_variables)\n",
    "                              if grad is not None)\n",
    "    return loss.numpy()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 97,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "iteration 0, objective = 1.4376771450042725\n",
      "iteration 1, objective = 32.11431014537811\n",
      "iteration 2, objective = 23.021116018295288\n",
      "iteration 3, objective = 20.9239142537117\n",
      "iteration 4, objective = 23.936439752578735\n",
      "iteration 5, objective = 24.098796725273132\n",
      "iteration 6, objective = 21.500775371279037\n",
      "iteration 7, objective = 19.011106729507446\n",
      "iteration 8, objective = 18.157492637634277\n",
      "iteration 9, objective = 18.19003267288208\n",
      "iteration 10, objective = 17.85881588675759\n",
      "iteration 11, objective = 16.842211763064068\n",
      "iteration 12, objective = 15.636714678544264\n",
      "iteration 13, objective = 14.796602623803276\n",
      "iteration 14, objective = 14.394345696767171\n",
      "iteration 15, objective = 14.105401486158371\n",
      "iteration 16, objective = 13.645142414990593\n",
      "iteration 17, objective = 13.014042920536465\n",
      "iteration 18, objective = 12.402221610671596\n",
      "iteration 19, objective = 11.954346233606339\n",
      "iteration 20, objective = 11.644453213328408\n",
      "iteration 21, objective = 11.34793416478417\n",
      "iteration 22, objective = 10.986181243606236\n",
      "iteration 23, objective = 10.58624334136645\n",
      "iteration 24, objective = 10.222976641654968\n",
      "iteration 25, objective = 9.932935948555286\n",
      "iteration 26, objective = 9.688411319697344\n",
      "iteration 27, objective = 9.440059402159282\n",
      "iteration 28, objective = 9.170494457771039\n",
      "iteration 29, objective = 8.9017365415891\n",
      "iteration 30, objective = 8.661752012468153\n",
      "iteration 31, objective = 8.454140949994326\n",
      "iteration 32, objective = 8.260137836138407\n",
      "iteration 33, objective = 8.06242515409694\n",
      "iteration 34, objective = 7.862287524768284\n",
      "iteration 35, objective = 7.672740360101064\n",
      "iteration 36, objective = 7.501205708529498\n",
      "iteration 37, objective = 7.3429211754547925\n",
      "iteration 38, objective = 7.187887097016359\n",
      "iteration 39, objective = 7.033089379966259\n",
      "iteration 40, objective = 6.883218605343888\n",
      "iteration 41, objective = 6.743290648573921\n",
      "iteration 42, objective = 6.612802078557569\n",
      "iteration 43, objective = 6.487064217979258\n",
      "iteration 44, objective = 6.363205371962653\n",
      "iteration 45, objective = 6.242686076008755\n",
      "iteration 46, objective = 6.128189909965434\n",
      "iteration 47, objective = 6.019960422068834\n",
      "iteration 48, objective = 5.915791123497243\n",
      "iteration 49, objective = 5.813893393278122\n",
      "iteration 50, objective = 5.71497258719276\n",
      "iteration 51, objective = 5.62028146133973\n",
      "iteration 52, objective = 5.5298804573293\n",
      "iteration 53, objective = 5.442607241648215\n",
      "iteration 54, objective = 5.357606029510498\n",
      "iteration 55, objective = 5.274984353354999\n",
      "iteration 56, objective = 5.195452239429741\n",
      "iteration 57, objective = 5.119073920208832\n",
      "iteration 58, objective = 5.045195488606469\n",
      "iteration 59, objective = 4.9732685983181\n",
      "iteration 60, objective = 4.903294742107391\n",
      "iteration 61, objective = 4.835828763823355\n",
      "iteration 62, objective = 4.770593506003183\n",
      "iteration 63, objective = 4.707261617295444\n",
      "iteration 64, objective = 4.64560099198268\n",
      "iteration 65, objective = 4.585666175141479\n",
      "iteration 66, objective = 4.5276471154013676\n",
      "iteration 67, objective = 4.471305047764497\n",
      "iteration 68, objective = 4.416529956935109\n",
      "iteration 69, objective = 4.363179435900279\n",
      "iteration 70, objective = 4.311377609279794\n",
      "iteration 71, objective = 4.260999599264728\n",
      "iteration 72, objective = 4.211966020603702\n",
      "iteration 73, objective = 4.164328281943862\n",
      "iteration 74, objective = 4.117786174615224\n",
      "iteration 75, objective = 4.072523716248964\n",
      "iteration 76, objective = 4.028463591228832\n",
      "iteration 77, objective = 3.9855186396684403\n",
      "iteration 78, objective = 3.9436167455926725\n",
      "iteration 79, objective = 3.90274513438344\n",
      "iteration 80, objective = 3.8627916007866094\n",
      "iteration 81, objective = 3.823851549043888\n",
      "iteration 82, objective = 3.785865923008287\n",
      "iteration 83, objective = 3.7487308773256482\n",
      "iteration 84, objective = 3.7125019283855663\n",
      "iteration 85, objective = 3.6771003638589104\n",
      "iteration 86, objective = 3.6424907911782975\n",
      "iteration 87, objective = 3.608642130412839\n",
      "iteration 88, objective = 3.5755323914999373\n",
      "iteration 89, objective = 3.5431965947151185\n",
      "iteration 90, objective = 3.5115129325416063\n",
      "iteration 91, objective = 3.4806269485017527\n",
      "iteration 92, objective = 3.4503531552130178\n",
      "iteration 93, objective = 3.420758986092628\n",
      "iteration 94, objective = 3.3916950872069913\n",
      "iteration 95, objective = 3.363314556578795\n",
      "iteration 96, objective = 3.335521610127282\n",
      "iteration 97, objective = 3.3082046490542742\n",
      "iteration 98, objective = 3.281456130923647\n",
      "iteration 99, objective = 3.255226867198944\n",
      "iteration 100, objective = 3.229611632257405\n",
      "iteration 101, objective = 3.204398980327681\n",
      "iteration 102, objective = 3.1796504455862693\n",
      "iteration 103, objective = 3.155371167911933\n",
      "iteration 104, objective = 3.131481625352587\n",
      "iteration 105, objective = 3.1080991102839417\n",
      "iteration 106, objective = 3.0852750472933335\n",
      "iteration 107, objective = 3.0626844195304095\n",
      "iteration 108, objective = 3.0405206838879018\n",
      "iteration 109, objective = 3.018832729621367\n",
      "iteration 110, objective = 2.9974841647319965\n",
      "iteration 111, objective = 2.9765032652233328\n",
      "iteration 112, objective = 2.9560128307975497\n",
      "iteration 113, objective = 2.935819641539925\n",
      "iteration 114, objective = 2.916053889627042\n",
      "iteration 115, objective = 2.8965033215695413\n",
      "iteration 116, objective = 2.877372117124052\n",
      "iteration 117, objective = 2.858495291511891\n",
      "iteration 118, objective = 2.8399260534959683\n",
      "iteration 119, objective = 2.8215998431046803\n",
      "iteration 120, objective = 2.803747384508779\n",
      "iteration 121, objective = 2.7861076397973985\n",
      "iteration 122, objective = 2.7687616740784993\n",
      "iteration 123, objective = 2.7517124169295832\n",
      "iteration 124, objective = 2.734882227897644\n",
      "iteration 125, objective = 2.7183301198104073\n",
      "iteration 126, objective = 2.701943214484087\n",
      "iteration 127, objective = 2.6858566300943494\n",
      "iteration 128, objective = 2.6699821602466494\n",
      "iteration 129, objective = 2.654370730198347\n",
      "iteration 130, objective = 2.639047977578549\n",
      "iteration 131, objective = 2.6239289767814404\n",
      "iteration 132, objective = 2.609141691734916\n",
      "iteration 133, objective = 2.594479303306608\n",
      "iteration 134, objective = 2.579917312551428\n",
      "iteration 135, objective = 2.5656983624486362\n",
      "iteration 136, objective = 2.551760539521266\n",
      "iteration 137, objective = 2.537932414939438\n",
      "iteration 138, objective = 2.5242967313999753\n",
      "iteration 139, objective = 2.510891758969852\n",
      "iteration 140, objective = 2.4975701380283275\n",
      "iteration 141, objective = 2.4845196537568537\n",
      "iteration 142, objective = 2.4715543510196927\n",
      "iteration 143, objective = 2.4588752827710576\n",
      "iteration 144, objective = 2.446358568503939\n",
      "iteration 145, objective = 2.4340680592680632\n",
      "iteration 146, objective = 2.4218941172774957\n",
      "iteration 147, objective = 2.409887153554607\n",
      "iteration 148, objective = 2.3980532924600895\n"
     ]
    },
    {
     "ename": "KeyboardInterrupt",
     "evalue": "",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mKeyboardInterrupt\u001b[0m                         Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-97-8a300b317a7f>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m      1\u001b[0m \u001b[0mlosses\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      2\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mi\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m1000000\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m     \u001b[0mobj\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtrainingStep\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minteractions\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m      4\u001b[0m     \u001b[0mlosses\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mlosses\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0mobj\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0;36m1000\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      5\u001b[0m     print(\"iteration \" + str(i) + \", objective = \" +\n",
      "\u001b[0;32m<ipython-input-96-661340915c83>\u001b[0m in \u001b[0;36mtrainingStep\u001b[0;34m(interactions)\u001b[0m\n\u001b[1;32m     10\u001b[0m         \u001b[0mloss\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mreduce_mean\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mmodel\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0muserIDs\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mu\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mitemIDs\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mitemIDs\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mj\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mu\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mj\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32min\u001b[0m \u001b[0msample\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     11\u001b[0m         \u001b[0mloss\u001b[0m \u001b[0;34m+=\u001b[0m \u001b[0mmodel\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mreg\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 12\u001b[0;31m     \u001b[0mgradients\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtape\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgradient\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mloss\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmodel\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtrainable_variables\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     13\u001b[0m     optimizer.apply_gradients((grad, var) for\n\u001b[1;32m     14\u001b[0m                               \u001b[0;34m(\u001b[0m\u001b[0mgrad\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mvar\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mzip\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mgradients\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmodel\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtrainable_variables\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/lib/python3.5/dist-packages/tensorflow_core/python/eager/backprop.py\u001b[0m in \u001b[0;36mgradient\u001b[0;34m(self, target, sources, output_gradients, unconnected_gradients)\u001b[0m\n\u001b[1;32m   1027\u001b[0m         \u001b[0moutput_gradients\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0moutput_gradients\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1028\u001b[0m         \u001b[0msources_raw\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mflat_sources_raw\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1029\u001b[0;31m         unconnected_gradients=unconnected_gradients)\n\u001b[0m\u001b[1;32m   1030\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1031\u001b[0m     \u001b[0;32mif\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_persistent\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/lib/python3.5/dist-packages/tensorflow_core/python/eager/imperative_grad.py\u001b[0m in \u001b[0;36mimperative_grad\u001b[0;34m(tape, target, sources, output_gradients, sources_raw, unconnected_gradients)\u001b[0m\n\u001b[1;32m     75\u001b[0m       \u001b[0moutput_gradients\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     76\u001b[0m       \u001b[0msources_raw\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 77\u001b[0;31m       compat.as_str(unconnected_gradients.value))\n\u001b[0m",
      "\u001b[0;32m/usr/local/lib/python3.5/dist-packages/tensorflow_core/python/eager/backprop.py\u001b[0m in \u001b[0;36m_gradient_function\u001b[0;34m(op_name, attr_tuple, num_inputs, inputs, outputs, out_grads, skip_input_indices)\u001b[0m\n\u001b[1;32m    139\u001b[0m     \u001b[0;32mreturn\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m*\u001b[0m \u001b[0mnum_inputs\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    140\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 141\u001b[0;31m   \u001b[0;32mreturn\u001b[0m \u001b[0mgrad_fn\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmock_op\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0mout_grads\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    142\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    143\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/lib/python3.5/dist-packages/tensorflow_core/python/ops/math_grad.py\u001b[0m in \u001b[0;36m_SubGrad\u001b[0;34m(op, grad)\u001b[0m\n\u001b[1;32m   1185\u001b[0m   if (isinstance(grad, ops.Tensor) and\n\u001b[1;32m   1186\u001b[0m       _ShapesFullySpecifiedAndEqual(x, y, grad)):\n\u001b[0;32m-> 1187\u001b[0;31m     \u001b[0;32mreturn\u001b[0m \u001b[0mgrad\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m-\u001b[0m\u001b[0mgrad\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m   1188\u001b[0m   (sx, rx, must_reduce_x), (sy, ry, must_reduce_y) = (\n\u001b[1;32m   1189\u001b[0m       SmartBroadcastGradientArgs(x, y, grad))\n",
      "\u001b[0;32m/usr/local/lib/python3.5/dist-packages/tensorflow_core/python/ops/gen_math_ops.py\u001b[0m in \u001b[0;36mneg\u001b[0;34m(x, name)\u001b[0m\n\u001b[1;32m   6283\u001b[0m       _result = _pywrap_tensorflow.TFE_Py_FastPathExecute(\n\u001b[1;32m   6284\u001b[0m         \u001b[0m_ctx\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_context_handle\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtld\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdevice_name\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"Neg\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtld\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mop_callbacks\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 6285\u001b[0;31m         x)\n\u001b[0m\u001b[1;32m   6286\u001b[0m       \u001b[0;32mreturn\u001b[0m \u001b[0m_result\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   6287\u001b[0m     \u001b[0;32mexcept\u001b[0m \u001b[0m_core\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_FallbackException\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mKeyboardInterrupt\u001b[0m: "
     ]
    }
   ],
   "source": [
    "losses = []\n",
    "for i in range(1000000):\n",
    "    obj = trainingStep(interactions)\n",
    "    losses = (losses + [obj])[-1000:]\n",
    "    print(\"iteration \" + str(i) + \", objective = \" +\n",
    "          str(sum(losses) / len(losses)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 103,
   "metadata": {},
   "outputs": [],
   "source": [
    "optimizer = tf.keras.optimizers.Adam(0.001)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 104,
   "metadata": {},
   "outputs": [],
   "source": [
    "class BPRbatch(tf.keras.Model):\n",
    "    def __init__(self, K, lamb):\n",
    "        super(BPRbatch, self).__init__()\n",
    "        # Initialize variables\n",
    "        self.betaI = tf.Variable(tf.random.normal([len(itemIDs)],stddev=0.001))\n",
    "        self.gammaU = tf.Variable(tf.random.normal([len(userIDs),K],stddev=0.001))\n",
    "        self.gammaI = tf.Variable(tf.random.normal([len(itemIDs),K],stddev=0.001))\n",
    "        # Regularization coefficient\n",
    "        self.lamb = lamb\n",
    "\n",
    "    # Prediction for a single instance\n",
    "    def predict(self, u, i):\n",
    "        p = self.betaI[i] + tf.tensordot(self.gammaU[u], self.gammaI[i], 1)\n",
    "        return p\n",
    "\n",
    "    # Regularizer\n",
    "    def reg(self):\n",
    "        return self.lamb * (tf.nn.l2_loss(self.betaI) +\\\n",
    "                            tf.nn.l2_loss(self.gammaU) +\\\n",
    "                            tf.nn.l2_loss(self.gammaI))\n",
    "    \n",
    "    def score(self, sampleU, sampleI):\n",
    "        u = tf.convert_to_tensor(sampleU, dtype=tf.int32)\n",
    "        i = tf.convert_to_tensor(sampleI, dtype=tf.int32)\n",
    "        beta_i = tf.nn.embedding_lookup(self.betaI, i)\n",
    "        gamma_u = tf.nn.embedding_lookup(self.gammaU, u)\n",
    "        gamma_i = tf.nn.embedding_lookup(self.gammaI, i)\n",
    "        x_ui = beta_i + tf.reduce_sum(tf.multiply(gamma_u, gamma_i), 1)\n",
    "        return x_ui\n",
    "\n",
    "    def call(self, sampleU, sampleI, sampleJ):\n",
    "        x_ui = self.score(sampleU, sampleI)\n",
    "        x_uj = self.score(sampleU, sampleJ)\n",
    "        return -tf.reduce_mean(tf.math.log(tf.math.sigmoid(x_ui - x_uj)))\n",
    "\n",
    "model = BPRbatch(5, 0.00001)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 105,
   "metadata": {},
   "outputs": [],
   "source": [
    "def trainingStep(interactions):\n",
    "    with tf.GradientTape() as tape:\n",
    "        sampleU, sampleI, sampleJ = [], [], []\n",
    "        for _ in range(100000):\n",
    "            u,i,_ = random.choice(interactions) # positive sample\n",
    "            j = random.choice(items) # negative sample\n",
    "            while j in itemsPerUser[u]:\n",
    "                j = random.choice(items)\n",
    "            sampleU.append(userIDs[u])\n",
    "            sampleI.append(itemIDs[i])\n",
    "            sampleJ.append(itemIDs[j])\n",
    "\n",
    "        loss = model(sampleU,sampleI,sampleJ)\n",
    "        loss += model.reg()\n",
    "    gradients = tape.gradient(loss, model.trainable_variables)\n",
    "    optimizer.apply_gradients((grad, var) for\n",
    "                              (grad, var) in zip(gradients, model.trainable_variables)\n",
    "                              if grad is not None)\n",
    "    return loss.numpy()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 106,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "iteration 0, objective = 1.4377176761627197\n",
      "iteration 1, objective = 1.2112258970737457\n",
      "iteration 2, objective = 1.0928723812103271\n",
      "iteration 3, objective = 1.049851879477501\n",
      "iteration 4, objective = 1.0337864995002746\n",
      "iteration 5, objective = 1.0133000612258911\n",
      "iteration 6, objective = 0.9868159294128418\n",
      "iteration 7, objective = 0.9628333523869514\n",
      "iteration 8, objective = 0.9454027745458815\n",
      "iteration 9, objective = 0.9316659271717072\n",
      "iteration 10, objective = 0.9182850610126149\n",
      "iteration 11, objective = 0.9050509730974833\n",
      "iteration 12, objective = 0.8934481189801142\n",
      "iteration 13, objective = 0.8840138401303973\n",
      "iteration 14, objective = 0.8757736523946126\n",
      "iteration 15, objective = 0.8676682896912098\n",
      "iteration 16, objective = 0.8596078227548039\n",
      "iteration 17, objective = 0.8521164357662201\n",
      "iteration 18, objective = 0.8454737506414715\n",
      "iteration 19, objective = 0.8394642174243927\n",
      "iteration 20, objective = 0.8337655379658654\n",
      "iteration 21, objective = 0.8282955614003268\n",
      "iteration 22, objective = 0.8231440005095109\n",
      "iteration 23, objective = 0.8183520684639612\n",
      "iteration 24, objective = 0.8138660478591919\n",
      "iteration 25, objective = 0.809625309247237\n",
      "iteration 26, objective = 0.805611769358317\n",
      "iteration 27, objective = 0.801803143961089\n",
      "iteration 28, objective = 0.7981718059243827\n",
      "iteration 29, objective = 0.7947135150432587\n",
      "iteration 30, objective = 0.7914450572383019\n",
      "iteration 31, objective = 0.7883593756705523\n",
      "iteration 32, objective = 0.7854148185614384\n",
      "iteration 33, objective = 0.7825768291950226\n",
      "iteration 34, objective = 0.7798531838825771\n",
      "iteration 35, objective = 0.7772700803147422\n",
      "iteration 36, objective = 0.7748167144285666\n",
      "iteration 37, objective = 0.7724551417325672\n",
      "iteration 38, objective = 0.7701767774728628\n",
      "iteration 39, objective = 0.7679892510175705\n",
      "iteration 40, objective = 0.7658968596923642\n",
      "iteration 41, objective = 0.7638907900878361\n",
      "iteration 42, objective = 0.7619547483532928\n",
      "iteration 43, objective = 0.7600866664539684\n",
      "iteration 44, objective = 0.7582888311809963\n",
      "iteration 45, objective = 0.7565593576949575\n",
      "iteration 46, objective = 0.7548875580442712\n",
      "iteration 47, objective = 0.7532714332143465\n",
      "iteration 48, objective = 0.7517099830569053\n",
      "iteration 49, objective = 0.7502002930641174\n",
      "iteration 50, objective = 0.7487378342478883\n",
      "iteration 51, objective = 0.7473248804991062\n",
      "iteration 52, objective = 0.7459557731196566\n",
      "iteration 53, objective = 0.7446259138760744\n",
      "iteration 54, objective = 0.7433364293792031\n",
      "iteration 55, objective = 0.7420834398695401\n",
      "iteration 56, objective = 0.7408682693514907\n",
      "iteration 57, objective = 0.7396889986663029\n",
      "iteration 58, objective = 0.7385393199274095\n",
      "iteration 59, objective = 0.7374192744493484\n",
      "iteration 60, objective = 0.7363320911516908\n",
      "iteration 61, objective = 0.7352725017455316\n",
      "iteration 62, objective = 0.7342419274269588\n",
      "iteration 63, objective = 0.733235701918602\n",
      "iteration 64, objective = 0.732253950375777\n",
      "iteration 65, objective = 0.7313001851240793\n",
      "iteration 66, objective = 0.7303672406210828\n",
      "iteration 67, objective = 0.7294564422439126\n",
      "iteration 68, objective = 0.7285648791686349\n",
      "iteration 69, objective = 0.7276940371309008\n",
      "iteration 70, objective = 0.7268427736322645\n",
      "iteration 71, objective = 0.72601125554906\n",
      "iteration 72, objective = 0.7251983031834641\n",
      "iteration 73, objective = 0.7244010358243376\n",
      "iteration 74, objective = 0.723620753288269\n",
      "iteration 75, objective = 0.7228572509790722\n",
      "iteration 76, objective = 0.7221074197199437\n",
      "iteration 77, objective = 0.7213737895855536\n",
      "iteration 78, objective = 0.7206527598296539\n",
      "iteration 79, objective = 0.7199452511966229\n",
      "iteration 80, objective = 0.7192528321419234\n",
      "iteration 81, objective = 0.7185704395538424\n",
      "iteration 82, objective = 0.7179024650389889\n",
      "iteration 83, objective = 0.7172463940722602\n",
      "iteration 84, objective = 0.7166028422467848\n",
      "iteration 85, objective = 0.7159675546856814\n",
      "iteration 86, objective = 0.7153454429801853\n",
      "iteration 87, objective = 0.7147328372706067\n",
      "iteration 88, objective = 0.7141314664583528\n"
     ]
    },
    {
     "ename": "KeyboardInterrupt",
     "evalue": "",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mKeyboardInterrupt\u001b[0m                         Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-106-8a300b317a7f>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m      1\u001b[0m \u001b[0mlosses\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      2\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mi\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m1000000\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m     \u001b[0mobj\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtrainingStep\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minteractions\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m      4\u001b[0m     \u001b[0mlosses\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mlosses\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0mobj\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0;36m1000\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      5\u001b[0m     print(\"iteration \" + str(i) + \", objective = \" +\n",
      "\u001b[0;32m<ipython-input-105-10e74bfa3ad6>\u001b[0m in \u001b[0;36mtrainingStep\u001b[0;34m(interactions)\u001b[0m\n\u001b[1;32m     11\u001b[0m             \u001b[0msampleJ\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mitemIDs\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mj\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     12\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 13\u001b[0;31m         \u001b[0mloss\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmodel\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msampleU\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0msampleI\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0msampleJ\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     14\u001b[0m         \u001b[0mloss\u001b[0m \u001b[0;34m+=\u001b[0m \u001b[0mmodel\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mreg\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     15\u001b[0m     \u001b[0mgradients\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtape\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgradient\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mloss\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmodel\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtrainable_variables\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/lib/python3.5/dist-packages/tensorflow_core/python/keras/engine/base_layer.py\u001b[0m in \u001b[0;36m__call__\u001b[0;34m(self, inputs, *args, **kwargs)\u001b[0m\n\u001b[1;32m    668\u001b[0m           \u001b[0;32mreturn\u001b[0m \u001b[0mops\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mconvert_to_tensor\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    669\u001b[0m         \u001b[0;32mreturn\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 670\u001b[0;31m       \u001b[0minputs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnest\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmap_structure\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0m_convert_non_tensor\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0minputs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    671\u001b[0m       \u001b[0minput_list\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnest\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mflatten\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minputs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    672\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/lib/python3.5/dist-packages/tensorflow_core/python/util/nest.py\u001b[0m in \u001b[0;36mmap_structure\u001b[0;34m(func, *structure, **kwargs)\u001b[0m\n\u001b[1;32m    566\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    567\u001b[0m   return pack_sequence_as(\n\u001b[0;32m--> 568\u001b[0;31m       \u001b[0mstructure\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0mfunc\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mx\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mentries\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    569\u001b[0m       expand_composites=expand_composites)\n\u001b[1;32m    570\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/lib/python3.5/dist-packages/tensorflow_core/python/util/nest.py\u001b[0m in \u001b[0;36m<listcomp>\u001b[0;34m(.0)\u001b[0m\n\u001b[1;32m    566\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    567\u001b[0m   return pack_sequence_as(\n\u001b[0;32m--> 568\u001b[0;31m       \u001b[0mstructure\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0mfunc\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mx\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mentries\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    569\u001b[0m       expand_composites=expand_composites)\n\u001b[1;32m    570\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/lib/python3.5/dist-packages/tensorflow_core/python/keras/engine/base_layer.py\u001b[0m in \u001b[0;36m_convert_non_tensor\u001b[0;34m(x)\u001b[0m\n\u001b[1;32m    666\u001b[0m         \u001b[0;31m# `SparseTensors` can't be converted to `Tensor`.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    667\u001b[0m         \u001b[0;32mif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mndarray\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mfloat\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mint\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 668\u001b[0;31m           \u001b[0;32mreturn\u001b[0m \u001b[0mops\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mconvert_to_tensor\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    669\u001b[0m         \u001b[0;32mreturn\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    670\u001b[0m       \u001b[0minputs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnest\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmap_structure\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0m_convert_non_tensor\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0minputs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/lib/python3.5/dist-packages/tensorflow_core/python/framework/ops.py\u001b[0m in \u001b[0;36mconvert_to_tensor\u001b[0;34m(value, dtype, name, as_ref, preferred_dtype, dtype_hint, ctx, accepted_result_types)\u001b[0m\n\u001b[1;32m   1312\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1313\u001b[0m     \u001b[0;32mif\u001b[0m \u001b[0mret\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1314\u001b[0;31m       \u001b[0mret\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mconversion_func\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mvalue\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdtype\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mdtype\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mas_ref\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mas_ref\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m   1315\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1316\u001b[0m     \u001b[0;32mif\u001b[0m \u001b[0mret\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0mNotImplemented\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/lib/python3.5/dist-packages/tensorflow_core/python/framework/tensor_conversion_registry.py\u001b[0m in \u001b[0;36m_default_conversion_function\u001b[0;34m(***failed resolving arguments***)\u001b[0m\n\u001b[1;32m     50\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m_default_conversion_function\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mvalue\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdtype\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mas_ref\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     51\u001b[0m   \u001b[0;32mdel\u001b[0m \u001b[0mas_ref\u001b[0m  \u001b[0;31m# Unused.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 52\u001b[0;31m   \u001b[0;32mreturn\u001b[0m \u001b[0mconstant_op\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mconstant\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mvalue\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdtype\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     53\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     54\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/lib/python3.5/dist-packages/tensorflow_core/python/framework/constant_op.py\u001b[0m in \u001b[0;36mconstant\u001b[0;34m(value, dtype, shape, name)\u001b[0m\n\u001b[1;32m    256\u001b[0m   \"\"\"\n\u001b[1;32m    257\u001b[0m   return _constant_impl(value, dtype, shape, name, verify_shape=False,\n\u001b[0;32m--> 258\u001b[0;31m                         allow_broadcast=True)\n\u001b[0m\u001b[1;32m    259\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    260\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/lib/python3.5/dist-packages/tensorflow_core/python/framework/constant_op.py\u001b[0m in \u001b[0;36m_constant_impl\u001b[0;34m(value, dtype, shape, name, verify_shape, allow_broadcast)\u001b[0m\n\u001b[1;32m    264\u001b[0m   \u001b[0mctx\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcontext\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcontext\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    265\u001b[0m   \u001b[0;32mif\u001b[0m \u001b[0mctx\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mexecuting_eagerly\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 266\u001b[0;31m     \u001b[0mt\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mconvert_to_eager_tensor\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mvalue\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mctx\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdtype\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    267\u001b[0m     \u001b[0;32mif\u001b[0m \u001b[0mshape\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    268\u001b[0m       \u001b[0;32mreturn\u001b[0m \u001b[0mt\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/lib/python3.5/dist-packages/tensorflow_core/python/framework/constant_op.py\u001b[0m in \u001b[0;36mconvert_to_eager_tensor\u001b[0;34m(value, ctx, dtype)\u001b[0m\n\u001b[1;32m     66\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     67\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 68\u001b[0;31m \u001b[0;32mdef\u001b[0m \u001b[0mconvert_to_eager_tensor\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mvalue\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mctx\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdtype\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     69\u001b[0m   \"\"\"Converts the given `value` to an `EagerTensor`.\n\u001b[1;32m     70\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mKeyboardInterrupt\u001b[0m: "
     ]
    }
   ],
   "source": [
    "losses = []\n",
    "for i in range(1000000):\n",
    "    obj = trainingStep(interactions)\n",
    "    losses = (losses + [obj])[-1000:]\n",
    "    print(\"iteration \" + str(i) + \", objective = \" +\n",
    "          str(sum(losses) / len(losses)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "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.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
