Closed sabrinadraude closed 4 years ago
Do you have any constraint violations in the results? I believe the HV calculation will return zero if there are no feasible solutions.
Ah yes, I had forgotten a + in one of the constraints definitions! Thank you :)
Do you know a good way to display hypervolume results? The example online compares the hypervolumes of different models. I was wondering if it could be used for comparing the hypervolumes of the solutions throughout the iterations ?
eg for 100 iterations can 100 hypervolumes be given?
Cheers,
Sabrina
I tend to do this outside of platypus, but I think you can do something like this (I've not tested this). I think the algorithm will just keep running from wherever you left it if you call run again. So, you can just put it in a loop and periodically calculate HV.
Make sure you keep the minimum & maximum constant for all HV calculations for them to be comparable.
hv = []
N = list(range(0, N, 500)) # Run the algorithm in chunks of 500
for n in N:
algorithm.run(n)
hyp = Hypervolume(minimum=[0, 240], maximum=[47, 600])
fi = hyp.calculate(algorithm.result)
hv.append(fi)
print(f"Hypervolume after {n} evaluations: {fi}")
plt.plot(N, hv)
plt.ylabel('Hypervolume')
plt.xlabel('Number of function evaluations.')
plt.show()
Thanks, this works! Gonna go try compare the different algorithms now.
Thanks :)
Hiya,
really love using this library! I've been using the 'Hypervolume' part of the Platypus library in python.
At present the hypervolume value I am getting is 0.0. I'm not sure if this is because I am minimising one objective and maximising the other? The hypervolume produces a value if I change the constraints to maximise for the minimisation objective.
I've tried a large variety of different values for minimum and maximum in the hypervolume but still get 0. the solution results themselves produce a nice curved pareto front. So I am not quite sure what I have done wrong with the hypervolume :
N = 10000 problem = Problem(len(job_allocation), 2, 2) problem.directions[1] = Problem.MINIMIZE problem.directions[0] = Problem.MAXIMIZE problem.constraints[:] = ">=0" problem.types[:] = Integer(0, my_counter_again-1) problem.function = lambda x: evaluation_function2(x, jobs, job_index, dur_datetime) algorithm = NSGAII(problem) algorithm.run(N)
hyp = Hypervolume(minimum=[0, 240], maximum=[47, 600]) fi = hyp.calculate(algorithm.result) print("Hypervolume value:", fi)
plot the results
plt.scatter([s.objectives[0] for s in algorithm.result], [s.objectives[1] for s in algorithm.result]) plt.xlim([25, 45]) plt.ylim([250, 600]) plt.xlabel("Priority score") plt.ylabel("Cost: £") plt.show() Any info would be helpful!
Cheers,
Sabrina