from __future__ import print_function import openturns as ot import otrobopt full_fun = ot.SymbolicFunction(['x', 'theta'], ['theta*x']) param_fun = ot.ParametricFunction(full_fun, [1], [1.0]) # Normal distribution associated to parameter theta dist_theta = ot.Normal(2.0, 1.0) # Definition of "analytical" mean measure associated to the parametric function mean_measure = otrobopt.MeanMeasure(param_fun, dist_theta) mean_measure_f = otrobopt.MeasureFunction(mean_measure) print(mean_measure_f) print(mean_measure_f.getInputDimension()) print(mean_measure_f.getOutputDimension()) x = [2.0] print(mean_measure_f(x)) print(mean_measure_f([x] * 10)) print(mean_measure_f.gradient(x)) ## Graphical comparison of both "analytical" and "discretized" mean measures #x_min = -2. #x_max = 2. #graph = ot.Graph() #graph.setGrid(True) #graph.setLegendPosition("topright")
measure = otrobopt.IndividualChanceMeasure(f, thetaDist, ot.GreaterOrEqual(), [0.95]) elif 'VarianceMeasure' == 'MeanStandardDeviationTradeoffMeasure': measure = otrobopt.MeanStandardDeviationTradeoffMeasure( f, thetaDist, [0.8]) elif 'VarianceMeasure' == 'QuantileMeasure': measure = otrobopt.QuantileMeasure(f, thetaDist, 0.99) else: measure = otrobopt.VarianceMeasure(f, thetaDist) N = 10 experiment = ot.LHSExperiment(N) factory = otrobopt.MeasureFactory(experiment) discretizedMeasure = factory.build(measure) continuous_measure = otrobopt.MeasureFunction(measure) discretized_measure = otrobopt.MeasureFunction(discretizedMeasure) x_min = -2.0 x_max = 2.0 n_points = 128 parametric_graph = f.draw(x_min, x_max, n_points) continuous_graph = continuous_measure.draw(x_min, x_max, n_points) discretized_graph = discretized_measure.draw(x_min, x_max, n_points) parametric_curve = parametric_graph.getDrawable(0) discretized_curve = discretized_graph.getDrawable(0) left_graph = ot.Graph(continuous_graph) left_graph.add(parametric_curve)
otrobopt.WorstCaseMeasure(f, ot.Uniform(-1.0, 4.0), False), otrobopt.JointChanceMeasure(f, ot.Normal(1.0, 1.0), ot.GreaterOrEqual(), 0.95), otrobopt.IndividualChanceMeasure(f, ot.Normal(1.0, 1.0), ot.GreaterOrEqual(), [0.95]), otrobopt.MeanStandardDeviationTradeoffMeasure(f, thetaDist, [0.8]), otrobopt.QuantileMeasure(f, thetaDist, 0.99) ] aggregated = otrobopt.AggregatedMeasure(measures) measures.append(aggregated) for measure in measures: myStudy.add('measure' + measure.__class__.__name__, measure) measure2 = otrobopt.MeanMeasure(f, thetaDist) measureFunction = otrobopt.MeasureFunction(measure2) myStudy.add('measureFunction', measureFunction) calJ = ot.SymbolicFunction( ['x1', 'x2'], ['15.0 * (x1^2 + x2^2) - 100.0 * exp(-5. * ((x1 + 1.6)^2+(x2 + 1.6)^2))']) # This is calligraphic G, the non-robust inequality constraints function calG = ot.SymbolicFunction( ['x1', 'x2'], ['(x1 - 0.5)^2 + x2^2 - 4.0', '(x1 + 0.5)^2 + x2^2 - 4.0']) # This is the perturbation function noise = ot.SymbolicFunction(['x1', 'x2', 'xi1', 'xi2'], ['x1 + xi1', 'x2 + xi2']) # This is capital J: J(x,xi) = calJ(x+xi), the parametric objective function JFull = ot.ComposedFunction(calJ, noise) J = ot.ParametricFunction(JFull, [2, 3], [0.0] * 2) # This is g, the parametric constraints