]> SALOME platform Git repositories - tools/eficas.git/blob - generator/OpenturnsSTD.py
Salome HOME
*** empty log message ***
[tools/eficas.git] / generator / OpenturnsSTD.py
1 #@ AJOUT OpenturnsSolver Macro
2 # -*- coding: iso-8859-1 -*-
3 # RESPONSABLE
4
5 """
6 Ce module contient le generateur Etude pour Openturns
7 """
8
9 __revision__ = "V1.0"
10
11 import os
12
13 defaultSTD = """#! /usr/bin/env python
14
15 class StudyFileGenerationError:
16   def __init__ (self, st):
17     self.st = st
18   def __str__(self):
19     return "'%s'" % self.st
20
21 raise StudyFileGenerationError, "The study file was not generated. Check analysis type."
22 """
23
24 headerSTD = """#! /usr/bin/env python
25
26 # Chargement du module systeme
27 import sys
28 sys.path[:0]=['%s']
29
30 # Chargement du module math
31 import math
32
33 # Chargement du module Open TURNS
34 from openturns import *
35
36 results = {}
37
38 """
39
40 viewerSTD = """
41 from openturns.viewer import ViewImage,StopViewer,WaitForViewer
42 """
43
44 footerSTD = """
45
46 # Flush des messages en attente
47 Log.Flush()
48
49 # Terminaison du fichier
50 #sys.exit( 0 )
51 """
52
53 #=============================================
54 #  La classe de creation du fichier STD
55 #=============================================
56
57 class STDGenerateur :
58
59   '''
60   Generation du fichier python
61   '''
62   def __init__ (self, appli, DictMCVal, ListeVariablesIn, ListeVariablesOut, DictLois ) :
63     self.DictMCVal = DictMCVal
64     self.ListeVariablesIn = ListeVariablesIn
65     self.ListeVariablesOut = ListeVariablesOut
66     self.DictLois = DictLois
67     #print "DictMCVal=", DictMCVal
68     print "ListeVariablesIn=", ListeVariablesIn
69     print "ListeVariablesOut=", ListeVariablesOut
70     #print "DictLois=", DictLois
71     self.texteSTD = defaultSTD
72     self.OpenTURNS_path = appli.CONFIGURATION.OpenTURNS_path
73
74     # Ce dictionnaire fait la correspondance entre le mot lu dans le dictionnaire des mots-clefs et la methode a appeler
75     self.traitement = {
76       "Min/Max" :
77       ( "MinMax",
78         { "Experiment Plane" : "ExperimentPlane",
79           "Random Sampling" : "MinMaxRandomSampling",
80           },
81         ),
82       "Central Uncertainty" :
83       ( "CentralUncertainty",
84         { "Taylor Variance Decomposition" : "TaylorVarianceDecomposition",
85           "Random Sampling" : "CentralUncertaintyRandomSampling",
86          },
87         ),
88       "Threshold Exceedence" :
89       ( "ThresholdExceedence",
90         { "Simulation" : "Simulation",
91           "FORM_SORM" : "Analytical",
92           "MonteCarlo" : "MonteCarlo",
93           "LHS" : "LHS",
94           "ImportanceSampling" : "ImportanceSampling",
95           "FirstOrder" : "FORM",
96           "SecondOrder" : "SORM",
97           "Cobyla" : "Cobyla",
98           "AbdoRackwitz" : "AbdoRackwitz",
99           },
100         ),
101       }
102
103     # Ce dictionnaire liste le nom des variables utilisees dans le script
104     # La clef est le nom attendu par les methodes, la valeur est le nom produit dans le fichier de sortie
105     # Le fait de passer par un dictionnaire permet de controler que les variables existent et sont correctement nommees
106     # meme si clef == valeur
107     self.variable = {
108       "n" : "n",
109       "p" : "p",
110       "wrapper" : "wrapper",
111       "wrapperdata" : "wrapperdata",
112       "frameworkdata" : "frameworkdata",
113       "framework" : "framework",
114       "studyid" : "studyid",
115       "studycase" : "studycase",
116       "componentname" : "componentname",
117       "model" : "model",
118       "scaledVector" : "scaledVector",
119       "translationVector" : "translationVector",
120       "levels" : "levels",
121       "myCenteredReductedGrid" : "myCenteredReductedGrid",
122       "myExperimentPlane" : "myExperimentPlane",
123       "inputSample" : "inputSample",
124       "outputSample" : "outputSample",
125       "minValue" : 'results["minValue"]',
126       "maxValue" : 'results["maxValue"]',
127       "flags" : "flags",
128       "inSize" : "inSize",
129       "distribution" : "distribution",
130       "marginal" : "marginal",
131       "collection" : "collection",
132       "copula" : "copula",
133       "correlation" : "correlation",
134       "R" : "R",
135       "vars" : "vars",
136       "description" : "description",
137       "inputRandomVector" : "inputRandomVector",
138       "outputRandomVector" : "outputRandomVector",
139       "myQuadraticCumul" : "myQuadraticCumul",
140       "meanFirstOrder" : 'results["meanFirstOrder"]',
141       "meanSecondOrder" : 'results["meanSecondOrder"]',
142       "standardDeviationFirstOrder" : 'results["standardDeviationFirstOrder"]',
143       "importanceFactors" : 'results["importanceFactors"]',
144       "importanceFactorsGraph" : "importanceFactorsGraph",
145       "importanceFactorsDrawing" : "importanceFactorsDrawing",
146       "empiricalMean" : 'results["empiricalMean"]',
147       "empiricalStandardDeviation" : 'results["empiricalStandardDeviation"]',
148       "empiricalQuantile" : 'results["empiricalQuantile"]',
149       "alpha" : "alpha",
150       "beta" : "beta",
151       "PCCcoefficient" : 'results["PCCcoefficient"]',
152       "PRCCcoefficient" : 'results["PRCCcoefficient"]',
153       "SRCcoefficient" : 'results["SRCcoefficient"]',
154       "SRRCcoefficient" : 'results["SRRCcoefficient"]',
155       "kernel" : "kernel",
156       "kernelSmoothedDist" : "kernelSmoothedDist",
157       "kernelSmoothedPDFDrawing" : "kernelSmoothedPDFDrawing",
158       "kernelSmoothedGraph" : "kernelSmoothedGraph",
159       "meanVector" : "meanVector",
160       "importanceDensity" : "importanceDensity",
161       "myEvent" : "myEvent",
162       "myAlgo" : "myAlgo",
163       "myResult" : "myResult",
164       "probability" : 'results["probability"]',
165       "standardDeviation" : 'results["standardDeviation"]',
166       "level" : "level",
167       "length" : "length",
168       "coefficientOfVariation" : 'results["coefficientOfVariation"]',
169       "convergenceGraph" : "convergenceGraph",
170       "convergenceDrawing" : "convergenceDrawing",
171       "simulationNumbers" : 'results["simulationNumbers"]',
172       "myOptimizer" : "myOptimizer",
173       "specificParameters" : "specificParameters",
174       "startingPoint" : "startingPoint",
175       "hasoferReliabilityIndex" : 'results["hasoferReliabilityIndex"]',
176       "standardSpaceDesignPoint" : 'results["standardSpaceDesignPoint"]',
177       "physicalSpaceDesignPoint" : 'results["physicalSpaceDesignPoint"]',
178       "eventProbabilitySensitivity" : 'results["eventProbabilitySensitivity"]',
179       "hasoferReliabilityIndexSensitivity" : 'results["hasoferReliabilityIndexSensitivity"]',
180       "eventProbabilitySensitivityGraph" : "eventProbabilitySensitivityGraph",
181       "eventProbabilitySensitivityDrawing" : "eventProbabilitySensitivityDrawing",
182       "hasoferReliabilityIndexSensitivityGraph" : "hasoferReliabilityIndexSensitivityGraph",
183       "hasoferReliabilityIndexSensitivityDrawing" : "hasoferReliabilityIndexSensitivityDrawing",
184       "modelEvaluationCalls" : 'results["modelEvaluationCalls"]',
185       "modelGradientCalls" : 'results["modelGradientCalls"]',
186       "modelHessianCalls" : 'results["modelHessianCalls"]',
187       "tvedtApproximation" : 'results["tvedtApproximation"]',
188       "hohenBichlerApproximation" : 'results["hohenBichlerApproximation"]',
189       "breitungApproximation" : 'results["breitungApproximation"]',
190       }
191
192     # Ce dictionnaire fait la correspondance entre le mot-clef du catalogue et le flag de la bibliotheque
193     self.logFlags = {
194       "DebugMessages"   : "Log.DBG",
195       "WrapperMessages" : "Log.WRAPPER",
196       "UserMessages"    : "Log.USER",
197       "InfoMessages"    : "Log.INFO",
198       "WarningMessages" : "Log.WARN",
199       "ErrorMessages"   : "Log.ERROR",
200       }
201     
202   def CreeSTD (self) :
203     '''
204     Pilotage de la creation du fichier python
205     '''
206     TypeAnalyse = None
207     if ( self.DictMCVal.has_key( 'Type' ) ):
208       TypeAnalyse =  self.DictMCVal[ 'Type' ]
209
210     Traitement = None
211     subDict = {}
212     if ( self.traitement.has_key( TypeAnalyse ) ):
213       (Traitement, subDict) =  self.traitement[ TypeAnalyse ]
214
215     if ( Traitement is not None ):
216       self.texteSTD = apply( STDGenerateur.__dict__[ Traitement ], (self, subDict) )
217     
218     return self.texteSTD
219
220   def Header (self) :
221     '''
222     Imprime l entete commun a tous les fichiers
223     '''
224     txt  = headerSTD % self.OpenTURNS_path
225     txt += viewerSTD
226     txt += "# Definit le niveau d'affichage de la log\n"
227     txt += "%s = Log.NONE\n" % self.variable["flags"]
228     for flag in self.logFlags.keys():
229       if ( self.DictMCVal.has_key( flag ) ):
230         val =  self.DictMCVal[ flag ]
231         op = "-"
232         if val == 'yes' :
233           op = "+"
234         txt += "%s = %s %s %s\n" % (self.variable["flags"], self.variable["flags"], op, self.logFlags[ flag ])
235     txt += "Log.Show( %s )\n" % self.variable["flags"]
236     txt += "\n"
237     return txt
238
239   def Footer (self) :
240     '''
241     Imprime le pied de page commun a tous les fichiers
242     '''
243     return footerSTD
244
245   def MinMax (self, subDict):
246     '''
247     Produit le fichier study correspondant a une analyse Min/Max
248     '''
249     txt  = self.Header()
250     txt += self.Model()
251     
252     Methode = None
253     if ( self.DictMCVal.has_key( 'Method' ) ):
254       Methode =  self.DictMCVal[ 'Method' ]
255
256     Traitement = None
257     if ( subDict.has_key( Methode ) ):
258       Traitement =  subDict[ Methode ]
259
260     if ( Traitement is not None ):
261       txt += apply( STDGenerateur.__dict__[ Traitement ], (self,) )
262
263     txt += self.MinMaxResult()
264     
265     txt += self.Footer()
266     return txt
267
268   def Model (self):
269     '''
270     Importe le modele physique
271     '''
272     fonction = None
273     if ( self.DictMCVal.has_key( 'FileName' ) ):
274       name =  self.DictMCVal[ 'FileName' ]
275       #fonction = name[name.rfind('/')+1:name.rfind('.xml')]
276       
277     txt  = "# Charge le modele physique\n"
278     txt  = "%s = WrapperFile( '%s' )\n" % (self.variable["wrapper"], name)
279     txt += "%s = %s.getWrapperData()\n" % (self.variable["wrapperdata"], self.variable["wrapper"])
280
281     txt += "# Ces lignes sont utiles pour le fonctionnement du script sous Salome\n"
282     txt += "if globals().has_key('%s'):\n" % self.variable["framework"]
283     txt += "  %s = %s.getFrameworkData()\n" % (self.variable["frameworkdata"], self.variable["wrapperdata"])
284     txt += "  %s.studyid_ = %s['%s']\n"  % (self.variable["frameworkdata"], self.variable["framework"], self.variable["studyid"])
285     txt += "  %s.studycase_ = %s['%s']\n"  % (self.variable["frameworkdata"], self.variable["framework"], self.variable["studycase"])
286     txt += "  %s.componentname_ = %s['%s']\n"  % (self.variable["frameworkdata"], self.variable["framework"], self.variable["componentname"])
287     txt += "  %s.setFrameworkData( %s )\n" % (self.variable["wrapperdata"], self.variable["frameworkdata"])
288     txt += "  %s.setWrapperData( %s )\n" % (self.variable["wrapper"], self.variable["wrapperdata"])
289     txt += "# Fin des lignes pour Salome\n"
290     
291     txt += "%s = NumericalMathFunction( %s )\n" % (self.variable["model"], self.variable["wrapper"],)
292     txt += "%s = %s.getInputNumericalPointDimension()\n" % (self.variable["n"], self.variable["model"])
293     txt += "\n"
294     return txt
295
296   def ExperimentPlane (self):
297     '''
298     Etude par plan d experience
299     '''
300     txt  = "# Etude par plan d'experience\n"
301     txt += self.Levels()
302     txt += self.CenteredReductedGrid()
303     txt += self.ScaledVector()
304     txt += self.TranslationVector()
305     txt += "%s = %s\n" % (self.variable["inputSample"], self.variable["myExperimentPlane"])
306     txt += "\n"
307     txt += "# Etude 'Min/Max'\n"
308     txt += "# Calcul\n"
309     txt += "%s = %s( %s )\n" % (self.variable["outputSample"], self.variable["model"], self.variable["inputSample"])
310     txt += "\n"
311     return txt
312
313   def MinMaxRandomSampling (self):
314     '''
315     Etude par echantillonage aleatoire
316     '''
317     size = 0
318     if ( self.DictMCVal.has_key( 'SimulationsNumber' ) ):
319       size =  self.DictMCVal[ 'SimulationsNumber' ]
320
321     txt  = "# Etude par echantillonage aleatoire\n"
322     txt += self.InputDistribution()
323     txt += self.InputRandomVector()
324     txt += "\n"
325     txt += "# Etude 'Min/Max'\n"
326     txt += "# Calcul\n"
327     txt += "%s = %d\n" % (self.variable["inSize"], size)
328     txt += "%s = RandomVector( %s, %s )\n" % (self.variable["outputRandomVector"], self.variable["model"], self.variable["inputRandomVector"])
329     txt += "%s = %s.getNumericalSample( %s )\n" % (self.variable["outputSample"], self.variable["outputRandomVector"], self.variable["inSize"])
330     return txt
331
332   def InputDistribution (self):
333     '''
334     Cree la loi jointe des variables d entree
335     '''
336     txt  = "# Definit la loi jointe des variables d'entree\n"
337     txt += "%s = DistributionCollection( %s )\n" % (self.variable["collection"], self.variable["n"])
338     txt += "%s = Description( %s )\n" % (self.variable["description"], self.variable["n"])
339     txt += "\n"
340
341     dictVariables = {}
342     for variable in self.ListeVariablesIn:
343       nomVar = variable['ModelVariable'].get_name()
344       dictVariables[ nomVar ] = variable['Distribution']
345
346     i = 0
347     sortedVarNames = dictVariables.keys()
348     sortedVarNames.sort()
349     for variable in sortedVarNames:
350       conceptloi = dictVariables[ variable ]
351       loi = self.DictLois[ conceptloi ]
352       if loi.has_key( 'Kind' ):
353         marginale = "%s_%d" % (self.variable["marginal"], i)
354         txt += "# Definit la loi marginale de la composante %d\n" % i
355         txt += "%s = %s\n" % (marginale, apply( STDGenerateur.__dict__[ loi[ 'Kind' ] ], (self, loi) ))
356         txt += "%s.setName( '%s' )\n" % (marginale, conceptloi.get_name())
357         txt += "%s[ %d ] = '%s'\n" % (self.variable["description"], i, variable)
358         txt += "%s[ %d ] = Distribution( %s )\n" % (self.variable["collection"], i, marginale)
359         txt += "\n"
360         i += 1
361
362     txt += self.Copula()
363
364     txt += "# Definit la loi jointe\n"
365     txt += "%s = ComposedDistribution( %s, Copula( %s ) )\n" % (self.variable["distribution"], self.variable["collection"], self.variable["copula"])
366     txt += "%s.setDescription( %s )\n" % (self.variable["distribution"], self.variable["description"])
367     txt += "\n"
368     return txt
369
370   def Copula (self):
371     '''
372     Cree la copule de la loi jointe
373     '''
374     txt  = "# Definit la copule de la loi jointe\n"
375
376     if ( not self.DictMCVal.has_key( 'Copula' ) ):
377       self.DictMCVal[ 'Copula' ] = 'Independent'
378
379     if ( self.DictMCVal[ 'Copula' ] in ( 'Independent', ) ):
380       txt += "%s = IndependentCopula( %s )\n" % (self.variable["copula"], self.variable["n"])
381     elif ( self.DictMCVal[ 'Copula' ] in ( 'Normal', ) ):
382       varList   = self.DictMCVal[ 'CorrelationMatrix' ][0]
383       dimension = len(varList)
384       txt += "%s = {}\n" % self.variable["correlation"]
385       for i in range( dimension ):
386         txt += "%s['%s'] = {}\n" % (self.variable["correlation"], varList[i])
387         for j in range ( dimension ):
388           txt += "%s['%s']['%s'] = %g\n" % (self.variable["correlation"], varList[i], varList[j], self.DictMCVal[ 'CorrelationMatrix' ][i+1][j])
389       txt += "%s = getCorrelationMatrixFromMap( %s.getVariableList(), %s )\n" % (self.variable["R"], self.variable["wrapperdata"], self.variable["correlation"])
390       txt += "%s = NormalCopula( %s )\n" % (self.variable["copula"], self.variable["R"])
391
392     txt += "\n"
393     return txt
394
395   def InputRandomVector (self):
396     '''
397     Cree le vector aleatoire d entree
398     '''
399     txt  = "# Definit le vecteur aleatoire d'entree\n"
400     txt += "%s = RandomVector( %s )\n" % (self.variable["inputRandomVector"], self.variable["distribution"])
401     txt += "\n"
402     return txt
403
404   def OutputRandomVector (self):
405     '''
406     Cree le vector aleatoire de sortie
407     '''
408     nomVar = "output"
409     for variable in self.ListeVariablesOut:
410       nomVar = variable['ModelVariable'].get_name()
411
412     txt  = "# Definit le vecteur aleatoire de sortie\n"
413     txt += "%s = RandomVector( %s, %s )\n" % (self.variable["outputRandomVector"], self.variable["model"], self.variable["inputRandomVector"])
414     txt += "%s.setName( '%s' )\n" % (self.variable["outputRandomVector"], nomVar)
415     txt += "\n"
416     return txt
417
418   def ScaledVector (self):
419     '''
420     Definit les coefficients multiplicateurs par composante du vecteur
421     '''
422     dimension = 0
423     if ( self.DictMCVal.has_key( 'UnitsPerDimension' ) ):
424       unitsPerDimension =  self.DictMCVal[ 'UnitsPerDimension' ]
425       dimension = len( unitsPerDimension )
426     
427     txt  = "# Definit les facteurs d'echelle dans chaque direction\n"
428     txt += "%s = NumericalPoint( %s )\n" % (self.variable["scaledVector"], self.variable["n"])
429     for i in range(dimension):
430       txt += "%s[%d] = %g\n" % (self.variable["scaledVector"], i, unitsPerDimension[i])
431     txt += "%s.scale( %s )\n" % (self.variable["myExperimentPlane"], self.variable["scaledVector"])
432     txt += "\n"
433     return txt
434
435   def TranslationVector (self):
436     '''
437     Definit le vecteur de translation
438     '''
439     dimension = 0
440     if ( self.DictMCVal.has_key( 'Center' ) ):
441       center =  self.DictMCVal[ 'Center' ]
442       dimension = len( center )
443     
444     txt  = "# Definit le vecteur de translation\n"
445     txt += "%s = NumericalPoint( %s )\n" % (self.variable["translationVector"], self.variable["n"])
446     for i in range(dimension):
447       txt += "%s[%d] = %g\n" % (self.variable["translationVector"], i, center[i])
448     txt += "%s.translate( %s )\n" % (self.variable["myExperimentPlane"], self.variable["translationVector"])
449     txt += "\n"
450     return txt
451
452   def Levels (self):
453     '''
454     Definit les niveaux du plan d experience
455     '''
456     dimension = 0
457     if ( self.DictMCVal.has_key( 'Levels' ) ):
458       levels =  self.DictMCVal[ 'Levels' ]
459       dimension = len( levels )
460     
461     txt  = "# Definit les niveaux de la structure de grille\n"
462     txt += "%s = NumericalPoint( %d )\n" % (self.variable["levels"], dimension)
463     for i in range(dimension):
464       txt += "%s[%d] = %g\n" % (self.variable["levels"], i, levels[i])
465     txt += "\n"
466     return txt
467
468   def CenteredReductedGrid (self):
469     '''
470     Definit la grille reduite du plan d experience
471     '''
472     plane = None
473     if ( self.DictMCVal.has_key( 'ExperimentPlane' ) ):
474       plane =  self.DictMCVal[ 'ExperimentPlane' ]
475
476     txt  = "# Cree le plan d'experience centre reduit\n"
477     txt += "%s = %s(%s, %s)\n" % (self.variable["myCenteredReductedGrid"], plane, self.variable["n"], self.variable["levels"])
478     txt += "%s = %s.generate()\n" % (self.variable["myExperimentPlane"], self.variable["myCenteredReductedGrid"])
479     txt += "\n"
480     return txt
481
482   def MinMaxResult (self):
483     '''
484     Produit les resultats de l etude
485     '''
486     txt  = "# Resultats\n"
487     txt += "%s = %s.getMin()\n" % (self.variable["minValue"], self.variable["outputSample"])
488     txt += "print '%s = ', %s\n" % ("minValue", self.variable["minValue"])
489     txt += "\n"
490     txt += "%s = %s.getMax()\n" % (self.variable["maxValue"], self.variable["outputSample"])
491     txt += "print '%s = ', %s\n" % ("maxValue", self.variable["maxValue"])
492     txt += "\n"
493     return txt
494
495   def CentralUncertainty (self, subDict):
496     '''
497     Produit le fichier study correspondant a une analyse d incertitude en valeur centrale
498     '''
499     txt  = self.Header()
500     txt += self.Model()
501     txt += self.InputDistribution()
502     txt += self.InputRandomVector()
503     txt += self.OutputRandomVector()
504    
505     Methode = None
506     if ( self.DictMCVal.has_key( 'Method' ) ):
507       Methode =  self.DictMCVal[ 'Method' ]
508
509     Traitement = None
510     if ( subDict.has_key( Methode ) ):
511       Traitement =  subDict[ Methode ]
512
513     if ( Traitement is not None ):
514       txt += "# Etude 'Central Uncertainty'\n"
515       txt += apply( STDGenerateur.__dict__[ Traitement ], (self,) )
516
517     txt += self.Footer()
518     return txt
519
520
521   def TaylorVarianceDecomposition (self):
522     '''
523     Etude par decomposition de Taylor
524     '''
525     txt  = "# Cumul quadratique (decomposition de Taylor)\n"
526     txt += "%s = QuadraticCumul( %s )\n" % (self.variable["myQuadraticCumul"], self.variable["outputRandomVector"])
527     txt += "\n"
528     txt += "# Resultats\n"
529     
530     if ( self.DictMCVal.has_key( 'MeanFirstOrder' ) ):
531       if ( self.DictMCVal[ 'MeanFirstOrder' ] == "yes" ):
532         txt += "%s = %s.getMeanFirstOrder()\n" % (self.variable["meanFirstOrder"], self.variable["myQuadraticCumul"])
533         txt += "print '%s = ', %s\n" % ("mean First Order", self.variable["meanFirstOrder"])
534         txt += "\n"
535        
536     if ( self.DictMCVal.has_key( 'MeanSecondOrder' ) ):
537       if ( self.DictMCVal[ 'MeanSecondOrder' ] == "yes" ):
538         txt += "%s = %s.getMeanSecondOrder()\n" % (self.variable["meanSecondOrder"], self.variable["myQuadraticCumul"])
539         txt += "print '%s = ', %s\n" % ("mean Second Order", self.variable["meanSecondOrder"])
540         txt += "\n"
541
542     if ( self.DictMCVal.has_key( 'StandardDeviationFirstOrder' ) ):
543       if ( self.DictMCVal[ 'StandardDeviationFirstOrder' ] == "yes" ):
544         txt += "%s = %s.getCovariance()\n" % (self.variable["standardDeviationFirstOrder"], self.variable["myQuadraticCumul"])
545         txt += "dim = %s.getDimension()\n" % self.variable["standardDeviationFirstOrder"]
546         txt += "for i in range( dim ):\n"
547         txt += "  %s[ i, i ] = math.sqrt( %s[ i, i ] )\n" % (self.variable["standardDeviationFirstOrder"], self.variable["standardDeviationFirstOrder"])
548         txt += "  print '%s = ', %s[ i, i ]\n" % ("standard Deviation First Order", self.variable["standardDeviationFirstOrder"])
549         txt += "\n"
550
551     if ( self.DictMCVal.has_key( 'ImportanceFactor' ) ):
552       if ( self.DictMCVal[ 'ImportanceFactor' ] == "yes" ):
553         txt += "%s = %s.getImportanceFactors()\n" % (self.variable["importanceFactors"], self.variable["myQuadraticCumul"])
554         txt += "for i in range(%s.getDimension()):\n" % self.variable["importanceFactors"]
555         txt += "  print %s.getDescription()[i], ':', %s[i]*100., '%%'\n" % (self.variable["distribution"], self.variable["importanceFactors"])
556         txt += "\n"
557         txt += "%s = %s.drawImportanceFactors()\n" % (self.variable["importanceFactorsGraph"], self.variable["myQuadraticCumul"])
558         txt += "#Show( %s )\n"  % self.variable["importanceFactorsGraph"]
559         txt += "%s = '%s'\n" % (self.variable["importanceFactorsDrawing"], self.DictMCVal[ 'ImportanceFactorDrawingFilename' ])
560         txt += "%s.draw( %s )\n" % (self.variable["importanceFactorsGraph"], self.variable["importanceFactorsDrawing"])
561         txt += "ViewImage( %s.getBitmap() )\n"  % self.variable["importanceFactorsGraph"]
562         txt += "print 'bitmap =', %s.getBitmap()\n"  % self.variable["importanceFactorsGraph"]
563         txt += "print 'postscript =', %s.getPostscript()\n"  % self.variable["importanceFactorsGraph"]
564         txt += "\n"
565         
566     txt += "\n"
567     return txt
568
569   def CentralUncertaintyRandomSampling (self):
570     '''
571     Etude par echantillonage aleatoire
572     '''
573     size = 0
574     if ( self.DictMCVal.has_key( 'SimulationsNumber' ) ):
575       size =  self.DictMCVal[ 'SimulationsNumber' ]
576
577     txt  = "# Echantillonnage aleatoire de la variable de sortie\n"
578     txt += "%s = %d\n" % (self.variable["inSize"], size)
579     txt += "%s = %s.getNumericalSample( %s )\n" % (self.variable["inputSample"], self.variable["inputRandomVector"], self.variable["inSize"])
580     txt += "%s = %s( %s )\n" % (self.variable["outputSample"], self.variable["model"], self.variable["inputSample"])
581     txt += "\n"
582
583     if ( self.DictMCVal.has_key( 'EmpiricalMean' ) ):
584       if ( self.DictMCVal[ 'EmpiricalMean' ] == "yes" ):
585         txt += "%s = %s.computeMean()\n" % (self.variable["empiricalMean"], self.variable["outputSample"])
586         txt += "print '%s =', %s[0]\n" % ("empirical Mean", self.variable["empiricalMean"])
587         txt += "\n"
588
589     if ( self.DictMCVal.has_key( 'EmpiricalStandardDeviation' ) ):
590       if ( self.DictMCVal[ 'EmpiricalStandardDeviation' ] == "yes" ):
591         txt += "%s = %s.computeCovariance()\n" % (self.variable["empiricalStandardDeviation"], self.variable["outputSample"])
592         txt += "dim = %s.getDimension()\n" % self.variable["empiricalStandardDeviation"]
593         txt += "for i in range( dim ):\n"
594         txt += "  %s[ i, i ] = math.sqrt( %s[ i, i ] )\n" % (self.variable["empiricalStandardDeviation"], self.variable["empiricalStandardDeviation"])
595         txt += "  print '%s = ', %s[ i, i ]\n" % ("empirical Standard Deviation", self.variable["empiricalStandardDeviation"])
596         txt += "\n"
597
598     if ( self.DictMCVal.has_key( 'EmpiricalQuantile_Order' ) ):
599       ordre = self.DictMCVal[ 'EmpiricalQuantile_Order' ]
600       txt += "%s = %s.computeQuantile( %s )\n" % (self.variable["empiricalQuantile"], self.variable["outputSample"], ordre)
601       txt += "print '%s ( %s ) =', %s\n" % ("empirical Quantile", ordre, self.variable["empiricalQuantile"])
602       txt += "\n"
603    
604     if ( self.DictMCVal.has_key( 'CorrelationAnalysis' ) ):
605       if ( self.DictMCVal[ 'CorrelationAnalysis' ] == "yes" ):
606         txt += "if ( %s.getDimension() == 1 ):\n" % self.variable["outputSample"]
607         txt += "  %s = CorrelationAnalysis.PCC( %s, %s )\n" % (self.variable["PCCcoefficient"], self.variable["inputSample"], self.variable["outputSample"])
608         txt += "  print 'PCC Coefficients:'\n"
609         txt += "  for i in range( %s ):\n" % self.variable["n"]
610         txt += "    print %s.getDescription()[i], ':', %s[i]\n" % (self.variable["distribution"], self.variable["PCCcoefficient"])
611         txt += "\n"
612         txt += "  %s = CorrelationAnalysis.PRCC( %s, %s )\n" % (self.variable["PRCCcoefficient"], self.variable["inputSample"], self.variable["outputSample"])
613         txt += "  print 'PRCC Coefficients:'\n"
614         txt += "  for i in range( %s ):\n" % self.variable["n"]
615         txt += "    print %s.getDescription()[i], ':', %s[i]\n" % (self.variable["distribution"], self.variable["PRCCcoefficient"])
616         txt += "\n"
617         txt += "  %s = CorrelationAnalysis.SRC( %s, %s )\n" % (self.variable["SRCcoefficient"], self.variable["inputSample"], self.variable["outputSample"])
618         txt += "  print 'SRC Coefficients:'\n"
619         txt += "  for i in range( %s ):\n" % self.variable["n"]
620         txt += "    print %s.getDescription()[i], ':', %s[i]\n" % (self.variable["distribution"], self.variable["SRCcoefficient"])
621         txt += "\n"
622         txt += "  %s = CorrelationAnalysis.SRRC( %s, %s )\n" % (self.variable["SRRCcoefficient"], self.variable["inputSample"], self.variable["outputSample"])
623         txt += "  print 'SRRC Coefficients:'\n"
624         txt += "  for i in range( %s ):\n" % self.variable["n"]
625         txt += "    print %s.getDescription()[i], ':', %s[i]\n" % (self.variable["distribution"], self.variable["SRRCcoefficient"])
626         txt += "\n"
627    
628     if ( self.DictMCVal.has_key( 'KernelSmoothing' ) ):
629       if ( self.DictMCVal[ 'KernelSmoothing' ] == "yes" ):
630         txt += "# Kernel Smoohing\n"
631         txt += "%s = KernelSmoothing()\n" % self.variable["kernel"]
632         txt += "if ( %s.getDimension() == 1 ):\n" % self.variable["outputSample"]
633         txt += "  %s.setName( 'Output' )\n" % self.variable["outputSample"]
634         txt += "  %s = %s.buildImplementation( %s, 'TRUE')\n" % (self.variable["kernelSmoothedDist"], self.variable["kernel"], self.variable["outputSample"])
635         txt += "  %s = %s.drawPDF()\n" % (self.variable["kernelSmoothedGraph"], self.variable["kernelSmoothedDist"])
636         txt += "  #Show( %s )\n" % self.variable["kernelSmoothedGraph"]
637         txt += "  %s = '%s'\n" % (self.variable["kernelSmoothedPDFDrawing"], self.DictMCVal[ 'KernelSmoothingDrawingFilename' ])
638         txt += "  %s.draw( %s )\n" % (self.variable["kernelSmoothedGraph"], self.variable["kernelSmoothedPDFDrawing"])
639         txt += "  ViewImage( %s.getBitmap() )\n"  % self.variable["kernelSmoothedGraph"]
640         txt += "  print 'bitmap =', %s.getBitmap()\n"  % self.variable["kernelSmoothedGraph"]
641         txt += "  print 'postscript =', %s.getPostscript()\n"  % self.variable["kernelSmoothedGraph"]
642         txt += "\n"
643    
644     return txt
645
646   def ThresholdExceedence (self, subDict):
647     '''
648     Produit le fichier study correspondant a une analyse de depassement de seuil
649     '''
650     txt  = self.Header()
651     txt += "# Etude 'Threshold Exceedence'\n"
652
653     txt += self.RandomGenerator()
654     txt += self.Model()
655     txt += self.InputDistribution()
656     txt += self.InputRandomVector()
657     txt += self.OutputRandomVector()
658     txt += self.Event()
659    
660     Methode = None
661     if ( self.DictMCVal.has_key( 'Method' ) ):
662       Methode =  self.DictMCVal[ 'Method' ]
663
664     Traitement = None
665     if ( subDict.has_key( Methode ) ):
666       Traitement =  subDict[ Methode ]
667
668     if ( Traitement is not None ):
669       txt += apply( STDGenerateur.__dict__[ Traitement ], (self, subDict) )
670
671     txt += self.Footer()
672     return txt
673
674   def Simulation (self, subDict):
675     '''
676     Methodes de simulation
677     '''
678     Algorithme = None
679     if ( self.DictMCVal.has_key( 'Algorithm' ) ):
680       Algorithme =  self.DictMCVal[ 'Algorithm' ]
681
682     Traitement = None
683     if ( subDict.has_key( Algorithme ) ):
684       Traitement =  subDict[ Algorithme ]
685
686     if ( Traitement is not None ):
687       txt = apply( STDGenerateur.__dict__[ Traitement ], (self,) )
688
689     maxOuterSampling = None
690     if ( self.DictMCVal.has_key( 'MaximumOuterSampling' ) ):
691       maxOuterSampling = self.DictMCVal[ 'MaximumOuterSampling' ]
692       txt += "%s.setMaximumOuterSampling( %s )\n" % (self.variable["myAlgo"], maxOuterSampling)
693
694     blockSize = None
695     if ( self.DictMCVal.has_key( 'BlockSize' ) ):
696       blockSize = self.DictMCVal[ 'BlockSize' ]
697       txt += "%s.setBlockSize( %s )\n" % (self.variable["myAlgo"], blockSize)
698
699     maxCoefficientOfVariation = None
700     if ( self.DictMCVal.has_key( 'MaximumCoefficientOfVariation' ) ):
701       maxCoefficientOfVariation = self.DictMCVal[ 'MaximumCoefficientOfVariation' ]
702       txt += "%s.setMaximumCoefficientOfVariation( %s )\n" % (self.variable["myAlgo"], maxCoefficientOfVariation)
703
704     txt += "%s.run()\n"  % self.variable["myAlgo"]
705     txt += "\n"
706     txt += "# Resultats de la simulation\n"
707     txt += "%s = %s.getResult()\n"  % (self.variable["myResult"], self.variable["myAlgo"])
708     txt += "\n"
709
710     if ( self.DictMCVal.has_key( 'Probability' ) ):
711       if ( self.DictMCVal[ 'Probability' ] == "yes" ):
712         txt += "%s = %s.getProbabilityEstimate()\n" % (self.variable["probability"], self.variable["myResult"])
713         txt += "print '%s =', %s\n" % ("probability", self.variable["probability"])
714         txt += "\n"
715
716     if ( self.DictMCVal.has_key( 'StandardDeviation' ) ):
717       if ( self.DictMCVal[ 'StandardDeviation' ] == "yes" ):
718         txt += "%s = math.sqrt( %s.getProbabilityEstimate() )\n" % (self.variable["standardDeviation"], self.variable["myResult"])
719         txt += "print '%s =', %s\n" % ("standard Deviation", self.variable["standardDeviation"])
720         txt += "\n"
721
722     if ( self.DictMCVal.has_key( 'ConfidenceInterval' ) and self.DictMCVal.has_key( 'Probability' ) ):
723       if ( ( self.DictMCVal[ 'ConfidenceInterval' ] == "yes" ) and ( self.DictMCVal[ 'Probability' ] == "yes" ) ):
724         level = self.DictMCVal[ 'Level' ]
725         txt += "%s = %s.getConfidenceLength( %s )\n" % (self.variable["length"], self.variable["myResult"], level)
726         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"])
727         txt += "\n"
728
729     if ( self.DictMCVal.has_key( 'VariationCoefficient' ) ):
730       if ( self.DictMCVal[ 'VariationCoefficient' ] == "yes" ):
731         txt += "%s = %s.getCoefficientOfVariation()\n" % (self.variable["coefficientOfVariation"], self.variable["myResult"])
732         txt += "print '%s =', %s\n" % ("coefficient of Variation", self.variable["coefficientOfVariation"])
733         txt += "\n"
734
735     if ( self.DictMCVal.has_key( 'SimulationsNumber' ) ):
736       if ( self.DictMCVal[ 'SimulationsNumber' ] == "yes" ):
737         txt += "%s = %s.getOuterSampling()\n" % (self.variable["simulationNumbers"], self.variable["myResult"])
738         txt += "print '%s =', %s\n" % ("simulation Numbers", self.variable["simulationNumbers"])
739         txt += "\n"
740
741     if ( self.DictMCVal.has_key( 'ConvergenceGraph' ) and self.DictMCVal.has_key( 'ConfidenceInterval' ) ):
742       if ( ( self.DictMCVal[ 'ConvergenceGraph' ] == "yes" ) and ( self.DictMCVal[ 'ConfidenceInterval' ] == "yes" ) ):
743         txt += "%s = %s\n" % (self.variable["alpha"], self.DictMCVal[ 'Level' ])
744         txt += "%s = %s.drawProbabilityConvergence( %s )\n" % (self.variable["convergenceGraph"], self.variable["myAlgo"], self.variable["alpha"])
745         txt += "#Show( %s )\n" % self.variable["convergenceGraph"]
746         txt += "%s = '%s'\n" % (self.variable["convergenceDrawing"], self.DictMCVal[ 'ConvergenceDrawingFilename' ])
747         txt += "%s.draw( %s )\n" % (self.variable["convergenceGraph"], self.variable["convergenceDrawing"])
748         txt += "ViewImage( %s.getBitmap() )\n" % self.variable["convergenceGraph"]
749         txt += "\n"
750
751     return txt
752
753   def Analytical (self, subDict):
754     '''
755     Methodes analytiques
756     '''
757     txt = ""
758     
759     OptimizationAlgo = None
760     if ( self.DictMCVal.has_key( 'OptimizationAlgorithm' ) ):
761       OptimizationAlgo =  self.DictMCVal[ 'OptimizationAlgorithm' ]
762
763     Traitement = None
764     if ( subDict.has_key( OptimizationAlgo ) ):
765       Traitement =  subDict[ OptimizationAlgo ]
766
767     if ( Traitement is not None ):
768       txt += apply( STDGenerateur.__dict__[ Traitement ], (self,) )
769
770     txt += self.OptimizerSettings()
771     txt += self.PhysicalStartingPoint()
772
773     Approximation = None
774     if ( self.DictMCVal.has_key( 'Approximation' ) ):
775       Approximation =  self.DictMCVal[ 'Approximation' ]
776
777     Traitement = None
778     if ( subDict.has_key( Approximation ) ):
779       Traitement =  subDict[ Approximation ]
780
781     if ( Traitement is not None ):
782       txt += apply( STDGenerateur.__dict__[ Traitement ], (self,) )
783
784     txt += self.RunAlgorithm()
785     txt += self.AnalyticalResult()
786
787     return txt
788
789   def OptimizerSettings (self):
790     '''
791     Parametrage de l optimiseur
792     '''
793     txt = ""
794     
795     simulationNumbers = None
796     if ( self.DictMCVal.has_key( 'MaximumIterationsNumber' ) ):
797       simulationNumbers = self.DictMCVal[ 'MaximumIterationsNumber' ]
798       txt += "%s.setMaximumIterationsNumber( %s )\n" % (self.variable["myOptimizer"], simulationNumbers)
799
800     absoluteError = None
801     if ( self.DictMCVal.has_key( 'MaximumAbsoluteError' ) ):
802       absoluteError = self.DictMCVal[ 'MaximumAbsoluteError' ]
803       txt += "%s.setMaximumAbsoluteError( %s )\n" % (self.variable["myOptimizer"], absoluteError)
804
805     relativeError = None
806     if ( self.DictMCVal.has_key( 'MaximumRelativeError' ) ):
807       relativeError = self.DictMCVal[ 'MaximumRelativeError' ]
808       txt += "%s.setMaximumRelativeError( %s )\n" % (self.variable["myOptimizer"], relativeError)
809
810     residualError = None
811     if ( self.DictMCVal.has_key( 'MaximumResidualError' ) ):
812       residualError = self.DictMCVal[ 'MaximumResidualError' ]
813       txt += "%s.setMaximumResidualError( %s )\n" % (self.variable["myOptimizer"], residualError)
814
815     constraintError = None
816     if ( self.DictMCVal.has_key( 'MaximumConstraintError' ) ):
817       constraintError = self.DictMCVal[ 'MaximumConstraintError' ]
818       txt += "%s.setMaximumConstraintError( %s )\n" % (self.variable["myOptimizer"], constraintError)
819
820     txt += "\n"
821
822     return txt
823
824   def PhysicalStartingPoint (self):
825     '''
826     Point physique de depart
827     '''
828     txt  = "# Point physique de depart\n"
829
830     if ( self.DictMCVal.has_key( 'PhysicalStartingPoint' ) ):
831       point = self.DictMCVal[ 'PhysicalStartingPoint' ]
832       dimension = len( point )
833       txt += "%s = NumericalPoint( %d )\n" % (self.variable["startingPoint"], dimension)
834       for i in range( dimension ):
835         txt += "%s[ %d ] = %g\n" % (self.variable["startingPoint"], i, point[i])
836     else:
837       txt += "%s = %s.getMean()\n" % (self.variable["startingPoint"], self.variable["inputRandomVector"])
838       
839     txt += "\n"
840
841     return txt
842
843   def AnalyticalResult (self):
844     '''
845     Resultat des methodes analytiques
846     '''
847     txt  = "# Resultat des methodes analytiques\n"
848     txt += "%s = %s.getResult()\n" % (self.variable["myResult"], self.variable["myAlgo"])
849     
850     if ( self.DictMCVal.has_key( 'Probability' ) ):
851       if ( self.DictMCVal[ 'Probability' ] == "yes" ):
852         txt += "%s = %s.getEventProbability()\n" % (self.variable["probability"], self.variable["myResult"])
853         txt += "print '%s =', %s\n" % (self.variable["probability"], self.variable["probability"])
854         txt += "\n"
855
856     if ( self.DictMCVal.has_key( 'HasoferReliabilityIndex' ) ):
857       if ( self.DictMCVal[ 'HasoferReliabilityIndex' ] == "yes" ):
858         txt += "%s = %s.getHasoferReliabilityIndex()\n" % (self.variable["hasoferReliabilityIndex"], self.variable["myResult"])
859         txt += "print '%s =', %s\n" % ("hasofer Reliability Index", self.variable["hasoferReliabilityIndex"])
860         txt += "\n"
861
862     if ( self.DictMCVal.has_key( 'DesignPoint' ) ):
863       if ( self.DictMCVal[ 'DesignPoint' ] == "yes" ):
864         txt += "%s = %s.getStandardSpaceDesignPoint()\n" % (self.variable["standardSpaceDesignPoint"], self.variable["myResult"])
865         txt += "print '%s =', %s\n" % ("standard Space Design Point", self.variable["standardSpaceDesignPoint"])
866         txt += "%s = %s.getPhysicalSpaceDesignPoint()\n" % (self.variable["physicalSpaceDesignPoint"], self.variable["myResult"])
867         txt += "print '%s =', %s\n" % ("physical Space Design Point", self.variable["physicalSpaceDesignPoint"])
868         txt += "\n"
869
870     if ( self.DictMCVal.has_key( 'ImportanceFactor' ) ):
871       if ( self.DictMCVal[ 'ImportanceFactor' ] == "yes" ):
872         txt += "print 'Importance Factors:'\n"
873         txt += "%s = %s.getImportanceFactors()\n" % (self.variable["importanceFactors"], self.variable["myResult"])
874         txt += "for i in range(%s.getDimension()):\n" % self.variable["importanceFactors"]
875         txt += "  print %s.getDescription()[i], ':', %s[i]*100., '%%'\n" % (self.variable["distribution"], self.variable["importanceFactors"])
876         txt += "\n"
877         txt += "%s = %s.drawImportanceFactors()\n" % (self.variable["importanceFactorsGraph"], self.variable["myResult"])
878         txt += "#Show( %s )\n"  % self.variable["importanceFactorsGraph"]
879         txt += "%s = '%s'\n" % (self.variable["importanceFactorsDrawing"], self.DictMCVal[ 'ImportanceFactorDrawingFilename' ])
880         txt += "%s.draw( %s )\n" % (self.variable["importanceFactorsGraph"], self.variable["importanceFactorsDrawing"])
881         txt += "ViewImage( %s.getBitmap() )\n"  % self.variable["importanceFactorsGraph"]
882         txt += "print 'bitmap =', %s.getBitmap()\n"  % self.variable["importanceFactorsGraph"]
883         txt += "print 'postscript =', %s.getPostscript()\n"  % self.variable["importanceFactorsGraph"]
884         txt += "\n"
885
886     if ( self.DictMCVal.has_key( 'FORMEventProbabilitySensitivity' ) ):
887       if ( self.DictMCVal[ 'FORMEventProbabilitySensitivity' ] == "yes" ):
888         txt += "%s = %s.getEventProbabilitySensitivity()\n" % (self.variable["eventProbabilitySensitivity"], self.variable["myResult"])
889         txt += "print 'FORM Event Probability Sensitivity:'\n"
890         txt += "for i in range( %s ):\n" % self.variable["n"]
891         txt += "  print %s.getDescription()[i], ':'\n" % self.variable["distribution"]
892         txt += "  for j in range( %s[i].getDimension() ):\n" % self.variable["eventProbabilitySensitivity"]
893         txt += "    print '  ', %s[i].getDescription()[j], ':', %s[i][j]\n" % (self.variable["eventProbabilitySensitivity"], self.variable["eventProbabilitySensitivity"])
894         txt += "\n"
895         txt += "%s = %s.drawEventProbabilitySensitivity()[0]\n" % (self.variable["eventProbabilitySensitivityGraph"], self.variable["myResult"])
896         txt += "#Show( %s )\n" % self.variable["eventProbabilitySensitivityGraph"]
897         txt += "%s = '%s'\n" % (self.variable["eventProbabilitySensitivityDrawing"], self.DictMCVal[ 'FORMEventProbabilitySensitivityDrawingFilename' ])
898         txt += "%s.draw( %s )\n" % (self.variable["eventProbabilitySensitivityGraph"], self.variable["eventProbabilitySensitivityDrawing"])
899         txt += "ViewImage( %s.getBitmap() )\n"  % self.variable["eventProbabilitySensitivityGraph"]
900         txt += "print 'bitmap =', %s.getBitmap()\n"  % self.variable["eventProbabilitySensitivityGraph"]
901         txt += "print 'postscript =', %s.getPostscript()\n"  % self.variable["eventProbabilitySensitivityGraph"]
902         txt += "\n"
903
904     if ( self.DictMCVal.has_key( 'HasoferReliabilityIndexSensitivity' ) ):
905       if ( self.DictMCVal[ 'HasoferReliabilityIndexSensitivity' ] == "yes" ):
906         txt += "%s = %s.getHasoferReliabilityIndexSensitivity()\n" % (self.variable["hasoferReliabilityIndexSensitivity"], self.variable["myResult"])
907         txt += "print 'Hasofer Reliability Index Sensitivity:'\n"
908         txt += "for i in range( %s ):\n" % self.variable["n"]
909         txt += "  print %s.getDescription()[i], ':'\n" % self.variable["distribution"]
910         txt += "  for j in range( %s[i].getDimension() ):\n" % self.variable["hasoferReliabilityIndexSensitivity"]
911         txt += "    print '  ', %s[i].getDescription()[j], ':', %s[i][j]\n" % (self.variable["hasoferReliabilityIndexSensitivity"], self.variable["hasoferReliabilityIndexSensitivity"])
912         txt += "\n"
913         txt += "%s = %s.drawHasoferReliabilityIndexSensitivity()[0]\n" % (self.variable["hasoferReliabilityIndexSensitivityGraph"], self.variable["myResult"])
914         txt += "#Show( %s )\n" % self.variable["hasoferReliabilityIndexSensitivityGraph"]
915         txt += "%s = '%s'\n" % (self.variable["hasoferReliabilityIndexSensitivityDrawing"], self.DictMCVal[ 'HasoferReliabilityIndexSensitivityDrawingFilename' ])
916         txt += "%s.draw( %s )\n" % (self.variable["hasoferReliabilityIndexSensitivityGraph"], self.variable["hasoferReliabilityIndexSensitivityDrawing"])
917         txt += "ViewImage( %s.getBitmap() )\n"  % self.variable["hasoferReliabilityIndexSensitivityGraph"]
918         txt += "print 'bitmap =', %s.getBitmap()\n"  % self.variable["hasoferReliabilityIndexSensitivityGraph"]
919         txt += "print 'postscript =', %s.getPostscript()\n"  % self.variable["hasoferReliabilityIndexSensitivityGraph"]
920         txt += "\n"
921
922     if ( self.DictMCVal.has_key( 'TvedtApproximation' ) ):
923       if ( self.DictMCVal[ 'TvedtApproximation' ] == "yes" ):
924         txt += "%s = %s.getEventProbabilityTvedt()\n" % (self.variable["tvedtApproximation"], self.variable["myResult"])
925         txt += "print '%s =', %s\n" % ("Tvedt Approximation", self.variable["tvedtApproximation"])
926         txt += "\n"
927
928     if ( self.DictMCVal.has_key( 'HohenBichlerApproximation' ) ):
929       if ( self.DictMCVal[ 'HohenBichlerApproximation' ] == "yes" ):
930         txt += "%s = %s.getEventProbabilityHohenBichler()\n" % (self.variable["hohenBichlerApproximation"], self.variable["myResult"])
931         txt += "print '%s =', %s\n" % ("HohenBichler Approximation", self.variable["tvedtApproximation"])
932         txt += "\n"
933
934     if ( self.DictMCVal.has_key( 'BreitungApproximation' ) ):
935       if ( self.DictMCVal[ 'BreitungApproximation' ] == "yes" ):
936         txt += "%s = %s.getEventProbabilityBreitung()\n" % (self.variable["breitungApproximation"], self.variable["myResult"])
937         txt += "print '%s =', %s\n" % ("Breitung Approximation", self.variable["breitungApproximation"])
938         txt += "\n"
939
940
941     return txt
942
943   def RandomGenerator (self):
944     '''
945     Generateur Aleatoire
946     '''
947     txt = ""
948     
949     seed = None
950     if ( self.DictMCVal.has_key( 'RandomGeneratorSeed' ) ):
951       seed = self.DictMCVal[ 'RandomGeneratorSeed' ]
952       txt += "# Initialise le generateur aleatoire\n"
953       txt += "RandomGenerator.SetSeed( %s )\n" % seed
954       txt += "\n"
955     
956     return txt
957
958   def Event (self):
959     '''
960     Definition de l evenement de defaillance
961     '''
962     operator = None
963     if ( self.DictMCVal.has_key( 'ComparisonOperator' ) ):
964       operator = self.DictMCVal[ 'ComparisonOperator' ]
965
966     threshold = None
967     if ( self.DictMCVal.has_key( 'Threshold' ) ):
968       threshold = self.DictMCVal[ 'Threshold' ]
969     
970     txt  = "# Evenement de defaillance\n"
971     txt += "%s = Event( %s, ComparisonOperator( %s() ), %s )\n" % (self.variable["myEvent"], self.variable["outputRandomVector"], operator, threshold)
972     txt += "%s.setName( '%s' )\n" % (self.variable["myEvent"], "myEvent")
973     txt += "\n"
974     return txt
975     
976   def MonteCarlo (self):
977     '''
978     Methode de MonteCarlo
979     '''
980     txt  = "# Simulation par MonteCarlo\n"
981     txt += "%s = MonteCarlo( %s )\n"  % (self.variable["myAlgo"], self.variable["myEvent"])
982     txt += "\n"
983    
984     return txt
985
986   def LHS (self):
987     '''
988     Methode LHS
989     '''
990     txt  = "# Simulation par LHS\n"
991     txt += "%s = LHS( %s )\n"  % (self.variable["myAlgo"], self.variable["myEvent"])
992     txt += "\n"
993    
994     return txt
995
996   def ImportanceSampling (self):
997     '''
998     Methode de tirage d importance
999     '''
1000     dimension = 0
1001     if ( self.DictMCVal.has_key( 'MeanVector' ) ):
1002       meanVector =  self.DictMCVal[ 'MeanVector' ]
1003       dimension = len( meanVector )
1004         
1005     txt  = "# Simulation par Tirage d'importance\n"
1006     txt += "# Densite d'importance\n"
1007     txt += "%s = NumericalPoint( %s )\n" % (self.variable["meanVector"], self.variable["n"])
1008     for i in range(dimension):
1009       txt += "%s[%d] = %g\n" % (self.variable["meanVector"], i, meanVector[i])
1010       
1011     txt += "%s = Normal( %s, CovarianceMatrix( IdentityMatrix( %s ) ) )\n" % (self.variable["importanceDensity"], self.variable["meanVector"], self.variable["n"])
1012     txt += "%s = ImportanceSampling( %s, Distribution( %s ) )\n"  % (self.variable["myAlgo"], self.variable["myEvent"], self.variable["importanceDensity"])
1013     txt += "\n"
1014
1015     return txt
1016
1017   def FORM (self):
1018     '''
1019     Methode FORM
1020     '''
1021     txt  = "# Algorithme FORM\n"
1022     txt += "%s = FORM ( NearestPointAlgorithm( %s ), %s, %s )\n"  % (self.variable["myAlgo"], self.variable["myOptimizer"], self.variable["myEvent"], self.variable["startingPoint"])
1023     txt += "\n"
1024
1025     return txt
1026
1027   def SORM (self):
1028     '''
1029     Methode SORM
1030     '''
1031     txt  = "# Algorithme SORM\n"
1032     txt += "%s = SORM ( NearestPointAlgorithm( %s ), %s, %s )\n"  % (self.variable["myAlgo"], self.variable["myOptimizer"], self.variable["myEvent"], self.variable["startingPoint"])
1033     txt += "\n"
1034
1035     return txt
1036
1037   def RunAlgorithm (self):
1038     '''
1039     Do the computation
1040     '''
1041     txt = ""
1042     if ( self.DictMCVal.has_key( 'FunctionCallsNumber' ) ):
1043       if ( self.DictMCVal[ 'FunctionCallsNumber' ] == "yes" ):
1044         txt += "%s = %s.getEvaluationCallsNumber()\n" % (self.variable["modelEvaluationCalls"], self.variable["model"])
1045         txt += "%s = %s.getGradientCallsNumber()\n" % (self.variable["modelGradientCalls"], self.variable["model"])
1046         txt += "%s = %s.getHessianCallsNumber()\n" % (self.variable["modelHessianCalls"], self.variable["model"])
1047         txt += "\n"
1048
1049     txt += "# Perform the computation\n"
1050     txt += "%s.run()\n" % self.variable["myAlgo"]
1051     txt += "\n"
1052     
1053
1054     if ( self.DictMCVal.has_key( 'FunctionCallsNumber' ) ):
1055       if ( self.DictMCVal[ 'FunctionCallsNumber' ] == "yes" ):
1056         txt += "%s = %s.getEvaluationCallsNumber() - %s\n" % (self.variable["modelEvaluationCalls"], self.variable["model"], self.variable["modelEvaluationCalls"])
1057         txt += "%s = %s.getGradientCallsNumber() - %s\n" % (self.variable["modelGradientCalls"], self.variable["model"], self.variable["modelGradientCalls"])
1058         txt += "%s = %s.getHessianCallsNumber() - %s\n" % (self.variable["modelHessianCalls"], self.variable["model"], self.variable["modelHessianCalls"])
1059         txt += "\n"
1060         txt += "print '%s =', %s\n" % ("model Evaluation Calls", self.variable["modelEvaluationCalls"])
1061         txt += "print '%s =', %s\n" % ("model Gradient Calls", self.variable["modelGradientCalls"])
1062         txt += "print '%s =', %s\n" % ("model Hessian Calls", self.variable["modelHessianCalls"])
1063         txt += "\n"
1064
1065     return txt
1066
1067   def Cobyla (self):
1068     '''
1069     Methode Cobyla
1070     '''
1071     txt  = "# Optimisation par Cobyla\n"
1072     txt += "%s = Cobyla()\n" % self.variable["myOptimizer"]
1073     txt += "#%s = CobylaSpecificParameters()\n" % self.variable["specificParameters"]
1074     txt += "#%s.setSpecificParameters( %s )\n" % (self.variable["myOptimizer"], self.variable["specificParameters"])
1075     txt += "\n"
1076         
1077     return txt
1078
1079   def AbdoRackwitz (self):
1080     '''
1081     Methode AbdoRackwitz
1082     '''
1083     txt  = "# Optimisation par AbdoRackwitz\n"
1084     txt += "%s = AbdoRackwitz()\n" % self.variable["myOptimizer"]
1085     txt += "#%s = AbdoRackwitzSpecificParameters()\n" % self.variable["specificParameters"]
1086     txt += "#%s.setSpecificParameters( %s )\n" % (self.variable["myOptimizer"], self.variable["specificParameters"])
1087     txt += "\n"
1088     return txt
1089
1090   def Beta (self, loi):
1091     '''
1092     Definition de la loi Beta
1093     '''
1094     settings = {
1095       "RT" : "Beta.RT",
1096       "MuSigma" : "Beta.MUSIGMA",
1097       }
1098     if loi[ 'Settings' ] == 'RT' :
1099       arg1 = loi[ 'R' ]
1100       arg2 = loi[ 'T' ]
1101     else :
1102       arg1 = loi[ 'Mu'    ]
1103       arg2 = loi[ 'Sigma' ]
1104       
1105     arg3 = loi[ 'A' ]
1106     arg4 = loi[ 'B' ]
1107     txt = "Beta( %g, %g, %g, %g, %s )" % (arg1, arg2, arg3, arg4, settings[ loi[ 'Settings' ] ])
1108     return txt
1109   
1110   def Exponential (self, loi):
1111     '''
1112     Definition de la loi Exponential
1113     '''
1114     arg1 = loi[ 'Lambda' ]
1115     arg2 = loi[ 'Gamma'  ]
1116     txt = "Exponential( %g, %g )" % (arg1, arg2)
1117     return txt
1118   
1119   def Gamma (self, loi):
1120     '''
1121     Definition de la loi Gamma
1122     '''
1123     settings = {
1124       "KLambda" : "Gamma.KLAMBDA",
1125       "MuSigma" : "Gamma.MUSIGMA",
1126     }
1127     if loi[ 'Settings' ] == 'KLambda' :
1128       arg1 = loi[ 'K'      ]
1129       arg2 = loi[ 'Lambda' ]
1130     else :
1131       arg1 = loi[ 'Mu'    ]
1132       arg2 = loi[ 'Sigma' ]
1133       
1134     arg3 = loi[ 'Gamma' ]
1135     txt = "Gamma( %g, %g, %g, %s )" % (arg1, arg2, arg3, settings[ loi[ 'Settings' ] ])
1136     return txt
1137
1138   def Geometric (self, loi):
1139     '''
1140     Definition de la loi Geometric
1141     '''
1142     txt = "Geometric( %g )" % loi[ 'P' ]
1143     return txt
1144
1145   def Gumbel (self, loi):
1146     '''
1147     Definition de la loi Gumbel
1148     '''
1149     settings = {
1150       "AlphaBeta" : "Gumbel.ALPHABETA",
1151       "MuSigma" : "Gumbel.MUSIGMA",
1152     }
1153     if loi[ 'Settings' ] == 'AlphaBeta' :
1154       arg1 = loi[ 'Alpha' ]
1155       arg2 = loi[ 'Beta'  ]
1156     else :
1157       arg1 = loi[ 'Mu'    ]
1158       arg2 = loi[ 'Sigma' ]
1159       
1160     txt = "Gumbel( %g, %g, %s )" % (arg1, arg2, settings[ loi[ 'Settings' ] ])
1161     return txt
1162
1163   def Histogram (self, loi):
1164     '''
1165     Definition de la loi Histogram
1166     '''
1167     arg1 = loi[ 'First' ]
1168     arg2 = loi[ 'Values'  ]
1169     txt = "Histogram( %g, %s )" % (arg1, arg2)
1170     return txt
1171
1172   def Laplace (self, loi):
1173     '''
1174     Definition de la loi Laplace
1175     '''
1176     arg1 = loi[ 'Lambda' ]
1177     arg2 = loi[ 'Mu'     ]
1178     txt = "Laplace( %g, %g )" % (arg1, arg2)
1179     return txt
1180
1181   def Logistic (self, loi):
1182     '''
1183     Definition de la loi Logistic
1184     '''
1185     arg1 = loi[ 'Alpha' ]
1186     arg2 = loi[ 'Beta'  ]
1187     txt = "Logistic( %g, %g )" % (arg1, arg2)
1188     return txt
1189
1190   def LogNormal (self, loi):
1191     '''
1192     Definition de la loi LogNormal
1193     '''
1194     settings = {
1195       "MuSigmaLog" : "LogNormal.MUSIGMA_LOG",
1196       "MuSigma" : "LogNormal.MUSIGMA",
1197       "MuSigmaOverMu" : "LogNormal.MU_SIGMAOVERMU",
1198     }
1199     if loi[ 'Settings' ] == 'MuSigmaLog' :
1200       arg1 = loi[ 'MuLog' ]
1201       arg2 = loi[ 'SigmaLog' ]
1202     elif loi[ 'Settings' ] == 'MuSigmaOverMu' :
1203       arg1 = loi[ 'Mu' ]
1204       arg2 = loi[ 'SigmaOverMu' ]
1205     else :
1206       arg1 = loi[ 'Mu'    ]
1207       arg2 = loi[ 'Sigma' ]
1208       
1209     arg3 = loi[ 'Gamma' ]
1210     txt = "LogNormal( %g, %g, %g, %s )" % (arg1, arg2, arg3, settings[ loi[ 'Settings' ] ])
1211     return txt
1212
1213   def MultiNomial (self, loi):
1214     '''
1215     Definition de la loi MultiNomial
1216     '''
1217     arg1 = loi[ 'Values' ]
1218     arg2 = loi[ 'N' ]
1219     txt = "MultiNomial( NumericalPoint( %s ) , %d)" % (arg1, arg2)
1220     return txt
1221
1222   def NonCentralStudent (self, loi):
1223     '''
1224     Definition de la loi NonCentralStudent
1225     '''
1226     arg1 = loi[ 'Nu'    ]
1227     arg2 = loi[ 'Delta' ]
1228     arg3 = loi[ 'Gamma' ]
1229     txt = "NonCentralStudent( %g, %g )" % (arg1, arg2, arg3)
1230     return txt
1231
1232   def Normal (self, loi):
1233     '''
1234     Definition de la loi Normal
1235     '''
1236     arg1 = loi[ 'Mu'    ]
1237     arg2 = loi[ 'Sigma' ]
1238     txt = "Normal( %g, %g )" % (arg1, arg2)
1239     return txt
1240
1241   def TruncatedNormal (self, loi):
1242     '''
1243     Definition de la loi TruncatedNormal
1244     '''
1245     arg1 = loi[ 'MuN' ]
1246     arg2 = loi[ 'SigmaN' ]
1247     arg3 = loi[ 'A' ]
1248     arg4 = loi[ 'B' ]
1249     txt = "TruncatedNormal( %g, %g, %g, %g )" % (arg1, arg2, arg3, arg4)
1250     return txt
1251
1252   def Poisson (self, loi):
1253     '''
1254     Definition de la loi Poisson
1255     '''
1256     txt = "Poisson( %g )" % loi[ 'Lambda' ]
1257     return txt
1258
1259   def Rayleigh (self, loi):
1260     '''
1261     Definition de la loi Rayleigh
1262     '''
1263     arg1 = loi[ 'Sigma' ]
1264     arg2 = loi[ 'Gamma' ]
1265     txt = "Rayleigh( %g, %g )" % (arg1, arg2)
1266     return txt
1267
1268   def Student (self, loi):
1269     '''
1270     Definition de la loi Student
1271     '''
1272     arg1 = loi[ 'Mu' ]
1273     arg2 = loi[ 'Nu' ]
1274     arg3 = loi[ 'Sigma' ]
1275     txt = "Student( %g, %g, %g )" % (arg1, arg2, arg3)
1276     return txt
1277
1278   def Triangular (self, loi):
1279     '''
1280     Definition de la loi Triangular
1281     '''
1282     arg1 = loi[ 'A' ]
1283     arg2 = loi[ 'M' ]
1284     arg3 = loi[ 'B' ]
1285     txt = "Triangular( %g, %g, %g )" % (arg1, arg2, arg3)
1286     return txt
1287
1288   def Uniform (self, loi):
1289     '''
1290     Definition de la loi Uniform
1291     '''
1292     arg1 = loi[ 'A' ]
1293     arg2 = loi[ 'B' ]
1294     txt = "Uniform( %g, %g )" % (arg1, arg2)
1295     return txt
1296
1297   def UserDefined (self, loi):
1298     '''
1299     Definition de la loi UserDefined
1300     '''
1301     txt = "** UserDefined not defined yet **"
1302     return txt
1303
1304   def Weibull (self, loi):
1305     '''
1306     Definition de la loi Weibull
1307     '''
1308     settings = {
1309       "AlphaBeta" : "Weibull.ALPHABETA",
1310       "MuSigma" : "Weibull.MUSIGMA",
1311     }
1312     if loi[ 'Settings' ] == 'AlphaBeta' :
1313       arg1 = loi[ 'Alpha' ]
1314       arg2 = loi[ 'Beta'  ]
1315     else :
1316       arg1 = loi[ 'Mu'    ]
1317       arg2 = loi[ 'Sigma' ]
1318       
1319     arg3 = loi[ 'Gamma' ]
1320     txt = "Weibull( %g, %g, %g, %s )" % (arg1, arg2, arg3, settings[ loi[ 'Settings' ] ])
1321     return txt
1322
1323
1324
1325   def GraphiquePDF (self, loi, fichier):
1326     '''
1327     Produit une image PNG representant la PDF de la loi
1328     '''
1329     txt  = headerSTD % self.OpenTURNS_path
1330     txt += "dist = %s\n" % apply( STDGenerateur.__dict__[ loi[ 'Kind' ] ], (self, loi) )
1331     txt += "graph = dist.drawPDF()\n"
1332     txt += "graph.draw( '%s' )\n" % fichier
1333     txt += footerSTD
1334     return txt
1335