{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "ee453d40",
   "metadata": {},
   "outputs": [],
   "source": [
    "import sys, os\n",
    "sys.path.append(os.path.abspath(\"..\"))\n",
    "\n",
    "from datasets.datasets import SyntheticFACE, SyntheticFACE2, SyntheticMoons, Dataset, CaliforniaHousing, GermanCredit, GermanCreditv2, GiveMeSomeCredit, AdultIncome\n",
    "from visualisation import *\n",
    "\n",
    "from models.mlp_pytorch import PyTorchMLP\n",
    "\n",
    "from conformal.split_conformal import SplitConformalPrediction\n",
    "from conformal.localised_conformal_baselcp import BaseLCP\n",
    "from conformal.localised_conformal_tree import ConformalCONFEXTree\n",
    "\n",
    "from counterfactual_explanations.counterfactual_benchmarker import *\n",
    "from counterfactual_explanations.gradient_based.auxillary_models import *\n",
    "from counterfactual_explanations.gradient_based.cf_gradient_based import *\n",
    "from counterfactual_explanations.gradient_based.losses import *\n",
    "\n",
    "from counterfactual_explanations.milp_based.cf_conformal import *\n",
    "from counterfactual_explanations.milp_based.cf_mindist import *"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "f1292775",
   "metadata": {},
   "outputs": [],
   "source": [
    "%load_ext autoreload\n",
    "%autoreload 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "00a647ab",
   "metadata": {},
   "outputs": [],
   "source": [
    "Dataset = SyntheticFACE2\n",
    "factual = np.array([1, 2.5])\n",
    "y_target = 1 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "134cef74",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Axes: >"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 180020 characters]",
      "text/plain": [
       "<Figure size 640x480 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "dataset = Dataset(0.6, 0.2, 0.2)\n",
    "X_train, y_train, X_calib, y_calib, X_test, y_test = dataset.get_X_y_split()\n",
    "plot_split_dataset(X_train, X_test, y_train, y_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "a86e8297",
   "metadata": {},
   "outputs": [],
   "source": [
    "model = PyTorchMLP(config={}, input_properties=dataset.input_properties)\n",
    "model.load_or_train(Path(\"facedata2\"), X_train, y_train, True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "3b99e94f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Axes: >"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 119080 characters]",
      "text/plain": [
       "<Figure size 640x480 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plot_decision_boundary(model, X_calib, X_calib, y_calib, y_calib)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "b10fc3b8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Set parameter TimeLimit to value 60\n",
      "Gurobi Optimizer version 11.0.3 build v11.0.3rc0 (mac64[arm] - Darwin 23.6.0 23G80)\n",
      "\n",
      "CPU model: Apple M3 Pro\n",
      "Thread count: 12 physical cores, 12 logical processors, using up to 12 threads\n",
      "\n",
      "Academic license 2688232 - for non-commercial use only - registered to am___@kcl.ac.uk\n",
      "Optimize a model with 59 rows, 108 columns and 266 nonzeros\n",
      "Model fingerprint: 0x803cde87\n",
      "Model has 50 general constraints\n",
      "Variable types: 108 continuous, 0 integer (0 binary)\n",
      "Coefficient statistics:\n",
      "  Matrix range     [1e-03, 4e+00]\n",
      "  Objective range  [1e+00, 1e+00]\n",
      "  Bounds range     [0e+00, 0e+00]\n",
      "  RHS range        [5e-02, 3e+00]\n",
      "Presolve added 46 rows and 96 columns\n",
      "Presolve time: 0.00s\n",
      "Presolved: 105 rows, 204 columns, 358 nonzeros\n",
      "Presolved model has 100 SOS constraint(s)\n",
      "Variable types: 104 continuous, 100 integer (100 binary)\n",
      "\n",
      "Root relaxation: objective 0.000000e+00, 80 iterations, 0.00 seconds (0.00 work units)\n",
      "\n",
      "    Nodes    |    Current Node    |     Objective Bounds      |     Work\n",
      " Expl Unexpl |  Obj  Depth IntInf | Incumbent    BestBd   Gap | It/Node Time\n",
      "\n",
      "     0     0    0.00000    0   24          -    0.00000      -     -    0s\n",
      "     0     0    0.00000    0   24          -    0.00000      -     -    0s\n",
      "     0     2    0.00000    0   24          -    0.00000      -     -    0s\n",
      "*  511   152              24       2.1376185    0.00000   100%   2.9    0s\n",
      "*  512   152              24       2.0822954    0.00000   100%   2.9    0s\n",
      "*  545   152              25       2.0756120    0.00000   100%   2.9    0s\n",
      "H  606   152                       1.8466539    0.00000   100%   2.7    0s\n",
      "H  944   171                       0.8727687    0.03511  96.0%   2.1    0s\n",
      "\n",
      "Explored 1437 nodes (2323 simplex iterations) in 0.04 seconds (0.02 work units)\n",
      "Thread count was 12 (of 12 available processors)\n",
      "\n",
      "Solution count 5: 0.872769 1.84665 2.07561 ... 2.13762\n",
      "\n",
      "Optimal solution found (tolerance 1.00e-04)\n",
      "Best objective 8.727686699393e-01, best bound 8.727686699393e-01, gap 0.0000%\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<Axes: >"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 121800 characters]",
      "text/plain": [
       "<Figure size 640x480 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#Min distance CF\n",
    "cf_gen = MinDistanceCF(model, dataset.input_properties, config={\"db_distance\":0.05})\n",
    "counterfactual = cf_gen.generate_counterfactual(factual, y_target)\n",
    "plot_counterfactual(factual, counterfactual, model, X_calib, X_calib, y_calib, y_calib, faded_background=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "c9589805",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Gurobi Optimizer version 11.0.3 build v11.0.3rc0 (mac64[arm] - Darwin 23.6.0 23G80)\n",
      "\n",
      "CPU model: Apple M3 Pro\n",
      "Thread count: 12 physical cores, 12 logical processors, using up to 12 threads\n",
      "\n",
      "Academic license 2688232 - for non-commercial use only - registered to am___@kcl.ac.uk\n",
      "Optimize a model with 62 rows, 110 columns and 272 nonzeros\n",
      "Model fingerprint: 0x99b48b88\n",
      "Model has 50 general constraints\n",
      "Variable types: 110 continuous, 0 integer (0 binary)\n",
      "Coefficient statistics:\n",
      "  Matrix range     [1e-03, 4e+00]\n",
      "  Objective range  [1e+00, 1e+00]\n",
      "  Bounds range     [0e+00, 0e+00]\n",
      "  RHS range        [5e-02, 3e+00]\n",
      "Presolve added 43 rows and 94 columns\n",
      "Presolve time: 0.00s\n",
      "Presolved: 105 rows, 204 columns, 358 nonzeros\n",
      "Presolved model has 100 SOS constraint(s)\n",
      "Variable types: 104 continuous, 100 integer (100 binary)\n",
      "\n",
      "Root relaxation: objective 0.000000e+00, 80 iterations, 0.00 seconds (0.00 work units)\n",
      "\n",
      "    Nodes    |    Current Node    |     Objective Bounds      |     Work\n",
      " Expl Unexpl |  Obj  Depth IntInf | Incumbent    BestBd   Gap | It/Node Time\n",
      "\n",
      "     0     0    0.00000    0   24          -    0.00000      -     -    0s\n",
      "     0     0    0.00000    0   24          -    0.00000      -     -    0s\n",
      "     0     2    0.00000    0   24          -    0.00000      -     -    0s\n",
      "*  511   150              24       2.1376185    0.00000   100%   2.9    0s\n",
      "*  512   150              24       2.0822954    0.00000   100%   2.9    0s\n",
      "*  545   150              25       2.0756120    0.00000   100%   2.9    0s\n",
      "H  606   144                       1.9289348    0.00000   100%   2.7    0s\n",
      "H  997   184                       1.2143717    0.00000   100%   2.0    0s\n",
      "H 1067   200                       1.1342836    0.00000   100%   1.9    0s\n",
      "* 1136   200              36       0.9800385    0.00000   100%   1.9    0s\n",
      "\n",
      "Explored 1741 nodes (2544 simplex iterations) in 0.03 seconds (0.03 work units)\n",
      "Thread count was 12 (of 12 available processors)\n",
      "\n",
      "Solution count 7: 0.980038 1.13428 1.21437 ... 2.13762\n",
      "\n",
      "Optimal solution found (tolerance 1.00e-04)\n",
      "Best objective 9.800384852301e-01, best bound 9.800384852301e-01, gap 0.0000%\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<Axes: >"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 114792 characters]",
      "text/plain": [
       "<Figure size 640x480 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "conformalCF = ConformalCF(model, dataset.input_properties, config={\"conformal_class\": SplitConformalPrediction, \"conformal_config\": {\"alpha\": 0.03}})\n",
    "conformalCF.setup(X_train, y_train, X_calib, y_calib)\n",
    "counterfactual_conformal = conformalCF.generate_counterfactual(factual, y_target)\n",
    "plot_counterfactual(factual, counterfactual_conformal, model, X_calib, X_calib, y_calib, y_calib, conformal=conformalCF.conformal)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "20a1b6f1",
   "metadata": {},
   "outputs": [],
   "source": [
    "ccf = {\"alpha\": 0.03,\n",
    "        \"scorefn_name\":'linear',\n",
    "        \"kernel_name\":'box_l1', \n",
    "        \"kernel_bandwidth\": 0.35}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "f8b814f3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Axes: >"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 115636 characters]",
      "text/plain": [
       "<Figure size 640x480 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "conformal_cfxt = BaseLCP(model, dataset.input_properties, ccf)\n",
    "conformal_cfxt.calibrate(X_calib, y_calib, None)\n",
    "plot_conformal_prediction(model, conformal_cfxt, X_calib, X_calib, y_calib, y_calib)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "44cec580",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Gurobi Optimizer version 11.0.3 build v11.0.3rc0 (mac64[arm] - Darwin 23.6.0 23G80)\n",
      "\n",
      "CPU model: Apple M3 Pro\n",
      "Thread count: 12 physical cores, 12 logical processors, using up to 12 threads\n",
      "\n",
      "Academic license 2688232 - for non-commercial use only - registered to am___@kcl.ac.uk\n",
      "Optimize a model with 3657 rows, 4065 columns and 8897 nonzeros\n",
      "Model fingerprint: 0x48a27308\n",
      "Model has 1 quadratic constraint\n",
      "Model has 410 general constraints\n",
      "Variable types: 3346 continuous, 719 integer (719 binary)\n",
      "Coefficient statistics:\n",
      "  Matrix range     [1e-03, 1e+03]\n",
      "  QMatrix range    [1e+00, 1e+00]\n",
      "  QLMatrix range   [1e+00, 1e+00]\n",
      "  Objective range  [1e+00, 1e+00]\n",
      "  Bounds range     [1e+00, 1e+00]\n",
      "  RHS range        [1e-06, 1e+03]\n",
      "Presolve removed 442 rows and 854 columns\n",
      "Presolve time: 0.32s\n",
      "Presolved: 3215 rows, 3211 columns, 16595 nonzeros\n",
      "Presolved model has 718 SOS constraint(s)\n",
      "Variable types: 2261 continuous, 950 integer (769 binary)\n",
      "\n",
      "Root relaxation: objective 0.000000e+00, 904 iterations, 0.01 seconds (0.04 work units)\n",
      "\n",
      "    Nodes    |    Current Node    |     Objective Bounds      |     Work\n",
      " Expl Unexpl |  Obj  Depth IntInf | Incumbent    BestBd   Gap | It/Node Time\n",
      "\n",
      "     0     0    0.00000    0   34          -    0.00000      -     -    0s\n",
      "     0     0    0.00000    0   33          -    0.00000      -     -    0s\n",
      "     0     0    0.00000    0   33          -    0.00000      -     -    0s\n",
      "     0     0    0.00000    0   33          -    0.00000      -     -    0s\n",
      "     0     0    0.00000    0   33          -    0.00000      -     -    0s\n",
      "     0     0    0.00000    0   33          -    0.00000      -     -    0s\n",
      "     0     2    0.00000    0   33          -    0.00000      -     -    0s\n",
      "H  218   162                     162.8922762    0.00000   100%  27.8    1s\n",
      "H  259   167                      40.3870830    0.00000   100%  25.2    1s\n",
      "H  313   189                      38.4549697    0.00000   100%  22.6    1s\n",
      "H  396   202                      38.1922280    0.00000   100%  19.3    1s\n",
      "H  405   202                      35.9518890    0.00000   100%  18.9    1s\n",
      "H  600   238                      35.8237925    0.00000   100%  15.3    1s\n",
      "*  615   288              42       3.1503170    0.00000   100%  15.1    1s\n",
      "H 1745   793                       3.0718026    0.00000   100%   7.4    1s\n",
      "H 2811  1089                       3.0711479    0.25668  91.6%   6.4    1s\n",
      "  3631  1374    1.03360   31   15    3.07115    0.25668  91.6%   5.7    5s\n",
      "H 3679  1309                       3.0069934    0.25668  91.5%   6.6    5s\n",
      "* 3846  1241              32       2.9721611    0.25668  91.4%   7.2    5s\n",
      "* 3875  1161              30       2.9536934    0.25668  91.3%   7.3    5s\n",
      "* 3901  1095              40       2.9173744    0.25668  91.2%   7.4    5s\n",
      "H 4017  1033                       2.6078873    0.31168  88.0%   7.5    5s\n",
      "H 4038   977                       2.5966218    0.31168  88.0%   7.5    5s\n",
      "* 6072   684              52       2.5312955    0.93442  63.1%   6.2    6s\n",
      "H 6771   423                       2.5242250    1.14958  54.5%   5.9    6s\n",
      "H 6772   423                       2.4507788    1.14958  53.1%   5.9    6s\n",
      "H 7699   295                       2.4491281    1.38716  43.4%   5.8    7s\n",
      "* 7892   324              38       2.1630933    1.58972  26.5%   5.9    7s\n",
      "* 8037   324              38       2.1218614    1.58972  25.1%   5.9    7s\n",
      "\n",
      "Explored 9745 nodes (55996 simplex iterations) in 9.21 seconds (18.64 work units)\n",
      "Thread count was 12 (of 12 available processors)\n",
      "\n",
      "Solution count 10: 2.12186 2.16309 2.44913 ... 2.95369\n",
      "\n",
      "Optimal solution found (tolerance 1.00e-04)\n",
      "Best objective 2.121861432226e+00, best bound 2.121861432226e+00, gap 0.0000%\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<Axes: >"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 118996 characters]",
      "text/plain": [
       "<Figure size 640x480 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "conformalCF_b = ConformalCF(model, dataset.input_properties, config={\"conformal_class\": BaseLCP, \"conformal_config\": ccf})\n",
    "conformalCF_b.setup(X_train, y_train, X_calib, y_calib)\n",
    "counterfactual_conformal_b = conformalCF_b.generate_counterfactual(factual, y_target)\n",
    "plot_counterfactual(factual, counterfactual_conformal_b, model, X_calib, X_calib, y_calib, y_calib, conformal=conformalCF_b.conformal)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 181,
   "id": "d1c7205c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "np.float64(0.0)"
      ]
     },
     "execution_count": 181,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "conformal_cfxt.global_quantile"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "07c59fd4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Axes: >"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 113228 characters]",
      "text/plain": [
       "<Figure size 640x480 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "ccf2 = {\"alpha\": 0.05,\n",
    "        \"scorefn_name\":'linear2',\n",
    "        \"kernel_name\":'box_l1', \n",
    "        \"kernel_bandwidth\": 0.3,\n",
    "        \"inf_quantile\": False,\n",
    "        \"global_quantile\": False,\n",
    "        \"split_midpoint\": True,\n",
    "        }\n",
    "\n",
    "conformal_cfxt = ConformalCONFEXTree(model, dataset.input_properties, ccf2)\n",
    "conformal_cfxt.calibrate(X_calib, y_calib, None)\n",
    "plot_conformal_prediction(model, conformal_cfxt, X_calib, X_calib, y_calib, y_calib)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "b5ea4656",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Axes: >"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 122512 characters]",
      "text/plain": [
       "<Figure size 640x480 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "schut = WachterGenerator(model, dataset.input_properties, config={\"mad\": True})\n",
    "schut.setup(X_train, y_train, X_calib, y_calib)\n",
    "cfschut = schut.generate_counterfactual(factual, y_target)\n",
    "plot_counterfactual(factual, cfschut, model, X_calib, X_calib, y_calib, y_calib)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "id": "f0e05f2d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Gurobi Optimizer version 11.0.3 build v11.0.3rc0 (mac64[arm] - Darwin 23.6.0 23G80)\n",
      "\n",
      "CPU model: Apple M3 Pro\n",
      "Thread count: 12 physical cores, 12 logical processors, using up to 12 threads\n",
      "\n",
      "Academic license 2688232 - for non-commercial use only - registered to am___@kcl.ac.uk\n",
      "Optimize a model with 72 rows, 189 columns and 544 nonzeros\n",
      "Model fingerprint: 0x5f27bbfa\n",
      "Model has 3 quadratic constraints\n",
      "Model has 338 general constraints\n",
      "Variable types: 124 continuous, 65 integer (65 binary)\n",
      "Coefficient statistics:\n",
      "  Matrix range     [1e-03, 1e+02]\n",
      "  QMatrix range    [1e+00, 1e+00]\n",
      "  QLMatrix range   [1e+00, 1e+00]\n",
      "  Objective range  [1e+00, 1e+00]\n",
      "  Bounds range     [1e+00, 1e+00]\n",
      "  RHS range        [1e-06, 3e+00]\n",
      "  GenCon rhs range [3e-03, 9e+00]\n",
      "  GenCon coe range [1e+00, 1e+00]\n",
      "Presolve added 148 rows and 82 columns\n",
      "Presolve time: 0.02s\n",
      "Presolved: 220 rows, 271 columns, 1936 nonzeros\n",
      "Presolved model has 56 SOS constraint(s)\n",
      "Variable types: 165 continuous, 106 integer (106 binary)\n",
      "Found heuristic solution: objective 5.3990611\n",
      "\n",
      "Root relaxation: objective 0.000000e+00, 66 iterations, 0.00 seconds (0.00 work units)\n",
      "\n",
      "    Nodes    |    Current Node    |     Objective Bounds      |     Work\n",
      " Expl Unexpl |  Obj  Depth IntInf | Incumbent    BestBd   Gap | It/Node Time\n",
      "\n",
      "     0     0    0.00000    0    3    5.39906    0.00000   100%     -    0s\n",
      "H    0     0                       4.7601883    0.00000   100%     -    0s\n",
      "H    0     0                       2.9278669    0.00000   100%     -    0s\n",
      "H    0     0                       2.6165951    0.00000   100%     -    0s\n",
      "     0     0    0.00000    0    2    2.61660    0.00000   100%     -    0s\n",
      "     0     0    0.00000    0    2    2.61660    0.00000   100%     -    0s\n",
      "     0     0    0.00000    0    3    2.61660    0.00000   100%     -    0s\n",
      "     0     0    0.10418    0    3    2.61660    0.10418  96.0%     -    0s\n",
      "     0     0    0.17445    0    4    2.61660    0.17445  93.3%     -    0s\n",
      "     0     0    0.17445    0    7    2.61660    0.17445  93.3%     -    0s\n",
      "     0     0    0.59002    0   26    2.61660    0.59002  77.5%     -    0s\n",
      "     0     0    0.59002    0   26    2.61660    0.59002  77.5%     -    0s\n",
      "H    0     0                       2.5758761    0.68348  73.5%     -    0s\n",
      "     0     0    0.68348    0   22    2.57588    0.68348  73.5%     -    0s\n",
      "H    0     0                       1.8172170    0.74708  58.9%     -    0s\n",
      "     0     0    0.87586    0   22    1.81722    0.87586  51.8%     -    0s\n",
      "     0     0    1.17517    0   18    1.81722    1.17517  35.3%     -    0s\n",
      "     0     0    1.32786    0   18    1.81722    1.32786  26.9%     -    0s\n",
      "     0     0    1.34901    0   18    1.81722    1.34901  25.8%     -    0s\n",
      "\n",
      "Cutting planes:\n",
      "  Gomory: 8\n",
      "  Cover: 12\n",
      "  Implied bound: 14\n",
      "  Clique: 1\n",
      "  MIR: 22\n",
      "  Flow cover: 18\n",
      "  GUB cover: 2\n",
      "  Relax-and-lift: 22\n",
      "\n",
      "Explored 1 nodes (364 simplex iterations) in 0.11 seconds (0.11 work units)\n",
      "Thread count was 12 (of 12 available processors)\n",
      "\n",
      "Solution count 6: 1.81722 2.57588 2.6166 ... 5.39906\n",
      "\n",
      "Optimal solution found (tolerance 1.00e-04)\n",
      "Best objective 1.817216981632e+00, best bound 1.817216981632e+00, gap 0.0000%\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<Axes: >"
      ]
     },
     "execution_count": 89,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 117424 characters]",
      "text/plain": [
       "<Figure size 640x480 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "conformalCF_c = ConformalCF(model, dataset.input_properties, config={\"conformal_class\": ConformalCONFEXTree, \"conformal_config\": ccf2})\n",
    "conformalCF_c.setup(X_train, y_train, X_calib, y_calib)\n",
    "counterfactual_conformal_c = conformalCF_c.generate_counterfactual(factual, y_target)\n",
    "plot_counterfactual(factual, counterfactual_conformal_c, model, X_calib, X_calib, y_calib, y_calib, conformal=conformalCF_c.conformal)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "confexplus",
   "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.10.15"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
