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