return dec # build a model representing 'truth' from ouq_models import WrapModel from surrogate import marc_surr as toy nx = 3 ny = None nargs = dict(nx=nx, ny=ny, rnd=False) model = WrapModel('model', toy, **nargs) # set the bounds from mystic.bounds import MeasureBounds bnd = MeasureBounds(xlb, xub, n=npts, wlb=wlb, wub=wub) ## moment-based constraints ## normcon = normalize_moments() ###momcons = constrain_moments(a_ave, a_var, a_ave_err, a_var_err) ###is_cons = constrained(a_ave, a_var, a_ave_err, a_var_err) #momcon0 = constrain_moments(a_ave, a_var, a_ave_err, a_var_err, idx=0) #momcon1 = constrain_moments(b_ave, b_var, b_ave_err, b_var_err, idx=1) #is_con0 = constrained(a_ave, a_var, a_ave_err, a_var_err, idx=0) #is_con1 = constrained(b_ave, b_var, b_ave_err, b_var_err, idx=1) #is_cons = lambda c: bool(additive(is_con0)(is_con1)(c)) momcons = constrain_expected(model, o_ave, o_ave_err, (bnd.lower, bnd.upper)) is_cons = constrained_out(model, o_ave, o_ave_err) ## index-based constraints ## # impose constraints sequentially (faster, but assumes are decoupled)
from misc import param, npts, wlb, wub, is_cons, scons from ouq import ExpectedValue from mystic.bounds import MeasureBounds from mystic.monitors import VerboseLoggingMonitor, Monitor, VerboseMonitor from mystic.termination import VTRChangeOverGeneration as VTRCOG from mystic.termination import Or, VTR, ChangeOverGeneration as COG param['opts']['termination'] = COG(1e-10, 100) #NOTE: short stop? param['npop'] = 80 #NOTE: increase if poor convergence param['stepmon'] = VerboseLoggingMonitor(1, 20, filename='log.txt', label='lower') # build bounds bnd = MeasureBounds((0, 1, 0, 0, 0)[:nx], (1, 10, 10, 10, 10)[:nx], n=npts[:nx], wlb=wlb[:nx], wub=wub[:nx]) # build a model representing 'truth', and generate some data #print("building truth F'(x|a')...") true = dict(mu=.01, sigma=0., zmu=-.01, zsigma=0.) truth = NoisyModel('truth', model=toy, nx=nx, ny=ny, **true) #print('sampling truth...') data = truth.sample([(0, 1), (1, 10)] + [(0, 10)] * (nx - 2), pts=-16) Ns = 25 #XXX: number of samples, when model has randomness # build a model that approximates 'truth' #print('building model F(x|a) of truth...') approx = dict(mu=-.05, sigma=0., zmu=.05, zsigma=0.) model = NoisyModel('model', model=toy, nx=nx, ny=ny, **approx) #print('building estimator G(x) from truth data...')
ny = 3 #from toys import cost5x1 as toy; nx = 5; ny = 1 #from toys import function5x1 as toy; nx = 5; ny = 1 #from toys import cost5 as toy; nx = 5; ny = None #from toys import function5 as toy; nx = 5; ny = None Ns = 25 # build a model representing 'truth' nargs = dict(nx=nx, ny=ny, rnd=False) model = WrapModel('model', toy, **nargs) # build a model of success, relative to the cutoff sargs = dict(cutoff=(.5, .5, .5), nx=nx, ny=ny) success = SuccessModel('success', model, **sargs) # calculate upper bound on expected success, where x[0] has uncertainty bnd = MeasureBounds((0, 0, 0, 0, 0), (1, 10, 10, 0, 10), n=npts, wlb=wlb, wub=wub) rnd = Ns if success.rnd else None d = ProbOfFailure(success, bnd, constraint=scons, cvalid=is_cons, samples=rnd) d.upper_bound(axis=0, **param) print("upper bound per axis:") for axis, solver in d._upper.items(): print("%s: %s @ %s" % (axis, -solver.bestEnergy, solver.bestSolution))