Salome HOME
Documentation update with features and review corrections
[modules/adao.git] / src / daComposant / daAlgorithms / ExtendedBlue.py
1 # -*- coding: utf-8 -*-
2 #
3 # Copyright (C) 2008-2024 EDF R&D
4 #
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License.
9 #
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 # Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18 #
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #
21 # Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D
22
23 import numpy
24 from daCore import BasicObjects, NumericObjects
25 from daAlgorithms.Atoms import ecwexblue
26
27 # ==============================================================================
28 class ElementaryAlgorithm(BasicObjects.Algorithm):
29     def __init__(self):
30         BasicObjects.Algorithm.__init__(self, "EXTENDEDBLUE")
31         self.defineRequiredParameter(
32             name     = "Variant",
33             default  = "ExtendedBlue",
34             typecast = str,
35             message  = "Variant ou formulation de la méthode",
36             listval  = [
37                 "ExtendedBlue",
38             ],
39             listadv  = [
40                 "OneCorrection",
41             ],
42         )
43         self.defineRequiredParameter(
44             name     = "EstimationOf",
45             default  = "Parameters",
46             typecast = str,
47             message  = "Estimation d'état ou de paramètres",
48             listval  = ["State", "Parameters"],
49         )
50         self.defineRequiredParameter(
51             name     = "StoreInternalVariables",
52             default  = False,
53             typecast = bool,
54             message  = "Stockage des variables internes ou intermédiaires du calcul",
55         )
56         self.defineRequiredParameter(
57             name     = "StoreSupplementaryCalculations",
58             default  = [],
59             typecast = tuple,
60             message  = "Liste de calculs supplémentaires à stocker et/ou effectuer",
61             listval  = [
62                 "Analysis",
63                 "APosterioriCorrelations",
64                 "APosterioriCovariance",
65                 "APosterioriStandardDeviations",
66                 "APosterioriVariances",
67                 "BMA",
68                 "CostFunctionJ",
69                 "CostFunctionJAtCurrentOptimum",
70                 "CostFunctionJb",
71                 "CostFunctionJbAtCurrentOptimum",
72                 "CostFunctionJo",
73                 "CostFunctionJoAtCurrentOptimum",
74                 "CurrentOptimum",
75                 "CurrentState",
76                 "CurrentStepNumber",
77                 "ForecastState",
78                 "Innovation",
79                 "InnovationAtCurrentAnalysis",
80                 "MahalanobisConsistency",
81                 "OMA",
82                 "OMB",
83                 "SampledStateForQuantiles",
84                 "SigmaBck2",
85                 "SigmaObs2",
86                 "SimulatedObservationAtBackground",
87                 "SimulatedObservationAtCurrentOptimum",
88                 "SimulatedObservationAtCurrentState",
89                 "SimulatedObservationAtOptimum",
90                 "SimulationQuantiles",
91             ]
92         )
93         self.defineRequiredParameter(
94             name     = "Quantiles",
95             default  = [],
96             typecast = tuple,
97             message  = "Liste des valeurs de quantiles",
98             minval   = 0.,
99             maxval   = 1.,
100         )
101         self.defineRequiredParameter(
102             name     = "SetSeed",
103             typecast = numpy.random.seed,
104             message  = "Graine fixée pour le générateur aléatoire",
105         )
106         self.defineRequiredParameter(
107             name     = "NumberOfSamplesForQuantiles",
108             default  = 100,
109             typecast = int,
110             message  = "Nombre d'échantillons simulés pour le calcul des quantiles",
111             minval   = 1,
112         )
113         self.defineRequiredParameter(
114             name     = "SimulationForQuantiles",
115             default  = "Linear",
116             typecast = str,
117             message  = "Type de simulation en estimation des quantiles",
118             listval  = ["Linear", "NonLinear"]
119         )
120         self.defineRequiredParameter(  # Pas de type
121             name     = "StateBoundsForQuantiles",
122             message  = "Liste des paires de bornes pour les états utilisés en estimation des quantiles",
123         )
124         self.requireInputArguments(
125             mandatory= ("Xb", "Y", "HO", "R", "B"),
126             optional = ("U", "EM", "CM", "Q"),
127         )
128         self.setAttributes(
129             tags=(
130                 "DataAssimilation",
131                 "NonLinear",
132                 "Filter",
133             ),
134             features=(
135                 "LocalOptimization",
136                 "DerivativeNeeded",
137                 "ParallelDerivativesOnly",
138             ),
139         )
140
141     def run(self, Xb=None, Y=None, U=None, HO=None, EM=None, CM=None, R=None, B=None, Q=None, Parameters=None):
142         self._pre_run(Parameters, Xb, Y, U, HO, EM, CM, R, B, Q)
143         #
144         # --------------------------
145         if self._parameters["Variant"] == "ExtendedBlue":
146             NumericObjects.multiXOsteps(self, Xb, Y, U, HO, EM, CM, R, B, Q, ecwexblue.ecwexblue)
147         #
148         # --------------------------
149         elif self._parameters["Variant"] == "OneCorrection":
150             ecwexblue.ecwexblue(self, Xb, Y, U, HO, CM, R, B)
151         #
152         # --------------------------
153         else:
154             raise ValueError("Error in Variant name: %s"%self._parameters["Variant"])
155         #
156         self._post_run(HO, EM)
157         return 0
158
159 # ==============================================================================
160 if __name__ == "__main__":
161     print("\n AUTODIAGNOSTIC\n")