Comments (6)
From [email protected] on July 18, 2013 05:12:09
Thanks for the report.
It makes sense to add this to repr since the fitness can be constructed without argument (empty values).
I wonder if we shall not also add this to the str.
Status: Started
Owner: [email protected]
from deap.
From marc.andre.gardner on July 18, 2013 10:36:29
Just for the record, I tested the patch and there is no significant performance regression in any case.
I'm ok with the proposed fix.
from deap.
From felix.antoine.fortin on July 18, 2013 16:06:43
This seems reasonable. However, it looks like the original patch includes a typo, where we read "if self.values:", I guess OP meant "if self.valid:".
MAG is it what you tested? Performance impact would have been surprising since repr is never called when executing algorithms.
I propose a small variant of repr using the same idea, but more compact.
def __repr__(self):
"""Return the Python code to build a copy of the object."""
module = self.__module__
name = self.__class__.__name__
return "%s.%s(%r)" % (module, name, self.values if self.valid else ())
from deap.
From [email protected] on July 19, 2013 05:55:57
I propose to use the try/except clause, since most of the time the fitness will be valid.
def __str__(self):
"""Return the values of the Fitness object."""
try:
values = self.values
except TypeError:
values = tuple()
return str(values)
def __repr__(self):
"""Return the Python code to build a copy of the object."""
module = self.__module__
name = self.__class__.__name__
try:
values = self.values
except TypeError:
values = tuple()
return "%s.%s(%r)" % (module, name, values)
from deap.
From marc.andre.gardner on July 19, 2013 22:43:36
Actually I tested it by adding the condition directly into getValues (so it is indeed called when executing).
However, when I think again about that, I clearly see that it is not a good idea, since you want getValues to fail when there is no values to return.
Anyway, I'm fine with the try/except. Just a small detail : why not directly write it like :
def str(self):
"""Return the values of the Fitness object."""
try:
return str(self.values)
except TypeError:
return tuple()
from deap.
From [email protected] on July 26, 2013 08:42:08
Changeset 8ff6e5 fixes the issue using the if/else clause proposed by Felix. Thanks for the report
Status: Fixed
from deap.
Related Issues (20)
- Is there a high-level interface over DEAP? HOT 2
- Bug with Compiling ADFs
- Adding library to Code Library Search plugin
- function _violates_constraint(fitness) can be put into class ConstrainedFitness(Fitness)?
- MultiStatistics class supports different functions for each Statistics object
- Support for Linux ARM aarch64 HOT 5
- In the example bbob.py,how can I get the "fgeneric" and "bbobbenchmarks" module? HOT 1
- Improve convergence performance(array dimensions question)
- Support Python 3.11 and 3.12, including wheels on PyPI
- AttributeError: 'list' object has no attribute 'fitness' HOT 8
- scaling in deap.tools.uniform_reference_points HOT 1
- question about the height of gp tree HOT 1
- TypeError: Population must be a sequence. For dicts or sets, use sorted(d) HOT 7
- question about kfold
- Getting the Pareto Front for every generation
- Seeking Help for "ValueError: too many values to unpack" Issue in Python Program HOT 1
- cxSimulatedBinaryBounded raises Exception with various eta
- selNSGA3WithMemory fails if passed uniform_reference_points where nobj = 1
- gp.cxSemantic causes polyploidy
- How to use GA to find optimal set of solutions for multi-objective functions HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from deap.