# -*- coding: utf-8 -*-
#
-# Copyright (C) 2008-2020 EDF R&D
+# Copyright (C) 2008-2022 EDF R&D
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
#
# Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D
-import sys, logging
-from daCore import BasicObjects, PlatformInfo
import numpy
+from daCore import BasicObjects, NumericObjects, PlatformInfo
mpr = PlatformInfo.PlatformInfo().MachinePrecision()
-if sys.version_info.major > 2:
- unicode = str
# ==============================================================================
class ElementaryAlgorithm(BasicObjects.Algorithm):
mandatory= ("Xb", "HO" ),
optional = ("Y", ),
)
+ self.setAttributes(tags=(
+ "Checking",
+ ))
def run(self, Xb=None, Y=None, U=None, HO=None, EM=None, CM=None, R=None, B=None, Q=None, Parameters=None):
- self._pre_run(Parameters, Xb, Y, R, B, Q)
+ self._pre_run(Parameters, Xb, Y, U, HO, EM, CM, R, B, Q)
#
Hm = HO["Direct"].appliedTo
Ht = HO["Tangent"].appliedInXTo
Ha = HO["Adjoint"].appliedInXTo
#
- # ----------
Perturbations = [ 10**i for i in range(self._parameters["EpsilonMinimumExponent"],1) ]
Perturbations.reverse()
#
- X = numpy.asmatrix(numpy.ravel( Xb )).T
- NormeX = numpy.linalg.norm( X )
+ Xn = numpy.ravel( Xb ).reshape((-1,1))
+ NormeX = numpy.linalg.norm( Xn )
if Y is None:
- Y = numpy.asmatrix(numpy.ravel( Hm( X ) )).T
- Y = numpy.asmatrix(numpy.ravel( Y )).T
- NormeY = numpy.linalg.norm( Y )
+ Yn = numpy.ravel( Hm( Xn ) ).reshape((-1,1))
+ else:
+ Yn = numpy.ravel( Y ).reshape((-1,1))
+ NormeY = numpy.linalg.norm( Yn )
if self._toStore("CurrentState"):
- self.StoredVariables["CurrentState"].store( numpy.ravel(X) )
+ self.StoredVariables["CurrentState"].store( Xn )
if self._toStore("SimulatedObservationAtCurrentState"):
- self.StoredVariables["SimulatedObservationAtCurrentState"].store( numpy.ravel(Y) )
- #
- if len(self._parameters["InitialDirection"]) == 0:
- dX0 = []
- for v in X.A1:
- if abs(v) > 1.e-8:
- dX0.append( numpy.random.normal(0.,abs(v)) )
- else:
- dX0.append( numpy.random.normal(0.,X.mean()) )
- else:
- dX0 = numpy.asmatrix(numpy.ravel( self._parameters["InitialDirection"] ))
+ self.StoredVariables["SimulatedObservationAtCurrentState"].store( Yn )
#
- dX0 = float(self._parameters["AmplitudeOfInitialDirection"]) * numpy.matrix( dX0 ).T
+ dX0 = NumericObjects.SetInitialDirection(
+ self._parameters["InitialDirection"],
+ self._parameters["AmplitudeOfInitialDirection"],
+ Xn,
+ )
#
# Entete des resultats
# --------------------
Y doit etre dans l'image de F. S'il n'est pas donne, on prend Y = F(X).\n""" + __precision
#
if len(self._parameters["ResultTitle"]) > 0:
- __rt = unicode(self._parameters["ResultTitle"])
+ __rt = str(self._parameters["ResultTitle"])
msgs = u"\n"
msgs += __marge + "====" + "="*len(__rt) + "====\n"
msgs += __marge + " " + __rt + "\n"
msgs += "\n" + __marge + __entete
msgs += "\n" + __marge + "-"*__nbtirets
#
- Normalisation= -1
- #
# ----------
for i,amplitude in enumerate(Perturbations):
dX = amplitude * dX0
NormedX = numpy.linalg.norm( dX )
#
- TangentFXdX = numpy.asmatrix( Ht( (X,dX) ) )
- AdjointFXY = numpy.asmatrix( Ha( (X,Y) ) )
+ TangentFXdX = numpy.ravel( Ht( (Xn,dX) ) )
+ AdjointFXY = numpy.ravel( Ha( (Xn,Yn) ) )
#
- Residu = abs(float(numpy.dot( TangentFXdX.A1 , Y.A1 ) - numpy.dot( dX.A1 , AdjointFXY.A1 )))
+ Residu = abs(float(numpy.dot( TangentFXdX, Yn ) - numpy.dot( dX, AdjointFXY )))
#
msg = " %2i %5.0e %9.3e %9.3e %9.3e | %9.3e"%(i,amplitude,NormeX,NormeY,NormedX,Residu)
msgs += "\n" + __marge + msg