Skip to content

Commit

Permalink
chore: replace state.model with state.models[-1]
Browse files Browse the repository at this point in the history
  • Loading branch information
hollandjg committed Dec 1, 2023
1 parent 2452fd6 commit d690b1a
Showing 1 changed file with 16 additions and 27 deletions.
43 changes: 16 additions & 27 deletions docs/tutorials/basic/Tutorial-IV-Customization.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,7 @@
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"\n",
"[notice] A new release of pip is available: 23.2 -> 23.3.1\n",
"[notice] To update, run: python.exe -m pip install --upgrade pip\n"
]
}
],
"outputs": [],
"source": [
"#### Installation ####\n",
"!pip install -q \"autora[theorist-bms]\"\n",
Expand Down Expand Up @@ -82,15 +72,15 @@
" \"\"\"\n",
" \n",
" #Determine labels and variables\n",
" print(s.model)\n",
" model_label = f\"Model: {s.model}\" if hasattr(s.model,'repr') else \"Model\"\n",
" print(s.models[-1])\n",
" model_label = f\"Model: {s.models[-1]}\" if hasattr(s.models[-1],'repr') else \"Model\"\n",
" experiment_data = s.experiment_data.sort_values(by=[\"x\"])\n",
" ground_x = np.linspace(s.variables.independent_variables[0].value_range[0],s.variables.independent_variables[0].value_range[1],100)\n",
" \n",
" #Determine predicted ground truth\n",
" equation = sp.simplify(expr)\n",
" ground_predicted_y = [equation.evalf(subs={'x':x}) for x in ground_x]\n",
" model_predicted_y = s.model.predict(ground_x.reshape(-1, 1))\n",
" model_predicted_y = s.models[-1].predict(ground_x.reshape(-1, 1))\n",
"\n",
" #Plot the data and models\n",
" f = plt.figure(figsize=(4,3))\n",
Expand Down Expand Up @@ -194,18 +184,17 @@
]
},
{
"ename": "ValueError",
"evalue": "Invalid parameter 'seed' for estimator 1.0. Valid parameters are: ['epochs', 'prior_par', 'ts'].",
"ename": "TypeError",
"evalue": "experiment_runner() got an unexpected keyword argument 'random_state'",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32mc:\\Users\\cwill\\GitHub\\autora\\docs\\tutorials\\basic\\Tutorial-IV-Customization.ipynb Cell 8\u001b[0m line \u001b[0;36m7\n\u001b[0;32m <a href='vscode-notebook-cell:/c%3A/Users/cwill/GitHub/autora/docs/tutorials/basic/Tutorial-IV-Customization.ipynb#X10sZmlsZQ%3D%3D?line=4'>5</a>\u001b[0m s \u001b[39m=\u001b[39m experimentalist(s, num_samples\u001b[39m=\u001b[39m\u001b[39m10\u001b[39m, random_state\u001b[39m=\u001b[39m\u001b[39m42\u001b[39m\u001b[39m+\u001b[39mcycle)\n\u001b[0;32m <a href='vscode-notebook-cell:/c%3A/Users/cwill/GitHub/autora/docs/tutorials/basic/Tutorial-IV-Customization.ipynb#X10sZmlsZQ%3D%3D?line=5'>6</a>\u001b[0m s \u001b[39m=\u001b[39m experiment_runner(s, added_noise\u001b[39m=\u001b[39m\u001b[39m0.5\u001b[39m, random_state\u001b[39m=\u001b[39m\u001b[39m42\u001b[39m\u001b[39m+\u001b[39mcycle)\n\u001b[1;32m----> <a href='vscode-notebook-cell:/c%3A/Users/cwill/GitHub/autora/docs/tutorials/basic/Tutorial-IV-Customization.ipynb#X10sZmlsZQ%3D%3D?line=6'>7</a>\u001b[0m s \u001b[39m=\u001b[39m theorist(s, seed\u001b[39m=\u001b[39;49m\u001b[39m42\u001b[39;49m\u001b[39m+\u001b[39;49mcycle)\n\u001b[0;32m <a href='vscode-notebook-cell:/c%3A/Users/cwill/GitHub/autora/docs/tutorials/basic/Tutorial-IV-Customization.ipynb#X10sZmlsZQ%3D%3D?line=8'>9</a>\u001b[0m plot_from_state(s, \u001b[39m'\u001b[39m\u001b[39msin(x)\u001b[39m\u001b[39m'\u001b[39m)\n\u001b[0;32m <a href='vscode-notebook-cell:/c%3A/Users/cwill/GitHub/autora/docs/tutorials/basic/Tutorial-IV-Customization.ipynb#X10sZmlsZQ%3D%3D?line=10'>11</a>\u001b[0m \u001b[39mprint\u001b[39m(\u001b[39m'\u001b[39m\u001b[39m\\n\u001b[39;00m\u001b[39m\\033\u001b[39;00m\u001b[39m[1mUpdated State:\u001b[39m\u001b[39m\\033\u001b[39;00m\u001b[39m[0m\u001b[39m\u001b[39m'\u001b[39m)\n",
"File \u001b[1;32mc:\\Users\\cwill\\GitHub\\virtualEnvs\\autoraEnv\\lib\\site-packages\\autora\\state.py:1014\u001b[0m, in \u001b[0;36mdelta_to_state.<locals>._f\u001b[1;34m(state_, **kwargs)\u001b[0m\n\u001b[0;32m 1012\u001b[0m \u001b[39m@wraps\u001b[39m(f)\n\u001b[0;32m 1013\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m_f\u001b[39m(state_: S, \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m S:\n\u001b[1;32m-> 1014\u001b[0m delta \u001b[39m=\u001b[39m f(state_, \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs)\n\u001b[0;32m 1015\u001b[0m \u001b[39massert\u001b[39;00m \u001b[39misinstance\u001b[39m(delta, Mapping), (\n\u001b[0;32m 1016\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mOutput of \u001b[39m\u001b[39m%s\u001b[39;00m\u001b[39m must be a `Delta`, `UserDict`, \u001b[39m\u001b[39m\"\u001b[39m \u001b[39m\"\u001b[39m\u001b[39mor `dict`.\u001b[39m\u001b[39m\"\u001b[39m \u001b[39m%\u001b[39m f\n\u001b[0;32m 1017\u001b[0m )\n\u001b[0;32m 1018\u001b[0m new_state \u001b[39m=\u001b[39m state_ \u001b[39m+\u001b[39m delta\n",
"File \u001b[1;32mc:\\Users\\cwill\\GitHub\\virtualEnvs\\autoraEnv\\lib\\site-packages\\autora\\state.py:750\u001b[0m, in \u001b[0;36minputs_from_state.<locals>._f\u001b[1;34m(state_, **kwargs)\u001b[0m\n\u001b[0;32m 748\u001b[0m arguments_from_state[\u001b[39m\"\u001b[39m\u001b[39mstate\u001b[39m\u001b[39m\"\u001b[39m] \u001b[39m=\u001b[39m state_\n\u001b[0;32m 749\u001b[0m arguments \u001b[39m=\u001b[39m \u001b[39mdict\u001b[39m(arguments_from_state, \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs)\n\u001b[1;32m--> 750\u001b[0m result \u001b[39m=\u001b[39m f(\u001b[39m*\u001b[39m\u001b[39m*\u001b[39marguments)\n\u001b[0;32m 751\u001b[0m \u001b[39mreturn\u001b[39;00m result\n",
"File \u001b[1;32mc:\\Users\\cwill\\GitHub\\virtualEnvs\\autoraEnv\\lib\\site-packages\\autora\\state.py:1316\u001b[0m, in \u001b[0;36mestimator_on_state.<locals>.theorist\u001b[1;34m(experiment_data, variables, **kwargs)\u001b[0m\n\u001b[0;32m 1314\u001b[0m dvs \u001b[39m=\u001b[39m [v\u001b[39m.\u001b[39mname \u001b[39mfor\u001b[39;00m v \u001b[39min\u001b[39;00m variables\u001b[39m.\u001b[39mdependent_variables]\n\u001b[0;32m 1315\u001b[0m X, y \u001b[39m=\u001b[39m experiment_data[ivs], experiment_data[dvs]\n\u001b[1;32m-> 1316\u001b[0m new_model \u001b[39m=\u001b[39m estimator\u001b[39m.\u001b[39mset_params(\u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs)\u001b[39m.\u001b[39mfit(X, y)\n\u001b[0;32m 1317\u001b[0m \u001b[39mreturn\u001b[39;00m Delta(model\u001b[39m=\u001b[39mnew_model)\n",
"File \u001b[1;32mc:\\Users\\cwill\\GitHub\\virtualEnvs\\autoraEnv\\lib\\site-packages\\sklearn\\base.py:229\u001b[0m, in \u001b[0;36mBaseEstimator.set_params\u001b[1;34m(self, **params)\u001b[0m\n\u001b[0;32m 227\u001b[0m \u001b[39mif\u001b[39;00m key \u001b[39mnot\u001b[39;00m \u001b[39min\u001b[39;00m valid_params:\n\u001b[0;32m 228\u001b[0m local_valid_params \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_get_param_names()\n\u001b[1;32m--> 229\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mValueError\u001b[39;00m(\n\u001b[0;32m 230\u001b[0m \u001b[39mf\u001b[39m\u001b[39m\"\u001b[39m\u001b[39mInvalid parameter \u001b[39m\u001b[39m{\u001b[39;00mkey\u001b[39m!r}\u001b[39;00m\u001b[39m for estimator \u001b[39m\u001b[39m{\u001b[39;00m\u001b[39mself\u001b[39m\u001b[39m}\u001b[39;00m\u001b[39m. \u001b[39m\u001b[39m\"\u001b[39m\n\u001b[0;32m 231\u001b[0m \u001b[39mf\u001b[39m\u001b[39m\"\u001b[39m\u001b[39mValid parameters are: \u001b[39m\u001b[39m{\u001b[39;00mlocal_valid_params\u001b[39m!r}\u001b[39;00m\u001b[39m.\u001b[39m\u001b[39m\"\u001b[39m\n\u001b[0;32m 232\u001b[0m )\n\u001b[0;32m 234\u001b[0m \u001b[39mif\u001b[39;00m delim:\n\u001b[0;32m 235\u001b[0m nested_params[key][sub_key] \u001b[39m=\u001b[39m value\n",
"\u001b[1;31mValueError\u001b[0m: Invalid parameter 'seed' for estimator 1.0. Valid parameters are: ['epochs', 'prior_par', 'ts']."
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[3], line 6\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m cycle \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mrange\u001b[39m(\u001b[38;5;241m2\u001b[39m):\n\u001b[1;32m 5\u001b[0m s \u001b[38;5;241m=\u001b[39m experimentalist(s, num_samples\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m10\u001b[39m, random_state\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m42\u001b[39m\u001b[38;5;241m+\u001b[39mcycle)\n\u001b[0;32m----> 6\u001b[0m s \u001b[38;5;241m=\u001b[39m \u001b[43mexperiment_runner\u001b[49m\u001b[43m(\u001b[49m\u001b[43ms\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43madded_noise\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;241;43m0.5\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mrandom_state\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;241;43m42\u001b[39;49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[43mcycle\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 7\u001b[0m s \u001b[38;5;241m=\u001b[39m theorist(s)\n\u001b[1;32m 9\u001b[0m plot_from_state(s, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124msin(x)\u001b[39m\u001b[38;5;124m'\u001b[39m)\n",
"File \u001b[0;32m~/Developer/autora/.venv/lib/python3.9/site-packages/autora/state.py:939\u001b[0m, in \u001b[0;36mdelta_to_state.<locals>._f\u001b[0;34m(state_, **kwargs)\u001b[0m\n\u001b[1;32m 937\u001b[0m \u001b[38;5;129m@wraps\u001b[39m(f)\n\u001b[1;32m 938\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_f\u001b[39m(state_: S, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m S:\n\u001b[0;32m--> 939\u001b[0m delta \u001b[38;5;241m=\u001b[39m \u001b[43mf\u001b[49m\u001b[43m(\u001b[49m\u001b[43mstate_\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 940\u001b[0m \u001b[38;5;28;01massert\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(delta, Mapping), (\n\u001b[1;32m 941\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mOutput of \u001b[39m\u001b[38;5;132;01m%s\u001b[39;00m\u001b[38;5;124m must be a `Delta`, `UserDict`, \u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mor `dict`.\u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;241m%\u001b[39m f\n\u001b[1;32m 942\u001b[0m )\n\u001b[1;32m 943\u001b[0m new_state \u001b[38;5;241m=\u001b[39m state_ \u001b[38;5;241m+\u001b[39m delta\n",
"File \u001b[0;32m~/Developer/autora/.venv/lib/python3.9/site-packages/autora/state.py:675\u001b[0m, in \u001b[0;36minputs_from_state.<locals>._f\u001b[0;34m(state_, **kwargs)\u001b[0m\n\u001b[1;32m 673\u001b[0m arguments_from_state[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mstate\u001b[39m\u001b[38;5;124m\"\u001b[39m] \u001b[38;5;241m=\u001b[39m state_\n\u001b[1;32m 674\u001b[0m arguments \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mdict\u001b[39m(arguments_from_state, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n\u001b[0;32m--> 675\u001b[0m result \u001b[38;5;241m=\u001b[39m \u001b[43mf\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43marguments\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 676\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m result\n",
"File \u001b[0;32m~/Developer/autora/.venv/lib/python3.9/site-packages/autora/state.py:757\u001b[0m, in \u001b[0;36moutputs_to_delta.<locals>.decorator.<locals>.inner\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 755\u001b[0m \u001b[38;5;129m@wraps\u001b[39m(f)\n\u001b[1;32m 756\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21minner\u001b[39m(\u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs):\n\u001b[0;32m--> 757\u001b[0m result \u001b[38;5;241m=\u001b[39m \u001b[43mf\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 758\u001b[0m delta \u001b[38;5;241m=\u001b[39m Delta(\u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39m{output[\u001b[38;5;241m0\u001b[39m]: result})\n\u001b[1;32m 759\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m delta\n",
"\u001b[0;31mTypeError\u001b[0m: experiment_runner() got an unexpected keyword argument 'random_state'"
]
}
],
Expand Down Expand Up @@ -546,7 +535,7 @@
" s = experiment_runner(s, added_noise=0.5, random_state=42+cycle)\n",
" s = custom_theorist(s)\n",
" \n",
" print(s.model)\n",
" print(s.models[-1])\n",
" plot_from_state(s, 'sin(x)')\n",
"\n",
"#Report updated state\n",
Expand Down Expand Up @@ -622,9 +611,9 @@
"toc_visible": true
},
"kernelspec": {
"display_name": "autoraKernel",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "autorakernel"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
Expand Down

0 comments on commit d690b1a

Please sign in to comment.