Salome HOME
Documentation and reporting improvements
[modules/adao.git] / src / daComposant / daAlgorithms / ObserverTest.py
1 # -*- coding: utf-8 -*-
2 #
3 # Copyright (C) 2008-2021 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 logging
24 from daCore import BasicObjects
25 import numpy
26
27 # ==============================================================================
28 class ElementaryAlgorithm(BasicObjects.Algorithm):
29     def __init__(self):
30         BasicObjects.Algorithm.__init__(self, "OBSERVERTEST")
31         self.setAttributes(tags=(
32             "Checking",
33             ))
34
35     def run(self, Xb=None, Y=None, U=None, HO=None, EM=None, CM=None, R=None, B=None, Q=None, Parameters=None):
36         self._pre_run(Parameters, Xb, Y, U, HO, EM, CM, R, B, Q)
37         print("Results of observer check on all potential variables or commands,")
38         print("         only activated on selected ones by explicit association.")
39         print("")
40         #
41         __Xa = 1.+numpy.arange(3.)
42         __Xb = numpy.zeros(3)
43         __YY = 1.+numpy.arange(5.)
44         #
45         # Activation des observers sur toutes les variables stockables
46         # ------------------------------------------------------------
47         self.StoredVariables["Analysis"].store( __Xa )
48         self.StoredVariables["CurrentState"].store( __Xa )
49         self.StoredVariables["CurrentOptimum"].store( __Xa )
50         #
51         self.StoredVariables["CostFunctionJb"].store( 1. )
52         self.StoredVariables["CostFunctionJo"].store( 2. )
53         self.StoredVariables["CostFunctionJ" ].store( 3. )
54         self.StoredVariables["CostFunctionJbAtCurrentOptimum"].store( 4. )
55         self.StoredVariables["CostFunctionJoAtCurrentOptimum"].store( 5. )
56         self.StoredVariables["CostFunctionJAtCurrentOptimum" ].store( 6. )
57         self.StoredVariables["IndexOfOptimum"].store( 1 )
58         #
59         self.StoredVariables["APosterioriCovariance"].store( numpy.diag(__Xa) )
60         self.StoredVariables["APosterioriVariances"].store( __Xa )
61         self.StoredVariables["APosterioriStandardDeviations"].store( __Xa )
62         self.StoredVariables["APosterioriCorrelations"].store( numpy.diag(__Xa) )
63         self.StoredVariables["BMA"].store( __Xb - __Xa )
64         self.StoredVariables["OMA"].store( __YY )
65         self.StoredVariables["OMB"].store( __YY )
66         self.StoredVariables["Innovation"].store( __YY )
67         self.StoredVariables["InnovationAtCurrentState"].store( __YY )
68         self.StoredVariables["SigmaObs2"].store( 1. )
69         self.StoredVariables["SigmaBck2"].store( 1. )
70         self.StoredVariables["MahalanobisConsistency"].store( 1. )
71         self.StoredVariables["SimulationQuantiles"].store( numpy.matrix((__YY,__YY,__YY)) )
72         self.StoredVariables["SimulatedObservationAtBackground"].store( __YY )
73         self.StoredVariables["SimulatedObservationAtCurrentState"].store( __YY )
74         self.StoredVariables["SimulatedObservationAtOptimum"].store( __YY )
75         self.StoredVariables["SimulatedObservationAtCurrentOptimum"].store( __YY )
76         #
77         print("")
78         self._post_run()
79         return 0
80
81 # ==============================================================================
82 if __name__ == "__main__":
83     print('\n AUTODIAGNOSTIC\n')