Giter VIP home page Giter VIP logo

Comments (6)

cmd-ntrf avatar cmd-ntrf commented on July 25, 2024

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.

cmd-ntrf avatar cmd-ntrf commented on July 25, 2024

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.

cmd-ntrf avatar cmd-ntrf commented on July 25, 2024

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.

cmd-ntrf avatar cmd-ntrf commented on July 25, 2024

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.

cmd-ntrf avatar cmd-ntrf commented on July 25, 2024

From marc.andre.gardner on July 19, 2013 22:43:36

@felix

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.

cmd-ntrf avatar cmd-ntrf commented on July 25, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.