{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Verify that geocert works when accessed from lipMIP\n",
    "import torch \n",
    "import numpy as np \n",
    "import sys \n",
    "sys.path.append('..')\n",
    "sys.path.append('../geometric-certificates')\n",
    "import geocert_port as gp \n",
    "from hyperbox import Hyperbox\n",
    "from relu_nets import ReLUNet"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[3, 10, 10, 2]\n",
      "X tensor([0.4000, 0.5000, 0.8000])\n",
      "Academic license - for non-commercial use only\n"
     ]
    }
   ],
   "source": [
    "# Simple hyperbox test \n",
    "\n",
    "center = np.array([0.4, 0.5, 0.8])\n",
    "radius = 1.0 \n",
    "lo = np.zeros(3)\n",
    "\n",
    "hbox = Hyperbox.build_linf_ball(center, radius, global_lo=lo)\n",
    "simple_relunet = ReLUNet(layer_sizes=[3, 10, 10, 2])\n",
    "return_obj = gp.geocert_max_lipschitz(simple_relunet, hbox, 'l_inf', torch.tensor([1.0, -1.0]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'return_obj': GeoCert Return Object\n",
       " \tProblem Type: count_regions\n",
       " \tStatus: SUCCESS\n",
       " \tRadius 1.00\n",
       " \tNum Linear Regions: 186,\n",
       " 'linreg_coll': <geometric_certificates.plnn.LinearRegionCollection at 0x7f4495a46588>,\n",
       " 'max_lipschitz': 0.2467321753501892}"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "return_obj"
   ]
  },
  {
   "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.6.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
