for idim in chdimlist: for line in fileinput.input("surf_rxn.in.xml", inplace = 1): print line.replace('PAR_'+str(idim), str(chstart[ii])), ii=ii+1 print "Running the parameter inference" os.system('./SurfRxnInfer.x') # # Import data from MCMC file # # load chain file # it expects first column is line id, then the last # two columns are alpha and current log posterior print "Loading in chain file",chainfile all_samples, vnames = file_utils.extract_all_vars(chainfile,n_burnin,0,1) n_all_vars = len(vnames) n_cols = len(all_samples[0,:]) # Extract all MCMC chain variables in separate array d0 = all_samples[:,1:1+n_all_vars] samfile="insamples.dat" np.savetxt(samfile,d0) # Find PC coefficients corresponding to the chain samples print "Running KDE-Rosenblatt transformation to build input PCE" os.system(pcequad+' -o' + str(pcord)+' -f ' + samfile + ' -x ' + pctype + ' -w' + str(bw) + ' > pcequad.log') # Prepare the xml file for forward propagation for line in fileinput.input("surf_rxn.in.xml", inplace = 1): print line.replace('uncertain', 'det'), for line in fileinput.input("surf_rxn.in.xml", inplace = 1):
from pylab import * import file_utils rc('legend',loc='upper left', fontsize=12) rc('lines', linewidth=4, color='r') rc('axes',linewidth=3,grid=True,labelsize=22) rc('xtick',labelsize=20) rc('ytick',labelsize=20) chainfile="chain.dat"; # chain file nskip=5000; # skip first 'nskip' states nthin=10; # pick every 'nthin' state all_samples, vnames = file_utils.extract_all_vars(chainfile,nskip,0,1) n_all_vars = len(vnames) n_cols = len(all_samples[0,:]) chain = all_samples[:,0:1+n_all_vars] for i in range(n_all_vars): fig = plt.figure(figsize=(10,7)) ax=fig.add_axes([0.10,0.15,0.85,0.75]) plt.plot(chain[:,0],chain[:,i+1],color='black',linewidth=2) ax.set_xlabel("MCMC step",fontsize=22) ax.set_ylabel(vnames[i],fontsize=22) plt.savefig('chain_'+vnames[i]+'.eps') plt.clf()
sys.exit(1) if (np_kde < 1): print "The number of KDE points per dimension needs to be >= 1" print help_string sys.exit(1) # # Import data from MCMC file # # Section 1 # load chain file # it expects first column is line id, then the last # two columns are alpha and current log posterior print "Loading in data file", samples_file_name all_samples, vnames = file_utils.extract_all_vars(samples_file_name, n_burnin, debug, stride) n_all_vars = len(vnames) n_cols = len(all_samples[0, :]) # Extract all MCMC chain variables in separate array d0 = all_samples[:, 1:1 + n_all_vars] if (debug > 0): print d0.shape # Some settings to connect with code Cosmin gave me nthin = 1 # take only every nthin state (for faster kde) nskip = 0 # entries to skip #npdf = 100 # no of grid points for 1D pdf's istart = 0 # number of column with first MCMC variable #cend = 0 # number of extra columns at the end. cend = 0 # remove columns at end so code runs faster for debugging
for idim in chdimlist: for line in fileinput.input("surf_rxn.in.xml", inplace=1): print line.replace('PAR_' + str(idim), str(chstart[ii])), ii = ii + 1 print "Running the parameter inference" os.system('./SurfRxnInfer.x') # # Import data from MCMC file # # load chain file # it expects first column is line id, then the last # two columns are alpha and current log posterior print "Loading in chain file", chainfile all_samples, vnames = file_utils.extract_all_vars(chainfile, n_burnin, 0, 1) n_all_vars = len(vnames) n_cols = len(all_samples[0, :]) # Extract all MCMC chain variables in separate array d0 = all_samples[:, 1:1 + n_all_vars] samfile = "insamples.dat" np.savetxt(samfile, d0) # Find PC coefficients corresponding to the chain samples print "Running KDE-Rosenblatt transformation to build input PCE" os.system(pcequad + ' -o' + str(pcord) + ' -f ' + samfile + ' -x ' + pctype + ' -w' + str(bw) + ' > pcequad.log') # Prepare the xml file for forward propagation for line in fileinput.input("surf_rxn.in.xml", inplace=1): print line.replace('uncertain', 'det'),
print help_string sys.exit(1) # Base name of file for outputting results out_file_base = samples_file_name + ".nb" + str(n_burnin) + ".s" + str(stride) # # Import data from MCMC file # # Section 1 # load chain file # it expects first column is line id, then the last # two columns are alpha and current log posterior #d0 = npy.genfromtxt(chainfile) print "Loading in data file",samples_file_name all_samples, vnames = file_utils.extract_all_vars(samples_file_name,n_burnin,debug,stride) n_all_vars = len(vnames) n_cols = len(all_samples[0,:]) # Extract all MCMC chain variables in separate array d0 = all_samples[:,1:1+n_all_vars] if (debug > 0): print d0.shape # Some settings to connect with code Cosmin gave me nthin = 1 # take only every nthin state (for faster kde) nskip = 0 # entries to skip #npdf = 100 # no of grid points for 1D pdf's istart = 0 # number of column with first MCMC variable #cend = 0 # number of extra columns at the end. cend = 0 # remove columns at end so code runs faster for debugging