]> SALOME platform Git repositories - modules/adao.git/blob - src/daComposant/daAlgorithms/LinearLeastSquares.py
Salome HOME
Documentation and code update for PSO
[modules/adao.git] / src / daComposant / daAlgorithms / LinearLeastSquares.py
1 # -*- coding: utf-8 -*-
2 #
3 # Copyright (C) 2008-2023 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 from daCore import BasicObjects, NumericObjects
24 from daAlgorithms.Atoms import ecwlls
25
26 # ==============================================================================
27 class ElementaryAlgorithm(BasicObjects.Algorithm):
28     def __init__(self):
29         BasicObjects.Algorithm.__init__(self, "LINEARLEASTSQUARES")
30         self.defineRequiredParameter(
31             name     = "Variant",
32             default  = "LinearLeastSquares",
33             typecast = str,
34             message  = "Variant ou formulation de la méthode",
35             listval  = [
36                 "LinearLeastSquares",
37                 ],
38             listadv  = [
39                 "OneCorrection",
40                 ],
41             )
42         self.defineRequiredParameter(
43             name     = "EstimationOf",
44             default  = "Parameters",
45             typecast = str,
46             message  = "Estimation d'état ou de paramètres",
47             listval  = ["State", "Parameters"],
48             )
49         self.defineRequiredParameter(
50             name     = "StoreInternalVariables",
51             default  = False,
52             typecast = bool,
53             message  = "Stockage des variables internes ou intermédiaires du calcul",
54             )
55         self.defineRequiredParameter(
56             name     = "StoreSupplementaryCalculations",
57             default  = [],
58             typecast = tuple,
59             message  = "Liste de calculs supplémentaires à stocker et/ou effectuer",
60             listval  = [
61                 "Analysis",
62                 "CostFunctionJ",
63                 "CostFunctionJAtCurrentOptimum",
64                 "CostFunctionJb",
65                 "CostFunctionJbAtCurrentOptimum",
66                 "CostFunctionJo",
67                 "CostFunctionJoAtCurrentOptimum",
68                 "CurrentOptimum",
69                 "CurrentState",
70                 "CurrentStepNumber",
71                 "ForecastState",
72                 "InnovationAtCurrentAnalysis",
73                 "OMA",
74                 "SimulatedObservationAtCurrentOptimum",
75                 "SimulatedObservationAtCurrentState",
76                 "SimulatedObservationAtOptimum",
77                 ]
78             )
79         self.requireInputArguments(
80             mandatory= ("Y", "HO"),
81             optional = ("R"),
82             )
83         self.setAttributes(tags=(
84             "Optimization",
85             "Linear",
86             "Variational",
87             ))
88
89     def run(self, Xb=None, Y=None, U=None, HO=None, EM=None, CM=None, R=None, B=None, Q=None, Parameters=None):
90         self._pre_run(Parameters, Xb, Y, U, HO, EM, CM, R, B, Q)
91         #
92         #--------------------------
93         if   self._parameters["Variant"] == "LinearLeastSquares":
94             NumericObjects.multiXOsteps(self, Xb, Y, U, HO, EM, CM, R, B, Q, ecwlls.ecwlls)
95         #
96         #--------------------------
97         elif self._parameters["Variant"] == "OneCorrection":
98             ecwlls.ecwlls(self, Xb, Y, U, HO, CM, R, B)
99         #
100         #--------------------------
101         else:
102             raise ValueError("Error in Variant name: %s"%self._parameters["Variant"])
103         #
104         self._post_run(HO)
105         return 0
106
107 # ==============================================================================
108 if __name__ == "__main__":
109     print('\n AUTODIAGNOSTIC\n')