Updated iterative_fitter.py

pull/1/head
titusquah 5 years ago
parent 1ad6d8e925
commit 12723eed6b

@ -18,6 +18,7 @@
<w>maxiter</w>
<w>molality</w>
<w>ndarray</w>
<w>pitzer</w>
<w>pred</w>
<w>quah</w>
<w>rbfopt</w>

@ -2,11 +2,10 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="f4439dc0-6756-4612-8f7d-596d8949f300" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/dictionaries/Titus.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/dictionaries/Titus.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/data/xmls/PC88A_HCL_NdPrCeLaDySmY_w_pitzer.xml" beforeDir="false" afterPath="$PROJECT_DIR$/data/xmls/PC88A_HCL_NdPrCeLaDySmY_w_pitzer.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/data/xmls/twophase.xml" beforeDir="false" afterPath="$PROJECT_DIR$/data/xmls/twophase.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/docs/Examples/iterative_fitter_monitor.py" beforeDir="false" afterPath="$PROJECT_DIR$/docs/Examples/iterative_fitter_monitor.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/docs/Examples/outputs/temp.xml" beforeDir="false" afterPath="$PROJECT_DIR$/docs/Examples/outputs/temp.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/docs/Examples/iterative_fitter.py" beforeDir="false" afterPath="$PROJECT_DIR$/docs/Examples/iterative_fitter.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/llepe/llepe.py" beforeDir="false" afterPath="$PROJECT_DIR$/llepe/llepe.py" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
@ -350,7 +349,14 @@
<option name="project" value="LOCAL" />
<updated>1594785960460</updated>
</task>
<option name="localTasksCounter" value="26" />
<task id="LOCAL-00026" summary="Added new feature to include custom_object_dicts where user can optimize parameters in the dependent_params_dict.">
<created>1594852623912</created>
<option name="number" value="00026" />
<option name="presentableId" value="LOCAL-00026" />
<option name="project" value="LOCAL" />
<updated>1594852623912</updated>
</task>
<option name="localTasksCounter" value="27" />
<servers />
</component>
<component name="Vcs.Log.Tabs.Properties">
@ -384,7 +390,8 @@
<MESSAGE value="add outputs folder to examples" />
<MESSAGE value="updated iterative_fitter_monitor.py" />
<MESSAGE value="updated iterative_fitter.py to have more feedback" />
<option name="LAST_COMMIT_MESSAGE" value="updated iterative_fitter.py to have more feedback" />
<MESSAGE value="Added new feature to include custom_object_dicts where user can optimize parameters in the dependent_params_dict." />
<option name="LAST_COMMIT_MESSAGE" value="Added new feature to include custom_object_dicts where user can optimize parameters in the dependent_params_dict." />
</component>
<component name="WindowStateProjectService">
<state x="-1330" y="212" key="#Inspections" timestamp="1590787654691">
@ -426,46 +433,46 @@
<screen x="-1920" y="2" width="1920" height="1040" />
</state>
<state x="-1523" y="423" key="GitRewordDialog/0.0.1536.824/-1920.2.1920.1040@-1920.2.1920.1040" timestamp="1592321433648" />
<state width="1899" height="348" key="GridCell.Tab.0.bottom" timestamp="1594852467309">
<state width="1899" height="348" key="GridCell.Tab.0.bottom" timestamp="1594852783300">
<screen x="-1920" y="2" width="1920" height="1040" />
</state>
<state width="1899" height="348" key="GridCell.Tab.0.bottom/0.0.1536.824/-1920.2.1920.1040@-1920.2.1920.1040" timestamp="1594852467309" />
<state width="1899" height="348" key="GridCell.Tab.0.bottom/0.0.1536.824/-1920.2.1920.1040@-1920.2.1920.1040" timestamp="1594852783300" />
<state width="1897" height="281" key="GridCell.Tab.0.bottom/0.0.1536.824/-1920.2.1920.1040@0.0.1536.824" timestamp="1590795386435" />
<state width="1899" height="279" key="GridCell.Tab.0.bottom/0.0.1920.1040@0.0.1920.1040" timestamp="1594769549587" />
<state width="1899" height="348" key="GridCell.Tab.0.center" timestamp="1594852467309">
<state width="1899" height="348" key="GridCell.Tab.0.center" timestamp="1594852783299">
<screen x="-1920" y="2" width="1920" height="1040" />
</state>
<state width="1899" height="348" key="GridCell.Tab.0.center/0.0.1536.824/-1920.2.1920.1040@-1920.2.1920.1040" timestamp="1594852467309" />
<state width="1899" height="348" key="GridCell.Tab.0.center/0.0.1536.824/-1920.2.1920.1040@-1920.2.1920.1040" timestamp="1594852783299" />
<state width="1897" height="281" key="GridCell.Tab.0.center/0.0.1536.824/-1920.2.1920.1040@0.0.1536.824" timestamp="1590795386434" />
<state width="1899" height="279" key="GridCell.Tab.0.center/0.0.1920.1040@0.0.1920.1040" timestamp="1594769549587" />
<state width="1899" height="348" key="GridCell.Tab.0.left" timestamp="1594852467309">
<state width="1899" height="348" key="GridCell.Tab.0.left" timestamp="1594852783299">
<screen x="-1920" y="2" width="1920" height="1040" />
</state>
<state width="1899" height="348" key="GridCell.Tab.0.left/0.0.1536.824/-1920.2.1920.1040@-1920.2.1920.1040" timestamp="1594852467309" />
<state width="1899" height="348" key="GridCell.Tab.0.left/0.0.1536.824/-1920.2.1920.1040@-1920.2.1920.1040" timestamp="1594852783299" />
<state width="1897" height="281" key="GridCell.Tab.0.left/0.0.1536.824/-1920.2.1920.1040@0.0.1536.824" timestamp="1590795386433" />
<state width="1899" height="279" key="GridCell.Tab.0.left/0.0.1920.1040@0.0.1920.1040" timestamp="1594769549587" />
<state width="1899" height="348" key="GridCell.Tab.0.right" timestamp="1594852467309">
<state width="1899" height="348" key="GridCell.Tab.0.right" timestamp="1594852783300">
<screen x="-1920" y="2" width="1920" height="1040" />
</state>
<state width="1899" height="348" key="GridCell.Tab.0.right/0.0.1536.824/-1920.2.1920.1040@-1920.2.1920.1040" timestamp="1594852467309" />
<state width="1899" height="348" key="GridCell.Tab.0.right/0.0.1536.824/-1920.2.1920.1040@-1920.2.1920.1040" timestamp="1594852783300" />
<state width="1897" height="281" key="GridCell.Tab.0.right/0.0.1536.824/-1920.2.1920.1040@0.0.1536.824" timestamp="1590795386434" />
<state width="1899" height="279" key="GridCell.Tab.0.right/0.0.1920.1040@0.0.1920.1040" timestamp="1594769549587" />
<state width="1899" height="348" key="GridCell.Tab.1.bottom" timestamp="1594852467310">
<state width="1899" height="348" key="GridCell.Tab.1.bottom" timestamp="1594852783301">
<screen x="-1920" y="2" width="1920" height="1040" />
</state>
<state width="1899" height="348" key="GridCell.Tab.1.bottom/0.0.1536.824/-1920.2.1920.1040@-1920.2.1920.1040" timestamp="1594852467310" />
<state width="1899" height="348" key="GridCell.Tab.1.center" timestamp="1594852467310">
<state width="1899" height="348" key="GridCell.Tab.1.bottom/0.0.1536.824/-1920.2.1920.1040@-1920.2.1920.1040" timestamp="1594852783301" />
<state width="1899" height="348" key="GridCell.Tab.1.center" timestamp="1594852783301">
<screen x="-1920" y="2" width="1920" height="1040" />
</state>
<state width="1899" height="348" key="GridCell.Tab.1.center/0.0.1536.824/-1920.2.1920.1040@-1920.2.1920.1040" timestamp="1594852467310" />
<state width="1899" height="348" key="GridCell.Tab.1.left" timestamp="1594852467309">
<state width="1899" height="348" key="GridCell.Tab.1.center/0.0.1536.824/-1920.2.1920.1040@-1920.2.1920.1040" timestamp="1594852783301" />
<state width="1899" height="348" key="GridCell.Tab.1.left" timestamp="1594852783300">
<screen x="-1920" y="2" width="1920" height="1040" />
</state>
<state width="1899" height="348" key="GridCell.Tab.1.left/0.0.1536.824/-1920.2.1920.1040@-1920.2.1920.1040" timestamp="1594852467309" />
<state width="1899" height="348" key="GridCell.Tab.1.right" timestamp="1594852467310">
<state width="1899" height="348" key="GridCell.Tab.1.left/0.0.1536.824/-1920.2.1920.1040@-1920.2.1920.1040" timestamp="1594852783300" />
<state width="1899" height="348" key="GridCell.Tab.1.right" timestamp="1594852783301">
<screen x="-1920" y="2" width="1920" height="1040" />
</state>
<state width="1899" height="348" key="GridCell.Tab.1.right/0.0.1536.824/-1920.2.1920.1040@-1920.2.1920.1040" timestamp="1594852467310" />
<state width="1899" height="348" key="GridCell.Tab.1.right/0.0.1536.824/-1920.2.1920.1040@-1920.2.1920.1040" timestamp="1594852783301" />
<state x="-1460" y="164" key="SettingsEditor" timestamp="1591824476757">
<screen x="-1920" y="2" width="1920" height="1040" />
</state>
@ -517,11 +524,6 @@
<line>9</line>
<option name="timeStamp" value="1" />
</line-breakpoint>
<line-breakpoint enabled="true" suspend="THREAD" type="python-line">
<url>file://$PROJECT_DIR$/docs/examples/iterative_fitter.py</url>
<line>26</line>
<option name="timeStamp" value="5" />
</line-breakpoint>
</breakpoints>
<default-breakpoints>
<breakpoint type="python-exception">

@ -33,7 +33,7 @@
<thermo>
<const_cp Tmax="300.0" Tmin="298.0">
<t0 units="K">298.14999999999998</t0>
<h0 units="J/mol" updated="Updated at 8:35 7-15-2020">-1459900.0</h0>
<h0 units="J/mol" updated="Updated at 20:24 7-15-2020">-1376877.1544988335</h0>
<s0 units="J/mol/K"> 558.9824 </s0>
<cp0 units="J/mol/K"> 0.0</cp0>
</const_cp>
@ -50,7 +50,7 @@
<const_cp Tmax="300.0" Tmin="298.0">
<t0 units="K">298.14999999999998</t0>
<h0 units="J/mol" updated="Updated at 8:35 7-15-2020">-5178185.714285715</h0>
<h0 units="J/mol" updated="Updated at 20:24 7-15-2020">-4926549.797810851</h0>
<s0 units="J/mol/K"> 1117.965 </s0>
<cp0 units="J/mol/K">0.0</cp0>
</const_cp>
@ -67,7 +67,7 @@
<const_cp Tmax="300.0" Tmin="298.0">
<t0 units="K">298.14999999999998</t0>
<h0 units="J/mol" updated="Updated at 23:12 7-14-2020">-5177400.0</h0>
<h0 units="J/mol" updated="Updated at 20:24 7-15-2020">-4935519.640701385</h0>
<s0 units="J/mol/K"> 1117.965 </s0>
<cp0 units="J/mol/K">0.0</cp0>
</const_cp>
@ -85,7 +85,7 @@
<const_cp Tmax="300.0" Tmin="298.0">
<t0 units="K">298.14999999999998</t0>
<h0 units="J/mol" updated="Updated at 23:48 7-14-2020">-5177400.0</h0>
<h0 units="J/mol" updated="Updated at 20:24 7-15-2020">-4928317.781440989</h0>
<s0 units="J/mol/K"> 1117.965 </s0>
<cp0 units="J/mol/K">0.0</cp0>
</const_cp>
@ -103,7 +103,7 @@
<const_cp Tmax="300.0" Tmin="298.0">
<t0 units="K">298.14999999999998</t0>
<h0 units="J/mol" updated="Updated at 1:32 7-15-2020">-5177400.0</h0>
<h0 units="J/mol" updated="Updated at 20:24 7-15-2020">-4927428.65973482</h0>
<s0 units="J/mol/K"> 1117.965 </s0>
<cp0 units="J/mol/K">0.0</cp0>
</const_cp>
@ -120,7 +120,7 @@
<const_cp Tmax="300.0" Tmin="298.0">
<t0 units="K">298.14999999999998</t0>
<h0 units="J/mol" updated="Updated at 2:1 7-15-2020">-5177400.0</h0>
<h0 units="J/mol" updated="Updated at 20:24 7-15-2020">-4935155.356789877</h0>
<s0 units="J/mol/K"> 1117.965 </s0>
<cp0 units="J/mol/K">0.0</cp0>
</const_cp>
@ -138,7 +138,7 @@
<const_cp Tmax="300.0" Tmin="298.0">
<t0 units="K">298.14999999999998</t0>
<h0 units="J/mol" updated="Updated at 3:3 7-15-2020">-5178028.571428572</h0>
<h0 units="J/mol" updated="Updated at 20:24 7-15-2020">-4944228.17930387</h0>
<s0 units="J/mol/K"> 1117.965 </s0>
<cp0 units="J/mol/K">0.0</cp0>
</const_cp>
@ -157,7 +157,7 @@
<const_cp Tmax="300.0" Tmin="298.0">
<t0 units="K">298.14999999999998</t0>
<h0 units="J/mol" updated="Updated at 2:24 7-15-2020">-5177400.0</h0>
<h0 units="J/mol" updated="Updated at 20:24 7-15-2020">-4925606.187988869</h0>
<s0 units="J/mol/K"> 1117.965 </s0>
<cp0 units="J/mol/K">0.0</cp0>
</const_cp>
@ -245,10 +245,10 @@
</binarySaltParameters>
<binarySaltParameters anion="Cl-" cation="Pr+++">
<beta0 updated="Updated at 23:15 7-14-2020"> 1.229318338775545, 0.0, 0.0, 0.0, 0.0 </beta0>
<beta1 updated="Updated at 23:15 7-14-2020"> 7.705236327609295, 0.0, 0.0, 0.0, 0.0 </beta1>
<beta0 updated="Updated at 20:24 7-15-2020"> 0.5879108393945309, 0.0, 0.0, 0.0, 0.0 </beta0>
<beta1 updated="Updated at 20:24 7-15-2020"> 5.4483234694357385, 0.0, 0.0, 0.0, 0.0 </beta1>
<beta2> 0.0, 0.0, 0.0, 0.0, 0.0 </beta2>
<Cphi updated="Updated at 23:15 7-14-2020"> -0.020355000251503143, 0.0, 0.0, 0.0, 0.0 </Cphi>
<Cphi updated="Updated at 20:24 7-15-2020"> -0.02066999867229882, 0.0, 0.0, 0.0, 0.0 </Cphi>
<Alpha1> 2 </Alpha1>
<Alpha2> 0 </Alpha2>
<source>
@ -261,10 +261,10 @@
</binarySaltParameters>
<binarySaltParameters anion="Cl-" cation="Nd+++">
<beta0 updated="Updated at 8:35 7-15-2020"> 0.5877, 0.0, 0.0, 0.0, 0.0 </beta0>
<beta1 updated="Updated at 8:35 7-15-2020"> 5.206, 0.0, 0.0, 0.0, 0.0 </beta1>
<beta0 updated="Updated at 20:24 7-15-2020"> 0.7459775851223264, 0.0, 0.0, 0.0, 0.0 </beta0>
<beta1 updated="Updated at 20:24 7-15-2020"> 7.68392131299453, 0.0, 0.0, 0.0, 0.0 </beta1>
<beta2> 0.0, 0.0, 0.0, 0.0, 0.0 </beta2>
<Cphi updated="Updated at 8:35 7-15-2020"> -0.01969, 0.0, 0.0, 0.0, 0.0 </Cphi>
<Cphi updated="Updated at 20:24 7-15-2020"> -0.01963615126026457, 0.0, 0.0, 0.0, 0.0 </Cphi>
<Alpha1> 2 </Alpha1>
<Alpha2> 0 </Alpha2>
<source>
@ -277,10 +277,10 @@
</binarySaltParameters>
<binarySaltParameters anion="Cl-" cation="La+++">
<beta0 updated="Updated at 1:35 7-15-2020"> 1.199616118936196, 0.0, 0.0, 0.0, 0.0 </beta0>
<beta1 updated="Updated at 1:35 7-15-2020"> 13.377018086968107, 0.0, 0.0, 0.0, 0.0 </beta1>
<beta0 updated="Updated at 20:24 7-15-2020"> 0.5929999713109059, 0.0, 0.0, 0.0, 0.0 </beta0>
<beta1 updated="Updated at 20:24 7-15-2020"> 5.2769992484445485, 0.0, 0.0, 0.0, 0.0 </beta1>
<beta2> 0.0, 0.0, 0.0, 0.0, 0.0 </beta2>
<Cphi updated="Updated at 1:35 7-15-2020"> -0.023995730879246852, 0.0, 0.0, 0.0, 0.0 </Cphi>
<Cphi updated="Updated at 20:24 7-15-2020"> -0.024339999997603376, 0.0, 0.0, 0.0, 0.0 </Cphi>
<Alpha1> 2 </Alpha1>
<Alpha2> 0 </Alpha2>
<source>
@ -293,10 +293,10 @@
</binarySaltParameters>
<binarySaltParameters anion="Cl-" cation="Dy+++">
<beta0 updated="Updated at 2:4 7-15-2020"> 0.6129037619837437, 0.0, 0.0, 0.0, 0.0 </beta0>
<beta1 updated="Updated at 2:4 7-15-2020"> 5.359070120380359, 0.0, 0.0, 0.0, 0.0 </beta1>
<beta0 updated="Updated at 20:24 7-15-2020"> 0.612950248542597, 0.0, 0.0, 0.0, 0.0 </beta0>
<beta1 updated="Updated at 20:24 7-15-2020"> 5.3599329374557385, 0.0, 0.0, 0.0, 0.0 </beta1>
<beta2> 0.0, 0.0, 0.0, 0.0, 0.0 </beta2>
<Cphi updated="Updated at 2:4 7-15-2020"> -0.01969999915450973, 0.0, 0.0, 0.0, 0.0 </Cphi>
<Cphi updated="Updated at 20:24 7-15-2020"> -0.019699989216349984, 0.0, 0.0, 0.0, 0.0 </Cphi>
<Alpha1> 2 </Alpha1>
<Alpha2> 0 </Alpha2>
<source>
@ -309,10 +309,10 @@
</binarySaltParameters>
<binarySaltParameters anion="Cl-" cation="Ce+++">
<beta0 updated="Updated at 23:50 7-14-2020"> 0.4845924897449592, 0.0, 0.0, 0.0, 0.0 </beta0>
<beta1 updated="Updated at 23:50 7-14-2020"> 0.49100000000000005, 0.0, 0.0, 0.0, 0.0 </beta1>
<beta0 updated="Updated at 20:24 7-15-2020"> 0.6005000182766684, 0.0, 0.0, 0.0, 0.0 </beta0>
<beta1 updated="Updated at 20:24 7-15-2020"> 4.910000193972841, 0.0, 0.0, 0.0, 0.0 </beta1>
<beta2> 0.0, 0.0, 0.0, 0.0, 0.0 </beta2>
<Cphi updated="Updated at 23:50 7-14-2020"> -0.026227452256417736, 0.0, 0.0, 0.0, 0.0 </Cphi>
<Cphi updated="Updated at 20:24 7-15-2020"> -0.02618999999473301, 0.0, 0.0, 0.0, 0.0 </Cphi>
<Alpha1> 2 </Alpha1>
<Alpha2> 0 </Alpha2>
<source>
@ -325,10 +325,10 @@
</binarySaltParameters>
<binarySaltParameters anion="Cl-" cation="Y+++">
<beta0 updated="Updated at 3:3 7-15-2020"> 0.6248, 0.0, 0.0, 0.0, 0.0 </beta0>
<beta1 updated="Updated at 3:3 7-15-2020"> 5.66, 0.0, 0.0, 0.0, 0.0 </beta1>
<beta0 updated="Updated at 20:24 7-15-2020"> 0.9656352678202726, 0.0, 0.0, 0.0, 0.0 </beta0>
<beta1 updated="Updated at 20:24 7-15-2020"> 8.514180603037651, 0.0, 0.0, 0.0, 0.0 </beta1>
<beta2> 0.0, 0.0, 0.0, 0.0, 0.0 </beta2>
<Cphi updated="Updated at 3:3 7-15-2020"> -0.01563, 0.0, 0.0, 0.0, 0.0 </Cphi>
<Cphi updated="Updated at 20:24 7-15-2020"> -0.015467323909969704, 0.0, 0.0, 0.0, 0.0 </Cphi>
<Alpha1> 2 </Alpha1>
<Alpha2> 0 </Alpha2>
<source>
@ -341,10 +341,10 @@
</binarySaltParameters>
<binarySaltParameters anion="Cl-" cation="Sm+++">
<beta0 updated="Updated at 2:25 7-15-2020"> 0.5977999158894437, 0.0, 0.0, 0.0, 0.0 </beta0>
<beta1 updated="Updated at 2:25 7-15-2020"> 5.278997937589517, 0.0, 0.0, 0.0, 0.0 </beta1>
<beta0 updated="Updated at 20:24 7-15-2020"> 0.5977991228263208, 0.0, 0.0, 0.0, 0.0 </beta0>
<beta1 updated="Updated at 20:24 7-15-2020"> 5.278978156246855, 0.0, 0.0, 0.0, 0.0 </beta1>
<beta2> 0.0, 0.0, 0.0, 0.0, 0.0 </beta2>
<Cphi updated="Updated at 2:25 7-15-2020"> -0.019920000010410537, 0.0, 0.0, 0.0, 0.0 </Cphi>
<Cphi updated="Updated at 20:24 7-15-2020"> -0.019920000110321332, 0.0, 0.0, 0.0, 0.0 </Cphi>
<Alpha1> 2 </Alpha1>
<Alpha2> 0 </Alpha2>
<source>

@ -1,36 +1,92 @@
from scipy.optimize import curve_fit
import llepe
import pandas as pd
import numpy as np
import json
def linear(x, a, b):
return a * x + b
def mod_lin_param_df(lp_df, input_val, mini_species, mini_lin_param):
new_lp_df = lp_df.copy()
index = new_lp_df.index[new_lp_df['species'] == mini_species].tolist()[0]
new_lp_df.at[index, mini_lin_param] = input_val
return new_lp_df
species_list = 'Nd,Pr,Ce,La,Dy,Sm,Y'.split(',')
pitzer_param_list = ['beta0', 'beta1', 'Cphi']
pitzer_param_list = ['beta0', 'beta1']
lin_param_list = ['slope', 'intercept']
meas_pitzer_param_df = pd.read_csv("../../data/csvs/may_pitzer_params.csv")
pitzer_params_filename = "../../data/jsons/min_h0_pitzer_params.txt"
with open(pitzer_params_filename) as file:
pitzer_params_dict = json.load(file)
ext_h0_filename = "../../data/jsons/min_h0_guess_ext_h0.txt"
with open(ext_h0_filename) as file:
ext_h0_dict = json.load(file)
labeled_data = pd.read_csv("../../data/csvs/"
"zeroes_removed_PC88A_HCL_NdPrCeLaDySmY.csv")
exp_data = labeled_data.drop(labeled_data.columns[0], axis=1)
xml_file = "PC88A_HCL_NdPrCeLaDySmY_w_pitzer.xml"
lin_param_df = pd.read_csv("../../data/csvs"
"/zeroes_removed_min_h0_pitzer_lin_params.csv")
estimator_params = {'exp_data': exp_data,
'phases_xml_filename': xml_file,
'phase_names': ['HCl_electrolyte', 'PC88A_liquid'],
'aq_solvent_name': 'H2O(L)',
'extractant_name': '(HA)2(org)',
'diluant_name': 'dodecane',
'complex_names': ['{0}(H(A)2)3(org)'.format(species)
for species in species_list],
'extracted_species_ion_names': ['{0}+++'.format(species)
for species in
species_list],
'aq_solvent_rho': 1000.0,
'extractant_rho': 960.0,
'diluant_rho': 750.0,
'temp_xml_file_path': 'outputs/temp.xml',
'objective_function': llepe.lmse_perturbed_obj
}
estimator = llepe.LLEPE(**estimator_params)
def ext_to_complex(h0, custom_obj_dict, mini_species):
linear_params = custom_obj_dict['lin_param_df']
row = linear_params[linear_params['species'] == mini_species]
return row['slope'].values[0] * h0[0] + row['intercept'].values[0]
dependant_params_dict = {}
for species, complex_name in zip(species_list,
estimator_params['complex_names']):
inner_dict = {'upper_element_name': 'species',
'upper_attrib_name': 'name',
'upper_attrib_value': complex_name,
'lower_element_name': 'h0',
'lower_attrib_name': None,
'lower_attrib_value': None,
'input_format': '{0}',
'function': ext_to_complex,
'kwargs': {"mini_species": species},
'independent_params': '(HA)2(org)_h0'}
dependant_params_dict['{0}_h0'.format(complex_name)] = inner_dict
estimator.update_xml(pitzer_params_dict)
estimator.set_custom_objects_dict({'lin_param_df': lin_param_df})
estimator.set_dependant_params_dict(dependant_params_dict)
estimator.update_xml(ext_h0_dict,
dependant_params_dict=dependant_params_dict)
eps = 1e-4
mini_eps = 1e-8
x_guesses = [[-5178500.0, -1459500.0],
[-5178342.857142857, -1460300.0],
[-5178342.857142857, -1459500.0],
[-5178342.857142857, -1458300.0],
[-5178185.714285715, -1459900.0],
[-5178185.714285715, -1459500.0],
[-5178185.714285715, -1459100.0],
[-5178185.714285715, -1458300.0],
[-5178028.571428572, -1459900.0],
[-5178028.571428572, -1459100.0],
[-5178028.571428572, -1458300.0],
[-5177557.142857143, -1459900.0],
[-5177400.0, -1460300.0]]
pitzer_guess_df = meas_pitzer_param_df.copy()
pitzer_guess_dict = {'species': [],
'beta0': [],
'beta1': []}
for species in species_list:
pitzer_guess_dict['species'].append(species)
for param in pitzer_param_list:
mini_dict = pitzer_params_dict['{0}_{1}'.format(species, param)]
value = mini_dict['input_value']
pitzer_guess_dict[param].append(value)
pitzer_guess_df = pd.DataFrame(pitzer_guess_dict)
ext_h0_guess = ext_h0_dict['(HA)2(org)_h0']['input_value']
lin_guess_df = lin_param_df.copy()
ignore_list = []
optimizer = 'scipy_minimize'
output_dict = {'iter': [0],
@ -49,127 +105,78 @@ while rel_diff > 1e-4:
best_obj = 1e20
output_dict['iter'].append(i)
for species in species_list:
print(species)
lower_species = species.lower()
opt_values = {
'(HA)2(org)_h0': [],
'{0}(H(A)2)3(org)_h0'.format(species): [],
'beta0': [],
'beta1': [],
'Cphi': [],
'obj_value': [],
'guess': []}
for ind1, x_guess in enumerate(x_guesses):
print(ind1)
info_dict = {'(HA)2(org)_h0': {'upper_element_name': 'species',
'upper_attrib_name': 'name',
'upper_attrib_value': '(HA)2(org)',
'lower_element_name': 'h0',
'lower_attrib_name': None,
'lower_attrib_value': None,
'input_format': '{0}',
'input_value': x_guess[1]},
'{0}(H(A)2)3(org)_h0'.format(species): {
'upper_element_name': 'species',
'upper_attrib_name': 'name',
'upper_attrib_value': '{0}(H(A)2)3(org)'.format(
species),
'lower_element_name': 'h0',
'lower_attrib_name': None,
'lower_attrib_value': None,
'input_format': '{0}',
'input_value': x_guess[0]},
}
for pitzer_param in pitzer_param_list:
if '{0}_{1}'.format(species, pitzer_param) not in ignore_list:
pitzer_row = pitzer_guess_df[
pitzer_guess_df['species'] == species]
inner_dict = {'upper_element_name': 'binarySaltParameters',
'upper_attrib_name': 'cation',
'upper_attrib_value':
'{0}+++'.format(species),
'lower_element_name': pitzer_param,
'lower_attrib_name': None,
'lower_attrib_value': None,
'input_format': ' {0}, 0.0, 0.0, 0.0, 0.0 ',
'input_value':
pitzer_row[pitzer_param].values[0]
}
info_dict['{0}_{1}'.format(
species, pitzer_param)] = inner_dict
llepe_params = {
'exp_data': exp_data,
'phases_xml_filename': xml_file,
'opt_dict': info_dict,
'phase_names': ['HCl_electrolyte', 'PC88A_liquid'],
'aq_solvent_name': 'H2O(L)',
'extractant_name': '(HA)2(org)',
'diluant_name': 'dodecane',
'complex_names': ['{0}(H(A)2)3(org)'.format(species)
for species in species_list],
'extracted_species_ion_names': ['{0}+++'.format(species)
for species in species_list],
'aq_solvent_rho': 1000.0,
'extractant_rho': 960.0,
'diluant_rho': 750.0,
'objective_function': llepe.lmse_perturbed_obj,
'optimizer': optimizer,
'temp_xml_file_path': 'outputs/temp.xml'
}
estimator = llepe.LLEPE(**llepe_params)
estimator.update_xml(llepe_params['opt_dict'])
obj_kwargs = {'species_list': [species], 'epsilon': 1e-100}
bounds = [(1e-1, 1e1)] * len(info_dict)
optimizer_kwargs = {"method": 'l-bfgs-b',
"bounds": bounds}
opt_dict, obj_value = estimator.fit(
objective_kwargs=obj_kwargs,
optimizer_kwargs=optimizer_kwargs)
if obj_value < best_obj:
best_obj = obj_value
keys = list(opt_dict.keys())
info1 = [opt_dict[key]['input_value'] for key in keys]
info1.append(obj_value)
info1.append(x_guess)
opt_values_keys = opt_values.keys()
for ind, key in enumerate(opt_values_keys):
opt_values[key].append(info1[ind])
opt_value_df = pd.DataFrame(opt_values)
p_opt, p_cov = curve_fit(linear,
opt_value_df['(HA)2(org)_h0'].values,
opt_value_df['{0}(H(A)2)3(org)_h0'.format(
species)].values)
slope, intercept = p_opt
output_dict['{0}_slope'.format(species)].append(slope)
output_dict['{0}_intercept'.format(species)].append(intercept)
min_h0_df = opt_value_df[
opt_value_df['(HA)2(org)_h0']
== opt_value_df['(HA)2(org)_h0'].min()]
update_pitzer_dict = {}
for pitzer_param in pitzer_param_list:
key_name = '{0}_{1}'.format(species, pitzer_param)
output_dict[key_name].append(min_h0_df[pitzer_param].values[0])
inner_dict = {'upper_element_name': 'binarySaltParameters',
'upper_attrib_name': 'cation',
'upper_attrib_value':
'{0}+++'.format(species),
'lower_element_name': pitzer_param,
'lower_attrib_name': None,
'lower_attrib_value': None,
'input_format': ' {0}, 0.0, 0.0, 0.0, 0.0 ',
'input_value':
min_h0_df[pitzer_param].values[0]
}
update_pitzer_dict['{0}_{1}'.format(
species, pitzer_param)] = inner_dict
estimator.update_xml(update_pitzer_dict)
info_dict = {'(HA)2(org)_h0': {'upper_element_name': 'species',
'upper_attrib_name': 'name',
'upper_attrib_value': '(HA)2(org)',
'lower_element_name': 'h0',
'lower_attrib_name': None,
'lower_attrib_value': None,
'input_format': '{0}',
'input_value': ext_h0_guess}}
for pitzer_param in pitzer_param_list:
if '{0}_{1}'.format(species, pitzer_param) not in ignore_list:
pitzer_row = pitzer_guess_df[
pitzer_guess_df['species'] == species]
inner_dict = {'upper_element_name': 'binarySaltParameters',
'upper_attrib_name': 'cation',
'upper_attrib_value':
'{0}+++'.format(species),
'lower_element_name': pitzer_param,
'lower_attrib_name': None,
'lower_attrib_value': None,
'input_format': ' {0}, 0.0, 0.0, 0.0, 0.0 ',
'input_value':
pitzer_row[pitzer_param].values[0]
}
info_dict['{0}_{1}'.format(
species, pitzer_param)] = inner_dict
for lin_param in lin_param_list:
if '{0}_{1}'.format(species, lin_param) not in ignore_list:
lin_row = lin_guess_df[lin_guess_df['species'] == species]
inner_dict = {'custom_object_name': 'lin_param_df',
'function': mod_lin_param_df,
'kwargs': {'mini_species': species,
'mini_lin_param': lin_param},
'input_value': lin_row[lin_param].values[0]
}
info_dict['{0}_{1}'.format(
species, lin_param)] = inner_dict
estimator.set_opt_dict(info_dict)
estimator.update_custom_objects_dict(info_dict)
estimator.update_xml(info_dict)
obj_kwargs = {'species_list': [species], 'epsilon': 1e-100}
bounds = [(1e-1, 1e1)] * len(info_dict)
optimizer_kwargs = {"method": 'l-bfgs-b',
"bounds": bounds}
opt_dict, obj_value = estimator.fit(
objective_kwargs=obj_kwargs,
optimizer_kwargs=optimizer_kwargs)
if obj_value < best_obj:
best_obj = obj_value
keys = list(opt_dict.keys())
for lin_param in lin_param_list:
mini_dict = opt_dict['{0}_{1}'.format(species, lin_param)]
value = mini_dict['input_value']
output_dict['{0}_{1}'.format(species, lin_param)].append(value)
for pitzer_param in pitzer_param_list:
mini_dict = opt_dict['{0}_{1}'.format(species, pitzer_param)]
value = mini_dict['input_value']
output_dict['{0}_{1}'.format(species, pitzer_param)].append(value)
estimator.update_custom_objects_dict(info_dict)
estimator.update_xml(opt_dict)
pitzer_guess_dict = {'species': [],
'beta0': [],
'beta1': [],
'Cphi': []}
}
lin_guess_dict = {'species': [],
'slope': [],
'intercept:': []}
for species in species_list:
pitzer_guess_dict['species'].append(species)
lin_guess_dict['species'].append(species)
for pitzer_param in pitzer_param_list:
value_list = output_dict['{0}_{1}'.format(species, pitzer_param)]
value = value_list[-1]
@ -182,7 +189,20 @@ while rel_diff > 1e-4:
np.abs(value_list[-3]))
if mini_rel_diff1 < mini_eps and mini_rel_diff2 < mini_eps:
ignore_list.append('{0}_{1}'.format(species, pitzer_param))
for lin_param in lin_param_list:
value_list = output_dict['{0}_{1}'.format(species, lin_param)]
value = value_list[-1]
lin_guess_dict[lin_param].append(value)
if i > 2:
mini_rel_diff1 = np.abs(value_list[-1]
- value_list[-2]) / (
np.abs(value_list[-2]))
mini_rel_diff2 = np.abs(value_list[-2] - value_list[-3]) / (
np.abs(value_list[-3]))
if mini_rel_diff1 < mini_eps and mini_rel_diff2 < mini_eps:
ignore_list.append('{0}_{1}'.format(species, lin_param))
pitzer_guess_df = pd.DataFrame(pitzer_guess_dict)
lin_guess_df = pd.DataFrame(lin_guess_dict)
output_dict['best_obj'].append(best_obj)
output_df = pd.DataFrame(output_dict)
@ -191,4 +211,4 @@ while rel_diff > 1e-4:
rel_diff = np.sum(np.abs(new_row - old_row) / np.abs(old_row))
output_dict['rel_diff'].append(rel_diff)
output_df = pd.DataFrame(output_dict)
output_df.to_csv('outputs/iterative_fitter_output_df.csv')
output_df.to_csv('outputs/iterative_fitter_output.csv')

@ -1105,7 +1105,8 @@ class LLEPE:
if phases_xml_filename is None:
phases_xml_filename = self._phases_xml_filename
new_dict = copy.deepcopy(info_dict)
dep_dict = dependant_params_dict
dep_dict = copy.deepcopy(dependant_params_dict)
custom_objects_dict = copy.deepcopy(self._custom_objects_dict)
if dep_dict is not None:
new_dict.update(dep_dict)
@ -1123,10 +1124,12 @@ class LLEPE:
ind_vals = [new_dict[ind_param_name]['input_value']
for ind_param_name in ind_param_names]
if mod_kwargs is None:
new_dict[param_name]['input_value'] = mod_func(ind_vals)
else:
new_dict[param_name]['input_value'] = \
mod_func(ind_vals,
custom_objects_dict)
else:
new_dict[param_name]['input_value'] = \
mod_func(ind_vals, custom_objects_dict,
**mod_kwargs)
tree = ET.parse(phases_xml_filename)
root = tree.getroot()

Loading…
Cancel
Save