From 641b9166714bb8d9e0cd2b24f883f2abd2ced0d1 Mon Sep 17 00:00:00 2001 From: Jean-Philippe ARGAUD Date: Wed, 5 Apr 2017 12:31:06 +0200 Subject: [PATCH] Improvement of bounds treatment for DFO --- .../DerivativeFreeOptimization.py | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/daComposant/daAlgorithms/DerivativeFreeOptimization.py b/src/daComposant/daAlgorithms/DerivativeFreeOptimization.py index 221d4ef..e9d9a5f 100644 --- a/src/daComposant/daAlgorithms/DerivativeFreeOptimization.py +++ b/src/daComposant/daAlgorithms/DerivativeFreeOptimization.py @@ -213,9 +213,9 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): return CostFunction(_Xx, self._parameters["QualityCriterion"]) opt.set_min_objective(_f) if self._parameters["Bounds"] is not None: - lub = numpy.array(self._parameters["Bounds"]).reshape((Xini.size,2)) - lb = lub[:,0] - ub = lub[:,1] + lub = numpy.array(self._parameters["Bounds"],dtype=float).reshape((Xini.size,2)) + lb = lub[:,0] ; lb[numpy.isnan(lb)] = -float('inf') + ub = lub[:,1] ; ub[numpy.isnan(ub)] = +float('inf') if self._parameters["optdisp"]: print("%s: upper bounds %s"%(opt.get_algorithm_name(),ub)) print("%s: lower bounds %s"%(opt.get_algorithm_name(),lb)) @@ -249,9 +249,9 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): return CostFunction(_Xx, self._parameters["QualityCriterion"]) opt.set_min_objective(_f) if self._parameters["Bounds"] is not None: - lub = numpy.array(self._parameters["Bounds"]).reshape((Xini.size,2)) - lb = lub[:,0] - ub = lub[:,1] + lub = numpy.array(self._parameters["Bounds"],dtype=float).reshape((Xini.size,2)) + lb = lub[:,0] ; lb[numpy.isnan(lb)] = -float('inf') + ub = lub[:,1] ; ub[numpy.isnan(ub)] = +float('inf') if self._parameters["optdisp"]: print("%s: upper bounds %s"%(opt.get_algorithm_name(),ub)) print("%s: lower bounds %s"%(opt.get_algorithm_name(),lb)) @@ -273,9 +273,9 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): return CostFunction(_Xx, self._parameters["QualityCriterion"]) opt.set_min_objective(_f) if self._parameters["Bounds"] is not None: - lub = numpy.array(self._parameters["Bounds"]).reshape((Xini.size,2)) - lb = lub[:,0] - ub = lub[:,1] + lub = numpy.array(self._parameters["Bounds"],dtype=float).reshape((Xini.size,2)) + lb = lub[:,0] ; lb[numpy.isnan(lb)] = -float('inf') + ub = lub[:,1] ; ub[numpy.isnan(ub)] = +float('inf') if self._parameters["optdisp"]: print("%s: upper bounds %s"%(opt.get_algorithm_name(),ub)) print("%s: lower bounds %s"%(opt.get_algorithm_name(),lb)) @@ -297,9 +297,9 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): return CostFunction(_Xx, self._parameters["QualityCriterion"]) opt.set_min_objective(_f) if self._parameters["Bounds"] is not None: - lub = numpy.array(self._parameters["Bounds"]).reshape((Xini.size,2)) - lb = lub[:,0] - ub = lub[:,1] + lub = numpy.array(self._parameters["Bounds"],dtype=float).reshape((Xini.size,2)) + lb = lub[:,0] ; lb[numpy.isnan(lb)] = -float('inf') + ub = lub[:,1] ; ub[numpy.isnan(ub)] = +float('inf') if self._parameters["optdisp"]: print("%s: upper bounds %s"%(opt.get_algorithm_name(),ub)) print("%s: lower bounds %s"%(opt.get_algorithm_name(),lb)) @@ -321,9 +321,9 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): return CostFunction(_Xx, self._parameters["QualityCriterion"]) opt.set_min_objective(_f) if self._parameters["Bounds"] is not None: - lub = numpy.array(self._parameters["Bounds"]).reshape((Xini.size,2)) - lb = lub[:,0] - ub = lub[:,1] + lub = numpy.array(self._parameters["Bounds"],dtype=float).reshape((Xini.size,2)) + lb = lub[:,0] ; lb[numpy.isnan(lb)] = -float('inf') + ub = lub[:,1] ; ub[numpy.isnan(ub)] = +float('inf') if self._parameters["optdisp"]: print("%s: upper bounds %s"%(opt.get_algorithm_name(),ub)) print("%s: lower bounds %s"%(opt.get_algorithm_name(),lb)) -- 2.39.2