{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "![MOSEK ApS](https://www.mosek.com/static/images/branding/webgraphmoseklogocolor.png )" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Optimization problem over nonnegative trigonometric polynomials. #\n", "\n", "We consider the trigonometric polynomial\n", " \n", "$$H(\\omega) = x_0 + 2 \\sum_{k=1}^n [ \\Re(x_k) \\cos(\\omega k) + \\Im(x_k) \\sin(\\omega k) ],$$\n", "\n", "where $H(\\omega)$ is a real valued function paramtrized by the complex vector $x\\in {\\bf C}^{n+1}$, and where $\\Im(x_0)=0$.\n", "\n", "The example shows how to construct a *non-negative* polynomial $H(\\omega)\\geq 0, \\: \\forall \\omega$ that satisfies,\n", " \n", "$$1 - \\delta \\leq H(\\omega) \\leq 1 + \\delta, \\quad \\forall \\omega \\in [0, \\omega_p]$$\n", "\n", "while minimizing $\\sup_{\\omega\\in [\\omega_s,\\pi]} H(\\omega)$ over the variables $x$.\n", "\n", "In the signal processing literature such a trigonometric polynomial is known as (the squared amplitude response of) a Chebyshev lowpass filter. \n", "\n", "A squared amplitude response $H(\\omega)$ is always symmetric around $0$, so $\\Im(x_k)=0$, and we consider only\n", "\n", "$$H(\\omega) = x_0 + 2 \\sum_{k=1}^n x_k \\cos(\\omega k)$$\n", "\n", "over the real vector $x\\in {\\bf R}^{n+1}$. However, the concepts in the example are readily applied to the case with $x\\in {\\bf C}^{n+1}$.\n", "\n", "References:\n", " 1. \"Squared Functional Systems and Optimization Problems\", Y. Nesterov, 2004.\n", " \n", " 2. \"Convex Optimization of Non-negative Polynomials: Structured Algorithms and Applications\", Ph.D thesis, Y. Hachez, 2003.\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import mosek\n", "from mosek.fusion import *\n", "from math import cos, pi\n", "import numpy as np\n", "import sys" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Nonnegativity everywhere ###\n", "\n", "Nesterov proved in [1] that $H(\\omega) \\geq 0, \\: \\forall \\omega$ if and only if \n", "$$x_i = \\langle T_i^{n+1}, X \\rangle, \\quad X \\in {\\mathcal H}^{n+1}_+,$$\n", "where ${\\mathcal H}_+$ is the cone of Hermitian semidefinite matrices and $T_i$ is a Toeplitz matrix\n", "$$[T_i]_{kl} = \\left \\{ \\begin{array}{ll}1, & k-l=i\\\\0 & \\text{otherwise}.\\end{array} \\right .$$\n", "For example, for $n=2$ we have\n", "$$\n", " T_0 = \\left[\\begin{array}{ccc}\n", " 1 & 0 & 0\\\\0 & 1 & 0\\\\0 & 0 & 1\n", " \\end{array}\n", " \\right], \\quad\n", " T_1 = \\left[\\begin{array}{ccc}\n", " 0 & 0 & 0\\\\1 & 0 & 0\\\\0 & 1 & 0\n", " \\end{array}\n", " \\right],\n", " \\quad\n", " T_2 = \\left[\\begin{array}{ccc}\n", " 0 & 0 & 0\\\\0 & 0 & 0\\\\1 & 0 & 0\n", " \\end{array}\n", " \\right].\n", "$$\n", "In our case we have $\\Im(x_i)=0$, i.e., $X\\in {\\mathcal S}^{n+1}_+$ is a real symmetric semidefinite matrix.\n", "\n", "We define the *cone on nonnegative trigonometric polynomials* as\n", "$$\n", " K^n_{0,\\pi} = \\{ x\\in \\mathbf{R} \\times \\mathbf{C}^n \\mid x_i = \\langle X, T_i\\rangle, \\: i=0,\\dots,n, \\: X\\in\\mathcal{H}_+^{n+1} \\}.\n", "$$" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "def T_dot_X(n, i, X, a=1.0):\n", " if i>=n or i<=-n: return Expr.constTerm(0.0)\n", " else: return Expr.dot(Matrix.diag(n, a, -i), X)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "def trigpoly_0_pi(M, x):\n", " '''x[i] == '''\n", " n = int(x.getSize()-1)\n", " X = M.variable(\"X\", Domain.inPSDCone(n+1))\n", " \n", " for i in range(n+1):\n", " M.constraint(Expr.sub(T_dot_X(n+1,i,X), x.index(i)), Domain.equalsTo(0.0))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Note that we have dropped the imaginary part of $X$." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Nonnegativity on $[0,a]$ ###\n", "\n", "Similarly, $H(\\omega)$ is nonnegative on $[0,a]$ if and only if\n", "\n", "$$x_i =\n", "\\langle X_1, T_i^{n+1} \\rangle + \n", "\\langle X_2, T_{i+1}^n \\rangle +\n", "\\langle X_2, T_{i-1}^n \\rangle -\n", "2 \\cos(a)\\langle X_2, T_{i}^n \\rangle, \\quad \n", "X_1 \\in {\\mathcal H}^{n+1}_+, \\:\n", "X_2 \\in {\\mathcal H}^n_+,\n", "$$\n", "or equivalently\n", "$$\n", " K^n_{0,a} = \\{ x\\in \\mathbf{R}\\times \\mathbf{C}^n \\mid\n", " x_i = \\langle X_1, T_i^{n+1} \\rangle +\n", " \\langle X_2 , T_{i+1}^n \\rangle +\n", " \\langle X_2 , T_{i-1}^n \\rangle -\n", " 2\\cos(a)\\langle X_2 , T_i^n\\rangle, \\: X_1\\in \\mathcal{H}_+^{n+1}, X_2\\in\\mathcal{H}_+^n \\}.\n", "$$" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "def trigpoly_0_a(M, x, a):\n", " '''x[i] == + + - 2*cos(a)*'''\n", " n = int(x.getSize()-1)\n", " X1 = M.variable(Domain.inPSDCone(n+1))\n", " X2 = M.variable(Domain.inPSDCone(n))\n", "\n", " for i in range(n+1):\n", " M.constraint(Expr.sub(Expr.add([ T_dot_X(n+1,i,X1), \n", " T_dot_X(n,i+1,X2), \n", " T_dot_X(n,i-1,X2), \n", " T_dot_X(n,i,X2,-2*cos(a))]),\n", " x.index(i)), Domain.equalsTo(0.0))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Note that we have dropped the imaginary part of $X_1$ and $X_2$." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Nonnegativity on $[a,\\pi]$ ###\n", "\n", "Finally, $H(\\omega)$ is nonnegative on $[a,\\pi]$ if and only if\n", "\n", "$$x_i = \n", "\\langle X_1, T_i^{n+1} \\rangle -\n", "\\langle X_2, T_{i+1}^n \\rangle -\n", "\\langle X_2, T_{i-1}^n \\rangle +\n", "2 \\cos(a)\\langle X_2, T_{i}^n \\rangle, \\quad \n", "X_1 \\in {\\mathcal S}^{n+1}_+, \\:\n", "X_2 \\in {\\mathcal S}^n_+,\n", "$$\n", "or equivalently\n", "$$\n", " K^n_{a,\\pi} = \\{ x\\in \\mathbf{R}\\times \\mathbf{C}^n \\mid\n", " x_i = \\langle X_1, T_i^{n+1} \\rangle -\n", " \\langle X_2 , T_{i+1}^n \\rangle -\n", " \\langle X_2 , T_{i-1}^n \\rangle +\n", " 2\\cos(a)\\langle X_2 , T_i^n\\rangle, \\: X_1\\in \\mathcal{H}_+^{n+1}, X_2\\in\\mathcal{H}_+^n \\}.\n", "$$" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "def trigpoly_a_pi(M, x, a):\n", " '''x[i] == - - + 2*cos(a)*'''\n", " n = int(x.getSize()-1)\n", " X1 = M.variable(Domain.inPSDCone(n+1))\n", " X2 = M.variable(Domain.inPSDCone(n))\n", "\n", " for i in range(n+1):\n", " M.constraint(Expr.add([ T_dot_X(n+1,i,X1), \n", " T_dot_X(n,i+1,X2,-1.0), \n", " T_dot_X(n,i-1,X2,-1.0), \n", " T_dot_X(n,i,X2,2*cos(a)),\n", " Expr.neg(x.index(i)) ]),\n", " Domain.equalsTo(0.0))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Note that we have dropped the imaginary part of $X_1$ and $X_2$." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## An epigraph formulation ##\n", "The *epigraph* $H(\\omega) \\leq t$ can now be characterized simply as \n", "$-u \\in K^n_{[a,b]}, \\: u=(x_0-t, \\, x_{1:n}).$" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "def epigraph(M, x, t, a, b):\n", " '''Models 0 <= H(w) <= t, for all w in [a, b], where\n", " H(w) = x0 + 2*x1*cos(w) + 2*x2*cos(2*w) + ... + 2*xn*cos(n*w)'''\n", " n = int(x.getSize()-1) \n", " u = M.variable(n+1, Domain.unbounded())\n", " M.constraint(Expr.sub(t,Expr.add(x.index(0), u.index(0))), Domain.equalsTo(0.0)) \n", " M.constraint(Expr.add(x.slice(1,n+1), u.slice(1,n+1)), Domain.equalsTo(0.0))\n", " \n", " if a==0.0 and b==pi:\n", " trigpoly_0_pi(M, u)\n", " elif a==0.0 and b= 0\n", "trigpoly_0_pi(M, x)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Passband specifications ###" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "wp = pi/4\n", "delta = 0.05\n", "\n", "# H(w) <= (1+delta), w in [0, wp] \n", "epigraph(M, x, 1.0+delta, 0.0, wp)\n", "\n", "# (1-delta) <= H(w), w in [0, wp]\n", "hypograph(M, x, 1.0-delta, 0.0, wp)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Stopband specifications ###" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "ws = wp + pi/8\n", "\n", "# H(w) < t, w in [ws, pi]\n", "t = M.variable(\"t\", 1, Domain.greaterThan(0.0))\n", "epigraph(M, x, t, ws, pi)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Setting the objective ###" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [], "source": [ "M.objective(ObjectiveSense.Minimize, t)" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "M.setLogHandler(sys.stdout)" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Problem\n", " Name : trigpoly \n", " Objective sense : min \n", " Type : CONIC (conic optimization problem)\n", " Constraints : 67 \n", " Cones : 0 \n", " Scalar variables : 35 \n", " Matrix variables : 7 \n", " Integer variables : 0 \n", "\n", "Optimizer started.\n", "Presolve started.\n", "Linear dependency checker started.\n", "Linear dependency checker terminated.\n", "Eliminator started.\n", "Freed constraints in eliminator : 23\n", "Eliminator terminated.\n", "Eliminator started.\n", "Freed constraints in eliminator : 0\n", "Eliminator terminated.\n", "Eliminator - tries : 2 time : 0.00 \n", "Lin. dep. - tries : 1 time : 0.00 \n", "Lin. dep. - number : 0 \n", "Presolve terminated. Time: 0.01 \n", "Problem\n", " Name : trigpoly \n", " Objective sense : min \n", " Type : CONIC (conic optimization problem)\n", " Constraints : 67 \n", " Cones : 0 \n", " Scalar variables : 35 \n", " Matrix variables : 7 \n", " Integer variables : 0 \n", "\n", "Optimizer - threads : 20 \n", "Optimizer - solved problem : the primal \n", "Optimizer - Constraints : 44\n", "Optimizer - Cones : 1\n", "Optimizer - Scalar variables : 13 conic : 12 \n", "Optimizer - Semi-definite variables: 7 scalarized : 429 \n", "Factor - setup time : 0.00 dense det. time : 0.00 \n", "Factor - ML order time : 0.00 GP order time : 0.00 \n", "Factor - nonzeros before factor : 990 after factor : 990 \n", "Factor - dense dim. : 0 flops : 1.18e+05 \n", "ITE PFEAS DFEAS GFEAS PRSTATUS POBJ DOBJ MU TIME \n", "0 1.9e+01 1.0e+00 1.0e+00 0.00e+00 0.000000000e+00 0.000000000e+00 1.0e+00 0.03 \n", "1 6.0e+00 3.2e-01 3.2e-01 1.56e+00 -6.168509433e-03 -1.704940542e-02 3.2e-01 0.04 \n", "2 1.5e+00 8.0e-02 8.0e-02 1.59e+00 -3.629686898e-02 -5.729238420e-02 8.0e-02 0.05 \n", "3 3.1e-01 1.7e-02 1.7e-02 1.64e+00 -4.704273187e-03 -7.156318767e-03 1.7e-02 0.05 \n", "4 1.0e-01 5.6e-03 5.6e-03 1.91e-01 1.247879338e-03 3.220303293e-03 5.6e-03 0.05 \n", "5 5.8e-02 3.1e-03 3.1e-03 4.28e-01 4.186115053e-02 3.996134158e-02 3.1e-03 0.05 \n", "6 1.1e-02 5.9e-04 5.9e-04 4.33e-01 6.583025991e-02 6.538915159e-02 5.9e-04 0.05 \n", "7 2.7e-03 1.4e-04 1.4e-04 9.75e-01 7.102893174e-02 7.092631673e-02 1.4e-04 0.05 \n", "8 4.6e-04 2.4e-05 2.4e-05 1.01e+00 7.246509927e-02 7.245345168e-02 2.4e-05 0.06 \n", "9 3.3e-05 1.8e-06 1.8e-06 1.00e+00 7.271267688e-02 7.271184530e-02 1.8e-06 0.06 \n", "10 3.6e-06 1.9e-07 1.9e-07 1.00e+00 7.272951727e-02 7.272942593e-02 1.9e-07 0.06 \n", "11 5.8e-07 3.1e-08 3.1e-08 1.00e+00 7.273126748e-02 7.273125303e-02 3.1e-08 0.06 \n", "12 7.0e-08 3.9e-09 3.7e-09 1.00e+00 7.273156244e-02 7.273156074e-02 3.7e-09 0.06 \n", "13 6.3e-09 1.9e-09 3.4e-10 1.00e+00 7.273159968e-02 7.273159953e-02 3.4e-10 0.07 \n", "Optimizer terminated. Time: 0.07 \n", "\n", "\n", "Interior-point solution summary\n", " Problem status : PRIMAL_AND_DUAL_FEASIBLE\n", " Solution status : OPTIMAL\n", " Primal. obj: 7.2731599679e-02 nrm: 1e+00 Viol. con: 6e-09 var: 0e+00 barvar: 0e+00 \n", " Dual. obj: 7.2731599528e-02 nrm: 2e+00 Viol. con: 0e+00 var: 3e-10 barvar: 2e-09 \n" ] } ], "source": [ "M.solve()" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([ 0.33580937, 0.25254317, 0.1388759 , 0.02044169, -0.04797007,\n", " -0.05156956, -0.01627207, 0.01837092, 0.02948826, 0.02271378,\n", " -0.00952669])" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x.level()" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([0.0727316])" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "t.level()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Plotting the amplitude response ###" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAD8CAYAAACMwORRAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvNQv5yAAAIABJREFUeJzt3XtUVXXeP/D3h4viBVETBW+hqKnk5cBJpAywNPGSZk1Ol3Gq1TxUs2wyny5TM9rU5DyreSpb489Kp8dsctSc+lWOqWC/sryiIHhPRfOClyDwgooinM/vD5AHEWQD+5y9zznv11qsdS5f9n7vTr7P5rvPPltUFURE5FsCrA5ARETmY7kTEfkgljsRkQ9iuRMR+SCWOxGRD2K5ExH5IJY7EZEPYrkTEfkgljsRkQ8KsmrFHTp00KioKKtWT0TklbKysn5W1fD6xllW7lFRUcjMzLRq9UREXklEDhsZx2kZIiIfxHInIvJBLHciIh/Ecici8kEsdyIiH8RyJyLyQSx3IiIfZNnn3Btr/fr1+Oabb3DjjTciKioKvXv3RmRkpNWx3Or48eNYsWIFAgMDER0djejoaHTu3BkiYnU0IrIpryv3DRs2YMaMGVc9dtttt2Hy5MmYNGkS2rVrZ1Eyc5WWluL999/H4sWLsWnTpmueT0xMxEcffQSe5UtEtfG6aZnnn38eJSUl2Lt3L9LS0jBz5kwUFRXhySefRGRkJF5++WUUFxdbHbNJcnJyMGTIEDzzzDO4dOkSXn/9dezcuRP79+9HWloa3njjDWRnZ2PgwIH48MMPwYucE9E1VNWSn7i4ODWLy+XSrKwsffjhhxWARkRE6Pz587W8vNy0dXhCWVmZvvLKKxoUFKQRERH6xRdf1Dn2xx9/1KSkJAWgTz75pAdTEpGVAGSqgY71iXKvbuPGjRofH68AdMyYMVpQUOCW9ZjtwoULe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Mjo2pK5aGHHtLjx4+btuytW7dqXFycAtBx48bp0aNHTVt2U5SXl+vbb7+tISEh2rp1a33rrbdMneZbvXq19urVSwHoww8/bIvjECx38gqXLl3SLl266LBhw0zfIywqKtKUlBQFoKmpqabPlW/fvr3qAOXTTz9t2Z/vpaWlOn36dA0MDNSuXbtqenq6W9Zz+fJlfeutt7Rly5batm1bXbRokVvWY9SBAweqjp3cfffdbjs2cOXNPCgoSCMjI3XFihVuWY9RLHfyGvPmzVMA+t5775m2zJ07d2p0dLQGBwfr3LlzTVtuTSUlJTp16tSqvwx27NjhtnXVZvfu3VV71L/+9a89chBw//79mpCQoAD0l7/8pcf3Zl0ul86dO1dbtWqlbdq00QULFnhkqigrK6vqIG1qaqpln6phuZPXcLlcOnLkSG3VqpUeOHCgycv797//raGhoRoREaEbNmwwIWH9VqxYoR07dtSQkBCdM2eO28vG5XLp7NmzNSQkRG+44Qb97LPP3Lq+mi5fvqwzZ87UoKAgjYiI8NjU1PHjx6sOFN9555165MgRj6z3iosXL+rzzz+vIqI9evTQ7777zqPrV2W5k5c5cuSItmnTRpOSkhp9IMzlcukbb7yhIqJxcXEenxc+efJkVfHcfffdps55V3fw4EEdOXKkAtDRo0e7bT1GbN26VQcMGKAA9LHHHtPTp0+7ZT0ul0sXLFig7du31xYtWujs2bObdMC0qdatW6fR0dEqIjp16tQmHbRuKJY7eZ358+c3+sSmwsJCnTBhQtVUwfnz592QsH4ul0vfeecdDQkJ0bZt2+oHH3xg2l58WVmZvv3229qyZUtt3bq1vvvuu7b45MrFixf1pZde0oCAAI2IiNCFCxeammvfvn16xx13KABNSEjQH374wbRlN8W5c+f0t7/9rQLQbt266eeff+6R18PUcgeQAmAvgFwAv6/l+eYAPql8PgNAVH3LZLlTTS6XS8eNG6dBQUENmidfv369duvWTYODg3XWrFm2KLx9+/ZpUlKSAtDk5OQmfUrH5XLpypUr1eFwKAAdO3asx6cjjNi8ebM6nU4FoImJibp169YmLS8/P1+fe+45bd68uYaFhel7771n6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2pqpnr/zJrRVXHAsWkQ4Wx7qKiASjohj/qar/t5Yhtn4d6svvDa/BFap6GsAaACk1nrJdF9m53L39wtz15q8xLzoeFfOR3mQZgF9XflpjKIAzqnrC6lANISIRV+ZGRWQIKv5NFFqb6n9VZvsfAHtU9e06htn2dTCS3wteg3ARaVt5uwWAEQB+qDHMdl1k6BqqVlAvvzC3wfy/E5HxAMpQkf9RywLXQkQWo+KTDB1EJA/AK6g4mARVfR8V19UdAyAXwAUAj1mTtG4GtuEXAJ4SkTIAJQAesPofZQ23AZgMYEflnC8AvAygO+AVr4OR/HZ/DSIBfCQigah441mqqsvt3kU8Q5WIyAfZeVqGiIgaieVOROSDWO5ERD6I5U5E5INY7kREPojlTkTkg1juREQ+iOVOROSD/j975Qt3AUQKeQAAAABJRU5ErkJggg==\n", "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "xx = x.level()\n", "def H(w): return xx[0] + 2*sum([xx[i]*cos(i*w) for i in range(1,len(xx))])\n", "w = np.linspace(0, pi, 100)\n", "%matplotlib inline\n", "import matplotlib.pyplot as plt\n", "plt.plot(w, [H(wi) for wi in w], 'k')\n", "plt.show()\n" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "
This work is licensed under a Creative Commons Attribution 4.0 International License. The **MOSEK** logo and name are trademarks of Mosek ApS. The code is provided as-is. Compatibility with future release of **MOSEK** or the Fusion API are not guaranteed. For more information contact our [support](mailto:support@mosek.com). \n", "\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "anaconda-cloud": {}, "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.4" } }, "nbformat": 4, "nbformat_minor": 1 }