project-platypus / platypus Goto Github PK
View Code? Open in Web Editor NEWA Free and Open Source Python Library for Multiobjective Optimization
License: GNU General Public License v3.0
A Free and Open Source Python Library for Multiobjective Optimization
License: GNU General Public License v3.0
Hi,
Is there a way to use initial conditions to run NSGA II or any other MOEA algorithm in platypus?
Thanks,
Ivan
I wonder whether the Platypus support hybrid encoding for decision variables? For example encode simultaneously with Real and Binary.
Hello,
i am trying to solve a multi objective optimization problem, but the types of my variables are subset(x can only takes particular values), what is the proper type to use in this case(i.e problem.types=?)
Hi David,
I have the following code:
random.seed(1969)
def inverse_third_layer(x):
b= inverse_desired_output
W= weights_third_layer
bias= third_layer_bias
return [np.sum(W[0,:])*x[0] - np.sum(b + bias), np.sum(W[1,:])*x[1] - np.sum(b + bias), np.sum(W[2,:])*x[2] - np.sum(b + bias), np.sum(W[3,:])*x[3] - np.sum(b + bias),
np.sum(W[4,:])*x[4] - np.sum(b + bias), np.sum(W[5,:])*x[5] - np.sum(b + bias), np.sum(W[6,:])*x[6] - np.sum(b + bias), np.sum(W[7,:])*x[7] - np.sum(b + bias)], [x[0],
x[1], x[2], x[3], x[4], x[5], x[6], x[7]]
problem= Problem(8, 8, 8)
problem.types[:]= Real(0, 1)
problem.constraints[:]= ">=0"
problem.constraints[:]= "<=1"
problem.function= inverse_third_layer
algorithm= NSGAII(problem, population_size= 50, variator= UNDX())
algorithm.run(1000)
From it, I get a population of 50 feasible solutions. I would like to compare each objective vector by using the Hypervolume function. For that, I was hoping to iterate through each population to compute the Hypervolume as follows:
hyp= Hypervolume(minimum= [0,0,0,0,0,0,0,0], maximum= [2,2,2,2,2,2,2,2])
hyp_result= hyp.calculate(algorithm.result[0])
which gives this error message: TypeError: 'Solution' object is not iterable
Do you have any suggestions?
Many thanks,
Ivan
Hi,
Is there a way to fix a seed in order to get reproducible results? If so, could you show me how to do that.
Many thanks,
Ivan
I use a mix of Integer
and Real
in the problem types
list. (C.f. issue #31.) At the end of a run, when it's time to print the variables
from the solution object, I simply issue a Python print
. This works fine for Real
, but when I use Integer
the result is a list of Boolean values that appear to be the binary equivalent of the actual number. Example output:
scores = [471, 1668] low_freq_cutoff = [False, True, False, False, True, True, True, True, False], length_cutoff = 2 min_short_freq = [False, True, False, True, False, True, True, False, False, True, False, True, True, False, False, False, False, True, False, True, False, True, True, False, False, True, False, True, True, False, False, False, False, True, False, True, False, True, True, False, False, True, False, True, True, False, False, False, False, True, False, True, False, True, True, False, False, True, False, True, True, False, False, False, False, True, False, True, False, True, True, False, False, True, False, True, True, False, False, False, False, True, False, True, False, True, True, False, False, True, False, True, True, False, False, False, False, True, False, True, False, True, True, False, False, True, False, True, True, False, False, False, False, True, False, True, False, True, True, False, False, True, False, True, True, False, False, False, False, True, False, True, False, True, True, False, False, True, False, True, True, False, False, False, False, True, False, True, False, True, True, False, False, True, False, True, True, False, False, False] norm_exp = 0.09633 dict_exp = 0.07681 camel_bias = 0.88487 split_bias = 0.00008352
Best guess: it appears that maybe the definition of Integer in types.py
needs a __repr__()
, which I started trying to do, but then I couldn't figure out where the object actually stores the current value. I could only find min_value
and max_value
.
Perhaps someone else can figure out how to fix this?
Hi David,
I have the following code:
random.seed(1969)
def inverse_layer(x):
code lines
problem= Problem(8,8,8)
problem.types[:]= Real(0, 1)
problem.constraints[:]= ">=0"
problem.constraints[:]= "<=1"
problem.function= inverse_third_layer
algorithm= NSGAII(problem)
algorithm.run(700)
The script works as expected and I am able to print the output of objectives.
When I tried the commands:
hyp= Hypervolume(minimum= [0,0,0], maximum= [1, 1, 1])
hyp_result= calculate(algorithm.result.objectives, hyp)
I get this error message: TypeError: 'NSGAII' object does not support indexing
Is there a way to get around?
Many thanks,
Ivan
Hi @dhadka
I have a constrained optimization problem and not sure how to leverage the existing example and generalize it.
from platypus import NSGAII, Problem, Real
def belegundu(vars):
x = vars[0]
y = vars[1]
return [-2*x + y, 2*x + y], [-x + y - 1, x + y - 7]
Suppose that x and y are vectors, I am not sure how to translate it into a correct code using your framework, could you please shed some lights on this matter, I would be more than grateful.
Regards,
Aziz
Hi,
can you provide a simple example how to pass non-decision variable parameters to the objective function?
Thank you
I am trying to learn the Platypus package. I only slightly modified the routine shown as the site example below
def belegundu(vars):
x = vars[0]
y = vars[1]
return [-2x + y, 2x + y], [-x + y - 1, x + y - 7]
problem = Problem(2, 2, 2)
problem.types[:] = [Real(0, 5), Real(0, 3)]
problem.constraints[:] = "<=0"
problem.function = belegundu
algorithm = NSGAII(problem)
algorithm.run(10000)
to use the Binh and Korn function given here: https://en.wikipedia.org/wiki/Test_functions_for_optimization#Test_functions_for_multi-objective_optimization as shown below
from platypus import NSGAII, Problem, Real
def telegundu(vars):
x = vars[2.5]
y = vars[1.5]
return [4x**2 + 4y**2,(x-5)**2+(y-5)**2], (x-5)2+y2-25, (x-8)**2+(y+3)**2-7.7]
problem = Problem(2, 2, 2)
problem.types[:] = [Real(0, 5), Real(0, 3)]
problem.constraints[:] =[ "<=0",">=0"]
problem.function = telegundu
algorithm = NSGAII(problem)
algorithm.run(10000)
for solution in algorithm.result:
print(solution.objectives)
For some reason I get this error:
TypeError: unhashable type: 'list'
Any ideas?
Thank you
Ali
Thanks for creating Platypus.
I've started successfully using Platypus for some simple optimizations. In order to communicate to other people which version of Platypus I'm using (particularly in code that I develop), it would be really useful to have a proper release to reference. Failing that, at least a version number within the code itself would help.
How can i change the value of parameters in any heuristic? For example in NSGAII change the crossover rate or mutation rate
I couldn’t seem to find in the docs how elements in the solution correspond to the problem. Maybe I missed it?
I define a problem with the variable type of Permutation, for example [0,1,0]. When I try to run the NSGAII , it gives me the following message .
File "C:\Python27\ArcGIS10.3\Lib\site-packages\platypus\operators.py", line 638, in evolve
o1[i] = p2[i]
IndexError: list assignment index out of range
I have checked the PMX(Variator), but I cannot figure out the problem. Do you have any idea about the problem?
I'm getting an error, or I am confused about how the nsga-ii algorithm works.
Why do results generate points in objective space which are not in the original CSV, when Problem functions are simply referring to their original values? See below:
And why can't I assign Integer
type to the first variable? That seems to throw an error: IndexError: invalid index to scalar variable.
.
First I define the problem:
class BestActivity(Problem):
def __init__(self):
super(BestActivity, self).__init__(4, 2, 0)
self.types[:] = [Real(0,570), Real(20, 4830), Real(1, 5), Real(0.7046248913, 562.812972)]
self.directions[0] = Problem.MINIMIZE
self.directions[1] = Problem.MAXIMIZE
def evaluate(self, solution):
convenience = solution.variables[1]
desirability = solution.variables[2]
solution.objectives[:] = [convenience, desirability]
print(solution.variables)
Then a custom Generator with data from a csv file using list(df.itertuples().next())
from Pandas dataframe:
csv = pd.read_csv('nsga.csv', index_col=False, dtype={'key': np.int32, 'travel': np.int32, 'rating':np.float64, 'elevation': np.float64}).itertuples()
class MyGenerator(Generator):
def __init__(self):
super(MyGenerator, self).__init__()
def generate(self, problem):
solution = Solution(BestActivity())
solution.variables= list(csv.next())[1:]
return solution
Run and plot results:
algorithm = NSGAII(problem = BestActivity(), population_size = 542, generator = MyGenerator(), variator=None)
algorithm.run(10000)
x = [s.objectives[0] for s in algorithm.result]
y = [s.objectives[1] for s in algorithm.result]
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
plt.scatter(x,y)
plt.show()
Hello @dhadka , when I test the following example, all is okay:
#!/usr/bin/python
import sys
print sys.path
from platypus import Problem, Real, NSGAII
class Test(Problem):
def __init__(self):
super(Test, self).__init__(3, 1, 4)
self.types[:] = [Real(0, 25890), Real(0, 25890), Real(0, 25890)]
self.constraints[:] = ">=0"
def evaluate(self, solution):
x = solution.variables[0]
y = solution.variables[1]
z = solution.variables[2]
solution.objectives[:] = [x*2+y*6+z*12]
solution.constraints[:] = [25980-x,25980-y,25980-z,(x+y+z)-10000]
algorithm = NSGAII(Test())
algorithm.run(10000)
for s in algorithm.result:
print s.objectives[0],s
But when I add a new constraint segment (value must be 1000 always), ir returns an error. This is the code:
#!/usr/bin/python
import sys
print sys.path
from platypus import Problem, Real, NSGAII
class Test(Problem):
def __init__(self):
super(Test, self).__init__(4, 1, 5)
self.types[:] = [Real(0, 25890), Real(0, 25890), Real(0, 25890),Real(0,1000)]
self.constraints[0:3] = ">=0"
self.constraints[3:] = "==0"
def evaluate(self, solution):
x = solution.variables[0]
y = solution.variables[1]
z = solution.variables[2]
t = solution.variables[3]
solution.objectives[:] = [x*2+y*6+z*12+t*3]
solution.constraints[0:3] = [25980-x,25980-y,25980-z,(x+y+z+t)-10000]
solution.constraints[3:] = [1000-t]
algorithm = NSGAII(Test())
algorithm.run(10000)
for s in algorithm.result:
print s.objectives[0],s
This error:
File "/private/tmp/pppp/Platypus/platypus/core.py", line 318, in _constraint_eq return abs(x - y) TypeError: unsupported operand type(s) for -: 'list' and 'float'
So, where is the problem?
Hi!
I am trying to distribute the fitness evaluations using the MPIPool facility. Unfortunately, my code crashes with the following error message:
Traceback (most recent call last):
File "main_mpi.py", line 125, in invoke_master
engine.run(ITERATIONS*INDIVIDUALS)
File "build/bdist.linux-i686/egg/platypus/core.py", line 304, in run
File "build/bdist.linux-i686/egg/platypus/algorithms.py", line 173, in step
File "build/bdist.linux-i686/egg/platypus/algorithms.py", line 183, in initialize
File "build/bdist.linux-i686/egg/platypus/algorithms.py", line 72, in initialize
File "build/bdist.linux-i686/egg/platypus/core.py", line 277, in evaluate_all
File "build/bdist.linux-i686/egg/platypus/evaluator.py", line 88, in evaluate_all
File "build/bdist.linux-i686/egg/platypus/mpipool.py", line 195, in map
File "mpi4py/MPI/Comm.pyx", line 1173, in mpi4py.MPI.Comm.recv
File "mpi4py/MPI/msgpickle.pxi", line 303, in mpi4py.MPI.PyMPI_recv
File "mpi4py/MPI/msgpickle.pxi", line 269, in mpi4py.MPI.PyMPI_recv_match
File "mpi4py/MPI/msgpickle.pxi", line 111, in mpi4py.MPI.Pickle.load
File "mpi4py/MPI/msgpickle.pxi", line 100, in mpi4py.MPI.Pickle.cloads
TypeError: ('__init__() takes exactly 2 arguments (1 given)', <class 'platypus.mpipool.MPIPoolException'>, ())
I am surely missing something. Do you have any suggestions or insights about the cause? I'll try to provide a minimal example of my code, if necessary.
Thank you!
I have a project that handles ~70k parameters and I am trying to decide if Platypus is capable of handling such a vast parameter space. I feel it would be beneficial to provide in the documentation how convergence rates change with number of parameters.
Also, kind of inline with convergence, would it be possible to implement Playpus via
while not_converged == True: run()
Instead of run(iterations)
because in this alternate scenario you can just assume that after enough time has elapsed it will either not converge, or it will not converge in desired time.
Hello,
did you consider SCE-UA [1] as additional algorithm?
It would be interesting to evaluate the performance.
Do you have experience or some thoughts about the performance vs. algorithms like NSGA, CMA and MOPSO?
Thanks!
Fabian
Duan, Q., Sorooshian, S. and Gupta, V. K.: Optimal use of the SCE-UA global optimization method for calibrating watershed models, J. Hydrol., 158(3), 265–284, 1994.
I want to test your Platypus for Power System Controller optimization. But My software support python 3.3..
Can I use it with Python 3.3
Can you provide documentation on how to implement the indicators?
Hi !
I'm new to this filed and try to read the code implementation.
The weight_generator of MOEA/D is random_weights. But I don't understand why this random generating method is used in Platypus.
The original paper of MOEA/D suggests a uniformly generating way.
It seems the generate_recursive in normal_boundary_weights is more close to this approach.
I know how it works but I'm confused about why it is used. You know in that paper, a H parameter is introduced to generated the weight vectors.Could you please give me some explanations.
Thanks!!
Hi,
I was wondering whether I should recompile the whole project when I create a new encoding scheme rather than use the ones included (i.e Binary, Permutation, etc.) ?
Could you please shed some light on this concern because I am working on a specific problem for which I need to use a custom encoding scheme.
Thanks.
Aziz
Hello,
when trying to run the parallel examples from the doc, I get this error for the concurrent.futures variant:
Traceback (most recent call last):
File "exp_multi.py", line 48, in
results = experiment(algorithms, problems, nfe=10000, submit=pool.submit)
TypeError: experiment() got an unexpected keyword argument 'submit'
For multiprocessor it has as unexpected keyword argument 'map'
Would be great, if you have an advice to fix this.
Hi David,
I sent you a copy of the script and its input files. For some reason, the following command (at line 361):
extract_hypervolume_ind[count]= hyp.calculate([solution])
gives the following error: list index out of range (see below). When I try with a different set of input files, the scripts works as expected.
Any suggestions?
Many thanks,
Ivan
File "", line 1, in
runfile('C:/Users/IMarroquin/Desktop/toto/Platypus_Full_Optimization_Class_1.py', wdir='C:/Users/IMarroquin/Documents/My Python Scripts')
File "C:\Temp\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 880, in runfile
execfile(filename, namespace)
File "C:\Temp\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/IMarroquin/Desktop/toto/Platypus_Full_Optimization_Class_1.py", line 408, in
rstate= np.random.RandomState(seed),
File "C:\Temp\Anaconda3\lib\site-packages\hyperopt\fmin.py", line 307, in fmin
return_argmin=return_argmin,
File "C:\Temp\Anaconda3\lib\site-packages\hyperopt\base.py", line 635, in fmin
return_argmin=return_argmin)
File "C:\Temp\Anaconda3\lib\site-packages\hyperopt\fmin.py", line 320, in fmin
rval.exhaust()
File "C:\Temp\Anaconda3\lib\site-packages\hyperopt\fmin.py", line 199, in exhaust
self.run(self.max_evals - n_done, block_until_done=self.async)
File "C:\Temp\Anaconda3\lib\site-packages\hyperopt\fmin.py", line 173, in run
self.serial_evaluate()
File "C:\Temp\Anaconda3\lib\site-packages\hyperopt\fmin.py", line 92, in serial_evaluate
result = self.domain.evaluate(spec, ctrl)
File "C:\Temp\Anaconda3\lib\site-packages\hyperopt\base.py", line 840, in evaluate
rval = self.fn(pyll_rval)
File "C:/Users/IMarroquin/Desktop/toto/Platypus_Full_Optimization_Class_1.py", line 361, in optimize_parameters_inverse_third_layer
extract_hypervolume_ind[count]= hyp.calculate([solution])
File "C:\Temp\Anaconda3\lib\site-packages\platypus-0.1-py3.6.egg\platypus\indicators.py", line 197, in calculate
normalize(feasible, self.minimum, self.maximum)
File "C:\Temp\Anaconda3\lib\site-packages\platypus-0.1-py3.6.egg\platypus\core.py", line 1070, in normalize
if any([maximum[i]-minimum[i] < EPSILON for i in range(problem.nobjs)]):
File "C:\Temp\Anaconda3\lib\site-packages\platypus-0.1-py3.6.egg\platypus\core.py", line 1070, in
if any([maximum[i]-minimum[i] < EPSILON for i in range(problem.nobjs)]):
IndexError: list index out of range
Hi there,
I recently closed an issue regarding a custom made type.
I successfully added a custom type which is in the form of a matrix of size AxB where A=2 and B is of size N. The first column contains tuples while the second columns contains a list.
I am getting this error :
Traceback (most recent call last):
File "/home/myProblem.py", line 34, in
print myprob.types
File "/home/Platypus/platypus/core.py", line 80, in str
return "[" + ", ".join(list(map(str, self._data))) + "]"
TypeError: str returned non-string (type tuple)
It seems that I need to modify FixedLengthArray class also, is that right ?
Could you please shed some lights ? Any suggestion ?
Thanks
Hello,
Best regards.
I would like to implement a genetic algorithm into a library of techniques for solving large multi-objective problems over system-of-systems. Our architecture requires algorithms to operate in a stepwise fashion, returning a new bundle of 'decisions' which are then evaluated by our models, returning the objective values and constraints.
I couldn't tell from a quick browse through the source code whether this might be possible by accessing the step()
methods of the algorithm class?
Hi ther,
I have the following issue. If I use this command (between lines 582 - 583):
problem.types[:]= [Real(logs_min[0], logs_max[0]), Real(logs_min[1], logs_max[1]),
the script works but the variable values are not in the expected range.
So, I replace the above command by this one (between lines 584 - 587):
problem.types[0]= Real(logs_min[0], logs_max[0])
problem.types[1]= Real(logs_min[1], logs_max[1])
problem.types[2]= Real(logs_min[2], logs_max[2])
problem.types[0]= Real(logs_min[3], logs_max[3])
I get the following error (see below): 'NoneType' object has no attribute 'rand'. According to the documentation, I should be able to do it.
I attached a copy of the script for your reference.
Traceback (most recent call last):
File "New_Platypus_TPE55_Full_Optimization_Class_1.py", line 683, in
rstate= np.random.RandomState(seed),
File "C:\Anaconda3\lib\site-packages\hyperopt\fmin.py", line 307, in fmin
return_argmin=return_argmin,
File "C:\Anaconda3\lib\site-packages\hyperopt\base.py", line 635, in fmin
return_argmin=return_argmin)
File "C:\Anaconda3\lib\site-packages\hyperopt\fmin.py", line 320, in fmin
rval.exhaust()
File "C:\Anaconda3\lib\site-packages\hyperopt\fmin.py", line 199, in exhaust
self.run(self.max_evals - n_done, block_until_done=self.async)
File "C:\Anaconda3\lib\site-packages\hyperopt\fmin.py", line 173, in run
self.serial_evaluate()
File "C:\Anaconda3\lib\site-packages\hyperopt\fmin.py", line 92, in serial_eva
luate
result = self.domain.evaluate(spec, ctrl)
File "C:\Anaconda3\lib\site-packages\hyperopt\base.py", line 840, in evaluate
rval = self.fn(pyll_rval)
File "New_Platypus_TPE55_Full_Optimization_Class_1.py", line 612, in optimize_
parameters_inverse_second_layer_round_1
algorithm.run(n_iter)
File "C:\Anaconda3\lib\site-packages\platypus-0.1-py3.6.egg\platypus\core.py",
line 302, in run
File "C:\Anaconda3\lib\site-packages\platypus-0.1-py3.6.egg\platypus\algorithm
s.py", line 64, in step
File "C:\Anaconda3\lib\site-packages\platypus-0.1-py3.6.egg\platypus\algorithm
s.py", line 390, in initialize
File "C:\Anaconda3\lib\site-packages\platypus-0.1-py3.6.egg\platypus\algorithm
s.py", line 71, in initialize
File "C:\Anaconda3\lib\site-packages\platypus-0.1-py3.6.egg\platypus\algorithm
s.py", line 71, in
File "C:\Anaconda3\lib\site-packages\platypus-0.1-py3.6.egg\platypus\operators
.py", line 38, in generate
File "C:\Anaconda3\lib\site-packages\platypus-0.1-py3.6.egg\platypus\operators
.py", line 38, in
AttributeError: 'NoneType' object has no attribute 'rand'
Many thanks
Ivan
Hi David,
I found this paper: https://pdfs.semanticscholar.org/5757/e76802152ca7d4df6395e553017bf42b59ce.pdf
the authors propose an interesting way to select the nadir point from the generated solutions in the Pareto front. Part of the workflow requires to order the nondominated solutions from maximum to minimum. Then the sorted solutions are ranked according their position.
Does Platypus has an internal function to sort the nondominated solutions?
Many thanks,
Ivan
Hello, Can I set a seed for a simple Problem
?
Where will be set the seed ? In Problem
from platypus import Problem, Real, NSGAII, Integer,Subset,Permutation
class Test(Problem):
def __init__(self):
super(Test, self).__init__(8,1,6)
...
or in Algorithm
:
algorithm = NSGAII(Test,....)
Thanks.
While running ProcessPoolEvaluator in Windows iPython environment, I have the following error.
BrokenProcessPool: A process in the process pool was terminated abruptly while the future was running or pending.
Hello! Has anyone tested the performance of Platypus with several thousand of constraints? Should it go well?
Consider adding the above non-evolutionary optimization algorithms for use in the experimenter.
Hi David,
I get a the following error message:
runfile('C:/Users/IMarroquin/Desktop/toto/Problematic_Script.py', wdir='C:/Users/IMarroquin/Desktop/toto')
Nadir point obtained from maximum of all objectives 1.0
Best hypervolume indicator given by variables : [-0.02744351 -0.23101299 3.19304276] = 4.5761e-08
Computed probabilities for Lithofacies 3 : [ 0.03723548 0.0303772 0.93238723]
The addition of the probabilities 0.9999998807907104
Parameters used in inverse third layer with Eps NSGAII :
{'epsilons': 0.040684210526315795, 'iter': 5000}
Nadir point obtained from maximum of all objectives -1.0
Traceback (most recent call last):
File "", line 1, in
runfile('C:/Users/IMarroquin/Desktop/toto/Problematic_Script.py', wdir='C:/Users/IMarroquin/Desktop/toto')
File "C:\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 710, in runfile
execfile(filename, namespace)
File "C:\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 101, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/IMarroquin/Desktop/toto/Problematic_Script.py", line 439, in
rstate= np.random.RandomState(seed),
File "C:\Anaconda3\lib\site-packages\hyperopt\fmin.py", line 307, in fmin
return_argmin=return_argmin,
File "C:\Anaconda3\lib\site-packages\hyperopt\base.py", line 635, in fmin
return_argmin=return_argmin)
File "C:\Anaconda3\lib\site-packages\hyperopt\fmin.py", line 320, in fmin
rval.exhaust()
File "C:\Anaconda3\lib\site-packages\hyperopt\fmin.py", line 199, in exhaust
self.run(self.max_evals - n_done, block_until_done=self.async)
File "C:\Anaconda3\lib\site-packages\hyperopt\fmin.py", line 173, in run
self.serial_evaluate()
File "C:\Anaconda3\lib\site-packages\hyperopt\fmin.py", line 92, in serial_evaluate
result = self.domain.evaluate(spec, ctrl)
File "C:\Anaconda3\lib\site-packages\hyperopt\base.py", line 840, in evaluate
rval = self.fn(pyll_rval)
File "C:/Users/IMarroquin/Desktop/toto/Problematic_Script.py", line 390, in optimize_parameters_inverse_third_layer
extract_hypervolume_ind[count]= hyp.calculate([solution])
File "C:\Anaconda3\lib\site-packages\platypus-0.1-py3.6.egg\platypus\indicators.py", line 197, in calculate
normalize(feasible, self.minimum, self.maximum)
File "C:\Anaconda3\lib\site-packages\platypus-0.1-py3.6.egg\platypus\core.py", line 1071, in normalize
raise PlatypusError("objective with empty range")
PlatypusError: objective with empty range
For some reason, I get a Nadir point of Nadir point of -1.0 (see line code 371 - 372). Because of this value, the rest of the code breaks down:
File "C:/Users/IMarroquin/Desktop/toto/Problematic_Script.py", line 390, in optimize_parameters_inverse_third_layer
extract_hypervolume_ind[count]= hyp.calculate([solution])
What is the meaning of a Nadir point of -1? How should I handle this value so the script continue working? Can I do something like this (between lines 372 and 374):
if (maxi <= 0): #it will account for any potential negative Nadir point value
maxi= 0 # I force the hypervolume to be zero
else: # the Nadir point is a positive value bigger than zero and the script follows its normal path
......
I attached a copy of the script with its input data.
Many thanks,
Ivan
Hi,
I try to use the experimenter to run a three-dimensional problem with NSGA III and 1000 evaluation runs in parallel. The reason is that without parallelization it last 30h to compute it.
I do not want to compare different algorithms or problems. Can I force the experimenter to run thsi single problem with one algorithm in parallel?
Or do you have othe rrecommendations how to spead up the computation of this problem.
Thanks for your support!
Fabian
The reason is that in method "iterate" the comparison:
"if self.archive:" is made. But archive is initially empty and Python evaluates this to False.
Instead, we need:
"if self.archive is not None:"
If I attempt to use a problem.types
array that contains an Integer
type and a Real
, it runs for a while and then I get the error
platypus.core.PlatypusError: must define variator for mixed types
Unfortunately, I cannot find an explanation in the documentation about what this error means and what I can do about it. Looking at the source code, the error comes from isinstance
comparisons to the class of the first element in the list problem.types
. Now, the type Integer
is defined as a subclass of Binary
in the file types.py, and Binary
is a type defined in PlatypusConfig.default_variator
, so it seems like it should work and that the failure comes from not detecting the subclass relationship.
As a test of this hypothesis, I added definitions of Integer
to config.py like this (copying the definitions from Binary
, since Integer
is based on it anyway):
class _PlatypusConfig(object):
def __init__(self):
super(_PlatypusConfig, self).__init__()
self.default_variator = {Real : GAOperator(SBX(), PM()),
Binary : GAOperator(HUX(), BitFlip()),
Integer : GAOperator(HUX(), BitFlip()),
Permutation : CompoundOperator(PMX(), Insertion(), Swap()),
Subset : GAOperator(SSX(), Replace())}
self.default_mutator = {Real : PM(),
Binary : BitFlip(),
Integer : BitFlip(),
Permutation : CompoundMutation(Insertion(), Swap()),
Subset : Replace()}
...
and then bypassed the tests for all([isinstance(t, base_type) for t in problem.types])
on lines 56 and 74 in the file config.py (by simply writing if True:
). The result runs and seems to be working.
This was a hack and a correct solution is needed, but I wanted to report the problem and a possible direction to explore for fixing it.
Hello,
I'd like to run a platypus process with evaluating my objective function (and constraints) in parallel. Unfortunately, I didn't succeed. I've try to use the "ProcessPoolEvaluator", but it allows me to only parallelize different runs of the same optimization algorithm (using seeds) but not to parallelize the function evaluations on the same platypus run.
Is there any way to do so in platypus?
Thanks.
Hi David,
is it possible to use "population_size" parameter setting with EpsNSGAII and EpsMOEA? if not, how can I find the population size output by one of these techniques?
Many thanks,
Ivan
How Can I use Platypus with python V 3
Hi @dhadka,
I am having a strange behavior when running an example of a simple problem I have created.
You already pointed me out to the right implementation of a custom type previously and now I am wondering why I am having a bug. I have made available my source code and in the output file, from the first lines showing the matrix randomly generated is correctly displayed as expected but for other random matrix the outcome displayed is not what I was expecting.
Any reason why this is happening ?
Very appreciating any help in advance.
Regards
Can anyone please tell how can I find the values of variables after algorithm.run()
Hi David,
The online documentation gives good examples on how to set up constraints using a numeric value. I have the following question for you, I read a 2D array from an input file and determine min/max values per column. Then, I want to use these values to set a group constraints as follows:
problem.constraints[0]= ">=logs_min[0]"
problem.constraints[0]= "<=log_max[0]"
problem.constraints[1]= ">=logs_min[1]"
problem.constraints[1]= "<=log_max[1]"
problem.constraints[2]= ">=logs_min[2]"
problem.constraints[2]= "<=log_max[2]"
problem.constraints[0]= ">=logs_min[3]"
problem.constraints[0]= "<=log_max[3]"
I get the following error message: could not convert string to float: 'logs_min[0]'
I haven't been able to find a way to feed the min/max values to the above mentioned commands.
Any suggestions?
Thanks
Ivan
Running an algorithm with a relatively small number of function evaluations gives results that do no respect the constraints of the problem. It seems to me that more these should not be included in the results.
# load libararies
from platypus import NSGAII, Problem, Real
import matplotlib.pyplot as plt
# define optimization function
def belegundu(vars):
x = vars[0]
y = vars[1]
return [-2*x + y, 2*x + y], [-x + y - 1, x + y - 7]
# setup problem
problem = Problem(2, 2, 2)
problem.types[:] = [Real(0, 5), Real(0, 3)]
problem.constraints[:] = "<=0"
problem.function = belegundu
algorithm = NSGAII(problem)
# run algorithm and plot contstraints
algorithm.run(100)
x1= [s.constraints[0] for s in algorithm.result]
algorithm.run(10000)
x2= [s.constraints[0] for s in algorithm.result]
plt.hist(x1)
plt.hist(x2)
plt.xlabel("Constraint")
plt.ylabel("counts")
plt.legend(["100","1000"], title = "Function evaluations")
plt.show()
Please add platypus at https://pypi.python.org/pypi
with pip installation
Hi,
I use the Platypus Project for the optimization of a off-grid PV-Battery System. My decision variabls are the PV Panel Power and Battery capacity installed.
I defined them as Integers in the following manner:
from platypus import NSGAII, Problem, Integer
int1 = Integer(80, 200)
int2 = Integer(540, 1920)
problem.types[:] = [int1, int2]
Is there now a way to define a step size inside the integer range of min and max values.
You can imagine that there ar not Pv module with 81W but only in a 10W step, meaning 80W, 90W,100W...
Sts just my first time using Python and Platypus.
Thanks for your help!
Fabian
Hi, I want to use 24 cores or my computer (node);
I have this code to parallelize in python 2.7:
with platypus.MultiprocessingEvaluator(24) as evaluator:
algorithm = platypus.NSGAII(Material(),evaluator=evaluator)
algorithm.run(250000)
But when I see CPU consumption with htop
I see that cores are infraused (at least 24):
How can I modify for evaluations of indicators to be done in parallel?
Do I need something to the Problem
in the evaluation
function on Material()
@dhadka ?
Hi David,
I sent you a copy of a script that I am using to determine how many iterations take to get a pareto front that is - as much as possible - close to the optimal point. For that, I am using the NSGAII with UNDX and a population size of 100.
At each iteration, I compute the hypervolume for each individual objective and record the result. I looked for the objective with the smallest hypervolume value, to select it as the best objective for a given iteration.
I noticed the following issues:
Starting from iteration 6000, the algorithm produces the same objective with an hypervolume value of 0. When I examine the output file, none of the objectives have a hypervolume value of 0. Additionally, there are less and less number of objectives that are generated
The script ends with this error:
Run iteration : 18000
Traceback (most recent call last):
File "", line 1, in
runfile('C:/Users/IMarroquin/Documents/My Python Scripts/Optimization_MLP_Clusters/Platypus_Test_Optimization.py', wdir='C:/Users/IMarroquin/Documents/My Python Scripts')
File "C:\Temp\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 880, in runfile
execfile(filename, namespace)
File "C:\Temp\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/IMarroquin/Documents/My Python Scripts/Optimization_MLP_Clusters/Platypus_Test_Optimization.py", line 466, in
algorithm.run(iter)
File "C:\Temp\Anaconda3\lib\site-packages\platypus-0.1-py3.6.egg\platypus\core.py", line 302, in run
self.step()
File "C:\Temp\Anaconda3\lib\site-packages\platypus-0.1-py3.6.egg\platypus\algorithms.py", line 175, in step
self.iterate()
File "C:\Temp\Anaconda3\lib\site-packages\platypus-0.1-py3.6.egg\platypus\algorithms.py", line 196, in iterate
offspring.extend(self.variator.evolve(parents))
File "C:\Temp\Anaconda3\lib\site-packages\platypus-0.1-py3.6.egg\platypus\operators.py", line 410, in evolve
result.append(self.undx(parents))
File "C:\Temp\Anaconda3\lib\site-packages\platypus-0.1-py3.6.egg\platypus\operators.py", line 446, in undx
e = orthogonalize(d, e_eta)
File "C:\Temp\Anaconda3\lib\site-packages\platypus-0.1-py3.6.egg\platypus\tools.py", line 55, in orthogonalize
u = subtract(u, project(u, v))
File "C:\Temp\Anaconda3\lib\site-packages\platypus-0.1-py3.6.egg\platypus\tools.py", line 51, in project
return multiply(dot(u, v) / dot(v, v), v)
ZeroDivisionError: float division by zero
I attached the script and the data that I am using for your convenience - hoping this helps. Please note that Platypus related code begins at line 241.
Kind regards,
Ivan
Potential_Issues.zip
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.