1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2013 EDF R&D
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 Ce module contient le generateur Etude pour Openturns
25 from Extensions.i18n import tr
29 defaultSTD = """#! /usr/bin/env python
31 class StudyFileGenerationError:
32 def __init__ (self, st):
35 return "'%s'" % self.st
37 raise StudyFileGenerationError, "The study file was not generated. Check analysis type."
40 headerSTD = """#! /usr/bin/env python
42 # Chargement du module systeme
46 # Chargement du module math
49 # Chargement du module Open TURNS
50 from openturns import *
52 # Fonction verifiant si un echantillon contient des valeurs non valides (NaN)
53 def contain_nan_values(sample):
65 from openturns.viewer import View
67 # Fonction de test du serveur X
69 xserver_available = None
70 def is_xserver_available():
71 global xserver_available
72 if xserver_available is None:
73 xserver_available = True
75 subprocess.check_call('python -c "from matplotlib import pyplot;pyplot.figure()" >/dev/null 2>&1', shell = True)
77 xserver_available = False
78 return xserver_available
84 # Flush des messages en attente
87 # Terminaison du fichier
91 #=============================================
92 # La classe de creation du fichier STD
93 #=============================================
98 Generation du fichier python
100 def __init__ (self, appli, DictMCVal, ListeVariablesIn, ListeVariablesOut, DictLois ) :
101 self.DictMCVal = DictMCVal
102 self.ListeVariablesIn = ListeVariablesIn
103 self.ListeVariablesOut = ListeVariablesOut
104 self.DictLois = DictLois
105 #print "DictMCVal=", DictMCVal
106 print "ListeVariablesIn= %s", ListeVariablesIn
108 # A REPRENDRE DEPUIS ICI !!
109 print "ListeVariablesOut= %s", ListeVariablesOut
110 #print "DictLois=", DictLois
111 self.texteSTD = defaultSTD
112 self.OpenTURNS_path = appli.CONFIGURATION.OpenTURNS_path
114 # Ce dictionnaire fait la correspondance entre le mot lu dans le dictionnaire des mots-clefs et la methode a appeler
118 { "Experiment Plane" : "ExperimentPlane",
119 "Random Sampling" : "MinMaxRandomSampling",
122 "Central Uncertainty" :
123 ( "CentralUncertainty",
124 { "Taylor Variance Decomposition" : "TaylorVarianceDecomposition",
125 "Random Sampling" : "CentralUncertaintyRandomSampling",
128 "Threshold Exceedence" :
129 ( "ThresholdExceedence",
130 { "Simulation" : "Simulation",
131 "FORM_SORM" : "Analytical",
132 "MonteCarlo" : "MonteCarlo",
134 "ImportanceSampling" : "ImportanceSampling",
135 "FirstOrder" : "FORM",
136 "SecondOrder" : "SORM",
138 "AbdoRackwitz" : "AbdoRackwitz",
143 # Ce dictionnaire liste le nom des variables utilisees dans le script
144 # La clef est le nom attendu par les methodes, la valeur est le nom produit dans le fichier de sortie
145 # Le fait de passer par un dictionnaire permet de controler que les variables existent et sont correctement nommees
146 # meme si clef == valeur
150 "wrapper" : "wrapper",
151 "wrapperdata" : "wrapperdata",
152 "frameworkdata" : "frameworkdata",
153 "framework" : "framework",
154 "studyid" : "studyid",
155 "studycase" : "studycase",
156 "componentname" : "componentname",
158 "scaledVector" : "scaledVector",
159 "translationVector" : "translationVector",
161 "myCenteredReductedGrid" : "myCenteredReductedGrid",
162 "myExperimentPlane" : "myExperimentPlane",
163 "inputSample" : "inputSample",
164 "outputSample" : "outputSample",
165 "minValue" : 'results["minValue"]',
166 "maxValue" : 'results["maxValue"]',
169 "distribution" : "distribution",
170 "marginal" : "marginal",
171 "collection" : "collection",
173 "correlation" : "correlation",
176 "description" : "description",
177 "inputRandomVector" : "inputRandomVector",
178 "outputRandomVector" : "outputRandomVector",
179 "myQuadraticCumul" : "myQuadraticCumul",
180 "meanFirstOrder" : 'results["meanFirstOrder"]',
181 "meanSecondOrder" : 'results["meanSecondOrder"]',
182 "standardDeviationFirstOrder" : 'results["standardDeviationFirstOrder"]',
183 "importanceFactors" : 'results["importanceFactors"]',
184 "importanceFactorsGraph" : "importanceFactorsGraph",
185 "importanceFactorsDrawing" : "importanceFactorsDrawing",
186 "empiricalMean" : 'results["empiricalMean"]',
187 "empiricalStandardDeviation" : 'results["empiricalStandardDeviation"]',
188 "empiricalQuantile" : 'results["empiricalQuantile"]',
191 "PCCcoefficient" : 'results["PCCcoefficient"]',
192 "PRCCcoefficient" : 'results["PRCCcoefficient"]',
193 "SRCcoefficient" : 'results["SRCcoefficient"]',
194 "SRRCcoefficient" : 'results["SRRCcoefficient"]',
196 "kernelSmoothedDist" : "kernelSmoothedDist",
197 "kernelSmoothedPDFDrawing" : "kernelSmoothedPDFDrawing",
198 "kernelSmoothedGraph" : "kernelSmoothedGraph",
199 "meanVector" : "meanVector",
200 "importanceDensity" : "importanceDensity",
201 "myEvent" : "myEvent",
203 "myResult" : "myResult",
204 "probability" : 'results["probability"]',
205 "standardDeviation" : 'results["standardDeviation"]',
208 "coefficientOfVariation" : 'results["coefficientOfVariation"]',
209 "convergenceGraph" : "convergenceGraph",
210 "convergenceDrawing" : "convergenceDrawing",
211 "simulationNumbers" : 'results["simulationNumbers"]',
212 "myOptimizer" : "myOptimizer",
213 "specificParameters" : "specificParameters",
214 "startingPoint" : "startingPoint",
215 "hasoferReliabilityIndex" : 'results["hasoferReliabilityIndex"]',
216 "standardSpaceDesignPoint" : 'results["standardSpaceDesignPoint"]',
217 "physicalSpaceDesignPoint" : 'results["physicalSpaceDesignPoint"]',
218 "eventProbabilitySensitivity" : 'results["eventProbabilitySensitivity"]',
219 "hasoferReliabilityIndexSensitivity" : 'results["hasoferReliabilityIndexSensitivity"]',
220 "eventProbabilitySensitivityGraph" : "eventProbabilitySensitivityGraph",
221 "eventProbabilitySensitivityDrawing" : "eventProbabilitySensitivityDrawing",
222 "hasoferReliabilityIndexSensitivityGraph" : "hasoferReliabilityIndexSensitivityGraph",
223 "hasoferReliabilityIndexSensitivityDrawing" : "hasoferReliabilityIndexSensitivityDrawing",
224 "modelEvaluationCalls" : 'results["modelEvaluationCalls"]',
225 "modelGradientCalls" : 'results["modelGradientCalls"]',
226 "modelHessianCalls" : 'results["modelHessianCalls"]',
227 "tvedtApproximation" : 'results["tvedtApproximation"]',
228 "hohenBichlerApproximation" : 'results["hohenBichlerApproximation"]',
229 "breitungApproximation" : 'results["breitungApproximation"]',
232 # Ce dictionnaire fait la correspondance entre le mot-clef du catalogue et le flag de la bibliotheque
234 "DebugMessages" : "Log.DBG",
235 "WrapperMessages" : "Log.WRAPPER",
236 "UserMessages" : "Log.USER",
237 "InfoMessages" : "Log.INFO",
238 "WarningMessages" : "Log.WARN",
239 "ErrorMessages" : "Log.ERROR",
244 Pilotage de la creation du fichier python
247 if ( self.DictMCVal.has_key( 'Type' ) ):
248 TypeAnalyse = self.DictMCVal[ 'Type' ]
252 if ( self.traitement.has_key( TypeAnalyse ) ):
253 (Traitement, subDict) = self.traitement[ TypeAnalyse ]
255 if ( Traitement is not None ):
256 self.texteSTD = apply( STDGenerateur.__dict__[ Traitement ], (self, subDict) )
262 Imprime l entete commun a tous les fichiers
264 txt = headerSTD % self.OpenTURNS_path
266 txt += "# Definit le niveau d'affichage de la log\n"
267 txt += "%s = Log.NONE\n" % self.variable["flags"]
268 for flag in self.logFlags.keys():
269 if ( self.DictMCVal.has_key( flag ) ):
270 val = self.DictMCVal[ flag ]
274 txt += "%s = %s %s %s\n" % (self.variable["flags"], self.variable["flags"], op, self.logFlags[ flag ])
275 txt += "Log.Show( %s )\n" % self.variable["flags"]
281 Imprime le pied de page commun a tous les fichiers
285 def MinMax (self, subDict):
287 Produit le fichier study correspondant a une analyse Min/Max
293 if ( self.DictMCVal.has_key( 'Method' ) ):
294 Methode = self.DictMCVal[ 'Method' ]
297 if ( subDict.has_key( Methode ) ):
298 Traitement = subDict[ Methode ]
300 if ( Traitement is not None ):
301 txt += apply( STDGenerateur.__dict__[ Traitement ], (self,) )
303 txt += self.MinMaxResult()
310 Importe le modele physique
312 if ( self.DictMCVal.has_key( 'FileName' ) ):
313 name = self.DictMCVal[ 'FileName' ]
315 txt = "# Charge le modele physique\n"
316 txt += "%s = WrapperFile( '%s' )\n" % (self.variable["wrapper"], name)
317 txt += "%s = %s.getWrapperData()\n" % (self.variable["wrapperdata"], self.variable["wrapper"])
319 txt += "# Ces lignes sont utiles pour le fonctionnement du script sous Salome\n"
320 txt += "if globals().has_key('%s'):\n" % self.variable["framework"]
321 txt += " %s = %s.getFrameworkData()\n" % (self.variable["frameworkdata"], self.variable["wrapperdata"])
322 txt += " %s.studyid_ = %s['%s']\n" % (self.variable["frameworkdata"], self.variable["framework"], self.variable["studyid"])
323 txt += " %s.studycase_ = %s['%s']\n" % (self.variable["frameworkdata"], self.variable["framework"], self.variable["studycase"])
324 txt += " %s.componentname_ = %s['%s']\n" % (self.variable["frameworkdata"], self.variable["framework"], self.variable["componentname"])
325 txt += " %s.setFrameworkData( %s )\n" % (self.variable["wrapperdata"], self.variable["frameworkdata"])
326 txt += " %s.setWrapperData( %s )\n" % (self.variable["wrapper"], self.variable["wrapperdata"])
327 txt += "# Fin des lignes pour Salome\n"
329 txt += "%s = NumericalMathFunction( %s )\n" % (self.variable["model"], self.variable["wrapper"],)
330 txt += "%s = %s.getInputDimension()\n" % (self.variable["n"], self.variable["model"])
334 def ExperimentPlane (self):
336 Etude par plan d experience
338 txt = "# Etude par plan d'experience\n"
340 txt += self.CenteredReductedGrid()
341 txt += self.ScaledVector()
342 txt += self.TranslationVector()
343 txt += "%s = %s\n" % (self.variable["inputSample"], self.variable["myExperimentPlane"])
345 txt += "# Etude 'Min/Max'\n"
347 txt += "%s = %s( %s )\n" % (self.variable["outputSample"], self.variable["model"], self.variable["inputSample"])
348 txt += "if contain_nan_values( %s ):\n" % (self.variable["outputSample"])
349 txt += " raise Exception('Some computations failed')\n"
353 def MinMaxRandomSampling (self):
355 Etude par echantillonage aleatoire
358 if ( self.DictMCVal.has_key( 'SimulationsNumber' ) ):
359 size = self.DictMCVal[ 'SimulationsNumber' ]
361 txt = "# Etude par echantillonage aleatoire\n"
362 txt += self.InputDistribution()
363 txt += self.InputRandomVector()
365 txt += "# Etude 'Min/Max'\n"
367 txt += "%s = %d\n" % (self.variable["inSize"], size)
368 txt += "%s = RandomVector( %s, %s )\n" % (self.variable["outputRandomVector"], self.variable["model"], self.variable["inputRandomVector"])
369 txt += "%s = %s.getSample( %s )\n" % (self.variable["outputSample"], self.variable["outputRandomVector"], self.variable["inSize"])
370 txt += "if contain_nan_values( %s ):\n" % (self.variable["outputSample"])
371 txt += " raise Exception('Some computations failed')\n"
374 def InputDistribution (self):
376 Cree la loi jointe des variables d entree
378 txt = "# Definit la loi jointe des variables d'entree\n"
379 txt += "%s = DistributionCollection( %s )\n" % (self.variable["collection"], self.variable["n"])
380 txt += "%s = Description( %s )\n" % (self.variable["description"], self.variable["n"])
384 for variable in self.ListeVariablesIn:
385 nomVar = variable['ModelVariable'].get_name()
386 dictVariables[ nomVar ] = variable['Distribution']
389 sortedVarNames = dictVariables.keys()
390 sortedVarNames.sort()
391 for variable in sortedVarNames:
392 conceptloi = dictVariables[ variable ]
393 loi = self.DictLois[ conceptloi ]
394 if loi.has_key( 'Kind' ):
395 marginale = "%s_%d" % (self.variable["marginal"], i)
396 txt += "# Definit la loi marginale de la composante %d\n" % i
397 txt += "%s = %s\n" % (marginale, apply( STDGenerateur.__dict__[ loi[ 'Kind' ] ], (self, loi) ))
398 txt += "%s.setName( '%s' )\n" % (marginale, conceptloi.get_name())
399 txt += "%s[ %d ] = '%s'\n" % (self.variable["description"], i, variable)
400 txt += "%s[ %d ] = Distribution( %s )\n" % (self.variable["collection"], i, marginale)
406 txt += "# Definit la loi jointe\n"
407 txt += "%s = ComposedDistribution( %s, Copula( %s ) )\n" % (self.variable["distribution"], self.variable["collection"], self.variable["copula"])
408 txt += "%s.setDescription( %s )\n" % (self.variable["distribution"], self.variable["description"])
414 Cree la copule de la loi jointe
416 txt = "# Definit la copule de la loi jointe\n"
418 if ( not self.DictMCVal.has_key( 'Copula' ) ):
419 self.DictMCVal[ 'Copula' ] = 'Independent'
421 if ( self.DictMCVal[ 'Copula' ] in ( 'Independent', ) ):
422 txt += "%s = IndependentCopula( %s )\n" % (self.variable["copula"], self.variable["n"])
423 elif ( self.DictMCVal[ 'Copula' ] in ( 'Normal', ) ):
424 varList = self.DictMCVal[ 'CorrelationMatrix' ][0]
425 dimension = len(varList)
426 txt += "%s = {}\n" % self.variable["correlation"]
427 for i in range( dimension ):
428 txt += "%s['%s'] = {}\n" % (self.variable["correlation"], varList[i])
429 for j in range ( dimension ):
430 txt += "%s['%s']['%s'] = %g\n" % (self.variable["correlation"], varList[i], varList[j], self.DictMCVal[ 'CorrelationMatrix' ][i+1][j])
431 txt += "%s = getCorrelationMatrixFromMap( %s.getVariableList(), %s )\n" % (self.variable["R"], self.variable["wrapperdata"], self.variable["correlation"])
432 txt += "%s = NormalCopula( %s )\n" % (self.variable["copula"], self.variable["R"])
437 def InputRandomVector (self):
439 Cree le vector aleatoire d entree
441 txt = "# Definit le vecteur aleatoire d'entree\n"
442 txt += "%s = RandomVector( %s )\n" % (self.variable["inputRandomVector"], self.variable["distribution"])
446 def OutputRandomVector (self):
448 Cree le vector aleatoire de sortie
451 for variable in self.ListeVariablesOut:
452 nomVar = variable['ModelVariable'].get_name()
454 txt = "# Definit le vecteur aleatoire de sortie\n"
455 txt += "%s = RandomVector( %s, %s )\n" % (self.variable["outputRandomVector"], self.variable["model"], self.variable["inputRandomVector"])
456 txt += "%s.setName( '%s' )\n" % (self.variable["outputRandomVector"], nomVar)
460 def ScaledVector (self):
462 Definit les coefficients multiplicateurs par composante du vecteur
465 if ( self.DictMCVal.has_key( 'UnitsPerDimension' ) ):
466 unitsPerDimension = self.DictMCVal[ 'UnitsPerDimension' ]
467 dimension = len( unitsPerDimension )
469 txt = "# Definit les facteurs d'echelle dans chaque direction\n"
470 txt += "%s = NumericalPoint( %s )\n" % (self.variable["scaledVector"], self.variable["n"])
471 for i in range(dimension):
472 txt += "%s[%d] = %g\n" % (self.variable["scaledVector"], i, unitsPerDimension[i])
473 txt += "%s.scale( %s )\n" % (self.variable["myExperimentPlane"], self.variable["scaledVector"])
477 def TranslationVector (self):
479 Definit le vecteur de translation
482 if ( self.DictMCVal.has_key( 'Center' ) ):
483 center = self.DictMCVal[ 'Center' ]
484 dimension = len( center )
486 txt = "# Definit le vecteur de translation\n"
487 txt += "%s = NumericalPoint( %s )\n" % (self.variable["translationVector"], self.variable["n"])
488 for i in range(dimension):
489 txt += "%s[%d] = %g\n" % (self.variable["translationVector"], i, center[i])
490 txt += "%s.translate( %s )\n" % (self.variable["myExperimentPlane"], self.variable["translationVector"])
496 Definit les niveaux du plan d experience
499 if ( self.DictMCVal.has_key( 'Levels' ) ):
500 levels = self.DictMCVal[ 'Levels' ]
501 dimension = len( levels )
503 txt = "# Definit les niveaux de la structure de grille\n"
504 txt += "%s = NumericalPoint( %d )\n" % (self.variable["levels"], dimension)
505 for i in range(dimension):
506 txt += "%s[%d] = %g\n" % (self.variable["levels"], i, levels[i])
510 def CenteredReductedGrid (self):
512 Definit la grille reduite du plan d experience
515 if ( self.DictMCVal.has_key( 'ExperimentPlane' ) ):
516 plane = self.DictMCVal[ 'ExperimentPlane' ]
518 txt = "# Cree le plan d'experience centre reduit\n"
519 txt += "%s = %s(%s, %s)\n" % (self.variable["myCenteredReductedGrid"], plane, self.variable["n"], self.variable["levels"])
520 txt += "%s = %s.generate()\n" % (self.variable["myExperimentPlane"], self.variable["myCenteredReductedGrid"])
524 def MinMaxResult (self):
526 Produit les resultats de l etude
528 txt = "# Resultats\n"
529 txt += "%s = %s.getMin()\n" % (self.variable["minValue"], self.variable["outputSample"])
530 txt += "print '%s = ', %s\n" % ("minValue", self.variable["minValue"])
532 txt += "%s = %s.getMax()\n" % (self.variable["maxValue"], self.variable["outputSample"])
533 txt += "print '%s = ', %s\n" % ("maxValue", self.variable["maxValue"])
537 def CentralUncertainty (self, subDict):
539 Produit le fichier study correspondant a une analyse d incertitude en valeur centrale
543 txt += self.InputDistribution()
544 txt += self.InputRandomVector()
545 txt += self.OutputRandomVector()
548 if ( self.DictMCVal.has_key( 'Method' ) ):
549 Methode = self.DictMCVal[ 'Method' ]
552 if ( subDict.has_key( Methode ) ):
553 Traitement = subDict[ Methode ]
555 if ( Traitement is not None ):
556 txt += "# Etude 'Central Uncertainty'\n"
557 txt += apply( STDGenerateur.__dict__[ Traitement ], (self,) )
563 def TaylorVarianceDecomposition (self):
565 Etude par decomposition de Taylor
567 txt = "# Cumul quadratique (decomposition de Taylor)\n"
568 txt += "%s = QuadraticCumul( %s )\n" % (self.variable["myQuadraticCumul"], self.variable["outputRandomVector"])
570 txt += "# Resultats\n"
572 if ( self.DictMCVal.has_key( 'MeanFirstOrder' ) ):
573 if ( self.DictMCVal[ 'MeanFirstOrder' ] == "yes" ):
574 txt += "%s = %s.getMeanFirstOrder()\n" % (self.variable["meanFirstOrder"], self.variable["myQuadraticCumul"])
575 txt += "print '%s = ', %s\n" % ("mean First Order", self.variable["meanFirstOrder"])
578 if ( self.DictMCVal.has_key( 'MeanSecondOrder' ) ):
579 if ( self.DictMCVal[ 'MeanSecondOrder' ] == "yes" ):
580 txt += "%s = %s.getMeanSecondOrder()\n" % (self.variable["meanSecondOrder"], self.variable["myQuadraticCumul"])
581 txt += "print '%s = ', %s\n" % ("mean Second Order", self.variable["meanSecondOrder"])
584 if ( self.DictMCVal.has_key( 'StandardDeviationFirstOrder' ) ):
585 if ( self.DictMCVal[ 'StandardDeviationFirstOrder' ] == "yes" ):
586 txt += "%s = %s.getCovariance()\n" % (self.variable["standardDeviationFirstOrder"], self.variable["myQuadraticCumul"])
587 txt += "dim = %s.getDimension()\n" % self.variable["standardDeviationFirstOrder"]
588 txt += "for i in range( dim ):\n"
589 txt += " %s[ i, i ] = math.sqrt( %s[ i, i ] )\n" % (self.variable["standardDeviationFirstOrder"], self.variable["standardDeviationFirstOrder"])
590 txt += " print '%s = ', %s[ i, i ]\n" % ("standard Deviation First Order", self.variable["standardDeviationFirstOrder"])
593 if ( self.DictMCVal.has_key( 'ImportanceFactor' ) ):
594 if ( self.DictMCVal[ 'ImportanceFactor' ] == "yes" ):
595 txt += "%s = %s.getImportanceFactors()\n" % (self.variable["importanceFactors"], self.variable["myQuadraticCumul"])
596 txt += "for i in range(%s.getDimension()):\n" % self.variable["importanceFactors"]
597 txt += " print %s.getDescription()[i], ':', %s[i]*100., '%%'\n" % (self.variable["distribution"], self.variable["importanceFactors"])
599 txt += "%s = %s.drawImportanceFactors()\n" % (self.variable["importanceFactorsGraph"], self.variable["myQuadraticCumul"])
600 txt += "%s = '%s'\n" % (self.variable["importanceFactorsDrawing"], self.DictMCVal[ 'ImportanceFactorDrawingFilename' ])
601 txt += "%s.draw( %s )\n" % (self.variable["importanceFactorsGraph"], self.variable["importanceFactorsDrawing"])
602 txt += "if is_xserver_available():\n"
603 txt += " view = View(%s)\n" % self.variable["importanceFactorsGraph"]
604 txt += " view.show(block=True)\n"
606 txt += " print 'Warning: cannot display image', %s.getBitmap(), '(probably because no X server was found)'\n" % self.variable["importanceFactorsGraph"]
607 txt += "print 'bitmap =', %s.getBitmap()\n" % self.variable["importanceFactorsGraph"]
608 txt += "print 'postscript =', %s.getPostscript()\n" % self.variable["importanceFactorsGraph"]
614 def CentralUncertaintyRandomSampling (self):
616 Etude par echantillonage aleatoire
619 if ( self.DictMCVal.has_key( 'SimulationsNumber' ) ):
620 size = self.DictMCVal[ 'SimulationsNumber' ]
622 txt = "# Echantillonnage aleatoire de la variable de sortie\n"
623 txt += "%s = %d\n" % (self.variable["inSize"], size)
624 txt += "%s = %s.getSample( %s )\n" % (self.variable["inputSample"], self.variable["inputRandomVector"], self.variable["inSize"])
625 txt += "%s = %s( %s )\n" % (self.variable["outputSample"], self.variable["model"], self.variable["inputSample"])
626 txt += "if contain_nan_values( %s ):\n" % (self.variable["outputSample"])
627 txt += " raise Exception('Some computations failed')\n"
630 if ( self.DictMCVal.has_key( 'EmpiricalMean' ) ):
631 if ( self.DictMCVal[ 'EmpiricalMean' ] == "yes" ):
632 txt += "%s = %s.computeMean()\n" % (self.variable["empiricalMean"], self.variable["outputSample"])
633 txt += "print '%s =', %s[0]\n" % ("empirical Mean", self.variable["empiricalMean"])
636 if ( self.DictMCVal.has_key( 'EmpiricalStandardDeviation' ) ):
637 if ( self.DictMCVal[ 'EmpiricalStandardDeviation' ] == "yes" ):
638 txt += "%s = %s.computeCovariance()\n" % (self.variable["empiricalStandardDeviation"], self.variable["outputSample"])
639 txt += "dim = %s.getDimension()\n" % self.variable["empiricalStandardDeviation"]
640 txt += "for i in range( dim ):\n"
641 txt += " %s[ i, i ] = math.sqrt( %s[ i, i ] )\n" % (self.variable["empiricalStandardDeviation"], self.variable["empiricalStandardDeviation"])
642 txt += " print '%s = ', %s[ i, i ]\n" % ("empirical Standard Deviation", self.variable["empiricalStandardDeviation"])
645 if ( self.DictMCVal.has_key( 'EmpiricalQuantile_Order' ) ):
646 ordre = self.DictMCVal[ 'EmpiricalQuantile_Order' ]
647 txt += "%s = %s.computeQuantile( %s )\n" % (self.variable["empiricalQuantile"], self.variable["outputSample"], ordre)
648 txt += "print '%s ( %s ) =', %s\n" % ("empirical Quantile", ordre, self.variable["empiricalQuantile"])
651 if ( self.DictMCVal.has_key( 'CorrelationAnalysis' ) ):
652 if ( self.DictMCVal[ 'CorrelationAnalysis' ] == "yes" ):
653 txt += "if ( %s.getDimension() == 1 ):\n" % self.variable["outputSample"]
654 txt += " %s = CorrelationAnalysis.PCC( %s, %s )\n" % (self.variable["PCCcoefficient"], self.variable["inputSample"], self.variable["outputSample"])
655 txt += " print 'PCC Coefficients:'\n"
656 txt += " for i in range( %s ):\n" % self.variable["n"]
657 txt += " print %s.getDescription()[i], ':', %s[i]\n" % (self.variable["distribution"], self.variable["PCCcoefficient"])
659 txt += " %s = CorrelationAnalysis.PRCC( %s, %s )\n" % (self.variable["PRCCcoefficient"], self.variable["inputSample"], self.variable["outputSample"])
660 txt += " print 'PRCC Coefficients:'\n"
661 txt += " for i in range( %s ):\n" % self.variable["n"]
662 txt += " print %s.getDescription()[i], ':', %s[i]\n" % (self.variable["distribution"], self.variable["PRCCcoefficient"])
664 txt += " %s = CorrelationAnalysis.SRC( %s, %s )\n" % (self.variable["SRCcoefficient"], self.variable["inputSample"], self.variable["outputSample"])
665 txt += " print 'SRC Coefficients:'\n"
666 txt += " for i in range( %s ):\n" % self.variable["n"]
667 txt += " print %s.getDescription()[i], ':', %s[i]\n" % (self.variable["distribution"], self.variable["SRCcoefficient"])
669 txt += " %s = CorrelationAnalysis.SRRC( %s, %s )\n" % (self.variable["SRRCcoefficient"], self.variable["inputSample"], self.variable["outputSample"])
670 txt += " print 'SRRC Coefficients:'\n"
671 txt += " for i in range( %s ):\n" % self.variable["n"]
672 txt += " print %s.getDescription()[i], ':', %s[i]\n" % (self.variable["distribution"], self.variable["SRRCcoefficient"])
675 if ( self.DictMCVal.has_key( 'KernelSmoothing' ) ):
676 if ( self.DictMCVal[ 'KernelSmoothing' ] == "yes" ):
677 txt += "# Kernel Smoohing\n"
678 txt += "%s = KernelSmoothing()\n" % self.variable["kernel"]
679 txt += "if ( %s.getDimension() == 1 ):\n" % self.variable["outputSample"]
680 txt += " %s.setName( 'Output' )\n" % self.variable["outputSample"]
681 txt += " %s = %s.build( %s, 'TRUE')\n" % (self.variable["kernelSmoothedDist"], self.variable["kernel"], self.variable["outputSample"])
682 txt += " %s = %s.drawPDF()\n" % (self.variable["kernelSmoothedGraph"], self.variable["kernelSmoothedDist"])
683 txt += " %s = '%s'\n" % (self.variable["kernelSmoothedPDFDrawing"], self.DictMCVal[ 'KernelSmoothingDrawingFilename' ])
684 txt += " %s.draw( %s )\n" % (self.variable["kernelSmoothedGraph"], self.variable["kernelSmoothedPDFDrawing"])
685 txt += " if is_xserver_available():\n"
686 txt += " view = View(%s)\n" % self.variable["kernelSmoothedGraph"]
687 txt += " view.show(block=True)\n"
689 txt += " print 'Warning: cannot display image', %s.getBitmap(), '(probably because no X server was found)'\n" % self.variable["kernelSmoothedGraph"]
690 txt += " print 'bitmap =', %s.getBitmap()\n" % self.variable["kernelSmoothedGraph"]
691 txt += " print 'postscript =', %s.getPostscript()\n" % self.variable["kernelSmoothedGraph"]
696 def ThresholdExceedence (self, subDict):
698 Produit le fichier study correspondant a une analyse de depassement de seuil
701 txt += "# Etude 'Threshold Exceedence'\n"
703 txt += self.RandomGenerator()
705 txt += self.InputDistribution()
706 txt += self.InputRandomVector()
707 txt += self.OutputRandomVector()
711 if ( self.DictMCVal.has_key( 'Method' ) ):
712 Methode = self.DictMCVal[ 'Method' ]
715 if ( subDict.has_key( Methode ) ):
716 Traitement = subDict[ Methode ]
718 if ( Traitement is not None ):
719 txt += apply( STDGenerateur.__dict__[ Traitement ], (self, subDict) )
724 def Simulation (self, subDict):
726 Methodes de simulation
729 if ( self.DictMCVal.has_key( 'Algorithm' ) ):
730 Algorithme = self.DictMCVal[ 'Algorithm' ]
733 if ( subDict.has_key( Algorithme ) ):
734 Traitement = subDict[ Algorithme ]
736 if ( Traitement is not None ):
737 txt = apply( STDGenerateur.__dict__[ Traitement ], (self,) )
739 maxOuterSampling = None
740 if ( self.DictMCVal.has_key( 'MaximumOuterSampling' ) ):
741 maxOuterSampling = self.DictMCVal[ 'MaximumOuterSampling' ]
742 txt += "%s.setMaximumOuterSampling( %s )\n" % (self.variable["myAlgo"], maxOuterSampling)
745 if ( self.DictMCVal.has_key( 'BlockSize' ) ):
746 blockSize = self.DictMCVal[ 'BlockSize' ]
747 txt += "%s.setBlockSize( %s )\n" % (self.variable["myAlgo"], blockSize)
749 maxCoefficientOfVariation = None
750 if ( self.DictMCVal.has_key( 'MaximumCoefficientOfVariation' ) ):
751 maxCoefficientOfVariation = self.DictMCVal[ 'MaximumCoefficientOfVariation' ]
752 txt += "%s.setMaximumCoefficientOfVariation( %s )\n" % (self.variable["myAlgo"], maxCoefficientOfVariation)
754 txt += "%s.run()\n" % self.variable["myAlgo"]
756 txt += "# Resultats de la simulation\n"
757 txt += "%s = %s.getResult()\n" % (self.variable["myResult"], self.variable["myAlgo"])
760 if ( self.DictMCVal.has_key( 'Probability' ) ):
761 if ( self.DictMCVal[ 'Probability' ] == "yes" ):
762 txt += "%s = %s.getProbabilityEstimate()\n" % (self.variable["probability"], self.variable["myResult"])
763 txt += "print '%s =', %s\n" % ("probability", self.variable["probability"])
766 if ( self.DictMCVal.has_key( 'StandardDeviation' ) ):
767 if ( self.DictMCVal[ 'StandardDeviation' ] == "yes" ):
768 txt += "%s = math.sqrt( %s.getProbabilityEstimate() )\n" % (self.variable["standardDeviation"], self.variable["myResult"])
769 txt += "print '%s =', %s\n" % ("standard Deviation", self.variable["standardDeviation"])
772 if ( self.DictMCVal.has_key( 'ConfidenceInterval' ) and self.DictMCVal.has_key( 'Probability' ) ):
773 if ( ( self.DictMCVal[ 'ConfidenceInterval' ] == "yes" ) and ( self.DictMCVal[ 'Probability' ] == "yes" ) ):
774 level = self.DictMCVal[ 'Level' ]
775 txt += "%s = %s.getConfidenceLength( %s )\n" % (self.variable["length"], self.variable["myResult"], level)
776 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"])
779 if ( self.DictMCVal.has_key( 'VariationCoefficient' ) ):
780 if ( self.DictMCVal[ 'VariationCoefficient' ] == "yes" ):
781 txt += "%s = %s.getCoefficientOfVariation()\n" % (self.variable["coefficientOfVariation"], self.variable["myResult"])
782 txt += "print '%s =', %s\n" % ("coefficient of Variation", self.variable["coefficientOfVariation"])
785 if ( self.DictMCVal.has_key( 'SimulationsNumber' ) ):
786 if ( self.DictMCVal[ 'SimulationsNumber' ] == "yes" ):
787 txt += "%s = %s.getOuterSampling()\n" % (self.variable["simulationNumbers"], self.variable["myResult"])
788 txt += "print '%s =', %s\n" % ("simulation Numbers", self.variable["simulationNumbers"])
791 if ( self.DictMCVal.has_key( 'ConvergenceGraph' ) and self.DictMCVal.has_key( 'ConfidenceInterval' ) ):
792 if ( ( self.DictMCVal[ 'ConvergenceGraph' ] == "yes" ) and ( self.DictMCVal[ 'ConfidenceInterval' ] == "yes" ) ):
793 txt += "%s = %s\n" % (self.variable["alpha"], self.DictMCVal[ 'Level' ])
794 txt += "%s = %s.drawProbabilityConvergence( %s )\n" % (self.variable["convergenceGraph"], self.variable["myAlgo"], self.variable["alpha"])
795 txt += "%s = '%s'\n" % (self.variable["convergenceDrawing"], self.DictMCVal[ 'ConvergenceDrawingFilename' ])
796 txt += "%s.draw( %s )\n" % (self.variable["convergenceGraph"], self.variable["convergenceDrawing"])
797 txt += "if is_xserver_available():\n"
798 txt += " view = View(%s)\n" % self.variable["convergenceGraph"]
799 txt += " view.show(block=True)\n"
801 txt += " print 'Warning: cannot display image', %s.getBitmap(), '(probably because no X server was found)'\n" % self.variable["convergenceGraph"]
806 def Analytical (self, subDict):
812 OptimizationAlgo = None
813 if ( self.DictMCVal.has_key( 'OptimizationAlgorithm' ) ):
814 OptimizationAlgo = self.DictMCVal[ 'OptimizationAlgorithm' ]
817 if ( subDict.has_key( OptimizationAlgo ) ):
818 Traitement = subDict[ OptimizationAlgo ]
820 if ( Traitement is not None ):
821 txt += apply( STDGenerateur.__dict__[ Traitement ], (self,) )
823 txt += self.OptimizerSettings()
824 txt += self.PhysicalStartingPoint()
827 if ( self.DictMCVal.has_key( 'Approximation' ) ):
828 Approximation = self.DictMCVal[ 'Approximation' ]
831 if ( subDict.has_key( Approximation ) ):
832 Traitement = subDict[ Approximation ]
834 if ( Traitement is not None ):
835 txt += apply( STDGenerateur.__dict__[ Traitement ], (self,) )
837 txt += self.RunAlgorithm()
838 txt += self.AnalyticalResult()
842 def OptimizerSettings (self):
844 Parametrage de l optimiseur
848 simulationNumbers = None
849 if ( self.DictMCVal.has_key( 'MaximumIterationsNumber' ) ):
850 simulationNumbers = self.DictMCVal[ 'MaximumIterationsNumber' ]
851 txt += "%s.setMaximumIterationsNumber( %s )\n" % (self.variable["myOptimizer"], simulationNumbers)
854 if ( self.DictMCVal.has_key( 'MaximumAbsoluteError' ) ):
855 absoluteError = self.DictMCVal[ 'MaximumAbsoluteError' ]
856 txt += "%s.setMaximumAbsoluteError( %s )\n" % (self.variable["myOptimizer"], absoluteError)
859 if ( self.DictMCVal.has_key( 'MaximumRelativeError' ) ):
860 relativeError = self.DictMCVal[ 'MaximumRelativeError' ]
861 txt += "%s.setMaximumRelativeError( %s )\n" % (self.variable["myOptimizer"], relativeError)
864 if ( self.DictMCVal.has_key( 'MaximumResidualError' ) ):
865 residualError = self.DictMCVal[ 'MaximumResidualError' ]
866 txt += "%s.setMaximumResidualError( %s )\n" % (self.variable["myOptimizer"], residualError)
868 constraintError = None
869 if ( self.DictMCVal.has_key( 'MaximumConstraintError' ) ):
870 constraintError = self.DictMCVal[ 'MaximumConstraintError' ]
871 txt += "%s.setMaximumConstraintError( %s )\n" % (self.variable["myOptimizer"], constraintError)
877 def PhysicalStartingPoint (self):
879 Point physique de depart
881 txt = "# Point physique de depart\n"
883 if ( self.DictMCVal.has_key( 'PhysicalStartingPoint' ) ):
884 point = self.DictMCVal[ 'PhysicalStartingPoint' ]
885 dimension = len( point )
886 txt += "%s = NumericalPoint( %d )\n" % (self.variable["startingPoint"], dimension)
887 for i in range( dimension ):
888 txt += "%s[ %d ] = %g\n" % (self.variable["startingPoint"], i, point[i])
890 txt += "%s = %s.getMean()\n" % (self.variable["startingPoint"], self.variable["inputRandomVector"])
896 def AnalyticalResult (self):
898 Resultat des methodes analytiques
900 txt = "# Resultat des methodes analytiques\n"
901 txt += "%s = %s.getResult()\n" % (self.variable["myResult"], self.variable["myAlgo"])
903 if ( self.DictMCVal.has_key( 'Probability' ) ):
904 if ( self.DictMCVal[ 'Probability' ] == "yes" ):
905 txt += "%s = %s.getEventProbability()\n" % (self.variable["probability"], self.variable["myResult"])
906 txt += "print '%s =', %s\n" % (self.variable["probability"], self.variable["probability"])
909 if ( self.DictMCVal.has_key( 'HasoferReliabilityIndex' ) ):
910 if ( self.DictMCVal[ 'HasoferReliabilityIndex' ] == "yes" ):
911 txt += "%s = %s.getHasoferReliabilityIndex()\n" % (self.variable["hasoferReliabilityIndex"], self.variable["myResult"])
912 txt += "print '%s =', %s\n" % ("hasofer Reliability Index", self.variable["hasoferReliabilityIndex"])
915 if ( self.DictMCVal.has_key( 'DesignPoint' ) ):
916 if ( self.DictMCVal[ 'DesignPoint' ] == "yes" ):
917 txt += "%s = %s.getStandardSpaceDesignPoint()\n" % (self.variable["standardSpaceDesignPoint"], self.variable["myResult"])
918 txt += "print '%s =', %s\n" % ("standard Space Design Point", self.variable["standardSpaceDesignPoint"])
919 txt += "%s = %s.getPhysicalSpaceDesignPoint()\n" % (self.variable["physicalSpaceDesignPoint"], self.variable["myResult"])
920 txt += "print '%s =', %s\n" % ("physical Space Design Point", self.variable["physicalSpaceDesignPoint"])
923 if ( self.DictMCVal.has_key( 'ImportanceFactor' ) ):
924 if ( self.DictMCVal[ 'ImportanceFactor' ] == "yes" ):
925 txt += "print 'Importance Factors:'\n"
926 txt += "%s = %s.getImportanceFactors()\n" % (self.variable["importanceFactors"], self.variable["myResult"])
927 txt += "for i in range(%s.getDimension()):\n" % self.variable["importanceFactors"]
928 txt += " print %s.getDescription()[i], ':', %s[i]*100., '%%'\n" % (self.variable["distribution"], self.variable["importanceFactors"])
930 txt += "%s = %s.drawImportanceFactors()\n" % (self.variable["importanceFactorsGraph"], self.variable["myResult"])
931 txt += "%s = '%s'\n" % (self.variable["importanceFactorsDrawing"], self.DictMCVal[ 'ImportanceFactorDrawingFilename' ])
932 txt += "%s.draw( %s )\n" % (self.variable["importanceFactorsGraph"], self.variable["importanceFactorsDrawing"])
933 txt += "if is_xserver_available():\n"
934 txt += " view = View(%s)\n" % self.variable["importanceFactorsGraph"]
935 txt += " view.show(block=True)\n"
937 txt += " print 'Warning: cannot display image', %s.getBitmap(), '(probably because no X server was found)'\n" % self.variable["importanceFactorsGraph"]
938 txt += "print 'bitmap =', %s.getBitmap()\n" % self.variable["importanceFactorsGraph"]
939 txt += "print 'postscript =', %s.getPostscript()\n" % self.variable["importanceFactorsGraph"]
942 if ( self.DictMCVal.has_key( 'FORMEventProbabilitySensitivity' ) ):
943 if ( self.DictMCVal[ 'FORMEventProbabilitySensitivity' ] == "yes" ):
944 txt += "%s = %s.getEventProbabilitySensitivity()\n" % (self.variable["eventProbabilitySensitivity"], self.variable["myResult"])
945 txt += "print 'FORM Event Probability Sensitivity:'\n"
946 txt += "for i in range( %s ):\n" % self.variable["n"]
947 txt += " print %s.getDescription()[i], ':'\n" % self.variable["distribution"]
948 txt += " for j in range( %s[i].getDimension() ):\n" % self.variable["eventProbabilitySensitivity"]
949 txt += " print ' ', %s[i].getDescription()[j], ':', %s[i][j]\n" % (self.variable["eventProbabilitySensitivity"], self.variable["eventProbabilitySensitivity"])
951 txt += "%s = %s.drawEventProbabilitySensitivity()[0]\n" % (self.variable["eventProbabilitySensitivityGraph"], self.variable["myResult"])
952 txt += "%s = '%s'\n" % (self.variable["eventProbabilitySensitivityDrawing"], self.DictMCVal[ 'FORMEventProbabilitySensitivityDrawingFilename' ])
953 txt += "%s.draw( %s )\n" % (self.variable["eventProbabilitySensitivityGraph"], self.variable["eventProbabilitySensitivityDrawing"])
954 txt += "if is_xserver_available():\n"
955 txt += " view = View(%s)\n" % self.variable["eventProbabilitySensitivityGraph"]
956 txt += " view.show(block=True)\n"
958 txt += " print 'Warning: cannot display image', %s.getBitmap(), '(probably because no X server was found)'\n" % self.variable["eventProbabilitySensitivityGraph"]
959 txt += "print 'bitmap =', %s.getBitmap()\n" % self.variable["eventProbabilitySensitivityGraph"]
960 txt += "print 'postscript =', %s.getPostscript()\n" % self.variable["eventProbabilitySensitivityGraph"]
963 if ( self.DictMCVal.has_key( 'HasoferReliabilityIndexSensitivity' ) ):
964 if ( self.DictMCVal[ 'HasoferReliabilityIndexSensitivity' ] == "yes" ):
965 txt += "%s = %s.getHasoferReliabilityIndexSensitivity()\n" % (self.variable["hasoferReliabilityIndexSensitivity"], self.variable["myResult"])
966 txt += "print 'Hasofer Reliability Index Sensitivity:'\n"
967 txt += "for i in range( %s ):\n" % self.variable["n"]
968 txt += " print %s.getDescription()[i], ':'\n" % self.variable["distribution"]
969 txt += " for j in range( %s[i].getDimension() ):\n" % self.variable["hasoferReliabilityIndexSensitivity"]
970 txt += " print ' ', %s[i].getDescription()[j], ':', %s[i][j]\n" % (self.variable["hasoferReliabilityIndexSensitivity"], self.variable["hasoferReliabilityIndexSensitivity"])
972 txt += "%s = %s.drawHasoferReliabilityIndexSensitivity()[0]\n" % (self.variable["hasoferReliabilityIndexSensitivityGraph"], self.variable["myResult"])
973 txt += "%s = '%s'\n" % (self.variable["hasoferReliabilityIndexSensitivityDrawing"], self.DictMCVal[ 'HasoferReliabilityIndexSensitivityDrawingFilename' ])
974 txt += "%s.draw( %s )\n" % (self.variable["hasoferReliabilityIndexSensitivityGraph"], self.variable["hasoferReliabilityIndexSensitivityDrawing"])
975 txt += "if is_xserver_available():\n"
976 txt += " view = View(%s)\n" % self.variable["hasoferReliabilityIndexSensitivityGraph"]
977 txt += " view.show(block=True)\n"
979 txt += " print 'Warning: cannot display image', %s.getBitmap(), '(probably because no X server was found)'\n" % self.variable["hasoferReliabilityIndexSensitivityGraph"]
980 txt += "print 'bitmap =', %s.getBitmap()\n" % self.variable["hasoferReliabilityIndexSensitivityGraph"]
981 txt += "print 'postscript =', %s.getPostscript()\n" % self.variable["hasoferReliabilityIndexSensitivityGraph"]
984 if ( self.DictMCVal.has_key( 'TvedtApproximation' ) ):
985 if ( self.DictMCVal[ 'TvedtApproximation' ] == "yes" ):
986 txt += "%s = %s.getEventProbabilityTvedt()\n" % (self.variable["tvedtApproximation"], self.variable["myResult"])
987 txt += "print '%s =', %s\n" % ("Tvedt Approximation", self.variable["tvedtApproximation"])
990 if ( self.DictMCVal.has_key( 'HohenBichlerApproximation' ) ):
991 if ( self.DictMCVal[ 'HohenBichlerApproximation' ] == "yes" ):
992 txt += "%s = %s.getEventProbabilityHohenBichler()\n" % (self.variable["hohenBichlerApproximation"], self.variable["myResult"])
993 txt += "print '%s =', %s\n" % ("HohenBichler Approximation", self.variable["tvedtApproximation"])
996 if ( self.DictMCVal.has_key( 'BreitungApproximation' ) ):
997 if ( self.DictMCVal[ 'BreitungApproximation' ] == "yes" ):
998 txt += "%s = %s.getEventProbabilityBreitung()\n" % (self.variable["breitungApproximation"], self.variable["myResult"])
999 txt += "print '%s =', %s\n" % ("Breitung Approximation", self.variable["breitungApproximation"])
1005 def RandomGenerator (self):
1007 Generateur Aleatoire
1012 if ( self.DictMCVal.has_key( 'RandomGeneratorSeed' ) ):
1013 seed = self.DictMCVal[ 'RandomGeneratorSeed' ]
1014 txt += "# Initialise le generateur aleatoire\n"
1015 txt += "RandomGenerator.SetSeed( %s )\n" % seed
1022 Definition de l evenement de defaillance
1025 if ( self.DictMCVal.has_key( 'ComparisonOperator' ) ):
1026 operator = self.DictMCVal[ 'ComparisonOperator' ]
1029 if ( self.DictMCVal.has_key( 'Threshold' ) ):
1030 threshold = self.DictMCVal[ 'Threshold' ]
1032 txt = "# Evenement de defaillance\n"
1033 txt += "%s = Event( %s, ComparisonOperator( %s() ), %s )\n" % (self.variable["myEvent"], self.variable["outputRandomVector"], operator, threshold)
1034 txt += "%s.setName( '%s' )\n" % (self.variable["myEvent"], "myEvent")
1038 def MonteCarlo (self):
1040 Methode de MonteCarlo
1042 txt = "# Simulation par MonteCarlo\n"
1043 txt += "%s = MonteCarlo( %s )\n" % (self.variable["myAlgo"], self.variable["myEvent"])
1052 txt = "# Simulation par LHS\n"
1053 txt += "%s = LHS( %s )\n" % (self.variable["myAlgo"], self.variable["myEvent"])
1058 def ImportanceSampling (self):
1060 Methode de tirage d importance
1063 if ( self.DictMCVal.has_key( 'MeanVector' ) ):
1064 meanVector = self.DictMCVal[ 'MeanVector' ]
1065 dimension = len( meanVector )
1067 txt = "# Simulation par Tirage d'importance\n"
1068 txt += "# Densite d'importance\n"
1069 txt += "%s = NumericalPoint( %s )\n" % (self.variable["meanVector"], self.variable["n"])
1070 for i in range(dimension):
1071 txt += "%s[%d] = %g\n" % (self.variable["meanVector"], i, meanVector[i])
1073 txt += "%s = Normal( %s, CovarianceMatrix( IdentityMatrix( %s ) ) )\n" % (self.variable["importanceDensity"], self.variable["meanVector"], self.variable["n"])
1074 txt += "%s = ImportanceSampling( %s, Distribution( %s ) )\n" % (self.variable["myAlgo"], self.variable["myEvent"], self.variable["importanceDensity"])
1083 txt = "# Algorithme FORM\n"
1084 txt += "%s = FORM ( NearestPointAlgorithm( %s ), %s, %s )\n" % (self.variable["myAlgo"], self.variable["myOptimizer"], self.variable["myEvent"], self.variable["startingPoint"])
1093 txt = "# Algorithme SORM\n"
1094 txt += "%s = SORM ( NearestPointAlgorithm( %s ), %s, %s )\n" % (self.variable["myAlgo"], self.variable["myOptimizer"], self.variable["myEvent"], self.variable["startingPoint"])
1099 def RunAlgorithm (self):
1104 if ( self.DictMCVal.has_key( 'FunctionCallsNumber' ) ):
1105 if ( self.DictMCVal[ 'FunctionCallsNumber' ] == "yes" ):
1106 txt += "%s = %s.getEvaluationCallsNumber()\n" % (self.variable["modelEvaluationCalls"], self.variable["model"])
1107 txt += "%s = %s.getGradientCallsNumber()\n" % (self.variable["modelGradientCalls"], self.variable["model"])
1108 txt += "%s = %s.getHessianCallsNumber()\n" % (self.variable["modelHessianCalls"], self.variable["model"])
1111 txt += "# Perform the computation\n"
1112 txt += "%s.run()\n" % self.variable["myAlgo"]
1116 if ( self.DictMCVal.has_key( 'FunctionCallsNumber' ) ):
1117 if ( self.DictMCVal[ 'FunctionCallsNumber' ] == "yes" ):
1118 txt += "%s = %s.getEvaluationCallsNumber() - %s\n" % (self.variable["modelEvaluationCalls"], self.variable["model"], self.variable["modelEvaluationCalls"])
1119 txt += "%s = %s.getGradientCallsNumber() - %s\n" % (self.variable["modelGradientCalls"], self.variable["model"], self.variable["modelGradientCalls"])
1120 txt += "%s = %s.getHessianCallsNumber() - %s\n" % (self.variable["modelHessianCalls"], self.variable["model"], self.variable["modelHessianCalls"])
1122 txt += "print '%s =', %s\n" % ("model Evaluation Calls", self.variable["modelEvaluationCalls"])
1123 txt += "print '%s =', %s\n" % ("model Gradient Calls", self.variable["modelGradientCalls"])
1124 txt += "print '%s =', %s\n" % ("model Hessian Calls", self.variable["modelHessianCalls"])
1133 txt = "# Optimisation par Cobyla\n"
1134 txt += "%s = Cobyla()\n" % self.variable["myOptimizer"]
1135 txt += "#%s = CobylaSpecificParameters()\n" % self.variable["specificParameters"]
1136 txt += "#%s.setSpecificParameters( %s )\n" % (self.variable["myOptimizer"], self.variable["specificParameters"])
1141 def AbdoRackwitz (self):
1143 Methode AbdoRackwitz
1145 txt = "# Optimisation par AbdoRackwitz\n"
1146 txt += "%s = AbdoRackwitz()\n" % self.variable["myOptimizer"]
1147 txt += "#%s = AbdoRackwitzSpecificParameters()\n" % self.variable["specificParameters"]
1148 txt += "#%s.setSpecificParameters( %s )\n" % (self.variable["myOptimizer"], self.variable["specificParameters"])
1152 def Beta (self, loi):
1154 Definition de la loi Beta
1158 "MuSigma" : "Beta.MUSIGMA",
1160 if loi[ 'Settings' ] == 'RT' :
1165 arg2 = loi[ 'Sigma' ]
1169 txt = "Beta( %g, %g, %g, %g, %s )" % (arg1, arg2, arg3, arg4, settings[ loi[ 'Settings' ] ])
1172 def Exponential (self, loi):
1174 Definition de la loi Exponential
1176 arg1 = loi[ 'Lambda' ]
1177 arg2 = loi[ 'Gamma' ]
1178 txt = "Exponential( %g, %g )" % (arg1, arg2)
1181 def Gamma (self, loi):
1183 Definition de la loi Gamma
1186 "KLambda" : "Gamma.KLAMBDA",
1187 "MuSigma" : "Gamma.MUSIGMA",
1189 if loi[ 'Settings' ] == 'KLambda' :
1191 arg2 = loi[ 'Lambda' ]
1194 arg2 = loi[ 'Sigma' ]
1196 arg3 = loi[ 'Gamma' ]
1197 txt = "Gamma( %g, %g, %g, %s )" % (arg1, arg2, arg3, settings[ loi[ 'Settings' ] ])
1200 def Geometric (self, loi):
1202 Definition de la loi Geometric
1204 txt = "Geometric( %g )" % loi[ 'P' ]
1207 def Gumbel (self, loi):
1209 Definition de la loi Gumbel
1212 "AlphaBeta" : "Gumbel.ALPHABETA",
1213 "MuSigma" : "Gumbel.MUSIGMA",
1215 if loi[ 'Settings' ] == 'AlphaBeta' :
1216 arg1 = loi[ 'Alpha' ]
1217 arg2 = loi[ 'Beta' ]
1220 arg2 = loi[ 'Sigma' ]
1222 txt = "Gumbel( %g, %g, %s )" % (arg1, arg2, settings[ loi[ 'Settings' ] ])
1225 def Histogram (self, loi):
1227 Definition de la loi Histogram
1229 arg1 = loi[ 'First' ]
1230 arg2 = loi[ 'Values' ]
1231 txt = "Histogram( %g, %s )" % (arg1, arg2)
1234 def Laplace (self, loi):
1236 Definition de la loi Laplace
1238 arg1 = loi[ 'Lambda' ]
1240 txt = "Laplace( %g, %g )" % (arg1, arg2)
1243 def Logistic (self, loi):
1245 Definition de la loi Logistic
1247 arg1 = loi[ 'Alpha' ]
1248 arg2 = loi[ 'Beta' ]
1249 txt = "Logistic( %g, %g )" % (arg1, arg2)
1252 def LogNormal (self, loi):
1254 Definition de la loi LogNormal
1257 "MuSigmaLog" : "LogNormal.MUSIGMA_LOG",
1258 "MuSigma" : "LogNormal.MUSIGMA",
1259 "MuSigmaOverMu" : "LogNormal.MU_SIGMAOVERMU",
1261 if loi[ 'Settings' ] == 'MuSigmaLog' :
1262 arg1 = loi[ 'MuLog' ]
1263 arg2 = loi[ 'SigmaLog' ]
1264 elif loi[ 'Settings' ] == 'MuSigmaOverMu' :
1266 arg2 = loi[ 'SigmaOverMu' ]
1269 arg2 = loi[ 'Sigma' ]
1271 arg3 = loi[ 'Gamma' ]
1272 txt = "LogNormal( %g, %g, %g, %s )" % (arg1, arg2, arg3, settings[ loi[ 'Settings' ] ])
1275 def MultiNomial (self, loi):
1277 Definition de la loi MultiNomial
1279 arg1 = loi[ 'Values' ]
1281 txt = "MultiNomial( NumericalPoint( %s ) , %d)" % (arg1, arg2)
1284 def NonCentralStudent (self, loi):
1286 Definition de la loi NonCentralStudent
1289 arg2 = loi[ 'Delta' ]
1290 arg3 = loi[ 'Gamma' ]
1291 txt = "NonCentralStudent( %g, %g )" % (arg1, arg2, arg3)
1294 def Normal (self, loi):
1296 Definition de la loi Normal
1299 arg2 = loi[ 'Sigma' ]
1300 txt = "Normal( %g, %g )" % (arg1, arg2)
1303 def TruncatedNormal (self, loi):
1305 Definition de la loi TruncatedNormal
1308 arg2 = loi[ 'SigmaN' ]
1311 txt = "TruncatedNormal( %g, %g, %g, %g )" % (arg1, arg2, arg3, arg4)
1314 def Poisson (self, loi):
1316 Definition de la loi Poisson
1318 txt = "Poisson( %g )" % loi[ 'Lambda' ]
1321 def Rayleigh (self, loi):
1323 Definition de la loi Rayleigh
1325 arg1 = loi[ 'Sigma' ]
1326 arg2 = loi[ 'Gamma' ]
1327 txt = "Rayleigh( %g, %g )" % (arg1, arg2)
1330 def Student (self, loi):
1332 Definition de la loi Student
1336 arg3 = loi[ 'Sigma' ]
1337 txt = "Student( %g, %g, %g )" % (arg1, arg2, arg3)
1340 def Triangular (self, loi):
1342 Definition de la loi Triangular
1347 txt = "Triangular( %g, %g, %g )" % (arg1, arg2, arg3)
1350 def Uniform (self, loi):
1352 Definition de la loi Uniform
1356 txt = "Uniform( %g, %g )" % (arg1, arg2)
1359 def UserDefined (self, loi):
1361 Definition de la loi UserDefined
1363 txt = "** UserDefined not defined yet **"
1366 def Weibull (self, loi):
1368 Definition de la loi Weibull
1371 "AlphaBeta" : "Weibull.ALPHABETA",
1372 "MuSigma" : "Weibull.MUSIGMA",
1374 if loi[ 'Settings' ] == 'AlphaBeta' :
1375 arg1 = loi[ 'Alpha' ]
1376 arg2 = loi[ 'Beta' ]
1379 arg2 = loi[ 'Sigma' ]
1381 arg3 = loi[ 'Gamma' ]
1382 txt = "Weibull( %g, %g, %g, %s )" % (arg1, arg2, arg3, settings[ loi[ 'Settings' ] ])
1387 def GraphiquePDF (self, loi, chemin, fichier):
1389 Produit une image PNG representant la PDF de la loi
1391 txt = headerSTD % self.OpenTURNS_path
1392 txt += "dist = %s\n" % apply( STDGenerateur.__dict__[ loi[ 'Kind' ] ], (self, loi) )
1393 txt += "graph = dist.drawPDF()\n"
1394 txt += "graph.draw( '%s', '%s' , 640, 480, GraphImplementation.PNG)\n" % (chemin, fichier)