ValueSeriePrinterSaverAndGnuPlotter = BLOC (condition = " Template == 'ValueSeriePrinterSaverAndGnuPlotter' ",
ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "print info, var[:] \\nimport numpy, re\\nv=numpy.array(var[:], ndmin=1)\\nglobal istep\\ntry:\\n istep += 1\\nexcept:\\n istep = 0\\nf='/tmp/value_%s_%05i.txt'%(info,istep)\\nf=re.sub('\s','_',f)\\nprint 'Value saved in \\"%s\\"'%f\\nnumpy.savetxt(f,v)\\nimport Gnuplot\\nglobal ifig,gp\\ntry:\\n ifig += 1\\n gp('set style data lines')\\nexcept:\\n ifig = 0\\n gp = Gnuplot.Gnuplot(persist=1)\\n gp('set style data lines')\\ngp('set title \\"%s (Figure %i)\\"'%(info,ifig))\\ngp.plot( Gnuplot.Data( v, with_='lines lw 2' ) )" ),
),
- ValuePrinter = BLOC (condition = " Template == 'ValueMean' ",
+ ValueMean = BLOC (condition = " Template == 'ValueMean' ",
ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "import numpy\\nprint info, numpy.nanmean(var[-1])" ),
),
- ValuePrinter = BLOC (condition = " Template == 'ValueStandardError' ",
+ ValueStandardError = BLOC (condition = " Template == 'ValueStandardError' ",
ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "import numpy\\nprint info, numpy.nanstd(var[-1])" ),
),
- ValuePrinter = BLOC (condition = " Template == 'ValueVariance' ",
+ ValueVariance = BLOC (condition = " Template == 'ValueVariance' ",
ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "import numpy\\nprint info, numpy.nanvar(var[-1])" ),
),
- ValuePrinter = BLOC (condition = " Template == 'ValueRMS' ",
+ ValueRMS = BLOC (condition = " Template == 'ValueRMS' ",
ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "import numpy\\nv = numpy.matrix( numpy.ravel( var[-1] ) )\\nprint info, float( numpy.sqrt((1./v.size)*(v*v.T)) )" ),
),
)
# Calcul de la matrice de gain et de l'analyse
# --------------------------------------------
if Y.size <= Xb.size:
- if Y.size > 100: # len(R)
- _A = R + Hm * B * Ha
- _u = numpy.linalg.solve( _A , d )
- Xa = Xb + B * Ha * _u
- else:
- K = B * Ha * (R + Hm * B * Ha).I
- Xa = Xb + K*d
+ _A = R + Hm * B * Ha
+ _u = numpy.linalg.solve( _A , d )
+ Xa = Xb + B * Ha * _u
else:
- if Y.size > 100: # len(R)
- _A = BI + Ha * RI * Hm
- _u = numpy.linalg.solve( _A , Ha * RI * d )
- Xa = Xb + _u
- else:
- K = (BI + Ha * RI * Hm).I * Ha * RI
- Xa = Xb + K*d
+ _A = BI + Ha * RI * Hm
+ _u = numpy.linalg.solve( _A , Ha * RI * d )
+ Xa = Xb + _u
self.StoredVariables["Analysis"].store( Xa.A1 )
#
# Calcul de la fonction coût
# ---------------------------------
if "APosterioriCovariance" in self._parameters["StoreSupplementaryCalculations"] or \
"SimulationQuantiles" in self._parameters["StoreSupplementaryCalculations"]:
- if (Y.size <= Xb.size) and (Y.size > 100): K = B * Ha * (R + Hm * B * Ha).I
- elif (Y.size > Xb.size) and (Y.size > 100): K = (BI + Ha * RI * Hm).I * Ha * RI
- else: pass # K deja calcule
+ if (Y.size <= Xb.size): K = B * Ha * (R + Hm * B * Ha).I
+ elif (Y.size > Xb.size): K = (BI + Ha * RI * Hm).I * Ha * RI
A = B - K * Hm * B
if min(A.shape) != max(A.shape):
raise ValueError("The %s a posteriori covariance matrix A is of shape %s, despites it has to be a squared matrix. There is an error in the observation operator, please check it."%(self._name,str(A.shape)))
# Calcul de la matrice de gain et de l'analyse
# --------------------------------------------
if Y.size <= Xb.size:
- if Y.size > 100: # len(R)
- _A = R + Hm * B * Ha
- _u = numpy.linalg.solve( _A , d )
- Xa = Xb + B * Ha * _u
- else:
- K = B * Ha * (R + Hm * B * Ha).I
- Xa = Xb + K*d
+ _A = R + Hm * B * Ha
+ _u = numpy.linalg.solve( _A , d )
+ Xa = Xb + B * Ha * _u
else:
- if Y.size > 100: # len(R)
- _A = BI + Ha * RI * Hm
- _u = numpy.linalg.solve( _A , Ha * RI * d )
- Xa = Xb + _u
- else:
- K = (BI + Ha * RI * Hm).I * Ha * RI
- Xa = Xb + K*d
+ _A = BI + Ha * RI * Hm
+ _u = numpy.linalg.solve( _A , Ha * RI * d )
+ Xa = Xb + _u
self.StoredVariables["Analysis"].store( Xa.A1 )
#
# Calcul de la fonction coût
# ---------------------------------
if "APosterioriCovariance" in self._parameters["StoreSupplementaryCalculations"] or \
"SimulationQuantiles" in self._parameters["StoreSupplementaryCalculations"]:
- if (Y.size <= Xb.size) and (Y.size > 100): K = B * Ha * (R + Hm * B * Ha).I
- elif (Y.size > Xb.size) and (Y.size > 100): K = (BI + Ha * RI * Hm).I * Ha * RI
- else: pass # K deja calcule
+ if (Y.size <= Xb.size): K = B * Ha * (R + Hm * B * Ha).I
+ elif (Y.size > Xb.size): K = (BI + Ha * RI * Hm).I * Ha * RI
A = B - K * Hm * B
if min(A.shape) != max(A.shape):
raise ValueError("The %s a posteriori covariance matrix A is of shape %s, despites it has to be a squared matrix. There is an error in the observation operator, please check it."%(self._name,str(A.shape)))
if len(dim) != 3:
raise ValueError("For dimension %i, the variable definition \"%s\" is incorrect, it should be [min,max,step]."%(i,dim))
else:
- coordinatesList.append(numpy.linspace(dim[0],dim[1],1+int(float(dim[1])-float(dim[0])/float(dim[2]))))
+ coordinatesList.append(numpy.linspace(dim[0],dim[1],1+int((float(dim[1])-float(dim[0]))/float(dim[2]))))
sampleList = itertools.product(*coordinatesList)
elif len(self._parameters["SampleAsIndependantRandomVariables"]) > 0:
coordinatesList = []
}
"""
if (type(asFunction) is type({})) and \
- asFunction.has_key("useApproximatedDerivatives") and bool(asFunction["useApproximatedDerivatives"]) and \
- asFunction.has_key("Direct") and (asFunction["Direct"] is not None):
- if not asFunction.has_key("withCenteredDF"): asFunction["withCenteredDF"] = False
- if not asFunction.has_key("withIncrement"): asFunction["withIncrement"] = 0.01
- if not asFunction.has_key("withdX"): asFunction["withdX"] = None
- if not asFunction.has_key("withAvoidingRedundancy"): asFunction["withAvoidingRedundancy"] = True
- if not asFunction.has_key("withToleranceInRedundancy"): asFunction["withToleranceInRedundancy"] = 1.e-18
- if not asFunction.has_key("withLenghtOfRedundancy"): asFunction["withLenghtOfRedundancy"] = -1
- if not asFunction.has_key("withmpEnabled"): asFunction["withmpEnabled"] = False
- if not asFunction.has_key("withmpWorkers"): asFunction["withmpWorkers"] = None
+ ("useApproximatedDerivatives" in asFunction) and bool(asFunction["useApproximatedDerivatives"]) and \
+ ("Direct" in asFunction) and (asFunction["Direct"] is not None):
+ if "withCenteredDF" not in asFunction: asFunction["withCenteredDF"] = False
+ if "withIncrement" not in asFunction: asFunction["withIncrement"] = 0.01
+ if "withdX" not in asFunction: asFunction["withdX"] = None
+ if "withAvoidingRedundancy" not in asFunction: asFunction["withAvoidingRedundancy"] = True
+ if "withToleranceInRedundancy" not in asFunction: asFunction["withToleranceInRedundancy"] = 1.e-18
+ if "withLenghtOfRedundancy" not in asFunction: asFunction["withLenghtOfRedundancy"] = -1
+ if "withmpEnabled" not in asFunction: asFunction["withmpEnabled"] = False
+ if "withmpWorkers" not in asFunction: asFunction["withmpWorkers"] = None
from daNumerics.ApproximatedDerivatives import FDApproximation
FDA = FDApproximation(
Function = asFunction["Direct"],
self.__HO["Tangent"] = Operator( fromMethod = FDA.TangentOperator, avoidingRedundancy = avoidRC )
self.__HO["Adjoint"] = Operator( fromMethod = FDA.AdjointOperator, avoidingRedundancy = avoidRC )
elif (type(asFunction) is type({})) and \
- asFunction.has_key("Tangent") and asFunction.has_key("Adjoint") and \
+ ("Tangent" in asFunction) and ("Adjoint" in asFunction) and \
(asFunction["Tangent"] is not None) and (asFunction["Adjoint"] is not None):
- if not asFunction.has_key("Direct") or (asFunction["Direct"] is None):
+ if ("Direct" not in asFunction) or (asFunction["Direct"] is None):
self.__HO["Direct"] = Operator( fromMethod = asFunction["Tangent"], avoidingRedundancy = avoidRC )
else:
- self.__HO["Direct"] = Operator( fromMethod = asFunction["Direct"], avoidingRedundancy = avoidRC )
+ self.__HO["Direct"] = Operator( fromMethod = asFunction["Direct"], avoidingRedundancy = avoidRC )
self.__HO["Tangent"] = Operator( fromMethod = asFunction["Tangent"], avoidingRedundancy = avoidRC )
self.__HO["Adjoint"] = Operator( fromMethod = asFunction["Adjoint"], avoidingRedundancy = avoidRC )
elif asMatrix is not None:
}
"""
if (type(asFunction) is type({})) and \
- asFunction.has_key("useApproximatedDerivatives") and bool(asFunction["useApproximatedDerivatives"]) and \
- asFunction.has_key("Direct") and (asFunction["Direct"] is not None):
- if not asFunction.has_key("withCenteredDF"): asFunction["withCenteredDF"] = False
- if not asFunction.has_key("withIncrement"): asFunction["withIncrement"] = 0.01
- if not asFunction.has_key("withdX"): asFunction["withdX"] = None
- if not asFunction.has_key("withAvoidingRedundancy"): asFunction["withAvoidingRedundancy"] = True
- if not asFunction.has_key("withToleranceInRedundancy"): asFunction["withToleranceInRedundancy"] = 1.e-18
- if not asFunction.has_key("withLenghtOfRedundancy"): asFunction["withLenghtOfRedundancy"] = -1
- if not asFunction.has_key("withmpEnabled"): asFunction["withmpEnabled"] = False
- if not asFunction.has_key("withmpWorkers"): asFunction["withmpWorkers"] = None
+ ("useApproximatedDerivatives" in asFunction) and bool(asFunction["useApproximatedDerivatives"]) and \
+ ("Direct" in asFunction) and (asFunction["Direct"] is not None):
+ if "withCenteredDF" not in asFunction: asFunction["withCenteredDF"] = False
+ if "withIncrement" not in asFunction: asFunction["withIncrement"] = 0.01
+ if "withdX" not in asFunction: asFunction["withdX"] = None
+ if "withAvoidingRedundancy" not in asFunction: asFunction["withAvoidingRedundancy"] = True
+ if "withToleranceInRedundancy" not in asFunction: asFunction["withToleranceInRedundancy"] = 1.e-18
+ if "withLenghtOfRedundancy" not in asFunction: asFunction["withLenghtOfRedundancy"] = -1
+ if "withmpEnabled" not in asFunction: asFunction["withmpEnabled"] = False
+ if "withmpWorkers" not in asFunction: asFunction["withmpWorkers"] = None
from daNumerics.ApproximatedDerivatives import FDApproximation
FDA = FDApproximation(
Function = asFunction["Direct"],
mpEnabled = asFunction["withmpEnabled"],
mpWorkers = asFunction["withmpWorkers"],
)
- self.__EM["Direct"] = Operator( fromMethod = FDA.DirectOperator, avoidingRedundancy = avoidRC )
+ self.__EM["Direct"] = Operator( fromMethod = FDA.DirectOperator, avoidingRedundancy = avoidRC )
self.__EM["Tangent"] = Operator( fromMethod = FDA.TangentOperator, avoidingRedundancy = avoidRC )
self.__EM["Adjoint"] = Operator( fromMethod = FDA.AdjointOperator, avoidingRedundancy = avoidRC )
elif (type(asFunction) is type({})) and \
- asFunction.has_key("Tangent") and asFunction.has_key("Adjoint") and \
+ ("Tangent" in asFunction) and ("Adjoint" in asFunction) and \
(asFunction["Tangent"] is not None) and (asFunction["Adjoint"] is not None):
- if not asFunction.has_key("Direct") or (asFunction["Direct"] is None):
+ if ("Direct" not in asFunction) or (asFunction["Direct"] is None):
self.__EM["Direct"] = Operator( fromMethod = asFunction["Tangent"], avoidingRedundancy = avoidRC )
else:
self.__EM["Direct"] = Operator( fromMethod = asFunction["Direct"], avoidingRedundancy = avoidRC )
}
"""
if (type(asFunction) is type({})) and \
- asFunction.has_key("useApproximatedDerivatives") and bool(asFunction["useApproximatedDerivatives"]) and \
- asFunction.has_key("Direct") and (asFunction["Direct"] is not None):
- if not asFunction.has_key("withCenteredDF"): asFunction["withCenteredDF"] = False
- if not asFunction.has_key("withIncrement"): asFunction["withIncrement"] = 0.01
- if not asFunction.has_key("withdX"): asFunction["withdX"] = None
- if not asFunction.has_key("withAvoidingRedundancy"): asFunction["withAvoidingRedundancy"] = True
- if not asFunction.has_key("withToleranceInRedundancy"): asFunction["withToleranceInRedundancy"] = 1.e-18
- if not asFunction.has_key("withLenghtOfRedundancy"): asFunction["withLenghtOfRedundancy"] = -1
- if not asFunction.has_key("withmpEnabled"): asFunction["withmpEnabled"] = False
- if not asFunction.has_key("withmpWorkers"): asFunction["withmpWorkers"] = None
+ ("useApproximatedDerivatives" in asFunction) and bool(asFunction["useApproximatedDerivatives"]) and \
+ ("Direct" in asFunction) and (asFunction["Direct"] is not None):
+ if "withCenteredDF" not in asFunction: asFunction["withCenteredDF"] = False
+ if "withIncrement" not in asFunction: asFunction["withIncrement"] = 0.01
+ if "withdX" not in asFunction: asFunction["withdX"] = None
+ if "withAvoidingRedundancy" not in asFunction: asFunction["withAvoidingRedundancy"] = True
+ if "withToleranceInRedundancy" not in asFunction: asFunction["withToleranceInRedundancy"] = 1.e-18
+ if "withLenghtOfRedundancy" not in asFunction: asFunction["withLenghtOfRedundancy"] = -1
+ if "withmpEnabled" not in asFunction: asFunction["withmpEnabled"] = False
+ if "withmpWorkers" not in asFunction: asFunction["withmpWorkers"] = None
from daNumerics.ApproximatedDerivatives import FDApproximation
FDA = FDApproximation(
Function = asFunction["Direct"],
mpEnabled = asFunction["withmpEnabled"],
mpWorkers = asFunction["withmpWorkers"],
)
- self.__CM["Direct"] = Operator( fromMethod = FDA.DirectOperator, avoidingRedundancy = avoidRC )
+ self.__CM["Direct"] = Operator( fromMethod = FDA.DirectOperator, avoidingRedundancy = avoidRC )
self.__CM["Tangent"] = Operator( fromMethod = FDA.TangentOperator, avoidingRedundancy = avoidRC )
self.__CM["Adjoint"] = Operator( fromMethod = FDA.AdjointOperator, avoidingRedundancy = avoidRC )
elif (type(asFunction) is type({})) and \
- asFunction.has_key("Tangent") and asFunction.has_key("Adjoint") and \
+ ("Tangent" in asFunction) and ("Adjoint" in asFunction) and \
(asFunction["Tangent"] is not None) and (asFunction["Adjoint"] is not None):
- if not asFunction.has_key("Direct") or (asFunction["Direct"] is None):
+ if ("Direct" not in asFunction) or (asFunction["Direct"] is None):
self.__CM["Direct"] = Operator( fromMethod = asFunction["Tangent"], avoidingRedundancy = avoidRC )
else:
- self.__CM["Direct"] = Operator( fromMethod = asFunction["Direct"], avoidingRedundancy = avoidRC )
+ self.__CM["Direct"] = Operator( fromMethod = asFunction["Direct"], avoidingRedundancy = avoidRC )
self.__CM["Tangent"] = Operator( fromMethod = asFunction["Tangent"], avoidingRedundancy = avoidRC )
self.__CM["Adjoint"] = Operator( fromMethod = asFunction["Adjoint"], avoidingRedundancy = avoidRC )
elif asMatrix is not None:
#
# Instancie un objet du type élémentaire du fichier
# -------------------------------------------------
- if self.__StoredInputs.has_key(name):
+ if name in self.__StoredInputs:
raise ValueError("A default input with the same name \"%s\" already exists."%str(name))
- elif self.__StoredDiagnostics.has_key(name):
+ elif name in self.__StoredDiagnostics:
raise ValueError("A diagnostic with the same name \"%s\" already exists."%str(name))
else:
self.__StoredDiagnostics[name] = self.__diagnosticFile.ElementaryDiagnostic(
if self.__CM is not None and len(self.__CM) > 0 and not(type(self.__CM) is type({})) and not( __CM_shape[1] == max(__U_shape) ):
raise ValueError("Shape characteristic of control model (CM) \"%s\" and control (U) \"%s\" are incompatible."%(__CM_shape,__U_shape))
#
- if self.__StoredInputs.has_key("AlgorithmParameters") \
- and self.__StoredInputs["AlgorithmParameters"].has_key("Bounds") \
+ if ("AlgorithmParameters" in self.__StoredInputs) \
+ and ("Bounds" in self.__StoredInputs["AlgorithmParameters"]) \
and (type(self.__StoredInputs["AlgorithmParameters"]["Bounds"]) is type([]) or type(self.__StoredInputs["AlgorithmParameters"]["Bounds"]) is type(())) \
and (len(self.__StoredInputs["AlgorithmParameters"]["Bounds"]) != max(__Xb_shape)):
raise ValueError("The number \"%s\" of bound pairs for the state (X) components is different of the size \"%s\" of the state itself." \
stockée qui est renvoyée, et le diagnostic est inatteignable.
"""
if key is not None:
- if self.__algorithm.has_key(key):
+ if key in self.__algorithm:
return self.__algorithm.get( key )
- elif self.__StoredInputs.has_key(key):
+ elif key in self.__StoredInputs:
return self.__StoredInputs[key]
- elif self.__StoredDiagnostics.has_key(key):
+ elif key in self.__StoredDiagnostics:
return self.__StoredDiagnostics[key]
else:
raise ValueError("The requested key \"%s\" does not exists as an input, a diagnostic or a stored variable."%key)
# Association interne de l'observer à la variable
# -----------------------------------------------
for n in VariableNames:
- if not self.__algorithm.has_key( n ):
+ if n not in self.__algorithm:
raise ValueError("An observer requires to be set on a variable named %s which does not exist."%n)
else:
self.__algorithm.StoredVariables[ n ].setDataObserver(
# Association interne de l'observer à la variable
# -----------------------------------------------
for n in VariableNames:
- if not self.__algorithm.has_key( n ):
+ if n not in self.__algorithm:
raise ValueError("An observer requires to be removed on a variable named %s which does not exist."%n)
else:
self.__algorithm.StoredVariables[ n ].removeDataObserver(
def __len__(self):
return self.shape[0]
+# ==============================================================================
+def CostFunction3D(
+ _x,
+ _Hm = None, # Pour simuler Hm(x) : HO["Direct"].appliedTo
+ _HmX = None, # Simulation déjà faite de Hm(x)
+ _arg = None, # Arguments supplementaires pour Hm, sous la forme d'un tuple
+ _BI = None,
+ _RI = None,
+ _Xb = None,
+ _Y = None,
+ _SIV = False, # A résorber pour la 8.0
+ _SSC = [], # self._parameters["StoreSupplementaryCalculations"]
+ _nPS = 0, # nbPreviousSteps
+ _QM = "DA", # QualityMeasure
+ _SSV = {}, # Entrée et/ou sortie : self.StoredVariables
+ _fRt = False, # Restitue ou pas la sortie étendue
+ _sSc = True, # Stocke ou pas les SSC
+ ):
+ """
+ Fonction-coût générale utile pour les algorithmes statiques/3D : 3DVAR, BLUE
+ et dérivés, Kalman et dérivés, LeastSquares, SamplingTest, PSO, SA, Tabu,
+ DFO, QuantileRegression
+ """
+ if not _sSc:
+ _SIV = False
+ _SSC = {}
+ else:
+ for k in ["CostFunctionJ",
+ "CostFunctionJb",
+ "CostFunctionJo",
+ "CurrentOptimum",
+ "CurrentState",
+ "IndexOfOptimum",
+ "SimulatedObservationAtCurrentOptimum",
+ "SimulatedObservationAtCurrentState",
+ ]:
+ if k not in _SSV:
+ _SSV[k] = []
+ if hasattr(_SSV[k],"store"):
+ _SSV[k].append = _SSV[k].store # Pour utiliser "append" au lieu de "store"
+ #
+ _X = numpy.asmatrix(numpy.ravel( _x )).T
+ if _SIV or "CurrentState" in _SSC or "CurrentOptimum" in _SSC:
+ _SSV["CurrentState"].append( _X )
+ #
+ if _HmX is not None:
+ _HX = _HmX
+ else:
+ if _Hm is None:
+ raise ValueError("%s Operator has to be defined."%(self.__name,))
+ if _arg is None:
+ _HX = _Hm( _X )
+ else:
+ _HX = _Hm( _X, *_arg )
+ _HX = numpy.asmatrix(numpy.ravel( _HX )).T
+ #
+ if "SimulatedObservationAtCurrentState" in _SSC or \
+ "SimulatedObservationAtCurrentOptimum" in _SSC:
+ _SSV["SimulatedObservationAtCurrentState"].append( _HX )
+ #
+ if numpy.any(numpy.isnan(_HX)):
+ Jb, Jo, J = numpy.nan, numpy.nan, numpy.nan
+ else:
+ _Y = numpy.asmatrix(numpy.ravel( _Y )).T
+ if _QM in ["AugmentedWeightedLeastSquares", "AWLS", "AugmentedPonderatedLeastSquares", "APLS", "DA"]:
+ if _BI is None or _RI is None:
+ raise ValueError("Background and Observation error covariance matrix has to be properly defined!")
+ _Xb = numpy.asmatrix(numpy.ravel( _Xb )).T
+ Jb = 0.5 * (_X - _Xb).T * _BI * (_X - _Xb)
+ Jo = 0.5 * (_Y - _HX).T * _RI * (_Y - _HX)
+ elif _QM in ["WeightedLeastSquares", "WLS", "PonderatedLeastSquares", "PLS"]:
+ if _RI is None:
+ raise ValueError("Observation error covariance matrix has to be properly defined!")
+ Jb = 0.
+ Jo = 0.5 * (_Y - _HX).T * _RI * (_Y - _HX)
+ elif _QM in ["LeastSquares", "LS", "L2"]:
+ Jb = 0.
+ Jo = 0.5 * (_Y - _HX).T * (_Y - _HX)
+ elif _QM in ["AbsoluteValue", "L1"]:
+ Jb = 0.
+ Jo = numpy.sum( numpy.abs(_Y - _HX) )
+ elif _QM in ["MaximumError", "ME"]:
+ Jb = 0.
+ Jo = numpy.max( numpy.abs(_Y - _HX) )
+ elif _QM in ["QR", "Null"]:
+ Jb = 0.
+ Jo = 0.
+ else:
+ raise ValueError("Unknown asked quality measure!")
+ #
+ J = float( Jb ) + float( Jo )
+ #
+ if _sSc:
+ _SSV["CostFunctionJb"].append( Jb )
+ _SSV["CostFunctionJo"].append( Jo )
+ _SSV["CostFunctionJ" ].append( J )
+ #
+ if "IndexOfOptimum" in _SSC or \
+ "CurrentOptimum" in _SSC or \
+ "SimulatedObservationAtCurrentOptimum" in _SSC:
+ IndexMin = numpy.argmin( _SSV["CostFunctionJ"][_nPS:] ) + _nPS
+ if "IndexOfOptimum" in _SSC:
+ _SSV["IndexOfOptimum"].append( IndexMin )
+ if "CurrentOptimum" in _SSC:
+ _SSV["CurrentOptimum"].append( _SSV["CurrentState"][IndexMin] )
+ if "SimulatedObservationAtCurrentOptimum" in _SSC:
+ _SSV["SimulatedObservationAtCurrentOptimum"].append( _SSV["SimulatedObservationAtCurrentState"][IndexMin] )
+ #
+ if _fRt:
+ return _SSV
+ else:
+ if _QM in ["QR"]: # Pour le QuantileRegression
+ return _HX
+ else:
+ return J
+
# ==============================================================================
if __name__ == "__main__":
print '\n AUTODIAGNOSTIC \n'
#
# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
#
-# Author: André Ribes, andre.ribes@edf.fr, EDF R&D
+# Author: Andre Ribes, andre.ribes@edf.fr, EDF R&D
import sys
import traceback
from daYacsSchemaCreator.infos_daComposant import *
+def _Internal_Add_dir_script_ports(node, sf, ed, br, t_type):
+ # On conserve le pointeur de "node" et "typ"
+ __scriptfile = str( sf )
+ __exist_dir = bool( ed )
+ __base_dir = str( br )
+ __full_name = os.path.join(__base_dir, os.path.basename(__scriptfile))
+ if os.path.exists(__full_name):
+ node.getInputPort("script").edInitPy(__full_name)
+ else:
+ node.getInputPort("script").edInitPy(__scriptfile)
+ if __exist_dir:
+ node.edAddInputPort("studydir", t_type)
+ node.getInputPort("studydir").edInitPy(__base_dir)
+
def create_yacs_proc(study_config):
logging.debug("[create_yacs_proc]")
t_bool = proc.getTypeCode("bool")
t_param_input = proc.getTypeCode("SALOME_TYPES/ParametricInput")
t_param_output = proc.getTypeCode("SALOME_TYPES/ParametricOutput")
- repertory = False
- base_repertory = ""
if "Repertory" in study_config.keys():
base_repertory = study_config["Repertory"]
- repertory = True
+ repertory = True
+ else:
+ base_repertory = ""
+ repertory = False
# Create ADAO case bloc
ADAO_Case = runtime.createBloc("ADAO_Case_Bloc")
init_config = study_config["UserDataInit"]
factory_init_node = catalogAd.getNodeFromNodeMap("UserDataInitFromScript")
init_node = factory_init_node.cloneNode("UserDataInit")
- if repertory and not os.path.exists(init_config["Data"]):
- init_node.getInputPort("script").edInitPy(os.path.join(base_repertory, os.path.basename(init_config["Data"])))
- elif repertory and os.path.exists(init_config["Data"]):
- init_node.getInputPort("script").edInitPy(init_config["Data"])
- init_node.edAddInputPort("studydir", t_string)
- init_node.getInputPort("studydir").edInitPy(base_repertory)
- else:
- init_node.getInputPort("script").edInitPy(init_config["Data"])
+ _Internal_Add_dir_script_ports( init_node, init_config["Data"], repertory, base_repertory, t_string)
init_node_script = init_node.getScript()
init_node_script += "# Import script and get data\n__import__(module_name)\nuser_script_module = sys.modules[module_name]\n\n"
init_node_script += "init_data = user_script_module.init_data\n"
# Step 1: get input data from user configuration
- for key in study_config.keys():
- if key in AssimData:
+ st_keys = study_config.keys()
+ st_keys.sort()
+ for key in st_keys:
+ ad_keys = AssimData
+ ad_keys.sort()
+ if key in ad_keys:
data_config = study_config[key]
key_type = key + "Type"
# Create node
factory_back_node = catalogAd.getNodeFromNodeMap("CreateDictFromScript")
back_node = factory_back_node.cloneNode("Get" + key)
- if repertory and not os.path.exists(data_config["Data"]):
- back_node.getInputPort("script").edInitPy(os.path.join(base_repertory, os.path.basename(data_config["Data"])))
- elif repertory and os.path.exists(data_config["Data"]):
- back_node.getInputPort("script").edInitPy(data_config["Data"])
- back_node.edAddInputPort("studydir", t_string)
- back_node.getInputPort("studydir").edInitPy(base_repertory)
- else:
- back_node.getInputPort("script").edInitPy(data_config["Data"])
+ _Internal_Add_dir_script_ports( back_node, data_config["Data"], repertory, base_repertory, t_string)
back_node.edAddOutputPort(key, t_pyobj)
ADAO_Case.edAddChild(back_node)
# Set content of the node
# Create node
factory_back_node = catalogAd.getNodeFromNodeMap("CreateNumpyVectorFromScript")
back_node = factory_back_node.cloneNode("Get" + key)
- if repertory and not os.path.exists(data_config["Data"]):
- back_node.getInputPort("script").edInitPy(os.path.join(base_repertory, os.path.basename(data_config["Data"])))
- elif repertory and os.path.exists(data_config["Data"]):
- back_node.getInputPort("script").edInitPy(data_config["Data"])
- back_node.edAddInputPort("studydir", t_string)
- back_node.getInputPort("studydir").edInitPy(base_repertory)
- else:
- back_node.getInputPort("script").edInitPy(data_config["Data"])
+ _Internal_Add_dir_script_ports( back_node, data_config["Data"], repertory, base_repertory, t_string)
back_node.edAddOutputPort(key, t_pyobj)
ADAO_Case.edAddChild(back_node)
# Set content of the node
# Create node
factory_back_node = catalogAd.getNodeFromNodeMap("CreateNumpyVectorSerieFromScript")
back_node = factory_back_node.cloneNode("Get" + key)
- if repertory and not os.path.exists(data_config["Data"]):
- back_node.getInputPort("script").edInitPy(os.path.join(base_repertory, os.path.basename(data_config["Data"])))
- elif repertory and os.path.exists(data_config["Data"]):
- back_node.getInputPort("script").edInitPy(data_config["Data"])
- back_node.edAddInputPort("studydir", t_string)
- back_node.getInputPort("studydir").edInitPy(base_repertory)
- else:
- back_node.getInputPort("script").edInitPy(data_config["Data"])
+ _Internal_Add_dir_script_ports( back_node, data_config["Data"], repertory, base_repertory, t_string)
back_node.edAddOutputPort(key, t_pyobj)
ADAO_Case.edAddChild(back_node)
# Set content of the node
# Create node
factory_back_node = catalogAd.getNodeFromNodeMap("CreateNumpy%sFromScript"%(data_config["Type"],))
back_node = factory_back_node.cloneNode("Get" + key)
- if repertory and not os.path.exists(data_config["Data"]):
- back_node.getInputPort("script").edInitPy(os.path.join(base_repertory, os.path.basename(data_config["Data"])))
- elif repertory and os.path.exists(data_config["Data"]):
- back_node.getInputPort("script").edInitPy(data_config["Data"])
- back_node.edAddInputPort("studydir", t_string)
- back_node.getInputPort("studydir").edInitPy(base_repertory)
- else:
- back_node.getInputPort("script").edInitPy(data_config["Data"])
+ _Internal_Add_dir_script_ports( back_node, data_config["Data"], repertory, base_repertory, t_string)
back_node.edAddOutputPort(key, t_pyobj)
ADAO_Case.edAddChild(back_node)
# Set content of the node
for FunctionName in TheData["Function"]:
port_name = key + FunctionName
CAS_node.edAddInputPort(port_name, t_string)
- if repertory and not os.path.exists(TheData["Script"][FunctionName]):
+ if os.path.exists(os.path.join(base_repertory, os.path.basename(TheData["Script"][FunctionName]))):
CAS_node.getInputPort(port_name).edInitPy(os.path.join(base_repertory, os.path.basename(TheData["Script"][FunctionName])))
- elif repertory and os.path.exists(TheData["Script"][FunctionName]):
- CAS_node.getInputPort(port_name).edInitPy(TheData["Script"][FunctionName])
- try:
- CAS_node.edAddInputPort("studydir", t_string)
- CAS_node.getInputPort("studydir").edInitPy(base_repertory)
- except: pass
else:
CAS_node.getInputPort(port_name).edInitPy(TheData["Script"][FunctionName])
+ try:
+ CAS_node.edAddInputPort("studydir", t_string)
+ CAS_node.getInputPort("studydir").edInitPy(base_repertory)
+ except: pass
# Step 3: create compute bloc
compute_bloc = runtime.createBloc("compute_bloc")
break
# We create a new pyscript node
opt_script_nodeOO = runtime.createScriptNode("", "FunctionNodeOO")
- if repertory and not os.path.exists(script_filename):
+ if repertory and os.path.exists(os.path.join(base_repertory, os.path.basename(script_filename))):
script_filename = os.path.join(base_repertory, os.path.basename(script_filename))
try:
script_str= open(script_filename, 'r')
# We create a new pyscript node
opt_script_nodeOO = runtime.createScriptNode("", "FunctionNodeOO")
- if repertory and not os.path.exists(script_filename):
+ if repertory and os.path.exists(os.path.join(base_repertory, os.path.basename(script_filename))):
script_filename = os.path.join(base_repertory, os.path.basename(script_filename))
try:
script_str= open(script_filename, 'r')
# We create a new pyscript node
opt_script_nodeOO = runtime.createScriptNode("", "FunctionNodeOO")
- if repertory and not os.path.exists(script_filename):
+ if repertory and os.path.exists(os.path.join(base_repertory, os.path.basename(script_filename))):
script_filename = os.path.join(base_repertory, os.path.basename(script_filename))
try:
script_str= open(script_filename, 'r')
break
# We create a new pyscript node
opt_script_nodeEM = runtime.createScriptNode("", "FunctionNodeEM")
- if repertory and not os.path.exists(script_filename):
+ if repertory and os.path.exists(os.path.join(base_repertory, os.path.basename(script_filename))):
script_filename = os.path.join(base_repertory, os.path.basename(script_filename))
try:
script_str= open(script_filename, 'r')
break
# We create a new pyscript node
opt_script_nodeEM = runtime.createScriptNode("", "FunctionNodeEM")
- if repertory and not os.path.exists(script_filename):
+ if repertory and os.path.exists(os.path.join(base_repertory, os.path.basename(script_filename))):
script_filename = os.path.join(base_repertory, os.path.basename(script_filename))
try:
script_str= open(script_filename, 'r')
break
# We create a new pyscript node
opt_script_nodeEM = runtime.createScriptNode("", "FunctionNodeEM")
- if repertory and not os.path.exists(script_filename):
+ if repertory and os.path.exists(os.path.join(base_repertory, os.path.basename(script_filename))):
script_filename = os.path.join(base_repertory, os.path.basename(script_filename))
try:
script_str= open(script_filename, 'r')
else:
factory_observation_node = catalogAd.getNodeFromNodeMap("ObservationNodeFile")
observation_node = factory_observation_node.cloneNode("Observation")
- if repertory and not os.path.exists(observer_cfg["Script"]):
- observation_node.getInputPort("script").edInitPy(os.path.join(base_repertory, os.path.basename(observer_cfg["Script"])))
- elif repertory and os.path.exists(observer_cfg["Script"]):
- observation_node.getInputPort("script").edInitPy(observer_cfg["Script"])
- observation_node.edAddInputPort("studydir", t_string)
- observation_node.getInputPort("studydir").edInitPy(base_repertory)
- else:
- observation_node.getInputPort("script").edInitPy(observer_cfg["Script"])
+ _Internal_Add_dir_script_ports( observation_node, observer_cfg["Script"], repertory, base_repertory, t_string)
observer_bloc.edAddChild(observation_node)
ADAO_Case.edAddDFLink(extract_data_node.getOutputPort("var"), observation_node.getInputPort("var"))
ADAO_Case.edAddDFLink(extract_data_node.getOutputPort("info"), observation_node.getInputPort("info"))
analysis_node = factory_analysis_node.cloneNode("UserPostAnalysis")
default_script = analysis_node.getScript()
analysis_file_name = analysis_config["Data"]
- if repertory and not os.path.exists(analysis_file_name):
+ if repertory and os.path.exists(os.path.join(base_repertory, os.path.basename(analysis_file_name))):
analysis_file_name = os.path.join(base_repertory, os.path.basename(analysis_file_name))
try:
analysis_file = open(analysis_file_name, 'r')