1 #@ AJOUT OpenturnsSolver Macro
2 # -*- coding: iso-8859-1 -*-
6 Ce module contient le generateur Etude pour Openturns
13 defaultSTD = """#! /usr/bin/env python
15 class StudyFileGenerationError:
16 def __init__ (self, st):
19 return "'%s'" % self.st
21 raise StudyFileGenerationError, "The study file was not generated"
24 headerSTD = """#! /usr/bin/env python
26 # Chargement du module systeme
28 sys.path.append( '%s' )
30 # Chargement du module math
33 # Chargement du module Open TURNS
34 from openturns import *
35 from openturns_viewer import ViewImage,StopViewer,WaitForViewer
41 # Terminaison du fichier
45 #=============================================
46 # La classe de creation du fichier STD
47 #=============================================
52 Generation du fichier python
54 def __init__ (self, appli, DictMCVal, ListeVariables, DictLois ) :
55 self.DictMCVal = DictMCVal
56 self.ListeVariables = ListeVariables
57 self.DictLois = DictLois
58 print "DictMCVal=", DictMCVal
59 print "ListeVariables=", ListeVariables
60 print "DictLois=", DictLois
61 self.texteSTD = defaultSTD
62 self.OpenTURNS_path = appli.CONFIGURATION.OpenTURNS_path
64 # Ce dictionnaire fait la correspondance entre le mot lu dans le dictionnaire des mots-clefs et la methode a appeler
68 { "Experiment Plane" : "ExperimentPlane",
69 "Random Sampling" : "MinMaxRandomSampling",
72 "Central Uncertainty" :
73 ( "CentralUncertainty",
74 { "Taylor Variance Decomposition" : "TaylorVarianceDecomposition",
75 "Random Sampling" : "CentralUncertaintyRandomSampling",
78 "Threshold Exceedence" :
79 ( "ThresholdExceedence",
80 { "Simulation" : "Simulation",
81 "Analytical" : "Analytical",
82 "MonteCarlo" : "MonteCarlo",
84 "ImportanceSampling" : "ImportanceSampling",
85 "FirstOrder" : "FORM",
86 "SecondOrder" : "SORM",
88 "AbdoRackwitz" : "AbdoRackwitz",
93 # Ce dictionnaire liste le nom des variables utilisees dans le script
94 # La clef est le nom attendu par les methodes, la valeur est le nom produit dans le fichier de sortie
95 # Le fait de passer par un dictionnaire permet de controler que les variables existent et sont correctement nommees
96 # meme si clef == valeur
101 "scaledVector" : "scaledVector",
102 "translationVector" : "translationVector",
104 "myCenteredReductedGrid" : "myCenteredReductedGrid",
105 "myExperimentPlane" : "myExperimentPlane",
106 "inputSample" : "inputSample",
107 "outputSample" : "outputSample",
108 "minValue" : "minValue",
109 "maxValue" : "maxValue",
112 "distribution" : "distribution",
113 "marginal" : "marginal",
114 "collection" : "collection",
116 "inputRandomVector" : "inputRandomVector",
117 "outputRandomVector" : "outputRandomVector",
118 "myQuadraticCumul" : "myQuadraticCumul",
119 "meanFirstOrder" : "meanFirstOrder",
120 "meanSecondOrder" : "meanSecondOrder",
121 "standardDeviationFirstOrder" : "standardDeviationFirstOrder",
122 "importanceFactors" : "importanceFactors",
123 "importanceFactorsGraph" : "importanceFactorsGraph",
124 "importanceFactorsDrawing" : "importanceFactorsDrawing",
125 "empiricalMean" : "empiricalMean",
126 "empiricalStandardDeviation" : "empiricalStandardDeviation",
127 "empiricalQuantile" : "empiricalQuantile",
130 "PCCcoefficient" : "PCCcoefficient",
131 "PRCCcoefficient" : "PRCCcoefficient",
132 "SRCcoefficient" : "SRCcoefficient",
133 "SRRCcoefficient" : "SRRCcoefficient",
135 "kernelSmoothedDist" : "kernelSmoothedDist",
136 "kernelSmoothedPDF" : "kernelSmoothedPDF",
137 "myEvent" : "myEvent",
139 "myResult" : "myResult",
140 "probability" : "probability",
141 "standardDeviation" : "standardDeviation",
144 "coefficientOfVariation" : "coefficientOfVariation",
145 "convergenceGraph" : "convergenceGraph",
146 "iterations" : "iterations",
147 "myOptimizer" : "myOptimizer",
148 "specificParameters" : "specificParameters",
149 "startingPoint" : "startingPoint",
150 "hasoferReliabilityIndex" : "hasoferReliabilityIndex",
151 "standardSpaceDesignPoint" : "standardSpaceDesignPoint",
152 "physicalSpaceDesignPoint" : "physicalSpaceDesignPoint",
153 "eventProbabilitySensitivity" : "eventProbabilitySensitivity",
154 "hasoferReliabilityIndexSensitivity" : "hasoferReliabilityIndexSensitivity",
155 "eventProbabilitySensitivityGraph" : "eventProbabilitySensitivityGraph",
156 "hasoferReliabilityIndexSensitivityGraph" : "hasoferReliabilityIndexSensitivityGraph",
157 "modelEvaluationCalls" : "modelEvaluationCalls",
158 "modelGradientCalls" : "modelGradientCalls",
159 "modelHessianCalls" : "modelHessianCalls",
160 "tvedtApproximation" : "tvedtApproximation",
161 "hohenBichlerApproximation" : "hohenBichlerApproximation",
162 "breitungApproximation" : "breitungApproximation",
165 # Ce dictionnaire fait la correspondance entre le mot-clef du catalogue et le flag de la bibliotheque
167 "DebugMessages" : "Log.DBG",
168 "WrapperMessages" : "Log.WRAPPER",
169 "UserMessages" : "Log.USER",
170 "InfoMessages" : "Log.INFO",
171 "WarningMessages" : "Log.WARN",
172 "ErrorMessages" : "Log.ERROR",
177 Pilotage de la creation du fichier python
180 if ( self.DictMCVal.has_key( 'Type' ) ):
181 TypeAnalyse = self.DictMCVal[ 'Type' ]
185 if ( self.traitement.has_key( TypeAnalyse ) ):
186 (Traitement, subDict) = self.traitement[ TypeAnalyse ]
188 if ( Traitement is not None ):
189 self.texteSTD = apply( STDGenerateur.__dict__[ Traitement ], (self, subDict) )
195 Imprime l entete commun a tous les fichiers
197 txt = headerSTD % self.OpenTURNS_path
198 txt += "# Definit le niveau d'affichage de la log\n"
199 txt += "%s = Log.NONE\n" % self.variable["flags"]
200 for flag in self.logFlags.keys():
201 if ( self.DictMCVal.has_key( flag ) ):
202 val = self.DictMCVal[ flag ]
206 txt += "%s = %s %s %s\n" % (self.variable["flags"], self.variable["flags"], op, self.logFlags[ flag ])
207 txt += "Log.Show( %s )\n" % self.variable["flags"]
213 Imprime le pied de page commun a tous les fichiers
217 def MinMax (self, subDict):
219 Produit le fichier study correspondant a une analyse Min/Max
222 txt += "# Etude 'Min/Max'\n"
227 if ( self.DictMCVal.has_key( 'Method' ) ):
228 Methode = self.DictMCVal[ 'Method' ]
231 if ( subDict.has_key( Methode ) ):
232 Traitement = subDict[ Methode ]
234 if ( Traitement is not None ):
235 txt += apply( STDGenerateur.__dict__[ Traitement ], (self,) )
237 txt += self.MinMaxComputation()
238 txt += self.MinMaxResult()
245 Importe le modele physique
248 if ( self.DictMCVal.has_key( 'FileName' ) ):
249 name = self.DictMCVal[ 'FileName' ]
250 fonction = name[name.rfind('/')+1:name.rfind('.xml')]
252 txt = "# Charge le modele physique\n"
253 txt += "%s = NumericalMathFunction( '%s' )\n" % (self.variable["model"], fonction)
254 txt += "%s = %s.getInputNumericalPointDimension()\n" % (self.variable["n"], self.variable["model"])
258 def ExperimentPlane (self):
260 Etude par plan d experience
262 txt = "# Etude par plan d'experience\n"
264 txt += self.CenteredReductedGrid()
265 txt += self.ScaledVector()
266 txt += self.TranslationVector()
267 txt += "%s = %s\n" % (self.variable["inputSample"], self.variable["myExperimentPlane"])
271 def MinMaxRandomSampling (self):
273 Etude par echantillonage aleatoire
276 if ( self.DictMCVal.has_key( 'PointsNumber' ) ):
277 size = self.DictMCVal[ 'PointsNumber' ]
279 txt = "# Etude par echantillonage aleatoire\n"
280 txt += self.InputDistribution()
281 txt += self.InputRandomVector()
282 txt += "%s = %d\n" % (self.variable["inSize"], size)
283 txt += "%s = %s.getNumericalSample( %s )\n" % (self.variable["inputSample"], self.variable["inputRandomVector"], self.variable["inSize"])
287 def InputDistribution (self):
289 Cree la loi jointe des variables d entree
291 txt = "# Definit la loi jointe des variables d'entree\n"
292 txt += "%s = DistributionCollection( %d )\n" % (self.variable["collection"], len( self.ListeVariables ))
296 for variable in self.ListeVariables:
297 nomVar = variable['ModelVariable'].get_name()
298 dictVariables[ nomVar ] = variable['Distribution']
301 sortedVarNames = dictVariables.keys()
302 sortedVarNames.sort()
303 for variable in sortedVarNames:
304 conceptloi = dictVariables[ variable ]
305 loi = self.DictLois[ conceptloi ]
306 if loi.has_key( 'Kind' ):
307 marginale = "%s_%d" % (self.variable["marginal"], i)
308 txt += "# Definit la loi marginale de la composante %d\n" % i
309 txt += "%s = %s\n" % (marginale, apply( STDGenerateur.__dict__[ loi[ 'Kind' ] ], (self, loi, i, self.variable["collection"]) ))
310 txt += "%s[ %d ] = Distribution( %s )\n" % (self.variable["collection"], i, marginale)
314 txt += self.Copula( len( self.ListeVariables ) )
316 txt += "# Definit la loi jointe\n"
317 txt += "%s = ComposedDistribution( %s, Copula( %s ) )\n" % (self.variable["distribution"], self.variable["collection"], self.variable["copula"])
321 def Copula (self, dimension):
323 Cree la copule de la loi jointe
325 txt = "# Definit la copule de la loi jointe\n"
326 txt += "%s = IndependentCopula( %d )\n" % (self.variable["copula"], dimension)
330 def InputRandomVector (self):
332 Cree le vector aleatoire d entree
334 txt = "# Definit le vecteur aleatoire d'entree\n"
335 txt += "%s = RandomVector( %s )\n" % (self.variable["inputRandomVector"], self.variable["distribution"])
339 def OutputRandomVector (self):
341 Cree le vector aleatoire de sortie
343 txt = "# Definit le vecteur aleatoire de sortie\n"
344 txt += "%s = RandomVector( %s, %s )\n" % (self.variable["outputRandomVector"], self.variable["model"], self.variable["inputRandomVector"])
348 def ScaledVector (self):
350 Definit les coefficients multiplicateurs par composante du vecteur
353 if ( self.DictMCVal.has_key( 'UnitsPerDimension' ) ):
354 unitsPerDimension = self.DictMCVal[ 'UnitsPerDimension' ]
355 dimension = len( unitsPerDimension )
357 txt = "# Definit les facteurs d'echelle dans chaque direction\n"
358 txt += "%s = NumericalPoint( %s )\n" % (self.variable["scaledVector"], self.variable["n"])
359 for i in range(dimension):
360 txt += "%s[%d] = %g\n" % (self.variable["scaledVector"], i, unitsPerDimension[i])
361 txt += "%s.scale( %s )\n" % (self.variable["myExperimentPlane"], self.variable["scaledVector"])
365 def TranslationVector (self):
367 Definit le vecteur de translation
370 if ( self.DictMCVal.has_key( 'Center' ) ):
371 center = self.DictMCVal[ 'Center' ]
372 dimension = len( center )
374 txt = "# Definit le vecteur de translation\n"
375 txt += "%s = NumericalPoint( %s )\n" % (self.variable["translationVector"], self.variable["n"])
376 for i in range(dimension):
377 txt += "%s[%d] = %g\n" % (self.variable["translationVector"], i, center[i])
378 txt += "%s.translate( %s )\n" % (self.variable["myExperimentPlane"], self.variable["translationVector"])
384 Definit les niveaux du plan d experience
387 if ( self.DictMCVal.has_key( 'Levels' ) ):
388 levels = self.DictMCVal[ 'Levels' ]
389 dimension = len( levels )
391 txt = "# Definit les niveaux de la structure de grille\n"
392 txt += "%s = NumericalPoint( %d )\n" % (self.variable["levels"], dimension)
393 for i in range(dimension):
394 txt += "%s[%d] = %g\n" % (self.variable["levels"], i, levels[i])
398 def CenteredReductedGrid (self):
400 Definit la grille reduite du plan d experience
403 if ( self.DictMCVal.has_key( 'ExperimentPlane' ) ):
404 plane = self.DictMCVal[ 'ExperimentPlane' ]
406 txt = "# Cree le plan d'experience centre reduit\n"
407 txt += "%s = %s(%s, %s)\n" % (self.variable["myCenteredReductedGrid"], plane, self.variable["n"], self.variable["levels"])
408 txt += "%s = %s.generate()\n" % (self.variable["myExperimentPlane"], self.variable["myCenteredReductedGrid"])
412 def MinMaxComputation (self):
414 Realise le calcul deterministe
417 txt += "%s = %s( %s )\n" % (self.variable["outputSample"], self.variable["model"], self.variable["inputSample"])
421 def MinMaxResult (self):
423 Produit les resultats de l etude
425 txt = "# Resultats\n"
426 txt += "%s = %s.getMin()\n" % (self.variable["minValue"], self.variable["outputSample"])
427 txt += "print '%s = ', %s\n" % (self.variable["minValue"], self.variable["minValue"])
429 txt += "%s = %s.getMax()\n" % (self.variable["maxValue"], self.variable["outputSample"])
430 txt += "print '%s = ', %s\n" % (self.variable["maxValue"], self.variable["maxValue"])
434 def CentralUncertainty (self, subDict):
436 Produit le fichier study correspondant a une analyse d incertitude en valeur centrale
439 txt += "# Etude 'Central Uncertainty'\n"
442 txt += self.InputDistribution()
443 txt += self.InputRandomVector()
444 txt += self.OutputRandomVector()
447 if ( self.DictMCVal.has_key( 'Method' ) ):
448 Methode = self.DictMCVal[ 'Method' ]
451 if ( subDict.has_key( Methode ) ):
452 Traitement = subDict[ Methode ]
454 if ( Traitement is not None ):
455 txt += apply( STDGenerateur.__dict__[ Traitement ], (self,) )
461 def TaylorVarianceDecomposition (self):
463 Etude par decomposition de Taylor
465 txt = "# Cumul quadratique (decomposition de Taylor)\n"
466 txt += "%s = QuadraticCumul( %s )\n" % (self.variable["myQuadraticCumul"], self.variable["outputRandomVector"])
468 txt += "# Resultats\n"
470 if ( self.DictMCVal.has_key( 'MeanFirstOrder' ) ):
471 if ( self.DictMCVal[ 'MeanFirstOrder' ] == "yes" ):
472 txt += "%s = %s.getMeanFirstOrder()\n" % (self.variable["meanFirstOrder"], self.variable["myQuadraticCumul"])
473 txt += "print '%s = ', %s\n" % (self.variable["meanFirstOrder"], self.variable["meanFirstOrder"])
476 if ( self.DictMCVal.has_key( 'MeanSecondOrder' ) ):
477 if ( self.DictMCVal[ 'MeanSecondOrder' ] == "yes" ):
478 txt += "%s = %s.getMeanSecondOrder()\n" % (self.variable["meanSecondOrder"], self.variable["myQuadraticCumul"])
479 txt += "print '%s = ', %s\n" % (self.variable["meanSecondOrder"], self.variable["meanSecondOrder"])
482 if ( self.DictMCVal.has_key( 'StandardDeviationFirstOrder' ) ):
483 if ( self.DictMCVal[ 'StandardDeviationFirstOrder' ] == "yes" ):
484 txt += "%s = %s.getCovariance()\n" % (self.variable["standardDeviationFirstOrder"], self.variable["myQuadraticCumul"])
485 txt += "dim = %s.getDimension()\n" % self.variable["standardDeviationFirstOrder"]
486 txt += "for i in range( dim ):\n"
487 txt += " %s[ i, i ] = math.sqrt( %s[ i, i ] )\n" % (self.variable["standardDeviationFirstOrder"], self.variable["standardDeviationFirstOrder"])
488 txt += "print '%s = ', %s\n" % (self.variable["standardDeviationFirstOrder"], self.variable["standardDeviationFirstOrder"])
491 if ( self.DictMCVal.has_key( 'NumericalResults' ) ):
492 if ( self.DictMCVal[ 'NumericalResults' ] == "yes" ):
493 txt += "if ( %s.getDimension() == 1):\n" % self.variable["outputRandomVector"]
494 txt += " %s = %s.getImportanceFactors()\n" % (self.variable["importanceFactors"], self.variable["myQuadraticCumul"])
495 txt += " print '%s = ', %s\n" % (self.variable["importanceFactors"], self.variable["importanceFactors"])
498 if ( self.DictMCVal.has_key( 'GraphicalResults' ) ):
499 if ( self.DictMCVal[ 'GraphicalResults' ] == "yes" ):
500 txt += "%s = %s.drawImportanceFactors()\n" % (self.variable["importanceFactorsGraph"], self.variable["myQuadraticCumul"])
501 txt += "Show( %s )\n" % self.variable["importanceFactorsGraph"]
502 txt += "%s.draw( '%s' )\n" % (self.variable["importanceFactorsGraph"], self.variable["importanceFactorsDrawing"])
503 txt += "ViewImage( %s.getBitmap() )\n" % self.variable["importanceFactorsGraph"]
504 txt += "print 'bitmap =', %s.getBitmap()\n" % self.variable["importanceFactorsGraph"]
505 txt += "print 'postscript =', %s.getPostscript()\n" % self.variable["importanceFactorsGraph"]
511 def CentralUncertaintyRandomSampling (self):
513 Etude par echantillonage aleatoire
516 if ( self.DictMCVal.has_key( 'PointsNumber' ) ):
517 size = self.DictMCVal[ 'PointsNumber' ]
519 txt = "# Echantillonnage aleatoire de la variable de sortie\n"
520 txt += "%s = %d\n" % (self.variable["inSize"], size)
521 txt += "%s = %s.getNumericalSample( %s )\n" % (self.variable["outputSample"], self.variable["outputRandomVector"], self.variable["inSize"])
524 if ( self.DictMCVal.has_key( 'EmpiricalMean' ) ):
525 if ( self.DictMCVal[ 'EmpiricalMean' ] == "yes" ):
526 txt += "%s = %s.computeMean()\n" % (self.variable["empiricalMean"], self.variable["outputSample"])
527 txt += "print '%s =', %s\n" % (self.variable["empiricalMean"], self.variable["empiricalMean"])
530 if ( self.DictMCVal.has_key( 'EmpiricalStandardDeviation' ) ):
531 if ( self.DictMCVal[ 'EmpiricalStandardDeviation' ] == "yes" ):
532 txt += "%s = %s.computeCovariance()\n" % (self.variable["empiricalStandardDeviation"], self.variable["outputSample"])
533 txt += "dim = %s.getDimension()\n" % self.variable["empiricalStandardDeviation"]
534 txt += "for i in range( dim ):\n"
535 txt += " %s[ i, i ] = math.sqrt( %s[ i, i ] )\n" % (self.variable["empiricalStandardDeviation"], self.variable["empiricalStandardDeviation"])
536 txt += "print '%s = ', %s\n" % (self.variable["empiricalStandardDeviation"], self.variable["empiricalStandardDeviation"])
539 if ( self.DictMCVal.has_key( 'EmpiricalQuantile_Order' ) ):
540 ordre = self.DictMCVal[ 'EmpiricalQuantile_Order' ]
541 txt += "%s = %s.computeQuantile( %s )\n" % (self.variable["empiricalQuantile"], self.variable["outputSample"], ordre)
542 txt += "print '%s =', %s\n" % (self.variable["empiricalQuantile"], self.variable["empiricalQuantile"])
545 if ( self.DictMCVal.has_key( 'AnalysedCorrelations' ) ):
546 if ( self.DictMCVal[ 'AnalysedCorrelations' ] == "yes" ):
547 txt += "# Ou est le %s ?\n" % self.variable["inputSample"]
548 txt += "#if ( ( %s.getDimension() == 1 ) and ( %s.getDimension() == 1 ) ):\n" % (self.variable["inputSample"], self.variable["outputSample"])
549 txt += "# %s = CorrelationAnalysis.PCC( %s, %s )\n" % (self.variable["PCCcoefficient"], self.variable["inputSample"], self.variable["outputSample"])
550 txt += "# print '%s = ', %s\n" % (self.variable["PCCcoefficient"], self.variable["PCCcoefficient"])
551 txt += "# %s = CorrelationAnalysis.PRCC( %s, %s )\n" % (self.variable["PRCCcoefficient"], self.variable["inputSample"], self.variable["outputSample"])
552 txt += "# print '%s = ', %s\n" % (self.variable["PRCCcoefficient"], self.variable["PRCCcoefficient"])
553 txt += "# %s = CorrelationAnalysis.SRC( %s, %s )\n" % (self.variable["SRCcoefficient"], self.variable["inputSample"], self.variable["outputSample"])
554 txt += "# print '%s = ', %s\n" % (self.variable["SRCcoefficient"], self.variable["SRCcoefficient"])
555 txt += "# %s = CorrelationAnalysis.SRRC( %s, %s )\n" % (self.variable["SRRCcoefficient"], self.variable["inputSample"], self.variable["outputSample"])
556 txt += "# print '%s = ', %s\n" % (self.variable["SRRCcoefficient"], self.variable["SRRCcoefficient"])
559 if ( self.DictMCVal.has_key( 'KernelSmoothing' ) ):
560 if ( self.DictMCVal[ 'KernelSmoothing' ] == "yes" ):
561 txt += "# Kernel Smoohing\n"
562 txt += "%s = KernelSmoothing()\n" % self.variable["kernel"]
563 txt += "if ( %s.getDimension() == 1 ):\n" % self.variable["outputSample"]
564 txt += " %s = %s.buildImplementation( %s, 'TRUE')\n" % (self.variable["kernelSmoothedDist"], self.variable["kernel"], self.variable["outputSample"])
565 txt += " %s = %s.drawPDF()\n" % (self.variable["kernelSmoothedPDF"], self.variable["kernelSmoothedDist"])
566 txt += " Show( %s )\n" % self.variable["kernelSmoothedPDF"]
571 def ThresholdExceedence (self, subDict):
573 Produit le fichier study correspondant a une analyse de depassement de seuil
576 txt += "# Etude 'Threshold Exceedence'\n"
578 txt += self.RandomGenerator()
580 txt += self.InputDistribution()
581 txt += self.InputRandomVector()
582 txt += self.OutputRandomVector()
586 if ( self.DictMCVal.has_key( 'Method' ) ):
587 Methode = self.DictMCVal[ 'Method' ]
590 if ( subDict.has_key( Methode ) ):
591 Traitement = subDict[ Methode ]
593 if ( Traitement is not None ):
594 txt += apply( STDGenerateur.__dict__[ Traitement ], (self, subDict) )
599 def Simulation (self, subDict):
601 Methodes de simulation
604 if ( self.DictMCVal.has_key( 'Algorithm' ) ):
605 Algorithme = self.DictMCVal[ 'Algorithm' ]
608 if ( subDict.has_key( Algorithme ) ):
609 Traitement = subDict[ Algorithme ]
611 if ( Traitement is not None ):
612 txt = apply( STDGenerateur.__dict__[ Traitement ], (self,) )
614 maxOuterSampling = None
615 if ( self.DictMCVal.has_key( 'MaximumOuterSampling' ) ):
616 maxOuterSampling = self.DictMCVal[ 'MaximumOuterSampling' ]
617 txt += "%s.setMaximumOuterSampling( %s )\n" % (self.variable["myAlgo"], maxOuterSampling)
620 if ( self.DictMCVal.has_key( 'BlockSize' ) ):
621 maxOuterSampling = self.DictMCVal[ 'BlockSize' ]
622 txt += "%s.setBlockSize( %s )\n" % (self.variable["myAlgo"], blockSize)
624 maxCoefficientOfVariation = None
625 if ( self.DictMCVal.has_key( 'MaximumCoefficientOfVariation' ) ):
626 maxCoefficientOfVariation = self.DictMCVal[ 'MaximumCoefficientOfVariation' ]
627 txt += "%s.setMaximumCoefficientOfVariation( %s )\n" % (self.variable["myAlgo"], maxCoefficientOfVariation)
629 txt += "%s.run()\n" % self.variable["myAlgo"]
631 txt += "# Resultats de la simulation\n"
632 txt += "%s = %s.getResult()\n" % (self.variable["myResult"], self.variable["myAlgo"])
635 if ( self.DictMCVal.has_key( 'Probability' ) ):
636 if ( self.DictMCVal[ 'Probability' ] == "yes" ):
637 txt += "%s = %s.getProbabilityEstimate()\n" % (self.variable["probability"], self.variable["myResult"])
638 txt += "print '%s =', %s\n" % (self.variable["probability"], self.variable["probability"])
641 if ( self.DictMCVal.has_key( 'StandardDeviation' ) ):
642 if ( self.DictMCVal[ 'StandardDeviation' ] == "yes" ):
643 txt += "%s = math.sqrt( %s.getProbabilityEstimate() )\n" % (self.variable["standardDeviation"], self.variable["myResult"])
644 txt += "print '%s =', %s\n" % (self.variable["standardDeviation"], self.variable["standardDeviation"])
647 if ( self.DictMCVal.has_key( 'ConfidenceInterval' ) and self.DictMCVal.has_key( 'Probability' ) ):
648 if ( ( self.DictMCVal[ 'ConfidenceInterval' ] == "yes" ) and ( self.DictMCVal[ 'Probability' ] == "yes" ) ):
649 level = self.DictMCVal[ 'Level' ]
650 txt += "%s = %s.getConfidenceLength( %s )\n" % (self.variable["length"], self.variable["myResult"], level)
651 txt += "print 'confidence interval at %s = [', %s-0.5*%s, ',', %s+0.5*%s, ']'\n" % (level, self.variable["probability"], self.variable["length"], self.variable["probability"], self.variable["length"])
654 if ( self.DictMCVal.has_key( 'VariationCoefficient' ) ):
655 if ( self.DictMCVal[ 'VariationCoefficient' ] == "yes" ):
656 txt += "%s = %s.getCoefficientOfVariation()\n" % (self.variable["coefficientOfVariation"], self.variable["myResult"])
657 txt += "print '%s =', %s\n" % (self.variable["coefficientOfVariation"], self.variable["coefficientOfVariation"])
660 if ( self.DictMCVal.has_key( 'IterationNumber' ) ):
661 if ( self.DictMCVal[ 'IterationNumber' ] == "yes" ):
662 txt += "%s = %s.getOuterSampling()\n" % (self.variable["iterations"], self.variable["myResult"])
663 txt += "print '%s =', %s\n" % (self.variable["iterations"], self.variable["iterations"])
666 if ( self.DictMCVal.has_key( 'ConvergenceGraph' ) ):
667 if ( self.DictMCVal[ 'ConvergenceGraph' ] == "yes" ):
668 txt += "%s = %s.drawProbabilityConvergence()\n" % (self.variable["convergenceGraph"], self.variable["myAlgo"])
669 txt += "Show( %s )\n" % self.variable["convergenceGraph"]
674 def Analytical (self, subDict):
680 OptimizationAlgo = None
681 if ( self.DictMCVal.has_key( 'OptimizationAlgorithm' ) ):
682 OptimizationAlgo = self.DictMCVal[ 'OptimizationAlgorithm' ]
685 if ( subDict.has_key( OptimizationAlgo ) ):
686 Traitement = subDict[ OptimizationAlgo ]
688 if ( Traitement is not None ):
689 txt += apply( STDGenerateur.__dict__[ Traitement ], (self,) )
691 txt += self.OptimizerSettings()
692 txt += self.PhysicalStartingPoint()
695 if ( self.DictMCVal.has_key( 'Approximation' ) ):
696 Approximation = self.DictMCVal[ 'Approximation' ]
699 if ( subDict.has_key( Approximation ) ):
700 Traitement = subDict[ Approximation ]
702 if ( Traitement is not None ):
703 txt += apply( STDGenerateur.__dict__[ Traitement ], (self,) )
705 txt += self.RunAlgorithm()
706 txt += self.AnalyticalResult()
710 def OptimizerSettings (self):
712 Parametrage de l optimiseur
717 if ( self.DictMCVal.has_key( 'MaximumIterationsNumber' ) ):
718 iterations = self.DictMCVal[ 'MaximumIterationsNumber' ]
719 txt += "%s.setMaximumIterationsNumber( %s )\n" % (self.variable["myOptimizer"], iterations)
722 if ( self.DictMCVal.has_key( 'MaximumAbsoluteError' ) ):
723 absoluteError = self.DictMCVal[ 'MaximumAbsoluteError' ]
724 txt += "%s.setMaximumAbsoluteError( %s )\n" % (self.variable["myOptimizer"], absoluteError)
727 if ( self.DictMCVal.has_key( 'MaximumRelativeError' ) ):
728 relativeError = self.DictMCVal[ 'MaximumRelativeError' ]
729 txt += "%s.setMaximumRelativeError( %s )\n" % (self.variable["myOptimizer"], relativeError)
732 if ( self.DictMCVal.has_key( 'MaximumResidualError' ) ):
733 residualError = self.DictMCVal[ 'MaximumResidualError' ]
734 txt += "%s.setMaximumResidualError( %s )\n" % (self.variable["myOptimizer"], residualError)
736 constraintError = None
737 if ( self.DictMCVal.has_key( 'MaximumConstraintError' ) ):
738 constraintError = self.DictMCVal[ 'MaximumConstraintError' ]
739 txt += "%s.setMaximumConstraintError( %s )\n" % (self.variable["myOptimizer"], constraintError)
745 def PhysicalStartingPoint (self):
747 Point physique de depart
749 txt = "# Point physique de depart\n"
751 if ( self.DictMCVal.has_key( 'PhysicalStartingPoint' ) ):
752 point = self.DictMCVal[ 'PhysicalStartingPoint' ]
753 dimension = len( point )
754 txt += "%s = NumericalPoint( %d )\n" % (self.variable["startingPoint"], dimension)
755 for i in range( dimension ):
756 txt += "%s[ %d ] = %g\n" % (self.variable["startingPoint"], i, point[i])
758 txt += "%s = %s.getMean()\n" % (self.variable["startingPoint"], self.variable["inputRandomVector"])
764 def AnalyticalResult (self):
766 Resultat des methodes analytiques
768 txt = "# Resultat des methodes analytiques\n"
769 txt += "%s = %s.getResult()\n" % (self.variable["myResult"], self.variable["myAlgo"])
771 if ( self.DictMCVal.has_key( 'Probability' ) ):
772 if ( self.DictMCVal[ 'Probability' ] == "yes" ):
773 txt += "%s = %s.getEventProbability()\n" % (self.variable["probability"], self.variable["myResult"])
774 txt += "print '%s =', %s\n" % (self.variable["probability"], self.variable["probability"])
777 if ( self.DictMCVal.has_key( 'HasoferReliabilityIndex' ) ):
778 if ( self.DictMCVal[ 'HasoferReliabilityIndex' ] == "yes" ):
779 txt += "%s = %s.getHasoferReliabilityIndex()\n" % (self.variable["hasoferReliabilityIndex"], self.variable["myResult"])
780 txt += "print '%s =', %s\n" % (self.variable["hasoferReliabilityIndex"], self.variable["hasoferReliabilityIndex"])
783 if ( self.DictMCVal.has_key( 'DesignPoint' ) ):
784 if ( self.DictMCVal[ 'DesignPoint' ] == "yes" ):
785 txt += "%s = %s.getStandardSpaceDesignPoint()\n" % (self.variable["standardSpaceDesignPoint"], self.variable["myResult"])
786 txt += "print '%s =', %s\n" % (self.variable["standardSpaceDesignPoint"], self.variable["standardSpaceDesignPoint"])
787 txt += "%s = %s.getPhysicalSpaceDesignPoint()\n" % (self.variable["physicalSpaceDesignPoint"], self.variable["myResult"])
788 txt += "print '%s =', %s\n" % (self.variable["physicalSpaceDesignPoint"], self.variable["physicalSpaceDesignPoint"])
791 if ( self.DictMCVal.has_key( 'ImportanceFactorNumericalResults' ) ):
792 if ( self.DictMCVal[ 'ImportanceFactorNumericalResults' ] == "yes" ):
793 txt += "%s = %s.getImportanceFactors()\n" % (self.variable["importanceFactors"], self.variable["myResult"])
794 txt += "print '%s =', %s\n" % (self.variable["importanceFactors"], self.variable["importanceFactors"])
797 if ( self.DictMCVal.has_key( 'ImportanceFactorGraphicalResults' ) ):
798 if ( self.DictMCVal[ 'ImportanceFactorGraphicalResults' ] == "yes" ):
799 txt += "%s = %s.drawImportanceFactors()\n" % (self.variable["importanceFactorsGraph"], self.variable["myResult"])
800 txt += "Show( %s )\n" % self.variable["importanceFactorsGraph"]
803 if ( self.DictMCVal.has_key( 'FORMEventProbabilitySensitivityNumericalResults' ) ):
804 if ( self.DictMCVal[ 'FORMEventProbabilitySensitivityNumericalResults' ] == "yes" ):
805 txt += "%s = %s.getEventProbabilitySensitivity()\n" % (self.variable["eventProbabilitySensitivity"], self.variable["myResult"])
806 txt += "print '%s =', %s\n" % (self.variable["eventProbabilitySensitivity"], self.variable["eventProbabilitySensitivity"])
809 if ( self.DictMCVal.has_key( 'FORMEventProbabilitySensitivityGraphicalResults' ) ):
810 if ( self.DictMCVal[ 'FORMEventProbabilitySensitivityGraphicalResults' ] == "yes" ):
811 txt += "%s = %s.drawEventProbabilitySensitivity()\n" % (self.variable["eventProbabilitySensitivityGraph"], self.variable["myResult"])
812 txt += "Show( %s[0] )\n" % self.variable["eventProbabilitySensitivityGraph"]
815 if ( self.DictMCVal.has_key( 'HasoferReliabilityIndexSensitivityNumericalResults' ) ):
816 if ( self.DictMCVal[ 'HasoferReliabilityIndexSensitivityNumericalResults' ] == "yes" ):
817 txt += "%s = %s.getHasoferReliabilityIndexSensitivity()\n" % (self.variable["hasoferReliabilityIndexSensitivity"], self.variable["myResult"])
818 txt += "print '%s =', %s\n" % (self.variable["hasoferReliabilityIndexSensitivity"], self.variable["hasoferReliabilityIndexSensitivity"])
821 if ( self.DictMCVal.has_key( 'HasoferReliabilityIndexSensitivityGraphicalResults' ) ):
822 if ( self.DictMCVal[ 'HasoferReliabilityIndexSensitivityGraphicalResults' ] == "yes" ):
823 txt += "%s = %s.drawHasoferReliabilityIndexSensitivity()\n" % (self.variable["hasoferReliabilityIndexSensitivityGraph"], self.variable["myResult"])
824 txt += "Show( %s[0] )\n" % self.variable["hasoferReliabilityIndexSensitivityGraph"]
827 if ( self.DictMCVal.has_key( 'TvedtApproximation' ) ):
828 if ( self.DictMCVal[ 'TvedtApproximation' ] == "yes" ):
829 txt += "%s = %s.getEventProbabilityTvedt()\n" % (self.variable["tvedtApproximation"], self.variable["myResult"])
830 txt += "print '%s =', %s\n" % (self.variable["tvedtApproximation"], self.variable["tvedtApproximation"])
833 if ( self.DictMCVal.has_key( 'HohenBichlerApproximation' ) ):
834 if ( self.DictMCVal[ 'HohenBichlerApproximation' ] == "yes" ):
835 txt += "%s = %s.getEventProbabilityHohenBichler()\n" % (self.variable["hohenBichlerApproximation"], self.variable["myResult"])
836 txt += "print '%s =', %s\n" % (self.variable["hohenBichlerApproximation"], self.variable["tvedtApproximation"])
839 if ( self.DictMCVal.has_key( 'BreitungApproximation' ) ):
840 if ( self.DictMCVal[ 'BreitungApproximation' ] == "yes" ):
841 txt += "%s = %s.getEventProbabilityBreitung()\n" % (self.variable["breitungApproximation"], self.variable["myResult"])
842 txt += "print '%s =', %s\n" % (self.variable["breitungApproximation"], self.variable["breitungApproximation"])
848 def RandomGenerator (self):
855 if ( self.DictMCVal.has_key( 'RandomGeneratorSeed' ) ):
856 seed = self.DictMCVal[ 'RandomGeneratorSeed' ]
857 txt += "# Initialise le generateur aleatoire\n"
858 txt += "RandomGenerator.SetSeed( %s )\n" % seed
865 Definition de l evenement de defaillance
868 if ( self.DictMCVal.has_key( 'ComparisonOperator' ) ):
869 operator = self.DictMCVal[ 'ComparisonOperator' ]
872 if ( self.DictMCVal.has_key( 'Threshold' ) ):
873 threshold = self.DictMCVal[ 'Threshold' ]
875 txt = "# Evenement de defaillance\n"
876 txt += "%s = Event( %s, ComparisonOperator( %s() ), %s )\n" % (self.variable["myEvent"], self.variable["outputRandomVector"], operator, threshold)
880 def MonteCarlo (self):
882 Methode de MonteCarlo
884 txt = "# Simulation par MonteCarlo\n"
885 txt += "%s = MonteCarlo( %s )\n" % (self.variable["myAlgo"], self.variable["myEvent"])
894 txt = "# Simulation par LHS\n"
895 txt += "%s = LHS( %s )\n" % (self.variable["myAlgo"], self.variable["myEvent"])
900 def ImportanceSampling (self):
902 Methode de tirage d importance
904 txt = "# Simulation par Tirage d'importance\n"
905 txt += "%s = ImportanceSampling( %s )\n" % (self.variable["myAlgo"], self.variable["myEvent"])
914 txt = "# Algorithme FORM\n"
915 txt += "%s = FORM ( NearestPointAlgorithm( %s ), %s, %s )\n" % (self.variable["myAlgo"], self.variable["myOptimizer"], self.variable["myEvent"], self.variable["startingPoint"])
924 txt = "# Algorithme SORM\n"
925 txt += "%s = SORM ( NearestPointAlgorithm( %s ), %s, %s )\n" % (self.variable["myAlgo"], self.variable["myOptimizer"], self.variable["myEvent"], self.variable["startingPoint"])
930 def RunAlgorithm (self):
934 if ( self.DictMCVal.has_key( 'FunctionCallsNumber' ) ):
935 if ( self.DictMCVal[ 'FunctionCallsNumber' ] == "yes" ):
936 txt = "%s = %s.getEvaluationCallsNumber()\n" % (self.variable["modelEvaluationCalls"], self.variable["model"])
937 txt += "%s = %s.getGradientCallsNumber()\n" % (self.variable["modelGradientCalls"], self.variable["model"])
938 txt += "%s = %s.getHessianCallsNumber()\n" % (self.variable["modelHessianCalls"], self.variable["model"])
941 txt += "# Perform the computation\n"
942 txt += "%s.run()\n" % self.variable["myAlgo"]
946 if ( self.DictMCVal.has_key( 'FunctionCallsNumber' ) ):
947 if ( self.DictMCVal[ 'FunctionCallsNumber' ] == "yes" ):
948 txt += "%s = %s.getEvaluationCallsNumber() - %s\n" % (self.variable["modelEvaluationCalls"], self.variable["model"], self.variable["modelEvaluationCalls"])
949 txt += "%s = %s.getGradientCallsNumber() - %s\n" % (self.variable["modelGradientCalls"], self.variable["model"], self.variable["modelGradientCalls"])
950 txt += "%s = %s.getHessianCallsNumber() - %s\n" % (self.variable["modelHessianCalls"], self.variable["model"], self.variable["modelHessianCalls"])
952 txt += "print '%s =', %s\n" % (self.variable["modelEvaluationCalls"], self.variable["modelEvaluationCalls"])
953 txt += "print '%s =', %s\n" % (self.variable["modelGradientCalls"], self.variable["modelGradientCalls"])
954 txt += "print '%s =', %s\n" % (self.variable["modelHessianCalls"], self.variable["modelHessianCalls"])
963 txt = "# Optimisation par Cobyla\n"
964 txt += "%s = Cobyla()\n" % self.variable["myOptimizer"]
965 txt += "#%s = CobylaSpecificParameters()\n" % self.variable["specificParameters"]
966 txt += "#%s.setSpecificParameters( %s )\n" % (self.variable["myOptimizer"], self.variable["specificParameters"])
971 def AbdoRackwitz (self):
975 txt = "# Optimisation par AbdoRackwitz\n"
976 txt += "%s = AbdoRackwitz()\n" % self.variable["myOptimizer"]
977 txt += "#%s = AbdoRackwitzSpecificParameters()\n" % self.variable["specificParameters"]
978 txt += "#%s.setSpecificParameters( %s )\n" % (self.variable["myOptimizer"], self.variable["specificParameters"])
982 def Beta (self, loi, i, collection):
984 Definition de la loi Beta
988 "MuSigma" : "Beta.MUSIGMA",
990 if loi[ 'Settings' ] == 'RT' :
995 arg2 = loi[ 'Sigma' ]
999 txt = "Beta( %g, %g, %g, %g, %s )" % (arg1, arg2, arg3, arg4, settings[ loi[ 'Settings' ] ])
1002 def Exponential (self, loi, i, collection):
1004 Definition de la loi Exponential
1006 arg1 = loi[ 'Lambda' ]
1007 arg2 = loi[ 'Gamma' ]
1008 txt = "Exponential( %g, %g )" % (arg1, arg2)
1011 def Gamma (self, loi, i, collection):
1013 Definition de la loi Gamma
1016 "KLambda" : "Gamma.KLAMBDA",
1017 "MuSigma" : "Gamma.MUSIGMA",
1019 if loi[ 'Settings' ] == 'KLambda' :
1021 arg2 = loi[ 'Lambda' ]
1024 arg2 = loi[ 'Sigma' ]
1026 arg3 = loi[ 'Gamma' ]
1027 txt = "Gamma( %g, %g, %g, %s )" % (arg1, arg2, arg3, settings[ loi[ 'Settings' ] ])
1030 def Geometric (self, loi, i, collection):
1032 Definition de la loi Geometric
1034 txt = "Geometric( %g )" % loi[ 'P' ]
1037 def Gumbel (self, loi, i, collection):
1039 Definition de la loi Gumbel
1042 "AlphaBeta" : "Gamma.ALPHABETA",
1043 "MuSigma" : "Gamma.MUSIGMA",
1045 if loi[ 'Settings' ] == 'AlphaBeta' :
1046 arg1 = loi[ 'Alpha' ]
1047 arg2 = loi[ 'Beta' ]
1050 arg2 = loi[ 'Sigma' ]
1052 txt = "Gamma( %g, %g, %s )" % (arg1, arg2, settings[ loi[ 'Settings' ] ])
1055 def Histogram (self, loi, i, collection):
1057 Definition de la loi Histogram
1059 txt = "** Histogram not defined yet **"
1062 def Logistic (self, loi, i, collection):
1064 Definition de la loi Logistic
1066 arg1 = loi[ 'Alpha' ]
1067 arg2 = loi[ 'Beta' ]
1068 txt = "Logistic( %g, %g )" % (arg1, arg2)
1071 def LogNormal (self, loi, i, collection):
1073 Definition de la loi LogNormal
1076 "MuSigmaLog" : "LogNormal.MUSIGMA_LOG",
1077 "MuSigma" : "LogNormal.MUSIGMA",
1078 "MuSigmaOverMu" : "LogNormal.MU_SIGMAOVERMU",
1080 if loi[ 'Settings' ] == 'MuSigmaLog' :
1081 arg1 = loi[ 'MuLog' ]
1082 arg2 = loi[ 'SigmaLog' ]
1083 elif loi[ 'Settings' ] == 'MuSigmaOverMu' :
1085 arg2 = loi[ 'SigmaOverMu' ]
1088 arg2 = loi[ 'Sigma' ]
1090 arg3 = loi[ 'Gamma' ]
1091 txt = "LogNormal( %g, %g, %g, %s )" % (arg1, arg2, arg3, settings[ loi[ 'Settings' ] ])
1094 def MultiNomial (self, loi, i, collection):
1096 Definition de la loi MultiNomial
1098 arg1 = loi[ 'Values' ]
1100 txt = "MultiNomial( NumericalPoint( %s ) , %d)" % (arg1, arg2)
1103 def Normal (self, loi, i, collection):
1105 Definition de la loi Normal
1108 arg2 = loi[ 'Sigma' ]
1109 txt = "Normal( %g, %g )" % (arg1, arg2)
1112 def TruncatedNormal (self, loi, i, collection):
1114 Definition de la loi TruncatedNormal
1117 arg2 = loi[ 'SigmaN' ]
1120 txt = "TruncatedNormal( %g, %g, %g, %g )" % (arg1, arg2, arg3, arg4)
1123 def Poisson (self, loi, i, collection):
1125 Definition de la loi
1127 txt = "Poisson( %g )" % loi[ 'Lambda' ]
1130 def Student (self, loi, i, collection):
1132 Definition de la loi Student
1136 txt = "Student( %g, %g )" % (arg1, arg2)
1139 def Triangular (self, loi, i, collection):
1141 Definition de la loi Triangular
1146 txt = "Triangular( %g, %g, %g )" % (arg1, arg2, arg3)
1149 def Uniform (self, loi, i, collection):
1151 Definition de la loi Uniform
1155 txt = "Uniform( %g, %g )" % (arg1, arg2)
1158 def UserDefined (self, loi, i, collection):
1160 Definition de la loi UserDefined
1162 txt = "** UserDefined not defined yet **"
1165 def Weibull (self, loi, i, collection):
1167 Definition de la loi Weibull
1170 "AlphaBeta" : "Weibull.ALPHABETA",
1171 "MuSigma" : "Weibull.MUSIGMA",
1173 if loi[ 'Settings' ] == 'AlphaBeta' :
1174 arg1 = loi[ 'Alpha' ]
1175 arg2 = loi[ 'Beta' ]
1178 arg2 = loi[ 'Sigma' ]
1180 arg3 = loi[ 'Gamma' ]
1181 txt = "Weibull( %g, %g, %s )" % (arg1, arg2, arg3, settings[ loi[ 'Settings' ] ])