From e275b50e2c4fb0200f2f071c2ed4a63e462f5828 Mon Sep 17 00:00:00 2001 From: titusquah <46580668+titusquah@users.noreply.github.com> Date: Thu, 16 Jul 2020 07:04:46 -0600 Subject: [PATCH] Updated iterative_fitter.py --- .idea/workspace.xml | 68 +++++++++--------- .../xmls/PC88A_HCL_NdPrCeLaDySmY_w_pitzer.xml | 58 ++++++++-------- docs/Examples/iterative_fitter.py | 35 +++++++--- docs/Examples/iterative_fitter_monitor.py | 69 +++++++++++-------- docs/Examples/outputs/temp.xml | 58 ++++++++-------- 5 files changed, 159 insertions(+), 129 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 4330c24..e87437a 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,9 +1,11 @@ - + + + - + - + - + - + + + - - @@ -367,7 +366,14 @@ @@ -427,11 +433,11 @@ - + - + @@ -445,30 +451,30 @@ - - + + - - - + + + - - - + + + - - - + + + - + diff --git a/data/xmls/PC88A_HCL_NdPrCeLaDySmY_w_pitzer.xml b/data/xmls/PC88A_HCL_NdPrCeLaDySmY_w_pitzer.xml index 186f8b2..a6f87b7 100644 --- a/data/xmls/PC88A_HCL_NdPrCeLaDySmY_w_pitzer.xml +++ b/data/xmls/PC88A_HCL_NdPrCeLaDySmY_w_pitzer.xml @@ -33,7 +33,7 @@ 298.14999999999998 - -1376877.765519179 + -1376877.1544988335 558.9824 0.0 @@ -50,7 +50,7 @@ 298.14999999999998 - -4926549.797810851 + -4926549.797810851 1117.965 0.0 @@ -67,7 +67,7 @@ 298.14999999999998 - -4935519.640701385 + -4935519.640701385 1117.965 0.0 @@ -85,7 +85,7 @@ 298.14999999999998 - -4928317.781440989 + -4928317.781440989 1117.965 0.0 @@ -103,7 +103,7 @@ 298.14999999999998 - -4927428.65973482 + -4927428.65973482 1117.965 0.0 @@ -120,7 +120,7 @@ 298.14999999999998 - -4935155.356789877 + -4935155.356789877 1117.965 0.0 @@ -138,7 +138,7 @@ 298.14999999999998 - -4944228.17930387 + -4944228.17930387 1117.965 0.0 @@ -157,7 +157,7 @@ 298.14999999999998 - -4925606.187988869 + -4925606.187988869 1117.965 0.0 @@ -245,10 +245,10 @@ - 0.58791088654164, 0.0, 0.0, 0.0, 0.0 - 5.4483244544866825, 0.0, 0.0, 0.0, 0.0 + 0.9335616000781043, 0.0, 0.0, 0.0, 0.0 + 10.555396864028587, 0.0, 0.0, 0.0, 0.0 0.0, 0.0, 0.0, 0.0, 0.0 - -0.02066999867229882, 0.0, 0.0, 0.0, 0.0 + -0.02066999867229882, 0.0, 0.0, 0.0, 0.0 2 0 @@ -261,10 +261,10 @@ - 0.8967941630491562, 0.0, 0.0, 0.0, 0.0 - 9.427003409136933, 0.0, 0.0, 0.0, 0.0 + 0.951206693355039, 0.0, 0.0, 0.0, 0.0 + 9.262520235612426, 0.0, 0.0, 0.0, 0.0 0.0, 0.0, 0.0, 0.0, 0.0 - -0.01963615126026457, 0.0, 0.0, 0.0, 0.0 + -0.01963615126026457, 0.0, 0.0, 0.0, 0.0 2 0 @@ -277,10 +277,10 @@ - 0.5930012906158572, 0.0, 0.0, 0.0, 0.0 - 5.277035446184885, 0.0, 0.0, 0.0, 0.0 + 0.5362669407654791, 0.0, 0.0, 0.0, 0.0 + 19.878544145607385, 0.0, 0.0, 0.0, 0.0 0.0, 0.0, 0.0, 0.0, 0.0 - -0.024339999997603376, 0.0, 0.0, 0.0, 0.0 + -0.024339999997603376, 0.0, 0.0, 0.0, 0.0 2 0 @@ -293,10 +293,10 @@ - 0.6129503793974099, 0.0, 0.0, 0.0, 0.0 - 5.359935242327716, 0.0, 0.0, 0.0, 0.0 + 0.6129504699810289, 0.0, 0.0, 0.0, 0.0 + 5.359936728131316, 0.0, 0.0, 0.0, 0.0 0.0, 0.0, 0.0, 0.0, 0.0 - -0.019699989216349984, 0.0, 0.0, 0.0, 0.0 + -0.019699989216349984, 0.0, 0.0, 0.0, 0.0 2 0 @@ -309,10 +309,10 @@ - 0.6005000281456716, 0.0, 0.0, 0.0, 0.0 - 4.9100000484364354, 0.0, 0.0, 0.0, 0.0 + 0.3803360903827252, 0.0, 0.0, 0.0, 0.0 + 0.4715334506120701, 0.0, 0.0, 0.0, 0.0 0.0, 0.0, 0.0, 0.0, 0.0 - -0.02618999999473301, 0.0, 0.0, 0.0, 0.0 + -0.02618999999473301, 0.0, 0.0, 0.0, 0.0 2 0 @@ -325,10 +325,10 @@ - 0.96563586407358, 0.0, 0.0, 0.0, 0.0 - 8.514189357968196, 0.0, 0.0, 0.0, 0.0 + 0.8864576562457522, 0.0, 0.0, 0.0, 0.0 + 9.87156845120858, 0.0, 0.0, 0.0, 0.0 0.0, 0.0, 0.0, 0.0, 0.0 - -0.015467323909969704, 0.0, 0.0, 0.0, 0.0 + -0.015467323909969704, 0.0, 0.0, 0.0, 0.0 2 0 @@ -341,10 +341,10 @@ - 0.5977991609880217, 0.0, 0.0, 0.0, 0.0 - 5.278978873123928, 0.0, 0.0, 0.0, 0.0 + 0.6989806503460452, 0.0, 0.0, 0.0, 0.0 + 6.8744371885601625, 0.0, 0.0, 0.0, 0.0 0.0, 0.0, 0.0, 0.0, 0.0 - -0.019920000110321332, 0.0, 0.0, 0.0, 0.0 + -0.019920000110321332, 0.0, 0.0, 0.0, 0.0 2 0 diff --git a/docs/Examples/iterative_fitter.py b/docs/Examples/iterative_fitter.py index b8b5785..70196d6 100644 --- a/docs/Examples/iterative_fitter.py +++ b/docs/Examples/iterative_fitter.py @@ -91,7 +91,8 @@ ignore_list = [] optimizer = 'scipy_minimize' output_dict = {'iter': [0], 'best_obj': [1e20], - 'rel_diff': [1e20]} + 'rel_diff': [1e20], + 'ext_h0': [1e20]} for species in species_list: output_dict['{0}_slope'.format(species)] = [1e20] output_dict['{0}_intercept'.format(species)] = [1e20] @@ -103,6 +104,7 @@ while rel_diff > 1e-4: i += 1 print(i) best_obj = 1e20 + best_ext_h0 = 0 output_dict['iter'].append(i) for species in species_list: print(species) @@ -156,15 +158,27 @@ while rel_diff > 1e-4: optimizer_kwargs=optimizer_kwargs) if obj_value < best_obj: best_obj = obj_value - keys = list(opt_dict.keys()) + best_ext_h0 = opt_dict['(HA)2(org)_h0']['input_value'] + 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) + if '{0}_{1}'.format(species, lin_param) not in ignore_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) + else: + value = output_dict['{0}_{1}'.format(species, lin_param)][-1] + 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) + if '{0}_{1}'.format(species, pitzer_param) not in ignore_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) + else: + value = output_dict['{0}_{1}'.format( + species, pitzer_param)][-1] + 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': [], @@ -204,11 +218,12 @@ while rel_diff > 1e-4: pitzer_guess_df = pd.DataFrame(pitzer_guess_dict) lin_guess_df = pd.DataFrame(lin_guess_dict) + output_dict['best_ext_h0'].append(best_ext_h0) output_dict['best_obj'].append(best_obj) output_dict['rel_diff'].append(100) output_df = pd.DataFrame(output_dict) - old_row = output_df.iloc[-2, :].values[3:] - new_row = output_df.iloc[-1, :].values[3:] + old_row = output_df.iloc[-2, :].values[4:] + new_row = output_df.iloc[-1, :].values[4:] rel_diff = np.sum(np.abs(new_row - old_row) / np.abs(old_row)) del(output_dict['rel_diff'][-1]) output_dict['rel_diff'].append(rel_diff) diff --git a/docs/Examples/iterative_fitter_monitor.py b/docs/Examples/iterative_fitter_monitor.py index a8e6f87..670cf6e 100644 --- a/docs/Examples/iterative_fitter_monitor.py +++ b/docs/Examples/iterative_fitter_monitor.py @@ -2,38 +2,47 @@ import matplotlib.pyplot as plt import pandas as pd go = 'y' -parameters = 'slope,intercept,beta0,beta1,Cphi'.split(',') -while go == 'y': - go = input('continue? ') - if go != 'y': - break - plt.close('all') - df = pd.read_csv('outputs/iterative_fitter_output_df.csv') - info_cols = {parameter: [] for parameter in parameters} - for col in df.columns: - for parameter in parameters: - if parameter in col: - info_cols[parameter].append(col) +parameters = 'slope,intercept,beta0,beta1'.split(',') +# while go == 'y': +# go = input('continue? ') +# if go != 'y': +# break +# plt.close('all') +df = pd.read_csv('outputs/iterative_fitter_output.csv') +info_cols = {parameter: [] for parameter in parameters} +for col in df.columns: for parameter in parameters: - mini_df = df[info_cols[parameter]] - fig, ax = plt.subplots() - ax.set_title(parameter) - for col in info_cols[parameter]: - ax.plot(df['iters'].values, - df[col].values, - label=col, - linestyle='-', - marker='o') - ax.set_xlabel('iteration') - ax.set_ylabel('Value') - plt.legend() - plt.show() + if parameter in col: + info_cols[parameter].append(col) +for parameter in parameters: + mini_df = df[info_cols[parameter]] fig, ax = plt.subplots() - ax.set_title('best_obj_value') - ax.plot(df['iters'].values, - df['best_obj'].values, - linestyle='-', - marker='o') + ax.set_title(parameter) + for col in info_cols[parameter]: + ax.plot(df['iter'].values[1:], + df[col].values[1:], + label=col, + linestyle='-', + marker='o') ax.set_xlabel('iteration') ax.set_ylabel('Value') + plt.legend() plt.show() +fig, ax = plt.subplots() +ax.set_title('best_obj_value') +ax.plot(df['iter'].values[1:], + df['best_obj'].values[1:], + linestyle='-', + marker='o') +ax.set_xlabel('iteration') +ax.set_ylabel('Value') +plt.show() +fig, ax = plt.subplots() +ax.set_title('rel_diff') +ax.plot(df['iter'].values[1:], + df['rel_diff'].values[1:], + linestyle='-', + marker='o') +ax.set_xlabel('iteration') +ax.set_ylabel('Value') +plt.show() \ No newline at end of file diff --git a/docs/Examples/outputs/temp.xml b/docs/Examples/outputs/temp.xml index 186f8b2..a71d992 100644 --- a/docs/Examples/outputs/temp.xml +++ b/docs/Examples/outputs/temp.xml @@ -33,7 +33,7 @@ 298.14999999999998 - -1376877.765519179 + -1376877.154483614 558.9824 0.0 @@ -50,7 +50,7 @@ 298.14999999999998 - -4926549.797810851 + -4933435.73807457 1117.965 0.0 @@ -67,7 +67,7 @@ 298.14999999999998 - -4935519.640701385 + -4936620.461887979 1117.965 0.0 @@ -85,7 +85,7 @@ 298.14999999999998 - -4928317.781440989 + -4932173.388635787 1117.965 0.0 @@ -103,7 +103,7 @@ 298.14999999999998 - -4927428.65973482 + -4991281.90783811 1117.965 0.0 @@ -120,7 +120,7 @@ 298.14999999999998 - -4935155.356789877 + -4935739.024047113 1117.965 0.0 @@ -138,7 +138,7 @@ 298.14999999999998 - -4944228.17930387 + -4944084.986155681 1117.965 0.0 @@ -157,7 +157,7 @@ 298.14999999999998 - -4925606.187988869 + -4924682.918862937 1117.965 0.0 @@ -245,10 +245,10 @@ - 0.58791088654164, 0.0, 0.0, 0.0, 0.0 - 5.4483244544866825, 0.0, 0.0, 0.0, 0.0 + 0.9335616000781043, 0.0, 0.0, 0.0, 0.0 + 10.555396864028587, 0.0, 0.0, 0.0, 0.0 0.0, 0.0, 0.0, 0.0, 0.0 - -0.02066999867229882, 0.0, 0.0, 0.0, 0.0 + -0.02066999867229882, 0.0, 0.0, 0.0, 0.0 2 0 @@ -261,10 +261,10 @@ - 0.8967941630491562, 0.0, 0.0, 0.0, 0.0 - 9.427003409136933, 0.0, 0.0, 0.0, 0.0 + 0.951206693355039, 0.0, 0.0, 0.0, 0.0 + 9.262520235612426, 0.0, 0.0, 0.0, 0.0 0.0, 0.0, 0.0, 0.0, 0.0 - -0.01963615126026457, 0.0, 0.0, 0.0, 0.0 + -0.01963615126026457, 0.0, 0.0, 0.0, 0.0 2 0 @@ -277,10 +277,10 @@ - 0.5930012906158572, 0.0, 0.0, 0.0, 0.0 - 5.277035446184885, 0.0, 0.0, 0.0, 0.0 + 0.5362669407654791, 0.0, 0.0, 0.0, 0.0 + 19.878544145607385, 0.0, 0.0, 0.0, 0.0 0.0, 0.0, 0.0, 0.0, 0.0 - -0.024339999997603376, 0.0, 0.0, 0.0, 0.0 + -0.024339999997603376, 0.0, 0.0, 0.0, 0.0 2 0 @@ -293,10 +293,10 @@ - 0.6129503793974099, 0.0, 0.0, 0.0, 0.0 - 5.359935242327716, 0.0, 0.0, 0.0, 0.0 + 0.6129504699810289, 0.0, 0.0, 0.0, 0.0 + 5.359936728131316, 0.0, 0.0, 0.0, 0.0 0.0, 0.0, 0.0, 0.0, 0.0 - -0.019699989216349984, 0.0, 0.0, 0.0, 0.0 + -0.019699989216349984, 0.0, 0.0, 0.0, 0.0 2 0 @@ -309,10 +309,10 @@ - 0.6005000281456716, 0.0, 0.0, 0.0, 0.0 - 4.9100000484364354, 0.0, 0.0, 0.0, 0.0 + 0.3803360903827252, 0.0, 0.0, 0.0, 0.0 + 0.4715334506120701, 0.0, 0.0, 0.0, 0.0 0.0, 0.0, 0.0, 0.0, 0.0 - -0.02618999999473301, 0.0, 0.0, 0.0, 0.0 + -0.02618999999473301, 0.0, 0.0, 0.0, 0.0 2 0 @@ -325,10 +325,10 @@ - 0.96563586407358, 0.0, 0.0, 0.0, 0.0 - 8.514189357968196, 0.0, 0.0, 0.0, 0.0 + 0.8864576562457522, 0.0, 0.0, 0.0, 0.0 + 9.87156845120858, 0.0, 0.0, 0.0, 0.0 0.0, 0.0, 0.0, 0.0, 0.0 - -0.015467323909969704, 0.0, 0.0, 0.0, 0.0 + -0.015467323909969704, 0.0, 0.0, 0.0, 0.0 2 0 @@ -341,10 +341,10 @@ - 0.5977991609880217, 0.0, 0.0, 0.0, 0.0 - 5.278978873123928, 0.0, 0.0, 0.0, 0.0 + 0.6989806463779159, 0.0, 0.0, 0.0, 0.0 + 6.8744371885601625, 0.0, 0.0, 0.0, 0.0 0.0, 0.0, 0.0, 0.0, 0.0 - -0.019920000110321332, 0.0, 0.0, 0.0, 0.0 + -0.019920000110321332, 0.0, 0.0, 0.0, 0.0 2 0