Skip to content

Commit

Permalink
finished power transform; removed bug; removed globals
Browse files Browse the repository at this point in the history
  • Loading branch information
sohompaul committed Jun 13, 2020
1 parent 6190299 commit c480466
Show file tree
Hide file tree
Showing 2 changed files with 174 additions and 127 deletions.
61 changes: 26 additions & 35 deletions multitask/Demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,19 @@
"metadata": {},
"outputs": [],
"source": [
"def predict_property_neural(prop=None, mol_id=-1):\n",
"def predict_property_neural(*, clusters, A_all, X_all, E_all, prop=None, mol_id=-1):\n",
" kwargs = {\"clusters\": clusters, \"A_all\": A_all, \"X_all\": X_all, \"E_all\": E_all}\n",
" if mol_id == -1:\n",
" raise ValueError(\"ID must be between 1 and 133885\")\n",
" if prop == 'gap':\n",
" lumo = predict_property_neural(prop='lumo', mol_id=mol_id)\n",
" homo = predict_property_neural(prop='homo', mol_id=mol_id)\n",
" lumo = predict_property_neural(prop='lumo', mol_id=mol_id, **kwargs)\n",
" homo = predict_property_neural(prop='homo', mol_id=mol_id, **kwargs)\n",
" return lumo - homo\n",
" \n",
" if not any([prop in cluster for cluster in clusters]):\n",
" raise ValueError(\"Property was not found in clusters list\")\n",
" \n",
" return predict_property(prop, mol_id, clusters, N=N, F=F, S=S)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"predict_property_neural('A', 1)"
" return predict_property(prop=prop, mol_id=mol_id, **kwargs)"
]
},
{
Expand Down Expand Up @@ -267,11 +259,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"jupyter": {
"source_hidden": true
}
},
"metadata": {},
"outputs": [],
"source": [
"def batch_process(start_num, end_num, thermochemical=False):\n",
Expand Down Expand Up @@ -330,7 +318,7 @@
"metadata": {},
"outputs": [],
"source": [
"def lookup_property(prop=None, mol_id=-1):\n",
"def lookup_property(y_all, prop=None, mol_id=-1):\n",
" return y_all.loc[mol_id-1, prop]"
]
},
Expand All @@ -340,7 +328,7 @@
"metadata": {},
"outputs": [],
"source": [
"def prompt_user_for_calculation():\n",
"def prompt_user_for_calculation(*, clusters, y_all, A_all, X_all, E_all):\n",
" while True:\n",
" num = -1\n",
" while num < 1 or num > 133885:\n",
Expand Down Expand Up @@ -376,11 +364,12 @@
" else:\n",
" print('Beginning neural calculation:')\n",
" start = time.time()\n",
" print(predict_property_neural(prop=prop, mol_id=num))\n",
" kwargs = {\"clusters\": clusters, \"A_all\": A_all, \"X_all\": X_all, \"E_all\": E_all}\n",
" print(predict_property_neural(prop=prop, mol_id=num, **kwargs))\n",
" end = time.time()\n",
" print('Neural method took', end-start, 's')\n",
" print('Actual data:')\n",
" print(lookup_property(prop=prop, mol_id=num))"
" print(lookup_property(y_all, prop=prop, mol_id=num))"
]
},
{
Expand All @@ -389,7 +378,13 @@
"metadata": {},
"outputs": [],
"source": [
"prompt_user_for_calculation()"
"A_all, X_all, E_all, y_all = load_data()\n",
"\n",
"clusters = [['A', 'B', 'alpha'], \n",
" ['C', 'r2', 'u0'],\n",
" ['zpve', 'g298', 'cv'],\n",
" ['lumo', 'u298', 'h298'],\n",
" ['mu', 'homo']]"
]
},
{
Expand All @@ -398,19 +393,15 @@
"metadata": {},
"outputs": [],
"source": [
"properties = ['A', 'B', 'C', 'mu', 'homo', 'lumo', 'gap', 'zpve', 'u0', 'u298', 'h298', 'g298', 'cv']\n",
"\n",
"for prop in properties:\n",
" print(prop)\n",
" errors = list()\n",
" for index in np.random.choice(133885, 10):\n",
" pred = predict_property_neural(prop=prop, mol_id=index+1)\n",
" actual = lookup_property(prop=prop, mol_id=index+1)\n",
" err = abs((pred-actual)/actual)\n",
" print(f\"error on molecule {index+1} is {err:.2%}\")\n",
" errors.append(err)\n",
" print(f'avg error of {prop} is {sum(errors)/len(errors):.2%}')\n"
"prompt_user_for_calculation(clusters=clusters, A_all=A_all, X_all=X_all, E_all=E_all, y_all=y_all)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
Loading

0 comments on commit c480466

Please sign in to comment.