Skip to content

Commit

Permalink
Update demo.ipynb
Browse files Browse the repository at this point in the history
  • Loading branch information
Peiyuan Liao committed Aug 27, 2021
1 parent 2305b3c commit 1ad147c
Showing 1 changed file with 100 additions and 30 deletions.
130 changes: 100 additions & 30 deletions eth/demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -300,27 +300,14 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 17,
"id": "c557151e",
"metadata": {},
"outputs": [
{
"ename": "AttributeError",
"evalue": "'numpy.ndarray' object has no attribute 'values'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-16-e37d10770547>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0mW\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mlr\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcoef_\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mreshape\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0mb\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mlr\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mintercept_\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mreshape\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0mX\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mX\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvalues\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 4\u001b[0m \u001b[0mYt_expected\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mY\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvalues\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mreshape\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mAttributeError\u001b[0m: 'numpy.ndarray' object has no attribute 'values'"
]
}
],
"outputs": [],
"source": [
"W = lr.coef_.reshape(-1, 1)\n",
"b = lr.intercept_.reshape(-1, 1)\n",
"X = X.values[:]\n",
"Yt_expected = Y.values[:].reshape(-1, 1)\n",
"Yt_expected = Y.reshape(-1, 1)\n",
"\n",
"np.save('model/W.npy',W)\n",
"np.save('model/b.npy',b)\n",
Expand All @@ -330,23 +317,31 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 20,
"id": "051e409a",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.658287887486153\n"
]
}
],
"source": [
"shuffle = lambda x: np.random.shuffle(x)\n",
"shuffle(W)\n",
"shuffle(b)\n",
"print(mean_squared_error(y_test, np.matmul(X_test, W.reshape(-1)) + b.reshape(-1)))\n",
"print(mean_squared_error(Y, np.matmul(X, W.reshape(-1)) + b.reshape(-1)))\n",
"\n",
"np.save('model_shuffled/W.npy',W)\n",
"np.save('model_shuffled/b.npy',b)"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 21,
"id": "c701563a",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -401,12 +396,34 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 22,
"id": "02d90771",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Mean Squared Error actual: 0.658287887486153\n",
"... quantized 65536\n",
"Mean Squared Error simulated: 0.65811511933101396465\n",
"... quantized 65536\n",
"Circuit Outputs:\n",
"107823\n",
"Proof took 17.329 s\n",
"ERROR: Invalid proof\n",
"\u001b[31mAn unexpected error occurred:\u001b[39m\n",
"\n",
"Error: Could not verify the proof\n",
" at SimpleTaskDefinition.action (/Users/liaopeiyuan/Documents/GitHub/zkml-core/eth/hardhat.config.js:273:26)\n",
" at Environment._runTaskDefinition (/Users/liaopeiyuan/Documents/GitHub/zkml-core/eth/node_modules/\u001b[4mhardhat\u001b[24m/src/internal/core/runtime-environment.ts:217:14)\n",
" at Environment.run (/Users/liaopeiyuan/Documents/GitHub/zkml-core/eth/node_modules/\u001b[4mhardhat\u001b[24m/src/internal/core/runtime-environment.ts:129:14)\n",
" at main (/Users/liaopeiyuan/Documents/GitHub/zkml-core/eth/node_modules/\u001b[4mhardhat\u001b[24m/src/internal/cli/cli.ts:197:5)\n"
]
}
],
"source": [
"zkml claim_bounty --payment 0x2546BcD3c84621e976D8185a91A922aE77ECEc30 --model ./model_shuffled --dataset ./dataset --publickey ./keys/out_public.json --settings ./settings.json"
"zkml claim_bounty --payment 0xd3162F2B88d05C882a1B26031E144753337ACDBF --model ./model_shuffled --dataset ./dataset --publickey ./keys/out_public.json --settings ./settings.json"
]
},
{
Expand All @@ -423,33 +440,86 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 23,
"id": "f1477fd6",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Mean Squared Error actual: 0.0786589987376446\n",
"... quantized 12891\n",
"Mean Squared Error simulated: 0.07864249526948667579\n",
"... quantized 12888\n",
"Circuit Outputs:\n",
"12888\n",
"Proof took 16.409 s\n",
"INFO: OK!\n",
"Paying 0xd3162F2B88d05C882a1B26031E144753337ACDBF\n",
"With balance\n",
"108.616501100991896552\n",
"Your Public Key: \n",
"[\n",
" \u001b[33m4842771413884360979635609941922451201670854864962458988387057397512039623940n\u001b[39m,\n",
" \u001b[33m313941953243899344658502354250141108878460697882164557538046223348611775672n\u001b[39m\n",
"]\n",
"Your Private Key: \n",
"\u001b[33m5581888367090473215770974626509128864134834921982778138974737194930113876268n\u001b[39m\n",
"Current Balance\n",
"108.616501100991896552\n"
]
}
],
"source": [
"zkml claim_bounty --payment 0x2546BcD3c84621e976D8185a91A922aE77ECEc30 --model ./model --dataset ./dataset --publickey ./keys/out_public.json --settings ./settings.json"
"zkml claim_bounty --payment 0xd3162F2B88d05C882a1B26031E144753337ACDBF --model ./model --dataset ./dataset --publickey ./keys/out_public.json --settings ./settings.json"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 24,
"id": "e425fa00",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Available bounties on dataset: 14797455496207951391356508759149962584765968173479481191220882411966396840571\n",
"[]\n"
]
}
],
"source": [
"zkml list_bounties --hash 14797455496207951391356508759149962584765968173479481191220882411966396840571"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 25,
"id": "80df2810",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Available datasets:\n",
"[]\n"
]
}
],
"source": [
"zkml list_datasets"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a0ad997d",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down

0 comments on commit 1ad147c

Please sign in to comment.