def __repr__(self):
"x.__repr__() <==> repr(x)"
- return repr(self.__C)
+ if isinstance(self.__C, numpy.float64):
+ return repr(float(self.__C))
+ else:
+ return repr(self.__C)
def __str__(self):
"x.__str__() <==> str(x)"
"""
__author__ = "Jean-Philippe ARGAUD"
-import os, copy, types, sys, logging, math, numpy, scipy, itertools
+import os, copy, types, sys, logging, math, numpy, scipy, itertools, warnings
+import scipy.linalg # Py3.6
from daCore.BasicObjects import Operator, Covariance, PartialAlgorithm
from daCore.PlatformInfo import PlatformInfo, vt, vfloat
mpr = PlatformInfo().MachinePrecision()
def SingularValuesEstimation( __Ensemble, __Using = "SVDVALS"):
"Renvoie les valeurs singulières de l'ensemble et leur carré"
if __Using == "SVDVALS": # Recommandé
- import scipy
__sv = scipy.linalg.svdvals( __Ensemble )
__svsq = __sv**2
elif __Using == "SVD":
sampleList = itertools.product(*coordinatesList)
# ---------------------------
elif len(__SampleAsMinMaxLatinHyperCube) > 0:
- import scipy, warnings
if vt(scipy.version.version) <= vt("1.7.0"):
__msg = "In order to use Latin Hypercube sampling, you must at least use Scipy version 1.7.0 (and you are presently using Scipy %s). A void sample is then generated."%scipy.version.version
warnings.warn(__msg, FutureWarning, stacklevel=50)
sampleList = scipy.stats.qmc.scale(__sample, __l_bounds, __u_bounds)
# ---------------------------
elif len(__SampleAsMinMaxSobolSequence) > 0:
- import scipy, warnings
if vt(scipy.version.version) <= vt("1.7.0"):
__msg = "In order to use Latin Hypercube sampling, you must at least use Scipy version 1.7.0 (and you are presently using Scipy %s). A void sample is then generated."%scipy.version.version
warnings.warn(__msg, FutureWarning, stacklevel=50)
__sr = [numpy.mean(item, dtype=mfp).astype('float') for item in self.__values]
except Exception:
raise TypeError("Base type is incompatible with numpy")
- return( numpy.array(__sr).tolist() )
+ return numpy.array(__sr).tolist()
def stds(self, ddof=0):
"""
return [numpy.array(item).std(dtype=mfp).astype('float') for item in self.__values]
except Exception:
raise TypeError("Base type is incompatible with numpy")
- return( numpy.array(__sr).tolist() )
+ return numpy.array(__sr).tolist()
def sums(self):
"""
__sr = [numpy.array(item).sum() for item in self.__values]
except Exception:
raise TypeError("Base type is incompatible with numpy")
- return( numpy.array(__sr).tolist() )
+ return numpy.array(__sr).tolist()
def mins(self):
"""
__sr = [numpy.array(item).min() for item in self.__values]
except Exception:
raise TypeError("Base type is incompatible with numpy")
- return( numpy.array(__sr).tolist() )
+ return numpy.array(__sr).tolist()
def maxs(self):
"""
__sr = [numpy.array(item).max() for item in self.__values]
except Exception:
raise TypeError("Base type is incompatible with numpy")
- return( numpy.array(__sr).tolist() )
+ return numpy.array(__sr).tolist()
def powers(self, x2):
"""
__sr = [numpy.power(item, x2) for item in self.__values]
except Exception:
raise TypeError("Base type is incompatible with numpy")
- return( numpy.array(__sr).tolist() )
+ return numpy.array(__sr).tolist()
def norms(self, _ord=None):
"""
__sr = [numpy.linalg.norm(item, _ord) for item in self.__values]
except Exception:
raise TypeError("Base type is incompatible with numpy")
- return( numpy.array(__sr).tolist() )
+ return numpy.array(__sr).tolist()
def traces(self, offset=0):
"""
__sr = [numpy.trace(item, offset, dtype=mfp).astype('float') for item in self.__values]
except Exception:
raise TypeError("Base type is incompatible with numpy")
- return( numpy.array(__sr).tolist() )
+ return numpy.array(__sr).tolist()
def maes(self, _predictor=None):
"""
__sr = [numpy.mean(numpy.abs(numpy.ravel(item) - numpy.ravel(_predictor[i]))) for i, item in enumerate(self.__values)]
except Exception:
raise TypeError("Base type is incompatible with numpy")
- return( numpy.array(__sr).tolist() )
+ return numpy.array(__sr).tolist()
def mses(self, _predictor=None):
"""
__sr = [(numpy.linalg.norm(numpy.ravel(item) - numpy.ravel(_predictor[i]))**2 / __n) for i, item in enumerate(self.__values)]
except Exception:
raise TypeError("Base type is incompatible with numpy")
- return( numpy.array(__sr).tolist() )
+ return numpy.array(__sr).tolist()
msds = mses # Mean-Square Deviation (MSD=MSE)
__sr = [(numpy.linalg.norm(numpy.ravel(item) - numpy.ravel(_predictor[i])) / math.sqrt(__n)) for i, item in enumerate(self.__values)]
except Exception:
raise TypeError("Base type is incompatible with numpy")
- return( numpy.array(__sr).tolist() )
+ return numpy.array(__sr).tolist()
rmsds = rmses # Root-Mean-Square Deviation (RMSD=RMSE)
if "MaximumNumberOfSteps" in Params:
print(" [VERBOSE] Maximum possible number of iteration:",Params['MaximumNumberOfSteps'])
print(" [VERBOSE] Background read:",Background)
- print(" [VERBOSE] Bounds read:",Params['Bounds'])
+ __v = Params['Bounds']
+ if isinstance(__v, (numpy.ndarray, numpy.matrix, list, tuple)):
+ __v = numpy.array(__v).astype('float')
+ __v = numpy.where(numpy.isnan(__v), None, __v)
+ __v = __v.tolist()
+ print(" [VERBOSE] Bounds read:",__v)
#
if "DifferentialIncrement" not in Params:
Params["DifferentialIncrement"] = 0.001
print(" [VERBOSE] Links read")
print(" [VERBOSE] Optimization information read")
print(" [VERBOSE] Background read:",Background)
- print(" [VERBOSE] Bounds read:",Params['Bounds'])
+ __v = Params['Bounds']
+ if isinstance(__v, (numpy.ndarray, numpy.matrix, list, tuple)):
+ __v = numpy.array(__v).astype('float')
+ __v = numpy.where(numpy.isnan(__v), None, __v)
+ __v = __v.tolist()
+ print(" [VERBOSE] Bounds read:",__v)
#
if "DifferentialIncrement" not in Params:
Params["DifferentialIncrement"] = 0.001
keys = list(__resultats.keys())
keys.sort()
for k in keys:
- output.append("%18s = %s"%(k,tuple(__resultats[k])))
+ __v = __resultats[k]
+ if isinstance(__v, numpy.matrix): # no1
+ __v = __v.astype('float').tolist()
+ elif isinstance(__v, numpy.ndarray): # no2
+ __v = tuple(__v.astype('float').tolist())
+ else:
+ __v = tuple(__v)
+ output.append("%22s = %s"%(k,__v))
output.append("")
with open(__filename, 'w') as fid:
fid.write( "\n".join(output) )
keys = list(__resultats.keys())
keys.sort()
for k in keys:
- output.append("%s = %s"%(k,tuple(__resultats[k])))
+ __v = __resultats[k]
+ if isinstance(__v, numpy.matrix): # no1
+ __v = __v.astype('float').tolist()
+ elif isinstance(__v, numpy.ndarray): # no2
+ __v = tuple(__v.astype('float').tolist())
+ else:
+ __v = tuple(__v)
+ output.append("%s = %s"%(k,__v))
output.append("")
with open(__filename, 'w') as fid:
fid.write( "\n".join(output) )
keys = list(__resultats.keys())
keys.sort()
for k in keys:
- output.append("%18s = %s"%(k,tuple(__resultats[k])))
+ __v = __resultats[k]
+ if isinstance(__v, numpy.matrix): # no1
+ __v = __v.astype('float').tolist()
+ elif isinstance(__v, numpy.ndarray): # no2
+ __v = tuple(__v.astype('float').tolist())
+ else:
+ __v = tuple(__v)
+ output.append("%22s = %s"%(k,__v))
output.append("")
print( "\n".join(output) )
#---------------------------------------------
#
# Python script using ADAO TUI
#
+import numpy as np
from numpy import array, matrix
from adao import adaoBuilder
case = adaoBuilder.New('')
#
# Python script using ADAO TUI
#
+import numpy as np
from numpy import array, matrix
from adao import adaoBuilder
case = adaoBuilder.New('')
#
# Python script using ADAO TUI
#
+import numpy as np
from numpy import array, matrix
from adao import adaoBuilder
case = adaoBuilder.New('')
#
# Python script using ADAO TUI
#
+import numpy as np
from numpy import array, matrix
from adao import adaoBuilder
case = adaoBuilder.New('')
#
# Python script using ADAO TUI
#
+import numpy as np
from numpy import array, matrix
from adao import adaoBuilder
case = adaoBuilder.New('')