def run(): # experimental data for z=Normal(12,2) exp_x =np.array([5.04, 5.14, 4.78, 5.12, 5.11, 5.13, 4.97, 5.1 , 5.53, 5.09]) exp_y = np.array([3.33, 3.56, 2.94, 3.27, 3.54, 3.4 , 3.52, 3.63, 3.45, 3.19]) exp_data = np.array([-26.16, -18.39, -20.57, -45.24, -29.16, -22., -46.47, -3.15, -10.48, -16.88]) # measurement error sigma = 0.1 # Create parameters. Pass experimental input data to # non-calibration parameters. x = puq.NormalParameter('x', 'x', mean=5, dev=0.2, caldata=exp_x) y = puq.NormalParameter('y', 'y', mean=3.4, dev=0.25, caldata=exp_y) z = puq.UniformParameter('z', 'z', min=5, max=20) # set up host, uq and prog normally host = puq.InteractiveHost() uq = puq.Smolyak([x,y,z], level=2) prog = puq.TestProgram('python model_1.py', desc='model_1 calibration') # pass experimental results to Sweep return puq.Sweep(uq, host, prog, caldata=exp_data, calerr=sigma)
def value(self): value = self.w.value if value == 'Exact': return [self.name, self.label, self.w1.value] if value == 'Gaussian': return puq.NormalParameter(self.name, self.label, mean=self.w1.value, dev=self.w2.value) if value == 'Uniform': return puq.UniformParameter(self.name, self.label, min=self.w1.value, max=self.w2.value) return None
import puq import numpy as np # Calibration example/test case # Calibrate one parameter of a two parameter model # QoI is 0.2. There is a known variable with a # measurement error of .05 def model(x, y): return y**2 + 17 * x # The actual values of our parameters real_y = puq.NormalParameter('y', 'y', mean=5, dev=0.1) real_x = 0.2 # take some samples, run them through the model # and add some noise num_samples = 50 y_data = real_y.pdf.random(num_samples) y_err = np.ones(len(y_data)) * 0.1 # [0.1, 0.1, 0.1,...] y_data_noisy = y_data + y_err * np.random.randn(len(y_data)) # simulated noise y_caldata = np.column_stack((y_data_noisy, y_err)) z_data = model(real_x, y_data) z_err = np.ones(len(z_data)) z_data_noisy = z_data + z_err * np.random.randn(len(z_data)) # simulated noise # prior for x. Caltype is 'D' because x is not a stochastic.
def model(x, y, z): return x**2 + 0.75 * y**2 + 2 * y + x * y - 7 * z + 2 # experimental data for z=Normal(12,1) exp_x = np.array([ 5.29, 4.96, 5.3, 5.18, 4.93, 5.11, 4.98, 4.81, 5.27, 4.69, 5.06, 4.99, 4.87, 5.04, 5.15 ]) exp_y = np.array([ 3.51, 3.34, 3.45, 3.26, 3.45, 3.5, 3.37, 3.45, 3.42, 3.4, 3.2, 3.24, 3.39, 3.35, 3.4 ]) exp_data = np.array([ -18.28, -24.23, -24.5, -24.13, -25.36, -17.2, -16.5, -24.87, -16.25, -26.51, -12.3, -15.91, -27.96, -27.98, -34.41 ]) # measurement error for exp_data sigma = 0.1 # Create parameters. Pass experimental input data to # non-calibration parameters. x = puq.NormalParameter('x', 'x', mean=5, dev=0.2, caldata=exp_x) y = puq.NormalParameter('y', 'y', mean=3.4, dev=0.1, caldata=exp_y) z = puq.UniformParameter('z', 'z', min=5, max=20, caltype='S') [x, y, calibrated_z], kpdf = puq.calibrate([x, y, z], exp_data, sigma, model) print "Calibrated z is", calibrated_z
import puq import numpy as np import pylab def model(x): return (x-4)**3 # our real value of x real_x = puq.NormalParameter('x', 'x', mean=5, dev=0.1) # We take 25 samples of x num_samples = 25 x_data = real_x.pdf.lhs(num_samples) x_data.sort() # sort for easier plotting # compute z using our x samples z_data = model(x_data) # add some 'measurement' noise sigma = 0.1 z_data_noisy = z_data + sigma * np.random.randn(len(z_data)) # prior for x. All we assume is x is between 2 and 25 # caltype is 'S' because we want to calibrate # mean and deviation of x x = puq.UniformParameter('x', 'x', min=2, max=25, caltype='S') # do calibration [calibrated], kpdf = puq.calibrate([x], z_data_noisy, sigma, model) print(calibrated)