Skip to main content

Module gp_cgp

Module gp_cgp 

Source
Expand description

Cartesian Genetic Programming.

CGP encodes a directed acyclic computation graph on a fixed rows × cols grid. Each node stores (function_id, input_0, input_1), plus the final output gene picks which node produces the output. The genotype is a fixed-length integer vector, so populations are Tensor<B, 2, Int> and fit the tensor abstraction cleanly.

§Evolutionary engine

Canonical CGP uses a (1 + λ) Evolution Strategy with point mutation and no crossover. This module re-implements just that engine directly — not via crate::algorithms::es_classical — so the mutation logic can be specialized to the CGP genome semantics (constrained feed-forward connections, function_id range, …).

§Function set

The v1 function set is fixed at construction time:

idoparityformula
0add2a + b
1sub2a − b
2mul2a · b
3protected_div2a / b (or a if `
4sin1sin(a)
5cos1cos(a)
6tanh1tanh(a)
7const 1.001.0

§Phenotype evaluation

Evaluation runs on the host because the per-node dispatch is not a good fit for dense tensor ops; node values are computed in topological order (left-to-right across the grid columns). Genotype storage stays on-device to match the other strategies.

§Reference

  • Miller (2011), Cartesian Genetic Programming (Natural Computing Series).

Structs§

CartesianGeneticProgramming
Classical Cartesian GP with (1 + λ) ES.
CgpConfig
Static configuration for a CartesianGeneticProgramming run.
CgpState
Generation state for CartesianGeneticProgramming.

Constants§

FUNCTION_ARITIES
Fixed v1 function set: arity of each opcode.
NUM_FUNCTIONS
Number of opcodes in the v1 function set.

Functions§

evaluate_cgp
Evaluates a CGP genotype at a set of input rows.