Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SimulationSensitivityAnalysis is not really working with SystemEvent #2638

Open
adumasphi opened this issue Apr 30, 2024 · 1 comment
Open
Labels

Comments

@adumasphi
Copy link
Contributor

What happened?

When computing a probability with a system event, the sensitivity analysis is really difficult to apply because the history sample seems not to be propagated inside the result object.
Two constructors on the 3 given are not working at all.

How to reproduce the issue?

import openturns as ot

dim = 2
X = ot.RandomVector(ot.Normal(dim))
f1 = ot.MemoizeFunction(ot.SymbolicFunction(['x1', 'x2'], ['x1']))
f2 = ot.MemoizeFunction(ot.SymbolicFunction(['x1', 'x2'], ['x2']))
Y1 = ot.CompositeRandomVector(f1, X)
Y2 = ot.CompositeRandomVector(f2, X)
e1 = ot.ThresholdEvent(Y1, ot.Less(), 0.0)
e2 = ot.ThresholdEvent(Y2, ot.Greater(), 0.0)
event = ot.UnionEvent([e1, e2])

algo = ot.ProbabilitySimulationAlgorithm(event)
algo.setMaximumOuterSampling(150)
algo.setBlockSize(4)
algo.setMaximumCoefficientOfVariation(0.1)
algo.run()
result = algo.getResult()

# First constructor
# get the history from the result event is not possible
f_event = ot.MemoizeFunction(result.getEvent().getImplementation().asComposedEvent().getFunction())
print(f_event.getCacheInput().getSize())  # --> size = 0
# the event output should be the one of the composite function
# --> it is complicated to get the history, I must recompute it using the event
input_sample = f1.getInputHistory()
output_sample = event.asComposedEvent().getFunction()(input_sample)
ssa = ot.SimulationSensitivityAnalysis(event.asComposedEvent(), input_sample, output_sample)

# second constructor not working : empty samples and maybe not ideal
# to use the getImplementation anyway
ssa = ot.SimulationSensitivityAnalysis(result.getEvent().getImplementation().asComposedEvent())

# third constructor not working
ssa = ot.SimulationSensitivityAnalysis(result)

Version

1.22

Operating System

Linux

Installation media

conda

Additional Context

No response

@adumasphi adumasphi added the bug label Apr 30, 2024
@jschueller
Copy link
Member

jschueller commented May 2, 2024

A solution is to re-assemble a threshold event from the composed function with a memoize on top:

import openturns as ot

dim = 2
X = ot.RandomVector(ot.Normal(dim))
f1 = ot.SymbolicFunction(['x1', 'x2'], ['x1'])
f2 = ot.SymbolicFunction(['x1', 'x2'], ['x2'])
Y1 = ot.CompositeRandomVector(f1, X)
Y2 = ot.CompositeRandomVector(f2, X)
e1 = ot.ThresholdEvent(Y1, ot.Less(), 0.0)
e2 = ot.ThresholdEvent(Y2, ot.Greater(), 0.0)
event = ot.UnionEvent([e1, e2])

# rebuild event with memoize
event = event.asComposedEvent()
fm = ot.MemoizeFunction(event.getFunction())
crv = ot.CompositeRandomVector(fm, event.getAntecedent())
event = ot.ThresholdEvent(crv, event.getOperator(), event.getThreshold())

algo = ot.ProbabilitySimulationAlgorithm(event)
algo.setMaximumOuterSampling(150)
algo.setBlockSize(4)
algo.setMaximumCoefficientOfVariation(0.1)
algo.run()
result = algo.getResult()

x = fm.getInputHistory()
y = fm.getOutputHistory()
ssa = ot.SimulationSensitivityAnalysis(event, x, y)
print(ssa.computeImportanceFactors())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants