__n = Xb.size
__m = selfA._parameters["NumberOfMembers"]
#
- if hasattr(B,"asfullmatrix"): Pn = B.asfullmatrix(__n)
- else: Pn = B
if len(selfA.StoredVariables["Analysis"])==0 or not selfA._parameters["nextStep"]:
selfA.StoredVariables["Analysis"].store( Xb )
if selfA._toStore("APosterioriCovariance"):
- selfA.StoredVariables["APosterioriCovariance"].store( Pn )
- covarianceXa = Pn
+ if hasattr(B,"asfullmatrix"):
+ selfA.StoredVariables["APosterioriCovariance"].store( B.asfullmatrix(__n) )
+ else:
+ selfA.StoredVariables["APosterioriCovariance"].store( B )
#
# Calcul direct initial (on privilégie la mémorisation au recalcul)
__seed = numpy.random.get_state()
#
__n = Xb.size
__m = selfA._parameters["NumberOfMembers"]
- if hasattr(B,"asfullmatrix"): Pn = B.asfullmatrix(__n)
- else: Pn = B
- Xn = EnsembleOfBackgroundPerturbations( Xb, None, __m )
- #~ Xn = EnsembleOfBackgroundPerturbations( Xb, Pn, __m )
#
if len(selfA.StoredVariables["Analysis"])==0 or not selfA._parameters["nextStep"]:
+ Xn = EnsembleOfBackgroundPerturbations( Xb, None, __m )
selfA.StoredVariables["Analysis"].store( Xb )
if selfA._toStore("APosterioriCovariance"):
- selfA.StoredVariables["APosterioriCovariance"].store( Pn )
- covarianceXa = Pn
+ if hasattr(B,"asfullmatrix"):
+ selfA.StoredVariables["APosterioriCovariance"].store( B.asfullmatrix(__n) )
+ else:
+ selfA.StoredVariables["APosterioriCovariance"].store( B )
+ selfA._setInternalState("seed", numpy.random.get_state())
+ elif selfA._parameters["nextStep"]:
+ Xn = selfA._getInternalState("Xn")
#
previousJMinimum = numpy.finfo(float).max
#
for step in range(duration-1):
+ numpy.random.set_state(selfA._getInternalState("seed"))
if hasattr(Y,"store"):
Ynpu = numpy.ravel( Y[step+1] ).reshape((__p,1))
else:
Xn_predicted = Xn_predicted + Cm * Un
elif selfA._parameters["EstimationOf"] == "Parameters": # Observation of forecast
# --- > Par principe, M = Id, Q = 0
- Xn_predicted = Xn
+ Xn_predicted = EMX = Xn
HX_predicted = H( [(Xn_predicted[:,i], Un) for i in range(__m)],
argsAsSerie = True,
returnSerieAsArrayMatrix = True )
#
Xa = Xn.mean(axis=1, dtype=mfp).astype('float').reshape((__n,1))
#--------------------------
+ selfA._setInternalState("Xn", Xn)
+ selfA._setInternalState("seed", numpy.random.get_state())
+ #--------------------------
#
if selfA._parameters["StoreInternalVariables"] \
or selfA._toStore("CostFunctionJ") \
selfA.StoredVariables["CurrentState"].store( Xn )
if selfA._toStore("ForecastState"):
selfA.StoredVariables["ForecastState"].store( EMX )
+ if selfA._toStore("ForecastCovariance"):
+ selfA.StoredVariables["ForecastCovariance"].store( EnsembleErrorCovariance(EMX) )
if selfA._toStore("BMA"):
- selfA.StoredVariables["BMA"].store( EMX - Xa.reshape((__n,1)) )
+ selfA.StoredVariables["BMA"].store( EMX - Xa )
if selfA._toStore("InnovationAtCurrentState"):
selfA.StoredVariables["InnovationAtCurrentState"].store( - HX_predicted + Ynpu )
if selfA._toStore("SimulatedObservationAtCurrentState") \
previousJMinimum = J
XaMin = Xa
if selfA._toStore("APosterioriCovariance"):
- covarianceXaMin = Pn
+ covarianceXaMin = selfA.StoredVariables["APosterioriCovariance"][-1]
# ---> Pour les smoothers
if selfA._toStore("CurrentEnsembleState"):
selfA.StoredVariables["CurrentEnsembleState"].store( Xn )
#
__n = Xb.size
__m = selfA._parameters["NumberOfMembers"]
- if hasattr(B,"asfullmatrix"): Pn = B.asfullmatrix(__n)
- else: Pn = B
- if hasattr(R,"asfullmatrix"): Rn = R.asfullmatrix(__p)
- else: Rn = R
- if hasattr(Q,"asfullmatrix"): Qn = Q.asfullmatrix(__n)
- else: Qn = Q
- Xn = EnsembleOfBackgroundPerturbations( Xb, Pn, __m )
#
if len(selfA.StoredVariables["Analysis"])==0 or not selfA._parameters["nextStep"]:
+ if hasattr(B,"asfullmatrix"): Pn = B.asfullmatrix(__n)
+ else: Pn = B
+ Xn = EnsembleOfBackgroundPerturbations( Xb, Pn, __m )
selfA.StoredVariables["Analysis"].store( Xb )
if selfA._toStore("APosterioriCovariance"):
- selfA.StoredVariables["APosterioriCovariance"].store( Pn )
- covarianceXa = Pn
+ if hasattr(B,"asfullmatrix"):
+ selfA.StoredVariables["APosterioriCovariance"].store( B.asfullmatrix(__n) )
+ else:
+ selfA.StoredVariables["APosterioriCovariance"].store( B )
+ selfA._setInternalState("seed", numpy.random.get_state())
+ elif selfA._parameters["nextStep"]:
+ Xn = selfA._getInternalState("Xn")
#
previousJMinimum = numpy.finfo(float).max
#
for step in range(duration-1):
+ numpy.random.set_state(selfA._getInternalState("seed"))
if hasattr(Y,"store"):
Ynpu = numpy.ravel( Y[step+1] ).reshape((__p,1))
else:
#
Xa = Xn.mean(axis=1, dtype=mfp).astype('float').reshape((__n,1))
#--------------------------
+ selfA._setInternalState("Xn", Xn)
+ selfA._setInternalState("seed", numpy.random.get_state())
+ #--------------------------
#
if selfA._parameters["StoreInternalVariables"] \
or selfA._toStore("CostFunctionJ") \
selfA.StoredVariables["CurrentState"].store( Xn )
if selfA._toStore("ForecastState"):
selfA.StoredVariables["ForecastState"].store( E2 )
+ if selfA._toStore("ForecastCovariance"):
+ selfA.StoredVariables["ForecastCovariance"].store( EnsembleErrorCovariance(E2) )
if selfA._toStore("BMA"):
selfA.StoredVariables["BMA"].store( E2 - Xa )
if selfA._toStore("InnovationAtCurrentState"):
previousJMinimum = J
XaMin = Xa
if selfA._toStore("APosterioriCovariance"):
- covarianceXaMin = Pn
+ covarianceXaMin = selfA.StoredVariables["APosterioriCovariance"][-1]
#
# Stockage final supplémentaire de l'optimum en estimation de paramètres
# ----------------------------------------------------------------------
#
__n = Xb.size
__m = selfA._parameters["NumberOfMembers"]
- if hasattr(B,"asfullmatrix"): Pn = B.asfullmatrix(__n)
- else: Pn = B
- if hasattr(R,"asfullmatrix"): Rn = R.asfullmatrix(__p)
- else: Rn = R
- Xn = EnsembleOfBackgroundPerturbations( Xb, None, __m )
#
if len(selfA.StoredVariables["Analysis"])==0 or not selfA._parameters["nextStep"]:
+ Xn = EnsembleOfBackgroundPerturbations( Xb, None, __m )
selfA.StoredVariables["Analysis"].store( Xb )
if selfA._toStore("APosterioriCovariance"):
- selfA.StoredVariables["APosterioriCovariance"].store( Pn )
- covarianceXa = Pn
+ if hasattr(B,"asfullmatrix"):
+ selfA.StoredVariables["APosterioriCovariance"].store( B.asfullmatrix(__n) )
+ else:
+ selfA.StoredVariables["APosterioriCovariance"].store( B )
+ selfA._setInternalState("seed", numpy.random.get_state())
+ elif selfA._parameters["nextStep"]:
+ Xn = selfA._getInternalState("Xn")
#
previousJMinimum = numpy.finfo(float).max
#
for step in range(duration-1):
+ numpy.random.set_state(selfA._getInternalState("seed"))
if hasattr(Y,"store"):
Ynpu = numpy.ravel( Y[step+1] ).reshape((__p,1))
else:
Xn_predicted = Xn_predicted + Cm * Un
elif selfA._parameters["EstimationOf"] == "Parameters": # Observation of forecast
# --- > Par principe, M = Id, Q = 0
- Xn_predicted = Xn
+ Xn_predicted = EMX = Xn
#
#--------------------------
if VariantM == "MLEF13":
#
Xa = Xn.mean(axis=1, dtype=mfp).astype('float').reshape((__n,1))
#--------------------------
+ selfA._setInternalState("Xn", Xn)
+ selfA._setInternalState("seed", numpy.random.get_state())
+ #--------------------------
#
if selfA._parameters["StoreInternalVariables"] \
or selfA._toStore("CostFunctionJ") \
selfA.StoredVariables["CurrentState"].store( Xn )
if selfA._toStore("ForecastState"):
selfA.StoredVariables["ForecastState"].store( EMX )
+ if selfA._toStore("ForecastCovariance"):
+ selfA.StoredVariables["ForecastCovariance"].store( EnsembleErrorCovariance(EMX) )
if selfA._toStore("BMA"):
selfA.StoredVariables["BMA"].store( EMX - Xa )
if selfA._toStore("InnovationAtCurrentState"):
previousJMinimum = J
XaMin = Xa
if selfA._toStore("APosterioriCovariance"):
- covarianceXaMin = Pn
+ covarianceXaMin = selfA.StoredVariables["APosterioriCovariance"][-1]
#
# Stockage final supplémentaire de l'optimum en estimation de paramètres
# ----------------------------------------------------------------------
"""
#
# Initialisation
- Xn = numpy.ravel(Xb).reshape((-1,1))
- #
if selfA._parameters["EstimationOf"] == "State":
M = EM["Direct"].appliedTo
#
if len(selfA.StoredVariables["Analysis"])==0 or not selfA._parameters["nextStep"]:
+ Xn = numpy.ravel(Xb).reshape((-1,1))
selfA.StoredVariables["Analysis"].store( Xn )
if selfA._toStore("APosterioriCovariance"):
- if hasattr(B,"asfullmatrix"): Pn = B.asfullmatrix(Xn.size)
- else: Pn = B
- selfA.StoredVariables["APosterioriCovariance"].store( Pn )
+ if hasattr(B,"asfullmatrix"):
+ selfA.StoredVariables["APosterioriCovariance"].store( B.asfullmatrix(Xn.size) )
+ else:
+ selfA.StoredVariables["APosterioriCovariance"].store( B )
if selfA._toStore("ForecastState"):
selfA.StoredVariables["ForecastState"].store( Xn )
+ elif selfA._parameters["nextStep"]:
+ Xn = selfA._getInternalState("Xn")
+ else:
+ Xn = numpy.ravel(Xb).reshape((-1,1))
#
if hasattr(Y,"stepnumber"):
duration = Y.stepnumber()
Ynpu = numpy.ravel( Y ).reshape((-1,1))
#
if selfA._parameters["EstimationOf"] == "State": # Forecast
- Xn = selfA.StoredVariables["Analysis"][-1]
Xn_predicted = M( Xn )
if selfA._toStore("ForecastState"):
selfA.StoredVariables["ForecastState"].store( Xn_predicted )
Xn_predicted = numpy.ravel(Xn_predicted).reshape((-1,1))
#
oneCycle(selfA, Xn_predicted, Ynpu, U, HO, None, None, R, B, None)
+ #
+ Xn = selfA.StoredVariables["Analysis"][-1]
+ #--------------------------
+ selfA._setInternalState("Xn", Xn)
#
return 0
return 0
# ==============================================================================
-def senkf(selfA, Xb, Y, U, HO, EM, CM, R, B, Q, VariantM="KalmanFilterFormula"):
+def senkf(selfA, Xb, Y, U, HO, EM, CM, R, B, Q, VariantM="KalmanFilterFormula16"):
"""
Stochastic EnKF
"""
__n = Xb.size
__m = selfA._parameters["NumberOfMembers"]
#
- if hasattr(B,"asfullmatrix"): Pn = B.asfullmatrix(__n)
- else: Pn = B
if hasattr(R,"asfullmatrix"): Rn = R.asfullmatrix(__p)
else: Rn = R
- Xn = EnsembleOfBackgroundPerturbations( Xb, None, __m )
#
if len(selfA.StoredVariables["Analysis"])==0 or not selfA._parameters["nextStep"]:
+ Xn = EnsembleOfBackgroundPerturbations( Xb, None, __m )
selfA.StoredVariables["Analysis"].store( Xb )
if selfA._toStore("APosterioriCovariance"):
- selfA.StoredVariables["APosterioriCovariance"].store( Pn )
- covarianceXa = Pn
+ if hasattr(B,"asfullmatrix"):
+ selfA.StoredVariables["APosterioriCovariance"].store( B.asfullmatrix(__n) )
+ else:
+ selfA.StoredVariables["APosterioriCovariance"].store( B )
+ selfA._setInternalState("seed", numpy.random.get_state())
+ elif selfA._parameters["nextStep"]:
+ Xn = selfA._getInternalState("Xn")
#
previousJMinimum = numpy.finfo(float).max
#
for step in range(duration-1):
+ numpy.random.set_state(selfA._getInternalState("seed"))
if hasattr(Y,"store"):
Ynpu = numpy.ravel( Y[step+1] ).reshape((__p,1))
else:
Xn_predicted = Xn_predicted + Cm * Un
elif selfA._parameters["EstimationOf"] == "Parameters": # Observation of forecast
# --- > Par principe, M = Id, Q = 0
- Xn_predicted = Xn
+ Xn_predicted = EMX = Xn
HX_predicted = H( [(Xn_predicted[:,i], Un) for i in range(__m)],
argsAsSerie = True,
returnSerieAsArrayMatrix = True )
#
Xa = Xn.mean(axis=1, dtype=mfp).astype('float').reshape((__n,1))
#--------------------------
+ selfA._setInternalState("Xn", Xn)
+ selfA._setInternalState("seed", numpy.random.get_state())
+ #--------------------------
#
if selfA._parameters["StoreInternalVariables"] \
or selfA._toStore("CostFunctionJ") \
selfA.StoredVariables["CurrentState"].store( Xn )
if selfA._toStore("ForecastState"):
selfA.StoredVariables["ForecastState"].store( EMX )
+ if selfA._toStore("ForecastCovariance"):
+ selfA.StoredVariables["ForecastCovariance"].store( EnsembleErrorCovariance(EMX) )
if selfA._toStore("BMA"):
selfA.StoredVariables["BMA"].store( EMX - Xa )
if selfA._toStore("InnovationAtCurrentState"):
previousJMinimum = J
XaMin = Xa
if selfA._toStore("APosterioriCovariance"):
- covarianceXaMin = Pn
+ covarianceXaMin = selfA.StoredVariables["APosterioriCovariance"][-1]
#
# Stockage final supplémentaire de l'optimum en estimation de paramètres
# ----------------------------------------------------------------------