Пример #1
0
np.savetxt(input_data_file, np.transpose([xin, yin]))

## Run the inference code #####################################################
ii = 0
for idim in chdimlist:
    for line in fileinput.input("line_infer.xml", inplace=1):
        print(line.replace('PAR_' + str(idim), str(chstart[ii])), end=" ")
    ii = ii + 1
    print(ii)

print("Running the parameter inference")
os.system('./line_infer.x >& logMCMC.dat')

## Import data from MCMC file ###################################################
print("Loading in chain file ", chainfile)
all_samples, vnames = postp.extract_all_vars(chainfile, n_burnin, 0, stride)
n_all_vars = len(vnames)
print(all_samples.shape)

# Extract all MCMC chain variables in separate array
chn = all_samples[:, 0:1 + n_all_vars]
nchn = chn.shape[0]

if generate_plots:
    ## Find posterior predictive #######################################################
    # ideally we should have a deterministic forward model code,
    # but for a line it is simple enough to compute here
    print("\nSampling chain to compute posterior predictive distribution\n")

    # First set parameters to the default parameters; then replace the inferred parameters
    # with samples from the chain.
Пример #2
0
        stride = model.model_info["stride"]

        if demo_verbose > 1:
            print("n_skip:", n_skip)
            print("stride:", stride)

        # Base name of file for outputting results
        samples_file_name = model.model_info["output_file"]  #MCMC file name
        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)
Пример #3
0
        generate_plots = False
    else:
        assert False, "unhandled command line parsing option"

# Other input settings
dense_plots = True  # Set to True to get dense format for posterior plots in triangular format
chainfile = 'tmcmc_chain.dat'  # Name of the chain file

## Run the inference code #####################################################

print("Running TMCMC on bimodal posterior")
os.system('./tmcmc_bimodal.x >& logTMCMC.dat')

## Import data from MCMC file ###################################################
print("Loading in chain file ", chainfile)
all_samples, vnames = postp.extract_all_vars(chainfile, 0, 0, 1, False)
n_all_vars = len(vnames)
print(all_samples.shape)

# Extract all MCMC chain variables in separate array
chn = all_samples[:, 0:1 + n_all_vars]
nchn = chn.shape[0]

if generate_plots:

    ## Scatter plots from intermediate pdfs ##################################################################

    indx = 0
    while 1:
        fname = './TMCMCIntermediates/samples.dat.' + str(indx)
        if os.path.exists(fname):