@@ -631,7 +631,7 @@ def tenpar_high_phi_test():
631631 pst .pestpp_options ["ies_num_reals" ] = 10
632632 pst .pestpp_options ["ies_lambda_mults" ] = [0.5 , 1.0 ]
633633 pst .pestpp_options ["lambda_scale_fac" ] = [0.9 , 1.0 ]
634- pst .pestpp_options ['ies_subset_size' ] = 3
634+ pst .pestpp_options ['ies_subset_size' ] = 5
635635 pst .pestpp_options ["ies_debug_high_upgrade_phi" ] = True
636636 pst .pestpp_options ["ies_debug_fail_subset" ] = True
637637 pst .pestpp_options ["ies_debug_fail_remainder" ] = True
@@ -652,7 +652,7 @@ def tenpar_high_phi_test():
652652 pst .pestpp_options ["ies_num_reals" ] = 10
653653 pst .pestpp_options ["ies_lambda_mults" ] = [0.5 , 1.0 ]
654654 pst .pestpp_options ["lambda_scale_fac" ] = [0.9 , 1.0 ]
655- pst .pestpp_options ['ies_subset_size' ] = 3
655+ pst .pestpp_options ['ies_subset_size' ] = 5
656656 pst .pestpp_options ["ies_debug_high_subset_phi" ] = True
657657 pst .pestpp_options ["ies_debug_fail_subset" ] = True
658658 pst .pestpp_options ["ies_debug_fail_remainder" ] = True
@@ -676,7 +676,7 @@ def tenpar_high_phi_test():
676676 pst .pestpp_options ["ies_num_reals" ] = 10
677677 pst .pestpp_options ["ies_lambda_mults" ] = [0.5 , 1.0 ]
678678 pst .pestpp_options ["lambda_scale_fac" ] = [0.9 , 1.0 ]
679- pst .pestpp_options ['ies_subset_size' ] = 3
679+ pst .pestpp_options ['ies_subset_size' ] = 5
680680 #pst.pestpp_options["ies_debug_high_subset_phi"] = True
681681 #pst.pestpp_options["ies_debug_fail_subset"] = True
682682 #pst.pestpp_options["ies_debug_fail_remainder"] = True
@@ -1141,7 +1141,7 @@ def tenpar_upgrade_on_disk_test():
11411141
11421142
11431143def multimodal_test ():
1144- noptmax = 2
1144+ noptmax = 1
11451145 num_reals = 100
11461146 # can be "circle" or "h"
11471147 func = "circle"
@@ -1391,8 +1391,8 @@ def plot_mm1_results(noptmax=None, func="circle", show_info=False,mm_d = None):
13911391 df = pd .read_csv (fname .replace (".par." , ".obs." ), index_col = 0 ))
13921392 mm_pv = oe_pt_mm .phi_vector
13931393 pe_pr = pd .read_csv (os .path .join (mm_d , "mm1.0.par.csv" ))
1394- pe_pt_mm .index = pe_pt_mm .index .map (lambda x : str (int (np . float (x ))))
1395- pe_pr .index = pe_pr .index .map (lambda x : str (int (np . float (x ))))
1394+ pe_pt_mm .index = pe_pt_mm .index .map (lambda x : str (int (float (x ))))
1395+ pe_pr .index = pe_pr .index .map (lambda x : str (int (float (x ))))
13961396 pe_pr .index = pe_pr .index .map (lambda x : str (x ))
13971397
13981398 if show_info and noptmax > 0 :
@@ -1465,7 +1465,7 @@ def h(x, y):
14651465 axes [1 ].imshow (H , alpha = 0.7 ,extent = (- 4 ,4 ,- 4 ,4 ),cmap = "jet" )
14661466 H = np .flipud (H )
14671467 #axes[0].contour(X,Y,H,color="0.5",linestyles="dashed")
1468-
1468+ plt . tight_layout ()
14691469 plt .savefig (os .path .join (mm_d , "compare_{0:02d}.png" .format (noptmax )),dpi = 1000 )
14701470 plt .close (fig )
14711471
@@ -1476,6 +1476,152 @@ def h(x, y):
14761476 pyemu .os_utils .run (cmd , cwd = mm_d )
14771477
14781478
1479+ def plot_mm1_results_seq (noptmax = 1 , func = "circle" ,mm_d = None ):
1480+ import matplotlib .pyplot as plt
1481+ from matplotlib .patches import Circle
1482+
1483+ base_d = os .path .join ("mm1" , "master_base_{0}" .format (func ))
1484+ if mm_d is None :
1485+ mm_d = os .path .join ("mm1" , "master_mm_{0}_mt" .format (func ))
1486+ pst = pyemu .Pst (os .path .join (base_d , "mm1.pst" ))
1487+ if noptmax is None :
1488+ noptmax = pst .control_data .noptmax
1489+ org_noptmax = noptmax + 1
1490+ figcount = 0
1491+ for noptmax in [1 ]:
1492+ fname = os .path .join (base_d , "mm1.{0}.par.csv" .format (noptmax ))
1493+ for i in range (noptmax ):
1494+ if os .path .exists (fname ):
1495+ break
1496+ fname = os .path .join (base_d , "mm1.{0}.par.csv" .format (noptmax - i ))
1497+
1498+ pe_pt_base = pd .read_csv (fname )
1499+ oe_pt_base = pyemu .ObservationEnsemble (pst = pst , df = pd .read_csv (fname .replace (".par." , ".obs." ), index_col = 0 ))
1500+ base_pv = oe_pt_base .phi_vector
1501+
1502+ fname = os .path .join (mm_d , "mm1.{0}.par.csv" .format (noptmax ))
1503+ for i in range (noptmax ):
1504+ if os .path .exists (fname ):
1505+ break
1506+ fname = os .path .join (mm_d , "mm1.{0}.par.csv" .format (noptmax - i ))
1507+ pe_pt_mm = pd .read_csv (fname ,index_col = 0 )
1508+ pe_pt_mm .index = pe_pt_mm .index .astype (str )
1509+ oe_pt_mm = pyemu .ObservationEnsemble .from_dataframe (pst = pst ,
1510+ df = pd .read_csv (fname .replace (".par." , ".obs." ), index_col = 0 ))
1511+ oe_pt_mm .index = oe_pt_mm .index .astype (str )
1512+ mm_pv = oe_pt_mm .phi_vector
1513+ mm_pv .index = mm_pv .index .astype (str )
1514+ #mm_pv.sort_values(inplace=True,ascending=False)
1515+ pe_pr = pd .read_csv (os .path .join (mm_d , "mm1.0.par.csv" ),index_col = 0 )
1516+ pe_pr .index = pe_pr .index .astype (str )
1517+ #pe_pt_mm.index = pe_pt_mm.index.map(lambda x: str(int(float(x))))
1518+ #pe_pr.index = pe_pr.index.map(lambda x: str(int(float(x))))
1519+ #pe_pr.index = pe_pr.index.map(lambda x: str(x))
1520+ mm_info_fname = [f for f in os .listdir (mm_d ) if "mm1.{0}." .format (noptmax ) in f and f .endswith (".mm.info.csv" )][0 ]
1521+ print (mm_info_fname )
1522+
1523+ mm_df = pd .read_csv (os .path .join (mm_d , mm_info_fname ))
1524+ #mm_df.index = np.arange(mm_df.shape[0])
1525+ mm_df .loc [:, "pe_real_name" ] = mm_df .pe_real_name .apply (lambda x : str (x ))
1526+ mm_df .index = mm_df .pe_real_name
1527+ mm_df = mm_df .loc [mm_pv .index ]
1528+ print (mm_df .index )
1529+
1530+ fig , ax = plt .subplots (1 , 1 , figsize = (6 , 6 ))
1531+ c = Circle ([0 ,0 ],1 ,edgecolor = "r" ,facecolor = "none" )
1532+ ax .add_patch (c )
1533+
1534+ ax .scatter (pe_pr .par1 .values , pe_pr .par2 .values , marker = "." , color = "0.5" , alpha = 0.5 )
1535+ ax .set_title ("prior" )
1536+ ax .set_ylabel ("par2" )
1537+ ax .set_xlabel ("par1" )
1538+ plt .tight_layout ()
1539+ plt .savefig (os .path .join (mm_d , "prior.png" ),dpi = 1000 )
1540+ ax .scatter (pe_pt_base .par1 .values , pe_pt_base .par2 .values , marker = "." , color = "b" , alpha = 0.5 )
1541+ ax .set_title ("posterior" )
1542+
1543+ plt .tight_layout ()
1544+ plt .savefig (os .path .join (mm_d , "standard_solution.png" ),dpi = 1000 )
1545+ plt .close (fig )
1546+
1547+ previous_pvals = [[],[]]
1548+ ireal = 0
1549+ for mm_rname in mm_df .index :
1550+ if mm_rname not in pe_pt_mm .index :
1551+ print ("missing" ,mm_rname )
1552+ continue
1553+ if np .abs (pe_pr .loc [mm_rname ,"par1" ]) < 1 and np .abs (pe_pr .loc [mm_rname ,"par2" ]) < 1 :
1554+ print ("skipping" ,mm_rname )
1555+ continue
1556+ nei_cols = mm_df .columns [mm_df .columns .map (lambda x : "neighbor" in x )]
1557+ mm_rnames = set (pe_pr .index .tolist ())
1558+ df = mm_df .loc [mm_rname , :]
1559+ neis = df .loc [nei_cols ].apply (str )
1560+ neis = neis .loc [neis .apply (lambda x : x in mm_rnames )]
1561+ df = df .loc [neis .index ]
1562+ print (neis )
1563+ # print(pe_pt_mm.index)
1564+ pe_pr_nei = pe_pr .loc [neis , :]
1565+ #print(mm_rname, pe_pr.loc[mm_rname, :], pe_pt_mm.loc[mm_rname, :])
1566+
1567+ fig , ax = plt .subplots (1 , 1 , figsize = (6 , 6 ))
1568+ c = Circle ([0 ,0 ],1 ,edgecolor = "r" ,facecolor = "none" )
1569+ ax .add_patch (c )
1570+
1571+ ax .scatter (pe_pr .par1 .values , pe_pr .par2 .values , marker = "." , color = "0.5" , alpha = 0.5 )
1572+
1573+ #if len(previous_pvals[0]) > 0:
1574+ # ax.scatter(previous_pvals[0],previous_pvals[1],marker='.',color="b",alpha=0.5)
1575+
1576+ ax .scatter ([pe_pr .loc [mm_rname , "par1" ]], [pe_pr .loc [mm_rname , "par2" ]], marker = "^" , color = "0.5" , s = 50 )
1577+ ax .set_title ("multimodal upgrade realization {0}" .format (mm_rname ))
1578+ ax .set_ylabel ("par2" )
1579+ ax .set_xlabel ("par1" )
1580+ plt .tight_layout ()
1581+ plt .savefig (os .path .join (mm_d , "seqcompare_{0:02d}.png" .format (figcount )),dpi = 1000 )
1582+ figcount += 1
1583+
1584+
1585+ ax .scatter (pe_pr_nei .par1 .values , pe_pr_nei .par2 .values , marker = "." , color = "c" , s = 100 )
1586+ plt .tight_layout ()
1587+ plt .savefig (os .path .join (mm_d , "seqcompare_{0:02d}.png" .format (figcount )),dpi = 1000 )
1588+ figcount += 1
1589+
1590+ ax .scatter ([pe_pt_mm .loc [mm_rname , "par1" ]], [pe_pt_mm .loc [mm_rname , "par2" ]], marker = "^" , color = "b" ,
1591+ s = 50 )
1592+ previous_pvals [0 ].append (pe_pt_mm .loc [mm_rname , "par1" ])
1593+ previous_pvals [1 ].append (pe_pt_mm .loc [mm_rname , "par2" ])
1594+
1595+ ax .plot ([pe_pr .loc [mm_rname , "par1" ],pe_pt_mm .loc [mm_rname , "par1" ]],[pe_pr .loc [mm_rname , "par2" ],pe_pt_mm .loc [mm_rname , "par2" ]],
1596+ "b--" ,dashes = (1 ,1 ),lw = 1.5 )
1597+ plt .tight_layout ()
1598+ plt .savefig (os .path .join (mm_d , "seqcompare_{0:02d}.png" .format (figcount )),dpi = 1000 )
1599+ plt .close (fig )
1600+ figcount += 1
1601+ ireal += 1
1602+ if ireal > 10 :
1603+ break
1604+
1605+ fig , ax = plt .subplots (1 , 1 , figsize = (6 , 6 ))
1606+ c = Circle ([0 ,0 ],1 ,edgecolor = "r" ,facecolor = "none" )
1607+ ax .add_patch (c )
1608+
1609+ ax .scatter (pe_pr .par1 .values , pe_pr .par2 .values , marker = "." , color = "0.5" , alpha = 0.5 )
1610+ ax .scatter (pe_pt_mm .par1 .values , pe_pt_mm .par2 .values , marker = "." , color = "b" , alpha = 0.5 )
1611+ ax .set_title ("posterior" )
1612+ ax .set_ylabel ("par2" )
1613+ ax .set_xlabel ("par1" )
1614+ plt .tight_layout ()
1615+ plt .savefig (os .path .join (mm_d , "seqcompare_{0:02d}.png" .format (figcount )),dpi = 1000 )
1616+ plt .close (fig )
1617+ figcount += 1
1618+
1619+ pyemu .os_utils .run ("ffmpeg -i seqcompare_02.png -vf palettegen=16 -y palette.png" ,
1620+ cwd = mm_d )
1621+ cmd = "ffmpeg -framerate 1 -i seqcompare_%02d.png -i palette.png -y -filter_complex "
1622+ cmd += "\" scale=720:-1:flags=lanczos[x];[x][1:v]paletteuse\" -y -final_delay 250 seqcompare.gif"
1623+ pyemu .os_utils .run (cmd , cwd = mm_d )
1624+
14791625def mm_invest ():
14801626 # model_d = "mm1"
14811627 # test_d = os.path.join(model_d,"template")
@@ -4079,7 +4225,12 @@ def tenpar_iqr_bad_phi_sigma_test():
40794225
40804226
40814227if __name__ == "__main__" :
4082- tenpar_iqr_bad_phi_sigma_test ()
4228+ tenpar_high_phi_test ()
4229+ #tenpar_iqr_bad_phi_sigma_test()
4230+ #multimodal_test()
4231+ #plot_mm1_sweep_results()
4232+ #plot_mm1_results()
4233+ #plot_mm1_results_seq()
40834234 #tenpar_fixed_restart_test()
40844235 #freyberg_stacked_pe_invest()
40854236 #freyberg_mean_invest()
0 commit comments