from UQpy.SampleMethods import MCS from UQpy.RunModel import RunModel import numpy as np import matplotlib.pyplot as plt import scipy.stats as sp import time t = time.time() x = MCS(dimension=1, icdf=['Normal'], icdf_params=[[0,1]], nsamples=5) mu = 70e9 sigma = 1e9 # x = y x.samples = mu + x.samples*sigma t_MCS = time.time()-t print(t_MCS) print(x.samples)
from UQpy.SampleMethods import MCS from UQpy.RunModel import RunModel import numpy as np import matplotlib.pyplot as plt import scipy.stats as sp import time t = time.time() #x = MCS(dimension=1, icdf=['Normal'], icdf_params=[[0,1]], nsamples=3) mu = 70e9 sigma = 1e9 # x = y #x.samples = mu + x.samples*sigma x = MCS(dimension=1, icdf=['Normal'], icdf_params=[[mu, sigma]], nsamples=2) t_MCS = time.time() - t print(t_MCS) print(x.samples) np.savetxt('UQpy_Samples.txt', x.samples, fmt='%0.5f') t = time.time() z = RunModel(cpu=1, model_type=None, model_script='UQpy_Model.py', input_script='UQpy_Input.py', output_script='UQpy_Output.py', dimension=1) t_run = time.time() - t print(t_run) print('Samples: \n', z.model_eval.samples)
######################################################################################################################## # This will need to be rewritten when MCS is updated. # Define the distribution objects d1 = Uniform(loc=0.02, scale=0.06) d2 = Uniform(loc=0.02, scale=0.01) d3 = Uniform(loc=0.02, scale=0.01) d4 = Uniform(loc=0.0025, scale=0.0075) d5 = Uniform(loc=0.02, scale=0.06) d6 = Uniform(loc=0.02, scale=0.01) d7 = Uniform(loc=0.02, scale=0.01) d8 = Uniform(loc=0.0025, scale=0.0075) # Draw a single sample using MCS x = MCS(dist_object=[d1, d2, d3, d4, d5, d6, d7, d8], nsamples=1, random_state=349857) ######################################################################################################################## run_ = RunModel(samples=x.samples, ntasks=1, model_script='dyna_script.py', input_template='dyna_input.k', var_names=['x0', 'y0', 'z0', 'R0', 'x1', 'y1', 'z1', 'R1'], model_dir='dyna_test', cluster=True, verbose=False, fmt='{:>10.4f}', cores_per_task=48)
ax = fig.gca(projection='3d') ax.scatter(samples[:, 0], samples[:, 1], maximum_indentation, s=20, c='r') ax.set_title('Training data') ax.zaxis.set_major_locator(LinearLocator(10)) ax.zaxis.set_major_formatter(FormatStrFormatter('%.02f')) ax.view_init(20, 140) ax.set_xlabel('$k$', fontsize=15) ax.set_ylabel('$f0$', fontsize=15) ax.set_zlabel('Maximum identation', fontsize=15) plt.show() validation_sampling = LHS(dist_object=joint, nsamples=20, verbose=True) model_serial_third_party.run(samples=validation_sampling.samples) maximum_identation_validation = list() for result in model_serial_third_party.qoi_list[-20:]: maximum_identation_validation.append(max(result[1])) K = Kriging(reg_model='Linear', corr_model='Gaussian', nopt=20, corr_model_params=[1]) K.fit(samples=samples, values=maximum_forces) prediction_sampling = MCS( dist_object=[distribution_k_case_1, distribution_delta_case_1], nsamples=10000, verbose=True) prediction_results = pce.predict(prediction_sampling.samples)
# Create the model object abaqus_sfe_model = RunModel(model_script='abaqus_fire_analysis.py', input_template='abaqus_input.py', output_script='extract_abaqus_output.py', var_names=var_names, ntasks=24, model_dir='SFE_MCS', verbose=True, cores_per_task=1) print('Example: Created the model object.') # Towards defining the sampling scheme # The fire load density is assumed to be uniformly distributed between 50 MJ/number_of_variables^2 and 450 MJ/number_of_variables^2. # The yield strength is assumed to be normally distributed, with the parameters # being: mean = 250 MPa and coefficient of variation of 7%. # Creating samples using MCS d_n = Normal(loc=50, scale=400) d_u = Uniform(loc=2.50e8, scale=1.75e7) x_mcs = MCS(dist_object=[d_n, d_u], nsamples=100, random_state=987979) # Running simulations using the previously defined model object and samples sample_points = x_mcs.samples abaqus_sfe_model.run(samples=sample_points) # The outputs from the analysis are the values of the performance function. qois = abaqus_sfe_model.qoi_list # Save the samples and the qois in a dictionary called results with keys 'inputs' and 'outputs' results = {'inputs': sample_points, 'outputs': qois} # Pickle the results dictionary in the current directory. The basename and extension of the desired pickle file: res_basename = 'MCS_results' res_extension = '.pkl'
import numpy as np from UQpy.Distributions import Uniform from UQpy.RunModel import RunModel from UQpy.SampleMethods import MCS dist1 = Uniform(loc=15000, scale=10000) dist2 = Uniform(loc=450000, scale=80000) dist3 = Uniform(loc=2.0e8, scale=0.5e8) names_ = [ 'fc1', 'fy1', 'Es1', 'fc2', 'fy2', 'Es2', 'fc3', 'fy3', 'Es3', 'fc4', 'fy4', 'Es4', 'fc5', 'fy5', 'Es5', 'fc6', 'fy6', 'Es6' ] x = MCS(dist_object=[dist1, dist2, dist3] * 6, nsamples=5, random_state=938475) samples = np.array(x.samples).round(2) opensees_rc6_model = RunModel(samples=samples, ntasks=5, model_script='opensees_model.py', input_template='import_variables.tcl', var_names=names_, model_object_name="opensees_run", output_script='process_opensees_output.py', output_object_name='read_output') outputs = opensees_rc6_model.qoi_list print(outputs)
import numpy as np import matplotlib.pyplot as plt from UQpy.RunModel import RunModel from UQpy.SampleMethods import MCS from UQpy.Distributions import Uniform dist1 = Uniform(loc=0.9 * 1e5, scale=0.2 * 1e5) dist2 = Uniform(loc=1e-2, scale=1e-1) x = MCS(dist_object=[dist1, dist2], nsamples=2, random_state=np.random.RandomState(1821), verbose=True) samples = x.samples model_serial_third_party = RunModel( samples=samples, model_script='PythonAsThirdParty_model.py', input_template='elastic_contact_sphere.py', var_names=['k', 'f0'], output_script='process_3rd_party_output.py', model_object_name='read_output') qoi = model_serial_third_party.qoi_list a = 1
from UQpy.RunModel import RunModel import numpy as np import matplotlib.pyplot as plt import scipy.stats as sp import time t = time.time() #x = MCS(dimension=1, icdf=['Normal'], icdf_params=[[0,1]], nsamples=3) mu1 = 70e9 sigma1 = 1e9 mu2 = 0.0254 sigma2 = 0.00254 # x = y #x.samples = mu + x.samples*sigma x = MCS(dimension=2, icdf=['Normal', 'Normal'], icdf_params=[[mu1, sigma1], [mu2, sigma2]], nsamples=20) t_MCS = time.time() - t print(t_MCS) print(x.samples) np.savetxt('UQpy_Samples.txt', x.samples, fmt='%0.5f') t = time.time() z = RunModel(cpu=1, model_type=None, model_script='UQpy_Model.py', input_script='UQpy_Input.py', output_script='UQpy_Output.py', dimension=1) t_run = time.time() - t