]> SALOME platform Git repositories - modules/adao.git/commitdiff
Salome HOME
Minor internal improvements bis
authorJean-Philippe ARGAUD <jean-philippe.argaud@edf.fr>
Thu, 15 Apr 2021 19:22:18 +0000 (21:22 +0200)
committerJean-Philippe ARGAUD <jean-philippe.argaud@edf.fr>
Thu, 15 Apr 2021 19:22:18 +0000 (21:22 +0200)
src/daComposant/daAlgorithms/ExtendedBlue.py
src/daComposant/daCore/NumericObjects.py

index d526d7f781ef039668dedaf09111cc0b6d3d39bf..76906383268d725465a056d108d4bf73b4d6aacf 100644 (file)
@@ -21,7 +21,7 @@
 # Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D
 
 import logging
-from daCore import BasicObjects
+from daCore import BasicObjects, NumericObjects
 import numpy
 
 # ==============================================================================
@@ -216,36 +216,9 @@ class ElementaryAlgorithm(BasicObjects.Algorithm):
         if self._toStore("MahalanobisConsistency"):
             self.StoredVariables["MahalanobisConsistency"].store( float( 2.*J/d.size ) )
         if self._toStore("SimulationQuantiles"):
-            nech = self._parameters["NumberOfSamplesForQuantiles"]
             HtM  = HO["Tangent"].asMatrix(ValueForMethodForm = Xa)
             HtM  = HtM.reshape(Y.size,Xa.size) # ADAO & check shape
-            EXr  = None
-            YfQ  = None
-            for i in range(nech):
-                if self._parameters["SimulationForQuantiles"] == "Linear":
-                    dXr = numpy.matrix(numpy.random.multivariate_normal(Xa.A1,A) - Xa.A1).T
-                    dYr = numpy.matrix(numpy.ravel( HtM * dXr )).T
-                    Yr = HXa + dYr
-                    if self._toStore("SampledStateForQuantiles"): Xr = Xa+dXr
-                elif self._parameters["SimulationForQuantiles"] == "NonLinear":
-                    Xr = numpy.matrix(numpy.random.multivariate_normal(Xa.A1,A)).T
-                    Yr = numpy.matrix(numpy.ravel( H( Xr ) )).T
-                if YfQ is None:
-                    YfQ = Yr
-                    if self._toStore("SampledStateForQuantiles"): EXr = numpy.ravel(Xr)
-                else:
-                    YfQ = numpy.hstack((YfQ,Yr))
-                    if self._toStore("SampledStateForQuantiles"): EXr = numpy.vstack((EXr,numpy.ravel(Xr)))
-            YfQ.sort(axis=-1)
-            YQ = None
-            for quantile in self._parameters["Quantiles"]:
-                if not (0. <= float(quantile) <= 1.): continue
-                indice = int(nech * float(quantile) - 1./nech)
-                if YQ is None: YQ = YfQ[:,indice]
-                else:          YQ = numpy.hstack((YQ,YfQ[:,indice]))
-            self.StoredVariables["SimulationQuantiles"].store( YQ )
-            if self._toStore("SampledStateForQuantiles"):
-                self.StoredVariables["SampledStateForQuantiles"].store( EXr.T )
+            NumericObjects.QuantilesEstimations(self, A, Xa, HXa, H, HtM)
         if self._toStore("SimulatedObservationAtBackground"):
             self.StoredVariables["SimulatedObservationAtBackground"].store( numpy.ravel(HXb) )
         if self._toStore("SimulatedObservationAtCurrentState"):
index e6a8fcd7c8c80b7ca643ae65469272f517871ced..85d134a1e605c14e8b1d4adbb60b35510b97d482 100644 (file)
@@ -1667,35 +1667,7 @@ def incr3dvar(selfA, Xb, Y, U, HO, EM, CM, R, B, Q):
     if selfA._toStore("MahalanobisConsistency"):
         selfA.StoredVariables["MahalanobisConsistency"].store( float( 2.*MinJ/d.size ) )
     if selfA._toStore("SimulationQuantiles"):
-        nech = selfA._parameters["NumberOfSamplesForQuantiles"]
-        HXa  = numpy.matrix(numpy.ravel( HXa )).T
-        EXr  = None
-        YfQ  = None
-        for i in range(nech):
-            if selfA._parameters["SimulationForQuantiles"] == "Linear":
-                dXr = numpy.matrix(numpy.random.multivariate_normal(Xa.A1,A) - Xa.A1).T
-                dYr = numpy.matrix(numpy.ravel( HtM * dXr )).T
-                Yr = HXa + dYr
-                if selfA._toStore("SampledStateForQuantiles"): Xr = Xa+dXr
-            elif selfA._parameters["SimulationForQuantiles"] == "NonLinear":
-                Xr = numpy.matrix(numpy.random.multivariate_normal(Xa.A1,A)).T
-                Yr = numpy.matrix(numpy.ravel( Hm( Xr ) )).T
-            if YfQ is None:
-                YfQ = Yr
-                if selfA._toStore("SampledStateForQuantiles"): EXr = numpy.ravel(Xr)
-            else:
-                YfQ = numpy.hstack((YfQ,Yr))
-                if selfA._toStore("SampledStateForQuantiles"): EXr = numpy.vstack((EXr,numpy.ravel(Xr)))
-        YfQ.sort(axis=-1)
-        YQ = None
-        for quantile in selfA._parameters["Quantiles"]:
-            if not (0. <= float(quantile) <= 1.): continue
-            indice = int(nech * float(quantile) - 1./nech)
-            if YQ is None: YQ = YfQ[:,indice]
-            else:          YQ = numpy.hstack((YQ,YfQ[:,indice]))
-        selfA.StoredVariables["SimulationQuantiles"].store( YQ )
-        if selfA._toStore("SampledStateForQuantiles"):
-            selfA.StoredVariables["SampledStateForQuantiles"].store( EXr.T )
+        QuantilesEstimations(selfA, A, Xa, HXa, Hm, HtM)
     if selfA._toStore("SimulatedObservationAtBackground"):
         selfA.StoredVariables["SimulatedObservationAtBackground"].store( numpy.ravel(HXb) )
     if selfA._toStore("SimulatedObservationAtOptimum"):
@@ -2314,35 +2286,7 @@ def psas3dvar(selfA, Xb, Y, U, HO, EM, CM, R, B, Q):
     if selfA._toStore("MahalanobisConsistency"):
         selfA.StoredVariables["MahalanobisConsistency"].store( float( 2.*MinJ/d.size ) )
     if selfA._toStore("SimulationQuantiles"):
-        nech = selfA._parameters["NumberOfSamplesForQuantiles"]
-        HXa  = numpy.matrix(numpy.ravel( HXa )).T
-        EXr  = None
-        YfQ  = None
-        for i in range(nech):
-            if selfA._parameters["SimulationForQuantiles"] == "Linear":
-                dXr = numpy.matrix(numpy.random.multivariate_normal(Xa.A1,A) - Xa.A1).T
-                dYr = numpy.matrix(numpy.ravel( HtM * dXr )).T
-                Yr = HXa + dYr
-                if selfA._toStore("SampledStateForQuantiles"): Xr = Xa+dXr
-            elif selfA._parameters["SimulationForQuantiles"] == "NonLinear":
-                Xr = numpy.matrix(numpy.random.multivariate_normal(Xa.A1,A)).T
-                Yr = numpy.matrix(numpy.ravel( Hm( Xr ) )).T
-            if YfQ is None:
-                YfQ = Yr
-                if selfA._toStore("SampledStateForQuantiles"): EXr = numpy.ravel(Xr)
-            else:
-                YfQ = numpy.hstack((YfQ,Yr))
-                if selfA._toStore("SampledStateForQuantiles"): EXr = numpy.vstack((EXr,numpy.ravel(Xr)))
-        YfQ.sort(axis=-1)
-        YQ = None
-        for quantile in selfA._parameters["Quantiles"]:
-            if not (0. <= float(quantile) <= 1.): continue
-            indice = int(nech * float(quantile) - 1./nech)
-            if YQ is None: YQ = YfQ[:,indice]
-            else:          YQ = numpy.hstack((YQ,YfQ[:,indice]))
-        selfA.StoredVariables["SimulationQuantiles"].store( YQ )
-        if selfA._toStore("SampledStateForQuantiles"):
-            selfA.StoredVariables["SampledStateForQuantiles"].store( EXr.T )
+        QuantilesEstimations(selfA, A, Xa, HXa, Hm, HtM)
     if selfA._toStore("SimulatedObservationAtBackground"):
         selfA.StoredVariables["SimulatedObservationAtBackground"].store( numpy.ravel(HXb) )
     if selfA._toStore("SimulatedObservationAtOptimum"):
@@ -3306,35 +3250,7 @@ def van3dvar(selfA, Xb, Y, U, HO, EM, CM, R, B, Q):
     if selfA._toStore("MahalanobisConsistency"):
         selfA.StoredVariables["MahalanobisConsistency"].store( float( 2.*MinJ/d.size ) )
     if selfA._toStore("SimulationQuantiles"):
-        nech = selfA._parameters["NumberOfSamplesForQuantiles"]
-        HXa  = numpy.matrix(numpy.ravel( HXa )).T
-        EXr  = None
-        YfQ  = None
-        for i in range(nech):
-            if selfA._parameters["SimulationForQuantiles"] == "Linear":
-                dXr = numpy.matrix(numpy.random.multivariate_normal(Xa.A1,A) - Xa.A1).T
-                dYr = numpy.matrix(numpy.ravel( HtM * dXr )).T
-                Yr = HXa + dYr
-                if selfA._toStore("SampledStateForQuantiles"): Xr = Xa+dXr
-            elif selfA._parameters["SimulationForQuantiles"] == "NonLinear":
-                Xr = numpy.matrix(numpy.random.multivariate_normal(Xa.A1,A)).T
-                Yr = numpy.matrix(numpy.ravel( Hm( Xr ) )).T
-            if YfQ is None:
-                YfQ = Yr
-                if selfA._toStore("SampledStateForQuantiles"): EXr = numpy.ravel(Xr)
-            else:
-                YfQ = numpy.hstack((YfQ,Yr))
-                if selfA._toStore("SampledStateForQuantiles"): EXr = numpy.vstack((EXr,numpy.ravel(Xr)))
-        YfQ.sort(axis=-1)
-        YQ = None
-        for quantile in selfA._parameters["Quantiles"]:
-            if not (0. <= float(quantile) <= 1.): continue
-            indice = int(nech * float(quantile) - 1./nech)
-            if YQ is None: YQ = YfQ[:,indice]
-            else:          YQ = numpy.hstack((YQ,YfQ[:,indice]))
-        selfA.StoredVariables["SimulationQuantiles"].store( YQ )
-        if selfA._toStore("SampledStateForQuantiles"):
-            selfA.StoredVariables["SampledStateForQuantiles"].store( EXr.T )
+        QuantilesEstimations(selfA, A, Xa, HXa, Hm, HtM)
     if selfA._toStore("SimulatedObservationAtBackground"):
         selfA.StoredVariables["SimulatedObservationAtBackground"].store( numpy.ravel(HXb) )
     if selfA._toStore("SimulatedObservationAtOptimum"):