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