Example #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()
Example #2
0
monte_carlo_input_samples = numpy.genfromtxt(
    monte_carlo_input_samples_filename)
target_vector = SampleRandomVector(monte_carlo_input_samples)

#Define SROM and determine optimal parameters
srom_size = 20
input_srom = SROM(size=srom_size, dim=3)
input_srom.optimize(target_vector)

#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"
Example #3
0
#Get Monte carlo solution as a sample-based random variable:
mc_solution = SampleRandomVector(disp_samples)

#-------------SROM-----------------------

#generate SROM for random vector of stiffness & mass
sromsize = 25
dim = 2

#Assume we only have access to samples in this example and want SROM from them:
km_samples = np.array([k_samples, m_samples]).T
km_random_vector = SampleRandomVector(km_samples)

srom = SROM(sromsize, dim)
srom.optimize(km_random_vector)
(samples, probs) = srom.get_params()

#Run model to get max disp for each SROM stiffness sample
srom_disps = np.zeros(sromsize)
for i in range(sromsize):
    k = samples[i, 0]
    m = samples[i, 1]
    srom_disps[i] = model.get_max_disp(k, m)

#Form new SROM for the max displacement solution using samples from the model
srom_solution = SROM(sromsize, 1)
srom_solution.set_params(srom_disps, probs)

#----------------------------------------

#Compare solutions
Example #4
0
# -------------SROM-----------------------

# Generate SROM for random stiffness.
srom_size = 10
dim = 1
input_srom = SROM(srom_size, dim)
input_srom.optimize(displacement_samples)

# Compare SROM vs target stiffness distribution:
pp_input = Postprocessor(input_srom, displacement_samples)
pp_input.compare_cdfs()

# Run model to get max displacement for each SROM stiffness sample.
srom_displacements = np.zeros(srom_size)
(samples, probabilities) = input_srom.get_params()
for i, stiff in enumerate(samples):
    srom_displacements[i] = model.get_max_disp(stiff)

# 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.
Example #5
0
Run computational model for each input SROM sample - step 2
NOTE - this script will not run, Model class is not provided. But this 
script is representative of a common SROM workflow.

First, we load the SROM parameters that were generated in step 1, then we
get the samples for that SROM and evaluate the crack growth model for each one, 
and store the outputs (EOL) from the model.
'''

#Initialize crack growth model (not provided)
model = CrackGrowthModel()

dim = 3
srom_size = 20

sromfile = "srom_data/srom_m" + str(srom_size) + ".txt"
sromeolfile = "srom_data/srom_eol_m" + str(srom_size) + ".txt"

#Initialize SROM and load parameters from file
srom = SROM(srom_size, dim)
srom.load_params(sromfile)

#Evaluate the crack growth model for each SROM input sample
srom_outputs = np.zeros(srom_size)
(srom_samples, srom_probs) = srom.get_params()
for i, input in enumerate(srom_samples):
    srom_outputs[i] = model.evaluate(input)

#Save EOL outputs for step 3:
np.savetxt(sromeolfile, srom_outputs)
Example #6
0
#-------------SROM-----------------------

#generate SROM for random stiffness
sromsize = 10
dim = 1
input_srom = SROM(sromsize, dim)
input_srom.optimize(stiffness_rv)

#Compare SROM vs target stiffness distribution:
pp_input = Postprocessor(input_srom, stiffness_rv)
pp_input.compare_CDFs()

#Run model to get max disp for each SROM stiffness sample
srom_disps = np.zeros(sromsize)
(samples, probs) = input_srom.get_params()
for i, stiff in enumerate(samples):
    srom_disps[i] = model.get_max_disp(stiff)
 
#Form new SROM for the max disp. solution using samples from the model   
output_srom = SROM(sromsize, dim)
output_srom.set_params(srom_disps, probs)

#Compare solutions
pp_output = Postprocessor(output_srom, mc_solution)
pp_output.compare_CDFs()

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

#Need to calculate gradient of output wrt input samples first