Initialization#

Random expression generation.

  • grow() and full() – the two tree-creation methods of Koza (1992): full trees have every leaf at the maximum depth, grow trees may stop earlier;

  • ramped_half_and_half() – half grow, half full, over a range of depths, the standard initialization of genetic programming;

  • ptc2() – the probabilistic tree creation algorithm PTC2 of Luke (2000), which controls the size of the trees instead of their depth.

Examples#

>>> import numpy as np
>>> from eqdisco.expr import PrimitiveSet
>>> from eqdisco.generate import full, ramped_half_and_half
>>> pset = PrimitiveSet(n_features=2, functions=("add", "mul"))
>>> rng = np.random.default_rng(0)
>>> full(pset, 2, rng).depth
2
>>> len(ramped_half_and_half(pset, 10, rng, 1, 3))
10

Grow, full, ramped half-and-half and PTC2 tree generation.

Functions#

grow(pset, max_depth, rng[, min_depth])

Grow method: functions and terminals mixed until max_depth.

full(pset, depth, rng)

Full method: every leaf at depth depth.

ramped_half_and_half(pset, n, rng[, ...])

n expressions, half grow and half full, depths ramped over [min_depth, max_depth].

ptc2(pset, target_size, rng[, max_depth])

PTC2: a random tree with about target_size nodes (Luke, 2000).

random_expression(pset, rng[, max_depth, method])

Convenience wrapper: method is "grow", "full" or "ptc2" (then max_depth is the size).