Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: replace pp with ppft #39

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Requirements
* Requires Python 3+.
* Numpy and Pylab are required for several functions in ``ec.observers``.
* Pylab and Matplotlib are required for several functions in ``ec.analysis``.
* Parallel Python (pp) is required if ``ec.evaluators.parallel_evaluation_pp`` is used.
* Parallel Python (ppft) is required if ``ec.evaluators.parallel_evaluation_pp`` is used.


License
Expand Down
28 changes: 14 additions & 14 deletions examples/advanced/parallel_evaluation_pp_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import math

# Define an additional "necessary" function for the evaluator
# to see how it must be handled when using pp.
# to see how it must be handled when using ppft.
def my_squaring_function(x):
return x**2

Expand All @@ -15,36 +15,36 @@ def generate_rastrigin(random, args):
def evaluate_rastrigin(candidates, args):
fitness = []
for cs in candidates:
fit = 10 * len(cs) + sum([(my_squaring_function(x - 1) -
10 * math.cos(2 * math.pi * (x - 1)))
fit = 10 * len(cs) + sum([(my_squaring_function(x - 1) -
10 * math.cos(2 * math.pi * (x - 1)))
for x in cs])
fitness.append(fit)
return fitness
def main(prng=None, display=False):

def main(prng=None, display=False):
if prng is None:
prng = Random()
prng.seed(time())
prng.seed(time())

ea = inspyred.ec.DEA(prng)
if display:
ea.observer = inspyred.ec.observers.stats_observer
ea.observer = inspyred.ec.observers.stats_observer
ea.terminator = inspyred.ec.terminators.evaluation_termination
final_pop = ea.evolve(generator=generate_rastrigin,
final_pop = ea.evolve(generator=generate_rastrigin,
evaluator=inspyred.ec.evaluators.parallel_evaluation_pp,
pp_evaluator=evaluate_rastrigin,
pp_evaluator=evaluate_rastrigin,
pp_dependencies=(my_squaring_function,),
pp_modules=("math",),
pop_size=8,
pop_size=8,
bounder=inspyred.ec.Bounder(-5.12, 5.12),
maximize=False,
max_evaluations=256,
num_inputs=3)

if display:
best = max(final_pop)
best = max(final_pop)
print('Best Solution: \n{0}'.format(str(best)))
return ea

if __name__ == '__main__':
main(display=True)
2 changes: 1 addition & 1 deletion inspyred/ec/evaluators.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def parallel_evaluation_pp(candidates, args):
documentation for `Parallel Python <http://www.parallelpython.com>`_.

"""
import pp
import ppft as pp
logger = args['_ec'].logger

try:
Expand Down
Loading