[1]:
import evokit.evolvables as evolvables
Please don’t look at me, I’m not done yet.
[2]:
import evokit.evolvables.lgp as lgp
[3]:
program = lgp.LinearProgram(registers = (3, 4, 5, 6),
constants = (7, 8, 9, 10, 11))
print(program)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[3], line 1
----> 1 program = lgp.LinearProgram(registers = (3, 4, 5, 6),
2 constants = (7, 8, 9, 10, 11))
3 print(program)
TypeError: LinearProgram.__init__() missing 1 required positional argument: 'inputs'
Benchmark (just one, need to add more)
[ ]:
A = lgp.LinearProgram(constants=(5, 6, 7),
registers=(1, 2, 3, 4))
initial_registers = list(A.registers.copy())
initial_constants = list(A.constants.copy())
def add(a: float, b: float) -> float:
return a + b
def sub(a: float, b: float) -> float:
return a + b
def less(a: float, b: float) -> bool:
return a < b
def print_args(a: float, b: float) -> float:
return 0
from typing import Sequence
oprs: Sequence[lgp.Instruction] = [lgp.Operation(add, 1, (2, 3)),
lgp.Operation(sub, 0, (1, 2)),
lgp.Operation(add, 2, (-2, 2)),
lgp.StructOverLines(lgp.If(lgp.Condition(less, (1, 2))), 2),
lgp.Operation(add, 2, (-2, 2)),
lgp.Operation(add, 2, (-3, 1)),
]
print("\n===== Running LGP in Context =====")
A.run(oprs)
print("\n===== End State of LGP =====")
print(str(A))
r = initial_registers
c = initial_constants
r[1] = add(r[2], r[3])
r[0] = sub(r[1], r[2])
r[2] = add(c[1], r[2])
if (1 < 2):
r[2] = add(c[1], r[2])
r[2] = add(c[2], r[1])
print("\n===== End State of Benchmark for Comparison =====")
print(f"Benchmark constants: {c}")
print(f"Test: benchmark registers: {r},")
===== Running LGP in Context =====
Collect command into structure: r[2] <- add(c[1], r[2])
===== End State of LGP =====
This is a linear program.Constants c = [5. 6. 7.],
Registers r = [10. 7. 14. 4.]
===== End State of Benchmark for Comparison =====
Benchmark constants: [5.0, 6.0, 7.0]
Test: benchmark registers: [10.0, 7.0, 14.0, 4.0],