Edited parity plot to allow color to represent 3rd dimension. Still need to improve colorbar axis name.

pull/1/head
titusquah 5 years ago
parent 77e4cefd2c
commit 97ca231afc

@ -19,11 +19,13 @@
<w>ndarray</w>
<w>pred</w>
<w>quah</w>
<w>rbfopt</w>
<w>reeps</w>
<w>scipy</w>
<w>seaborn</w>
<w>slsqp</w>
<w>thermo</w>
<w>viridis</w>
<w>xmls</w>
</words>
</dictionary>

@ -4,13 +4,8 @@
<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/twophase.xml" beforeDir="false" afterPath="$PROJECT_DIR$/data/xmls/twophase.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/docs/Examples/1_getting_started.ipynb" beforeDir="false" afterPath="$PROJECT_DIR$/docs/Examples/1_getting_started.ipynb" afterDir="false" />
<change beforePath="$PROJECT_DIR$/reeps.py" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/setup.py" beforeDir="false" afterPath="$PROJECT_DIR$/setup.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/tests/__init__.py" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/reeps/reeps.py" beforeDir="false" afterPath="$PROJECT_DIR$/reeps/reeps.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/tests/test_multi_reeps.py" beforeDir="false" afterPath="$PROJECT_DIR$/tests/test_multi_reeps.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/tests/test_reeps.py" beforeDir="false" afterPath="$PROJECT_DIR$/tests/test_reeps.py" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -47,14 +42,11 @@
<property name="run.code.analysis.last.selected.profile" value="aDefault" />
<property name="settings.editor.selected.configurable" value="preferences.sourceCode" />
</component>
<component name="RunManager" selected="Python.test_multi_reeps">
<component name="RunManager" selected="Python.li_data_fit">
<configuration name="li_data_fit" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="parameter-estimation" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/../../anl_box/Box Sync/titus/one_rare_earth_fit" />
<option name="IS_MODULE_SDK" value="false" />
@ -69,7 +61,7 @@
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
<configuration name="scratch_1" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<configuration name="multi_re_data_transformer" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="parameter-estimation" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
@ -77,20 +69,20 @@
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$APPLICATION_CONFIG_DIR$/scratches" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/../../anl_box/Box Sync/titus/one_rare_earth_fit" />
<option name="IS_MODULE_SDK" value="false" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<option name="SCRIPT_NAME" value="$APPLICATION_CONFIG_DIR$/scratches/scratch_1.py" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/../../anl_box/Box Sync/titus/one_rare_earth_fit/multi_re_data_transformer.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="true" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
<option name="REDIRECT_INPUT" value="false" />
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
<configuration name="test_multi_reeps" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<configuration name="reeps" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="parameter-estimation" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
@ -98,32 +90,29 @@
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/tests" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/reeps" />
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/tests/test_multi_reeps.py" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/reeps/reeps.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="true" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
<option name="REDIRECT_INPUT" value="false" />
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
<configuration name="test_reeps" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<configuration name="scratch_2" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="parameter-estimation" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/tests" />
<option name="IS_MODULE_SDK" value="true" />
<option name="WORKING_DIRECTORY" value="$APPLICATION_CONFIG_DIR$/scratches" />
<option name="IS_MODULE_SDK" value="false" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/tests/test_reeps.py" />
<option name="SCRIPT_NAME" value="$APPLICATION_CONFIG_DIR$/scratches/scratch_2.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="true" />
<option name="EMULATE_TERMINAL" value="false" />
@ -132,27 +121,34 @@
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
<configuration name="Unittests in test_reeps.py" type="tests" factoryName="Unittests" temporary="true" nameIsGenerated="true">
<configuration name="single_re_data_transformer" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="parameter-estimation" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/tests" />
<option name="IS_MODULE_SDK" value="true" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/../../anl_box/Box Sync/titus/one_rare_earth_fit" />
<option name="IS_MODULE_SDK" value="false" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<option name="_new_additionalArguments" value="&quot;&quot;" />
<option name="_new_target" value="&quot;$PROJECT_DIR$/tests/test_reeps.py&quot;" />
<option name="_new_targetType" value="&quot;PATH&quot;" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/../../anl_box/Box Sync/titus/one_rare_earth_fit/single_re_data_transformer.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
<option name="REDIRECT_INPUT" value="false" />
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
<recent_temporary>
<list>
<item itemvalue="Python.test_multi_reeps" />
<item itemvalue="Python.test_reeps" />
<item itemvalue="Python.test_reeps" />
<item itemvalue="Python.li_data_fit" />
<item itemvalue="Python.test_multi_reeps" />
<item itemvalue="Python.scratch_2" />
<item itemvalue="Python.reeps" />
<item itemvalue="Python.multi_re_data_transformer" />
<item itemvalue="Python.single_re_data_transformer" />
</list>
</recent_temporary>
</component>
@ -245,7 +241,14 @@
<option name="project" value="LOCAL" />
<updated>1591388459379</updated>
</task>
<option name="localTasksCounter" value="10" />
<task id="LOCAL-00010" summary="Included package data in data/csvs and data/xmls. Note this only works for sdists. If bdist is needed, research &quot;manifest.in&quot; python setup files.">
<created>1591972483195</created>
<option name="number" value="00010" />
<option name="presentableId" value="LOCAL-00010" />
<option name="project" value="LOCAL" />
<updated>1591972483196</updated>
</task>
<option name="localTasksCounter" value="11" />
<servers />
</component>
<component name="Vcs.Log.Tabs.Properties">
@ -266,7 +269,8 @@
<MESSAGE value="Completed one composition parameter estimation" />
<MESSAGE value="Modified reeps to grab charge from REE in xml file for initial chlorine moles calculation" />
<MESSAGE value="Allow user to change optimizer and objective function. Also added r-squared evaluator. Changed temp file location to user temp folder. Added a prediction dictionary to access the values predicted by model." />
<option name="LAST_COMMIT_MESSAGE" value="Allow user to change optimizer and objective function. Also added r-squared evaluator. Changed temp file location to user temp folder. Added a prediction dictionary to access the values predicted by model." />
<MESSAGE value="Included package data in data/csvs and data/xmls. Note this only works for sdists. If bdist is needed, research &quot;manifest.in&quot; python setup files." />
<option name="LAST_COMMIT_MESSAGE" value="Included package data in data/csvs and data/xmls. Note this only works for sdists. If bdist is needed, research &quot;manifest.in&quot; python setup files." />
</component>
<component name="WindowStateProjectService">
<state x="-1330" y="212" key="#Inspections" timestamp="1590787654691">
@ -286,43 +290,43 @@
<screen x="-1920" y="2" width="1920" height="1040" />
</state>
<state x="-1213" y="379" key="ANALYSIS_DLG_com.intellij.analysis.BaseAnalysisAction$1/0.0.1536.824/-1920.2.1920.1040@-1920.2.1920.1040" timestamp="1590787657711" />
<state x="169" y="115" key="CommitChangelistDialog2" timestamp="1591972425540">
<state x="169" y="115" key="CommitChangelistDialog2" timestamp="1591972481244">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state x="-1364" y="117" key="CommitChangelistDialog2/0.0.1536.824/-1920.2.1920.1040@-1920.2.1920.1040" timestamp="1591212137077" />
<state x="169" y="115" key="CommitChangelistDialog2/0.0.1920.1040@0.0.1920.1040" timestamp="1591972425540" />
<state x="169" y="115" key="CommitChangelistDialog2/0.0.1920.1040@0.0.1920.1040" timestamp="1591972481244" />
<state x="-1828" y="94" width="1736" height="856" key="DiffContextDialog" timestamp="1591048879404">
<screen x="-1920" y="2" width="1920" height="1040" />
</state>
<state x="-1828" y="94" width="1736" height="856" key="DiffContextDialog/0.0.1536.824/-1920.2.1920.1040@-1920.2.1920.1040" timestamp="1591048879404" />
<state x="-1180" y="278" key="FileChooserDialogImpl" timestamp="1590786964173">
<state x="-1180" y="278" key="FileChooserDialogImpl" timestamp="1591977779746">
<screen x="-1920" y="2" width="1920" height="1040" />
</state>
<state x="-1180" y="278" key="FileChooserDialogImpl/0.0.1536.824/-1920.2.1920.1040@-1920.2.1920.1040" timestamp="1590786964173" />
<state width="1899" height="280" key="GridCell.Tab.0.bottom" timestamp="1591920388062">
<screen x="-1920" y="2" width="1920" height="1040" />
<state x="-1180" y="278" key="FileChooserDialogImpl/0.0.1536.824/-1920.2.1920.1040@-1920.2.1920.1040" timestamp="1591977779746" />
<state width="1899" height="280" key="GridCell.Tab.0.bottom" timestamp="1592250647211">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="1899" height="280" key="GridCell.Tab.0.bottom/0.0.1536.824/-1920.2.1920.1040@-1920.2.1920.1040" timestamp="1591920388062" />
<state width="1899" height="280" key="GridCell.Tab.0.bottom/0.0.1536.824/-1920.2.1920.1040@-1920.2.1920.1040" timestamp="1592019561222" />
<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="281" key="GridCell.Tab.0.bottom/0.0.1920.1040@0.0.1920.1040" timestamp="1591403861494" />
<state width="1899" height="280" key="GridCell.Tab.0.center" timestamp="1591920388062">
<screen x="-1920" y="2" width="1920" height="1040" />
<state width="1899" height="280" key="GridCell.Tab.0.bottom/0.0.1920.1040@0.0.1920.1040" timestamp="1592250647211" />
<state width="1899" height="280" key="GridCell.Tab.0.center" timestamp="1592250647211">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="1899" height="280" key="GridCell.Tab.0.center/0.0.1536.824/-1920.2.1920.1040@-1920.2.1920.1040" timestamp="1591920388062" />
<state width="1899" height="280" key="GridCell.Tab.0.center/0.0.1536.824/-1920.2.1920.1040@-1920.2.1920.1040" timestamp="1592019561222" />
<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="281" key="GridCell.Tab.0.center/0.0.1920.1040@0.0.1920.1040" timestamp="1591403861493" />
<state width="1899" height="280" key="GridCell.Tab.0.left" timestamp="1591920388061">
<screen x="-1920" y="2" width="1920" height="1040" />
<state width="1899" height="280" key="GridCell.Tab.0.center/0.0.1920.1040@0.0.1920.1040" timestamp="1592250647211" />
<state width="1899" height="280" key="GridCell.Tab.0.left" timestamp="1592250647211">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="1899" height="280" key="GridCell.Tab.0.left/0.0.1536.824/-1920.2.1920.1040@-1920.2.1920.1040" timestamp="1591920388061" />
<state width="1899" height="280" key="GridCell.Tab.0.left/0.0.1536.824/-1920.2.1920.1040@-1920.2.1920.1040" timestamp="1592019561220" />
<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="281" key="GridCell.Tab.0.left/0.0.1920.1040@0.0.1920.1040" timestamp="1591403861491" />
<state width="1899" height="280" key="GridCell.Tab.0.right" timestamp="1591920388062">
<screen x="-1920" y="2" width="1920" height="1040" />
<state width="1899" height="280" key="GridCell.Tab.0.left/0.0.1920.1040@0.0.1920.1040" timestamp="1592250647211" />
<state width="1899" height="280" key="GridCell.Tab.0.right" timestamp="1592250647211">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="1899" height="280" key="GridCell.Tab.0.right/0.0.1536.824/-1920.2.1920.1040@-1920.2.1920.1040" timestamp="1591920388062" />
<state width="1899" height="280" key="GridCell.Tab.0.right/0.0.1536.824/-1920.2.1920.1040@-1920.2.1920.1040" timestamp="1592019561222" />
<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="281" key="GridCell.Tab.0.right/0.0.1920.1040@0.0.1920.1040" timestamp="1591403861493" />
<state width="1899" height="280" key="GridCell.Tab.0.right/0.0.1920.1040@0.0.1920.1040" timestamp="1592250647211" />
<state x="-1460" y="164" key="SettingsEditor" timestamp="1591824476757">
<screen x="-1920" y="2" width="1920" height="1040" />
</state>
@ -335,12 +339,12 @@
<screen x="-1920" y="2" width="1920" height="1040" />
</state>
<state x="-1368" y="256" key="Vcs.Push.Dialog.v2/0.0.1536.824/-1920.2.1920.1040@-1920.2.1920.1040" timestamp="1591047662716" />
<state x="579" y="298" key="com.intellij.ide.util.TipDialog" timestamp="1591971684146">
<state x="263" y="182" width="1283" height="717" key="com.intellij.ide.util.TipDialog" timestamp="1592167059593">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state x="-1341" y="300" key="com.intellij.ide.util.TipDialog/0.0.1536.824/-1920.2.1920.1040@-1920.2.1920.1040" timestamp="1591885589059" />
<state x="463" y="236" key="com.intellij.ide.util.TipDialog/0.0.1536.824/-1920.2.1920.1040@0.0.1536.824" timestamp="1590784072879" />
<state x="579" y="298" key="com.intellij.ide.util.TipDialog/0.0.1920.1040@0.0.1920.1040" timestamp="1591971684146" />
<state x="263" y="182" width="1283" height="717" key="com.intellij.ide.util.TipDialog/0.0.1920.1040@0.0.1920.1040" timestamp="1592167059593" />
<state x="-1151" y="440" key="com.intellij.openapi.vcs.update.UpdateOrStatusOptionsDialogupdate-v2" timestamp="1591821870917">
<screen x="-1920" y="2" width="1920" height="1040" />
</state>
@ -351,10 +355,10 @@
</state>
<state x="-1219" y="166" key="refactoring.ChangeSignatureDialog/0.0.1536.824/-1920.2.1920.1040@-1920.2.1920.1040" timestamp="1591059193684" />
<state x="701" y="164" key="refactoring.ChangeSignatureDialog/0.0.1920.1040@0.0.1920.1040" timestamp="1591641371174" />
<state x="-1297" y="227" width="672" height="678" key="search.everywhere.popup" timestamp="1591739392623">
<state x="-1297" y="227" width="672" height="678" key="search.everywhere.popup" timestamp="1591993050079">
<screen x="-1920" y="2" width="1920" height="1040" />
</state>
<state x="-1297" y="227" width="672" height="678" key="search.everywhere.popup/0.0.1536.824/-1920.2.1920.1040@-1920.2.1920.1040" timestamp="1591739392623" />
<state x="-1297" y="227" width="672" height="678" key="search.everywhere.popup/0.0.1536.824/-1920.2.1920.1040@-1920.2.1920.1040" timestamp="1591993050079" />
<state x="623" y="225" width="672" height="678" key="search.everywhere.popup/0.0.1920.1040@0.0.1920.1040" timestamp="1591649653766" />
</component>
<component name="XDebuggerManager">

@ -64,7 +64,8 @@ class REEPS:
The ordering of the columns needs to be:
[h_i, h_eq, z_i, z_eq, {RE_1}_aq_i, {RE_1}_aq_eq, {RE_1}_d_eq,
[h_i, h_eq, z_i, z_eq,
{RE_1}_aq_i, {RE_1}_aq_eq, {RE_1}_d_eq,
{RE_2}_aq_i, {RE_2}_aq_eq, {RE_2}_d_eq,...
{RE_N}_aq_i, {RE_N}_aq_eq, {RE_N}_d_eq]
@ -347,15 +348,17 @@ class REEPS:
self.update_predicted_dict()
@staticmethod
def slsqp_optimizer(objective, x_guess):
def scipy_minimize(objective, x_guess, optimizer_kwargs=None):
""" The default optimizer for REEPS
Uses scipy.minimize with options
Uses scipy.minimize
By default, options are
.. code-block:: python
default_kwargs= {"method": 'SLSQP',
"bounds": [(1e-1, 1e1)*len(x_guess)],
"bounds": [(1e-1, 1e1)]*len(x_guess),
"constraints": (),
"options": {'disp': True,
'maxiter': 1000,
@ -363,14 +366,16 @@ class REEPS:
:param objective: (func) the objective function
:param x_guess: (np.ndarray) the initial guess (always 1)
:param optimizer_kwargs: (dict) dictionary of options for minimize
:returns: (np.ndarray) Optimized parameters
"""
optimizer_kwargs = {"method": 'SLSQP',
"bounds": [(1e-1, 1e1)] * len(x_guess),
"constraints": (),
"options": {'disp': True,
'maxiter': 1000,
'ftol': 1e-6}}
if optimizer_kwargs is None:
optimizer_kwargs = {"method": 'SLSQP',
"bounds": [(1e-1, 1e1)] * len(x_guess),
"constraints": (),
"options": {'disp': True,
'maxiter': 1000,
'ftol': 1e-6}}
res = minimize(objective, x_guess, **optimizer_kwargs)
est_parameters = res.x
return est_parameters
@ -450,7 +455,7 @@ class REEPS:
"""Change list of Cantera solutions by inputting
new xml file name and phase names
Also runs set_in_moles to set initial molality to 1 g/L
Also runs set_in_moles to set feed volume to 1 L
:param phases_xml_filename: (str) xml file with parameters
for equilibrium calc
@ -656,7 +661,7 @@ class REEPS:
This function also calls update_predicted_dict
:param feed_vol: (float) feed volume of mixture (g/L)
:param feed_vol: (float) feed volume of mixture (L)
"""
phases_copy = self._phases.copy()
exp_df = self._exp_df.copy()
@ -809,7 +814,7 @@ class REEPS:
"with at least 2 arguments: "
"f(objective_func,x_guess, kwargs)")
if optimizer == 'SLSQP':
optimizer = self.slsqp_optimizer
optimizer = self.scipy_minimize
self._optimizer = optimizer
return None
@ -939,7 +944,9 @@ class REEPS:
i = 0
for species_name in opt_dict.keys():
for thermo_prop in opt_dict[species_name].keys():
opt_dict[species_name][thermo_prop] *= x[i]
if not np.isnan(
x[i]): # if nan, do not update xml with nan
opt_dict[species_name][thermo_prop] *= x[i]
i += 1
self.update_xml(opt_dict, temp_xml_file_path)
@ -969,9 +976,12 @@ class REEPS:
with optimizer. Returns dictionary with opt_dict structure
:param objective_function: (function) function to compute objective
If 'None', last set objective or default function is used
:param optimizer: (function) function to perform optimization
:param optimizer_kwargs: (dict) arguments for optimizer
:param objective_kwargs: (dict) arguments for objective function
If 'None', last set optimizer or default is used
:param optimizer_kwargs: (dict) optional arguments for optimizer
:param objective_kwargs: (dict) optional arguments
for objective function
:returns opt_dict: (dict) optimized opt_dict. Has identical structure
as opt_dict
"""
@ -1043,6 +1053,8 @@ class REEPS:
def parity_plot(self,
compared_value=None,
color_axis=None,
plot_title=None,
save_path=None,
print_r_squared=False):
"""
@ -1052,6 +1064,16 @@ class REEPS:
:param compared_value: (str) Quantity to compare predicted and
experimental data. Can be any column containing "eq" in exp_df i.e.
h_eq, z_eq, {RE}_d_eq, etc.
:param plot_title: (str or boolean)
If None (default): Plot title will be generated from compared_value
Recommend to just explore. If h_eq, plot_title is
"H^+ eq conc".
If str: Plot title will be plot_title string
If "False": No plot title
:param color_axis: (dict)
:param save_path: (str) save path for parity plot
:param print_r_squared: (boolean) To plot or not to plot r-squared
value. Prints 2 places past decimal
@ -1071,33 +1093,57 @@ class REEPS:
name_breakdown = re.findall('[^_\W]+', compared_value)
compared_species = name_breakdown[0]
if compared_species == 'h':
species_name = '$H^+$'
default_title = '$H^+$ eq. conc. (mol/L)'
elif compared_species == 'z':
species_name = extractant_name
default_title = '{0} eq. conc. (mol/L)'.format(extractant_name)
else:
phase = name_breakdown[1]
if phase == 'aq':
re_charge = re_charges[re_species_list.index(compared_species)]
species_name = '$%s^{%d+}$' % (compared_species, re_charge)
default_title = '$%s^{%d+}$ eq. conc. (mol/L)' \
% (compared_species, re_charge)
elif phase == 'd':
species_name = '{0} distribution ratio'.format(
default_title = '{0} distribution ratio'.format(
compared_species)
else:
species_name = '{0} complex'.format(compared_species)
default_title = '{0} complex eq. conc. (mol/L)'.format(
compared_species)
fig, ax = plt.subplots()
p1 = sns.scatterplot(meas, pred, color="r",
label="{0} eq. conc. (mol/L)".format(
species_name),
legend=False)
if color_axis is None:
sns.scatterplot(meas, pred, color="r",
legend=False)
else:
key = list(color_axis.keys())[0]
value = list(color_axis.values())[0]
if key == 'predicted':
y = self.get_predicted_dict()[value]
elif key == 'measured':
y = self.get_exp_df()[value].values
else:
raise Exception('color_axis must be a dictionary with key'
'"predicted" or "measured"')
y = np.array(y)
meas = np.array(meas)
pred = np.array(pred)
p1 = ax.scatter(meas, pred, c=y, alpha=1, cmap='viridis')
c_bar = fig.colorbar(p1, format='%.2f')
# Fix next line. value is just the dictionary value.
c_bar.set_label(value, rotation=270, labelpad=20)
sns.lineplot(min_max_data, min_max_data, color="b", label="")
if print_r_squared:
p1.text(min_max_data[0],
ax.text(min_max_data[0],
min_max_data[1] * 0.9,
'$R^2$={0:.2f}'.format(self.r_squared(compared_value)))
plt.legend(loc='lower right')
else:
plt.legend()
# plt.legend(loc='lower right')
# else:
# plt.legend()
ax.set(xlabel='Measured', ylabel='Predicted')
if plot_title is None:
ax.set_title(default_title)
elif isinstance(plot_title, str):
ax.set_title(plot_title)
plt.show()
if save_path is not None:
plt.savefig(save_path, bbox_inches='tight')
@ -1110,7 +1156,7 @@ class REEPS:
:param compared_value: (str) Quantity to compare predicted and
experimental data. Can be any column containing "eq" in exp_df i.e.
h_eq, z_eq, {RE}_d_eq, etc.
h_eq, z_eq, {RE}_d_eq, etc. default is {RE}_aq_eq
"""
exp_df = self.get_exp_df()
predicted_dict = self.get_predicted_dict()

@ -15,8 +15,10 @@ def optimizer(func, x_guess):
ub = np.array([1e1])
bounds = (lb, ub)
options = {'c1': 1e-3, 'c2': 1e-3, 'w': 0.9}
mini_optimizer = ps.single.global_best.GlobalBestPSO(n_particles=100, dimensions=1,
options=options, bounds=bounds)
mini_optimizer = ps.single.global_best.GlobalBestPSO(n_particles=100,
dimensions=1,
options=options,
bounds=bounds)
f_opt, x_opt = mini_optimizer.optimize(func, iters=100)
return x_opt

Loading…
Cancel
Save