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