-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.#animate.py.1.1
More file actions
39 lines (30 loc) · 1.05 KB
/
Copy path.#animate.py.1.1
File metadata and controls
39 lines (30 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
'''
Created on Apr 24, 2011
@author: erik
'''
import matplotlib.pyplot as plt
import math
class Animation:
""" Class for animating a microGP experiment.
An Animation instance is initialized with a microGP experiment instance.
When called the instance plots the target function, and then successively
plots the best match from each generation.
"""
def __init__(self, experiment):
plt.ion()
self.target = experiment.target_func
self.domain = experiment.fitness_accuracy
self.best = experiment.best
def __call__(self):
y_values = []
for x in self.domain:
y_values.append(eval(self.target))
line, = plt.plot(self.domain, y_values)
plt.draw()
line, = plt.plot(self.domain, self.domain)
for function in self.best:
y_values = []
for x in self.domain:
y_values.append(function([x]))
line.set_ydata(y_values)
plt.draw()