New to genetic programming and

236 views
Skip to first unread message

palash hurkat

unread,
Aug 22, 2016, 9:44:41 AM8/22/16
to deap-users
I am new to both genetic programming and DEAP so having some trouble to understand both of them . I read the documentation and got the basic idea about genetic programming. However i am having trouble in implementation part. Few questions which i have in my mind -
Q)How to input a multi dimensional array/individual?
Q)What kind of output do i expect here ?

def protectedDiv(left, right):
    try:
        return left / right
    except ZeroDivisionError:
        return 1



pset = gp.PrimitiveSet("MAIN", 1)
pset.addPrimitive(operator.add, 2)
pset.addPrimitive(operator.sub, 2)
pset.addPrimitive(operator.mul, 2)
pset.addPrimitive(protectedDiv, 2)
pset.addPrimitive(operator.neg, 1)
pset.addPrimitive(math.cos, 1)
pset.addPrimitive(math.sin, 1)
pset.addEphemeralConstant("rand101", lambda: random.randint(-1,1))

pset.renameArguments(ARG0='x')

creator.create("FitnessMin", base.Fitness, weights=(-1.0,))
creator.create("Individual", gp.PrimitiveTree, fitness=creator.FitnessMin)


toolbox = base.Toolbox()
toolbox.register("expr", gp.genHalfAndHalf, pset=pset, min_=1, max_=2)
toolbox.register("individual", tools.initIterate, creator.Individual, toolbox.expr)
toolbox.register("population", tools.initRepeat, list, toolbox.individual)
toolbox.register("compile", gp.compile, pset=pset)

def evalSymbReg(individual, points):
    # Transform the tree expression in a callable function
    func = toolbox.compile(expr=individual)
    # Evaluate the mean squared error between the expression
    # and the real function : x**4 + x**3 + x**2 + x
    sqerrors = ((func(x) - x**4 - x**3 - x**2 - x)**2 for x in points)
    return math.fsum(sqerrors) / len(points),



toolbox.register("evaluate", evalSymbReg, points=[x/10. for x in range(-10,10)])
toolbox.register("select", tools.selTournament, tournsize=3)
toolbox.register("mate", gp.cxOnePoint)
toolbox.register("expr_mut", gp.genFull, min_=0, max_=2)
toolbox.register("mutate", gp.mutUniform, expr=toolbox.expr_mut, pset=pset)

toolbox.decorate("mate", gp.staticLimit(key=operator.attrgetter("height"), max_value=17))
toolbox.decorate("mutate", gp.staticLimit(key=operator.attrgetter("height"), max_value=17))

pop = toolbox.population(n=300)

hof = tools.HallOfFame(1)

pop, log = algorithms.eaSimple(pop, toolbox, 0.5, 0.1, 40,halloffame=hof, verbose=True)

François-Michel De Rainville

unread,
Aug 22, 2016, 9:51:26 AM8/22/16
to deap-users
Q)How to input a multi dimensional array/individual?
A) See the gp/numpy example

Q)What kind of output do i expect here ?
A) Where? You have the whole program copy-pasted. The output of the program is usually either the best individuals which are contained in the hall of fame or the final population which is contained in pop.

Regards,

--
You received this message because you are subscribed to the Google Groups "deap-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to deap-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

mehran zareh

unread,
Nov 30, 2016, 11:40:50 AM11/30/16
to deap-users
Hi,

I have the same problem. In the examples I found, only single input case is studied. I would like to know if you have already found any reference for that.

Thanks
Mehran

François-Michel De Rainville

unread,
Dec 3, 2016, 12:28:36 PM12/3/16
to deap-users
There generic programming advanced tutorial state exactly how to have multiple input to GP.

Cheers,

--

Genetic Programmer

unread,
Nov 17, 2017, 8:04:50 AM11/17/17
to deap-users
Hallo,

I have same same problem. Could you please sent me some links?

Best regards,
Richard.


Τη Σάββατο, 3 Δεκεμβρίου 2016 - 5:28:36 μ.μ. UTC, ο χρήστης François-Michel De Rainville έγραψε:
There generic programming advanced tutorial state exactly how to have multiple input to GP.

Cheers,
Le 30 nov. 2016 11:40, "mehran zareh" <mehra...@gmail.com> a écrit :
Hi,

I have the same problem. In the examples I found, only single input case is studied. I would like to know if you have already found any reference for that.

Thanks
Mehran

--
You received this message because you are subscribed to the Google Groups "deap-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to deap-users+...@googlegroups.com.

François-Michel De Rainville

unread,
Nov 17, 2017, 8:13:56 AM11/17/17
to deap-users
The docs states how to have multiple inputs:

"The first line creates a primitive set. Its arguments are the name of the procedure it will generate ("main") and its number of inputs, 2."

To unsubscribe from this group and stop receiving emails from it, send an email to deap-users+unsubscribe@googlegroups.com.

Roman Trotsyuk

unread,
Jul 26, 2018, 7:26:43 PM7/26/18
to deap-users
Dear François,

I have the same question as other people though I am not novice in GA and GP. May be it is better to make the documentation more clear and provide cross-cutting example then refer to documentation that people already have read and not found the answer? I think ease of use affects proliferation of the library.

Best Regards,
Roman

пятница, 17 ноября 2017 г., 13:04:50 UTC пользователь Genetic Programmer написал:
Reply all
Reply to author
Forward
0 new messages