out_file_base = samples_file_name + ".sk" + str(n_skip) + ".st" + str( stride) # Import variables of interest from the MCMC data file print("UQTk extract all vars") all_samples, v_names = uqtkinfpp.extract_all_vars( samples_file_name, n_skip, demo_verbose, stride, labels=labels_present) # Get statistics print("UQTk get_mcmc_stats") map_params = uqtkinfpp.get_mcmc_stats(all_samples, v_names, out_file_base, demo_verbose, desired_stats) print("\nMAP parameter set:") for idx in range(len(map_params)): print(v_names[idx], ":", map_params[idx]) # Save MAP parameter info to a file MAP_info = np.stack((v_names, map_params), axis=-1) np.savetxt(out_file_base + "_map_params.dat", MAP_info, fmt='%-8s') # Plot posteriors # first and last three columns do not contain variable samples if post_plots: uqtkinfpp.plot_all_posteriors(all_samples[:, 1:(1 + len(v_names))], v_names,
markeredgecolor='blue', markerfacecolor='b', markersize=5) ax.set_xlabel(vnames[j], fontsize=22) ax.set_ylabel(vnames[i], fontsize=22) plt.savefig('line_infer.chn_' + vnames[j] + '_' + vnames[i] + '.pdf') plt.clf() ## Plot posterior PDF 'triangle' ################################################ np_kde = 100 postp.plot_all_posteriors(chn[:, 1:], vnames, np_kde, "line_infer.posteriors", debug, dense_plots) if generate_stats: postp.get_mcmc_stats(all_samples, vnames, "line_infer", debug) # ## Find PC coefficients corresponding to the chain samples ####################### # samfile="chain_samples.dat" # # save chain samples minus the step column # np.savetxt(samfile,chn[:,1:]) # print("Running KDE-Rosenblatt transformation to build input PCE") # cmd = pcequad+' -o' + str(pcord)+' -f ' + samfile + ' -x ' + pctype + ' -w' + str(bw) + ' > pcequad.log' # print("Running",cmd) # os.system(cmd) # for res_file in [chainfile, samfile, 'quadpts.dat', 'quadpts_mapped.dat', 'PCcoeff.dat']: # shutil.copyfile(res_file, 'prob5_'+res_file) # # Plots for demontration of Rosenblatt transformation # fig = plt.figure(figsize=(8,6))