Skip to content

Commit

Permalink
chore: update nbs on 0.3.x
Browse files Browse the repository at this point in the history
* chore: update nbs and minor fix comparison nb
  • Loading branch information
andrei-stoian-zama authored Sep 5, 2022
1 parent e2d43a3 commit 393510e
Show file tree
Hide file tree
Showing 16 changed files with 698 additions and 435 deletions.
70 changes: 51 additions & 19 deletions docs/advanced_examples/ClassifierComparison.ipynb

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions docs/advanced_examples/ClientServer.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@
"name": "stdout",
"output_type": "stream",
"text": [
"total 28K\n",
"-rw-r--r-- 1 dev_user dev_user 453 Jun 21 09:16 client.zip\n",
"-rw-r--r-- 1 dev_user dev_user 5.2K Jun 21 09:16 serialized_processing.json\n",
"-rw-r--r-- 1 dev_user dev_user 13K Jun 21 09:16 server.zip\n"
"total 60K\r\n",
"-rw-r--r-- 1 dev_user dev_user 464 Sep 2 00:09 client.zip\r\n",
"-rw-r--r-- 1 dev_user dev_user 43K Sep 2 00:09 serialized_processing.json\r\n",
"-rw-r--r-- 1 dev_user dev_user 8.4K Sep 2 00:09 server.zip\r\n"
]
}
],
Expand Down Expand Up @@ -171,8 +171,8 @@
"name": "stdout",
"output_type": "stream",
"text": [
"total 16K\n",
"-rw-r--r-- 1 dev_user dev_user 13K Jun 21 09:16 server.zip\n"
"total 12K\r\n",
"-rw-r--r-- 1 dev_user dev_user 8.4K Sep 2 00:09 server.zip\r\n"
]
}
],
Expand All @@ -191,9 +191,9 @@
"name": "stdout",
"output_type": "stream",
"text": [
"total 12K\n",
"-rw-r--r-- 1 dev_user dev_user 453 Jun 21 09:16 client.zip\n",
"-rw-r--r-- 1 dev_user dev_user 5.2K Jun 21 09:16 serialized_processing.json\n"
"total 48K\r\n",
"-rw-r--r-- 1 dev_user dev_user 464 Sep 2 00:09 client.zip\r\n",
"-rw-r--r-- 1 dev_user dev_user 43K Sep 2 00:09 serialized_processing.json\r\n"
]
}
],
Expand All @@ -219,7 +219,7 @@
"name": "stderr",
"output_type": "stream",
"text": [
"KeySetCache: miss, regenerating /tmp/tmp61r9hui6/7071120041192343400/0_0\n"
"KeySetCache: miss, regenerating /tmp/tmpmomc9x1m/7071120041192343400/0_0\n"
]
}
],
Expand Down
131 changes: 16 additions & 115 deletions docs/advanced_examples/ConvolutionalNeuralNetwork.ipynb

Large diffs are not rendered by default.

108 changes: 90 additions & 18 deletions docs/advanced_examples/DecisionTreeClassifier.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,18 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Best hyper parameters: {'max_depth': None, 'max_features': None, 'min_samples_leaf': 10, 'min_samples_split': 100}\n",
"Best score: 0.9300712036006302\n"
]
}
],
"source": [
"# Find best hyper parameters with cross validation\n",
"from sklearn.model_selection import GridSearchCV\n",
Expand Down Expand Up @@ -107,7 +116,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -116,9 +125,18 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Sklearn average precision score: 0.95\n",
"Concrete average precision score: 0.97\n"
]
}
],
"source": [
"# Compute average precision on test\n",
"from sklearn.metrics import average_precision_score\n",
Expand All @@ -140,9 +158,22 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Number of test samples: 691\n",
"Number of spams in test samples: 304\n",
"True Negative (legit mail well classified) rate: 0.9612403100775194\n",
"False Positive (legit mail classified as spam) rate: 0.03875968992248062\n",
"False Negative (spam mail classified as legit) rate: 0.14473684210526316\n",
"True Positive (spam well classified) rate: 0.8552631578947368\n"
]
}
],
"source": [
"# Show the confusion matrix on x_test\n",
"from sklearn.metrics import confusion_matrix\n",
Expand Down Expand Up @@ -173,7 +204,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -190,18 +221,34 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Generating a key for an 6-bit circuit\n"
]
}
],
"source": [
"print(f\"Generating a key for an {circuit.graph.maximum_integer_bit_width()}-bit circuit\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Key generation time: 253.61 seconds\n"
]
}
],
"source": [
"time_begin = time.time()\n",
"circuit.client.keygen(force=False)\n",
Expand All @@ -210,9 +257,17 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 9,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Execution time: 0.08 seconds per sample\n"
]
}
],
"source": [
"# Predict in FHE for a few examples\n",
"time_begin = time.time()\n",
Expand All @@ -222,9 +277,18 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 10,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Prediction FHE: [0 0 0 1 0 1 0 0 0 0]\n",
"Prediction sklearn: [0 0 0 1 0 1 0 0 0 0]\n"
]
}
],
"source": [
"# Check prediction FHE vs sklearn\n",
"print(f\"Prediction FHE: {y_pred_fhe}\")\n",
Expand All @@ -233,9 +297,17 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 11,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"10/10 predictions are similar between the FHE model and the clear sklearn model.\n"
]
}
],
"source": [
"print(\n",
" f\"{numpy.sum(y_pred_fhe==y_pred[:10])}/\"\n",
Expand Down
83 changes: 72 additions & 11 deletions docs/advanced_examples/FullyConnectedNeuralNetwork.ipynb

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions docs/advanced_examples/GLMComparison.ipynb

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions docs/advanced_examples/KaggleTitanic.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Best hyperparameters found in 2.10s : {'learning_rate': 1, 'max_depth': 4, 'n_estimators': 4}\n"
"Best hyperparameters found in 6.97s : {'learning_rate': 1, 'max_depth': 4, 'n_estimators': 4}\n"
]
}
],
Expand Down Expand Up @@ -629,7 +629,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Best hyperparameters found in 50.34s : {'learning_rate': 0.1, 'max_depth': 4, 'n_bits': 2, 'n_estimators': 4}\n"
"Best hyperparameters found in 77.28s : {'learning_rate': 0.1, 'max_depth': 4, 'n_bits': 2, 'n_estimators': 4}\n"
]
}
],
Expand Down Expand Up @@ -674,16 +674,16 @@
"name": "stderr",
"output_type": "stream",
"text": [
"100%|█████████████████████████████████████████████████████████████████████████████████████████████| 418/418 [17:00<00:00, 2.44s/it]"
"100%|████████████████████████████████████████████████████████████████████████| 418/418 [14:31<00:00, 2.08s/it]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Key generation time: 20.20s\n",
"Total execution time for 418 inferences: 1020.74s\n",
"Execution time per inference in FHE: 2.44s\n"
"Key generation time: 53.37s\n",
"Total execution time for 418 inferences: 871.32s\n",
"Execution time per inference in FHE: 2.08s\n"
]
},
{
Expand Down
79 changes: 50 additions & 29 deletions docs/advanced_examples/LinearRegression.ipynb

Large diffs are not rendered by default.

58 changes: 48 additions & 10 deletions docs/advanced_examples/LogisticRegression.ipynb

Large diffs are not rendered by default.

40 changes: 20 additions & 20 deletions docs/advanced_examples/PoissonRegression.ipynb

Large diffs are not rendered by default.

69 changes: 31 additions & 38 deletions docs/advanced_examples/QuantizationAwareTraining.ipynb

Large diffs are not rendered by default.

Loading

0 comments on commit 393510e

Please sign in to comment.