forked from ellisk42/ec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpolynomial.py
34 lines (30 loc) · 1.34 KB
/
polynomial.py
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
from ec import commandlineArguments, explorationCompression
from grammar import Grammar
from arithmeticPrimitives import addition, multiplication, k0, k1
from type import tint, arrow
from task import Task
from utilities import eprint
primitives = [addition, multiplication, k0, k1]
MAXIMUMCOEFFICIENT = 9
NUMBEROFEXAMPLES = 5
tasks = [
Task("%dx^2 + %dx + %d"%(a,b,c),
arrow(tint,tint),
[((x,), a*x*x + b*x + c) for x in range(NUMBEROFEXAMPLES+1) ],
features = [float(a*x*x + b*x + c) for x in range(NUMBEROFEXAMPLES+1) ],
cache = True)
for a in range(MAXIMUMCOEFFICIENT+1)
for b in range(MAXIMUMCOEFFICIENT+1)
for c in range(MAXIMUMCOEFFICIENT+1)
]
def featureExtractor(program, tp):
e = program.evaluate([])
return [e(x) for x in range(NUMBEROFEXAMPLES+1)]
if __name__ == "__main__":
baseGrammar = Grammar.uniform(primitives)
explorationCompression(baseGrammar, tasks,
outputPrefix = "experimentOutputs/polynomial",
**commandlineArguments(frontierSize = 10**4,
iterations = 5,
featureExtractor = featureExtractor,
pseudoCounts = 10.0))