#!/usr/bin/env python

from __future__ import print_function
import openturns as ot
import otrobopt

# First test: theta of dimension 1
thetaDist = ot.Normal(2.0, 0.1)
f_base = ot.SymbolicFunction(['x', 'theta'], ['x*theta'])
f = ot.ParametricFunction(f_base, [1], [1.0])

x = [1.0]

measures = [otrobopt.MeanMeasure(f, thetaDist),
            otrobopt.VarianceMeasure(f, thetaDist),
            otrobopt.WorstCaseMeasure(f, ot.Uniform(-1.0, 4.0)),
            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:
    print(measure, '(continuous)', measure(x))
    N = 10000
    experiment = ot.LHSExperiment(N)
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")
Exemple #3
0
import otrobopt

#ot.Log.Show(ot.Log.Info)


calJ = ot.SymbolicFunction(['x', 'theta'], ['x^3 - 3*x + theta'])
calG = ot.SymbolicFunction(['x', 'theta'], ['-(x + theta - 2)'])
J = ot.ParametricFunction(calJ, [1], [0.5])
g = ot.ParametricFunction(calG, [1], [0.5])

dim = J.getInputDimension()


solver = ot.Cobyla()
solver.setMaximumIterationNumber(1000)
solver.setStartingPoint([0.0] * dim)

thetaDist = ot.Exponential(2.0)
robustnessMeasure = otrobopt.MeanMeasure(J, thetaDist)
reliabilityMeasure = otrobopt.JointChanceMeasure(g, thetaDist, ot.Greater(), 0.9)
problem = otrobopt.RobustOptimizationProblem(robustnessMeasure, reliabilityMeasure)
problem.setMinimization(False)

algo = otrobopt.SequentialMonteCarloRobustAlgorithm(problem, solver)
algo.setMaximumIterationNumber(10)
algo.setMaximumAbsoluteError(1e-3)
algo.setInitialSamplingSize(10)
algo.run()
result = algo.getResult()
print ('x*=', result.getOptimalPoint(), 'J(x*)=', result.getOptimalValue(), 'iteration=', result.getIterationNumber())
Exemple #4
0
import openturns as ot
import otrobopt
import os

fileName = 'myStudy.xml'

# Create a Study Object
myStudy = ot.Study()
myStudy.setStorageManager(ot.XMLStorageManager(fileName))

thetaDist = ot.Normal(2.0, 0.1)
f_base = ot.SymbolicFunction(['x', 'theta'], ['x*theta'])
f = ot.ParametricFunction(f_base, [1], [1.0])

measures = [
    otrobopt.MeanMeasure(f, thetaDist),
    otrobopt.VarianceMeasure(f, thetaDist),
    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)
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
thetaDist = ot.Normal(2.0, 0.1)

# Definition of "analytical" mean measure associated to the parametric function
mean_measure = otrobopt.MeanMeasure(param_fun, thetaDist)
variance_measure = otrobopt.VarianceMeasure(param_fun, thetaDist)
# Definition of "discretized" mean measure
N = 10
experiment = ot.LHSExperiment(thetaDist, N)
factory = otrobopt.MeasureFactory(experiment)
discretized_mean_measure_evaluation = factory.build(mean_measure)

coll = [mean_measure, variance_measure]
discretizedColl = factory.buildCollection(coll)
print(coll)

x = [1.0]
print(otrobopt.AggregatedMeasure(coll)(x))
Exemple #6
0
f_base = ot.SymbolicFunction(['x', 'theta'], ['x*theta'])
f = ot.ParametricFunction(f_base, [1], thetaDist.getMean())

if 'MeanMeasure' == 'JointChanceMeasure':
    measure = otrobopt.JointChanceMeasure(f, thetaDist, ot.GreaterOrEqual(),
                                          0.95)
elif 'MeanMeasure' == 'IndividualChanceMeasure':
    measure = otrobopt.IndividualChanceMeasure(f, thetaDist,
                                               ot.GreaterOrEqual(), [0.95])
elif 'MeanMeasure' == 'MeanStandardDeviationTradeoffMeasure':
    measure = otrobopt.MeanStandardDeviationTradeoffMeasure(
        f, thetaDist, [0.8])
elif 'MeanMeasure' == 'QuantileMeasure':
    measure = otrobopt.QuantileMeasure(f, thetaDist, 0.99)
else:
    measure = otrobopt.MeanMeasure(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)