Exemple #1
0
monte_carlo_end_of_life_sample_filename = "mc_data/eol_samples_MC.txt"

# Define target random variable from samples.
monte_carlo_samples = np.genfromtxt(monte_carlo_end_of_life_sample_filename)
target = SampleRandomVector(monte_carlo_samples)

# Define SROM, determine optimal parameters, store parameters.
input_srom = SROM(srom_size, dim)
input_srom.optimize(target, weights=[1, 1, 1], error="SSE")

# Compare the CDFs.
pp = Postprocessor(input_srom, target)
pp.compare_cdfs(save_figure=False)

# Run the model for each input SROM sample:
srom_end_of_life_data = np.zeros(srom_size)
(srom_samples, srom_probabilities) = input_srom.get_params()
for i, sample in enumerate(srom_samples):
    srom_end_of_life_data[i] = model.evaluate(sample)

# Generate SROM surrogate for the output.
eol_srom = SROMSurrogate(input_srom, srom_end_of_life_data)

# Make random variable with MC eol solution.
monte_carlo_eols = np.genfromtxt(monte_carlo_end_of_life_sample_filename)
eol_mc = SampleRandomVector(monte_carlo_eols)

# Compare final EOL solutions SROM vs MC:
pp = Postprocessor(eol_srom, eol_mc)
pp.compare_cdfs()
Exemple #2
0
#Compare the input CDFs (produces Figure 6)
post_processor = Postprocessor(input_srom, target_vector)
post_processor.compare_CDFs(variablenames=[r'$y_{0}$', r'log$C$', r'$n$'])

#Run the model for each input SROM sample:
srom_results = numpy.zeros(srom_size)
(srom_samples, srom_probs) = input_srom.get_params()

# TODO: define model here.
model = None

if model is None:
    raise ValueError("model has not been defined.")

for i, sample in enumerate(srom_samples):
    srom_results[i] = model.evaluate(sample)

#Generate SROM surrogate for the end of life
srom_surrogate_model = SROMSurrogate(input_srom, srom_results)

#Make random variable with MC end of life solution
monte_carlo_results_filename = "eol_samples_MC.txt"
monte_carlo_results_samples = numpy.genfromtxt(monte_carlo_results_filename)
target_vector = SampleRandomVector(monte_carlo_results_samples)

#Compare final EOL solutions SROM vs MC:
# (produces Figure 7)
post_processor = Postprocessor(srom_surrogate_model, target_vector)
post_processor.compare_CDFs(variablenames=["EOL"])
MC_eols = np.genfromtxt(mc_eol_file)

#Get SROM EOL samples, FD samples and input SROM from file
srom_eols = np.genfromtxt(srom_eol_file)
srom_fd_eols = np.genfromtxt(srom_fd_eol_file)
input_srom = SROM(sromsize, dim)
input_srom.load_params(srom_input_file)

#Get FD step sizes from file (the same for all samples, just pull the first)
#Step sizes chosen as approximately 2% of the median sample value of inputs
stepsizes = [0.0065, 0.083, 0.025]

#Calculate gradient from FiniteDifference class:
gradient = FD.compute_gradient(srom_eols, srom_fd_eols, stepsizes)

#Create SROM surrogate, sample, and create random variable solution
surrogate_PWL = SROMSurrogate(input_srom, srom_eols, gradient)
srom_eol_samples = surrogate_PWL.sample(MC_inputs)
solution_PWL = SampleRandomVector(srom_eol_samples)

#Store EOL samples for plotting later:
eolfile = "srom_data/srom_eol_samples_m" + str(sromsize) + ".txt"
#np.savetxt(eolfile, srom_eol_samples)  #NOTE - avoid overwriting paper data

#Make MC random variable solution
eol_mc = SampleRandomVector(MC_eols)

#COmpare solutions
pp = Postprocessor(solution_PWL, eol_mc)
pp.compare_CDFs()
Exemple #4
0
mc_eol_file = "mc_data/eol_samples_MC.txt"

#Define target random variable from samples
MCsamples = np.genfromtxt(samplesfile)
target = SampleRandomVector(MCsamples)

#Define SROM, determine optimal parameters, store parameters
input_srom = SROM(srom_size, dim)
input_srom.optimize(target, weights=[1, 1, 1], error="SSE")

#Compare the CDFs
pp = Postprocessor(srom, target)
pp.compare_CDFs(saveFig=False)

#Run the model for each input SROM sample:
srom_eols = np.zeros(srom_size)
(srom_samples, srom_probs) = input_srom.get_params()
for i, sample in enumerate(srom_samples):
    srom_eols[i] = model.evaluate(sample)

#Generate SROM surrogate for the output
eol_srom = SROMSurrogate(input_srom, srom_eols)

#Make random variable with MC eol solution
MC_eols = np.genfromtxt(mc_eol_file)
eol_mc = SampleRandomVector(MC_eols)

#Compare final EOL solutions SROM vs MC:
pp = Postprocessor(eol_srom, eol_mc)
pp.compare_CDFs()
Exemple #5
0
# Form new SROM for the max disp. solution using samples from the model.
output_srom = SROM(srom_size, dim)
output_srom.set_params(srom_displacements, probabilities)

# Compare solutions.
pp_output = Postprocessor(output_srom, monte_carlo_solution)
pp_output.compare_cdfs()

# --------Piecewise LINEAR surrogate with gradient info-------

# Need to calculate gradient of output wrt input samples first.

# Perturbation size for finite difference.
step_size = 1e-12
samples_fd = FD.get_perturbed_samples(samples, perturbation_values=[step_size])

# Run model to get perturbed outputs for FD calc.
perturbed_displacements = np.zeros(srom_size)
for i, stiff in enumerate(samples_fd):
    perturbed_displacements[i] = model.get_max_disp(stiff)
gradient = FD.compute_gradient(srom_displacements, perturbed_displacements,
                               [step_size])

surrogate_PWL = SROMSurrogate(input_srom, srom_displacements, gradient)
stiffness_samples = stiffness_random_variable.draw_random_sample(num_samples)
output_samples = surrogate_PWL.sample(stiffness_samples)
solution_PWL = SampleRandomVector(output_samples)

pp_pwl = Postprocessor(solution_PWL, monte_carlo_solution)
pp_pwl.compare_cdfs()
# Build up srom_size-to-SROM object map for plotting routine
sroms = OrderedDict()

for srom_size in srom_sizes:

    # Generate input SROM from file:
    srom = SROM(srom_size, target._dim)
    srom_filename = "srom_m" + str(srom_size) + ".txt"
    srom_filename = os.path.join(srom_dir, srom_filename)
    srom.load_params(srom_filename)

    # Generate SROM surrogate for output from EOLs & input srom:
    end_of_life_filename = "srom_eol_m" + str(srom_size) + ".txt"
    end_of_life_filename = os.path.join(srom_dir, end_of_life_filename)
    end_of_life_data = np.genfromtxt(end_of_life_filename)

    sroms[srom_size] = SROMSurrogate(srom, end_of_life_data)

Postprocessor.compare_srom_cdfs(sroms,
                                target,
                                plot_dir="plots",
                                plot_suffix=plot_suffix,
                                variable_names=variables,
                                y_limits=y_limits,
                                x_ticks=x_ticks,
                                cdf_y_label=True,
                                x_axis_padding=x_axis_padding,
                                axis_font_size=axis_font_size,
                                label_font_size=label_font_size,
                                legend_font_size=legend_font_size)
Exemple #7
0
# Get SROM EOL samples, FD samples and input SROM from file.
srom_end_of_life_data = np.genfromtxt(srom_end_of_life_filename)
srom_fd_end_of_life_data = np.genfromtxt(srom_fd_end_of_life_filename)
input_srom = SROM(srom_size, dim)
input_srom.load_params(srom_input_file)

# Get FD step sizes from file (the same for all samples, just pull the first)
# Step sizes chosen as approximately 2% of the median sample value of inputs
step_sizes = [0.0065, 0.083, 0.025]

# Calculate gradient from FiniteDifference class:
gradient = FD.compute_gradient(srom_end_of_life_data, srom_fd_end_of_life_data,
                               step_sizes)

# Create SROM surrogate, sample, and create random variable solution.
surrogate_PWL = SROMSurrogate(input_srom, srom_end_of_life_data, gradient)
srom_end_of_life_samples = surrogate_PWL.sample(monte_carlo_inputs)
solution_PWL = SampleRandomVector(srom_end_of_life_samples)

# Store EOL samples for plotting later:
end_of_life_filename = "srom_data/srom_eol_samples_m" + str(srom_size) + ".txt"
# np.savetxt(end_of_life_filename, srom_eol_samples)
# NOTE - avoid overwriting paper data

# Make MC random variable solution.
end_of_life_monte_carlo = SampleRandomVector(monte_carlo_end_of_life_data)

# Compare solutions.
pp = Postprocessor(solution_PWL, end_of_life_monte_carlo)
pp.compare_cdfs()
Exemple #8
0
target = SampleRandomVector(samples)

#Set x limits for each variable based on target:
#xlimits = [[np.min(samples), np.max(samples)]]

#Build up sromsize-to-SROM object map for plotting routine
sroms = OrderedDict()

for sromsize in sromsizes:

    #Generate input SROM from file:
    srom = SROM(sromsize, target._dim)
    sromfile = "srom_m" + str(sromsize) + ".txt"
    sromfile = os.path.join(srom_dir, sromfile)
    srom.load_params(sromfile)
        
    #Generate SROM surrogate for output from EOLs & input srom:
    eolfile = "srom_eol_m" + str(sromsize) + ".txt"
    eolfile = os.path.join(srom_dir, eolfile)
    eols = np.genfromtxt(eolfile)

    sroms[sromsize] = SROMSurrogate(srom, eols)
 
Postprocessor.compare_srom_CDFs(sroms, target, plotdir="plots",
                                plotsuffix=plot_suffix, variablenames=varz,                                     xlimits=xlimits, ylimits=ylimits, xticks=xticks,
                                cdfylabel=True, xaxispadding=xaxispadding,
                                axisfontsize=axisfontsize, 
                                labelfontsize=labelfontsize,
                                legendfontsize=legendfontsize)