forked from pystra/pystra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.py
executable file
·65 lines (48 loc) · 2.06 KB
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/python -tt
# -*- coding: utf-8 -*-
# import pyre library
from pyre import *
import time
import datetime
start_time = time.time()
def example_limitstatefunction(X1,X2,X3):
"""
example limit state function
"""
return 1 - X2*(1000*X3)**(-1) - (X1*(200*X3)**(-1))**2
# Define a main() function.
def main():
# Define limit state function
# - case 1: define directly as lambda function
#limit_state = LimitState(lambda X1,X2,X3: 1 - X2*(1000*X3)**(-1) - (X1*(200*X3)**(-1))**2)
# - case 2: use predefined function
limit_state = LimitState(example_limitstatefunction)
# Set some options (optional)
options = AnalysisOptions()
# options.printResults(False)
stochastic_model = StochasticModel()
# Define random variables
stochastic_model.addVariable( Lognormal('X1',500,100) )
stochastic_model.addVariable( Normal('X2',2000,400) )
stochastic_model.addVariable( Uniform('X3',5,0.5) )
# If the random variables are correlatet, then define a correlation matrix,
# else no correlatin matrix is needed
stochastic_model.setCorrelation( CorrelationMatrix([[1.0, 0.3, 0.2],
[0.3, 1.0, 0.2],
[0.2, 0.2, 1.0]]) )
# Performe FORM analysis
#Analysis = Form(analysis_options=options, stochastic_model=stochastic_model, limit_state=limit_state)
# Performe Distribution analysis
# Analysis = DistributionAnalysis(analysis_options=options, stochastic_model=stochastic_model, limit_state=limit_state)
# Performe Crude Monte Carlo Simulation
# Analysis = CrudeMonteCarlo(analysis_options=options, stochastic_model=stochastic_model, limit_state=limit_state)
# Performe Importance Sampling
# Analysis = ImportanceSampling(analysis_options=options, stochastic_model=stochastic_model, limit_state=limit_state)
# Some single results:
# beta = Analysis.getBeta()
# failure = Analysis.getFailure()
run_time = time.time() - start_time
print str(datetime.timedelta(seconds=run_time))
# This is the standard boilerplate that calls the main() function.
if __name__ == '__main__':
main()