{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import sys\n",
    "sys.path.append('..')\n",
    "from hyperbox import Hyperbox, BooleanHyperbox\n",
    "from interval_analysis import HBoxIA\n",
    "from relu_nets import ReLUNet\n",
    "from pre_activation_bounds import PreactivationBounds\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_net = ReLUNet(layer_sizes=[3, 4, 5, 6, 7, 8, 9, 10, 6])\n",
    "cube = Hyperbox.build_unit_hypercube(3)\n",
    "c_vector = np.ones(6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[-1.85551103e-04,  7.96394981e-04],\n",
       "       [-1.79808535e-05,  2.16115738e-03],\n",
       "       [-1.39372487e-03,  3.86018544e-04]])"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pab = PreactivationBounds.naive_ia(test_net, cube)\n",
    "pab.backprop_bounds(c_vector)\n",
    "\n",
    "pab.get_ith_layer_backprop_bounds(0, True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "ia_obj = HBoxIA(test_net, cube, c_vector)\n",
    "ia_obj.compute_forward()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "ia_obj.compute_backward()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[-1.8555124e-04,  7.9639512e-04],\n",
       "       [-1.7980929e-05,  2.1611578e-03],\n",
       "       [-1.3937252e-03,  3.8601866e-04]], dtype=float32)"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ia_obj.gradient_range.as_twocol()"
   ]
  },
  {
   "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.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
