nd2py.generator.eq package#
Submodules#
nd2py.generator.eq.enumerator module#
- class nd2py.generator.eq.enumerator.Enumerator(leafs: List[Variable | Number], binary: List[Type[Symbol]], unary: List[Type[Symbol]])[source]#
Bases:
objectEnumerate all possible expression trees of a given length.
This generator exhaustively constructs all valid expression trees by combining given leaf nodes, binary operators, and unary operators to reach the target tree size (measured by number of nodes).
Example
>>> from nd2py import Variable >>> from nd2py.generator.eq import Enumerator >>> x = Variable('x') >>> enumerator = Enumerator(leafs=[x], binary=[Add, Mul], unary=[]) >>> for eq in enumerator(length=3): print(eq) x + x x * x
- __init__(leafs: List[Variable | Number], binary: List[Type[Symbol]], unary: List[Type[Symbol]])[source]#
Initialize the enumerator.
- Parameters:
leafs – List of leaf symbols (Variable, Number instances).
binary – List of binary operator classes (e.g., Add, Sub, Mul, Div).
unary – List of unary operator classes (e.g., Sin, Cos, Log, Exp).
nd2py.generator.eq.gplearn_generator module#
- class nd2py.generator.eq.gplearn_generator.GPLearnGenerator(variables: List[Variable], binary: List[str | Symbol] = [Add, Sub, Mul, Div], unary: List[str | Symbol] = [Sqrt, Log, Abs, Neg, Inv, Sin, Cos, Tan], full_prob: float = 0.5, depth_range: Tuple[int, int] = (2, 6), const_range: Tuple[float, float] = None, rng: RandomState = None, edge_list: Tuple[List[int], List[int]] = None, num_nodes: int = None, scalar_number_only=True)[source]#
Bases:
object- __init__(variables: List[Variable], binary: List[str | Symbol] = [Add, Sub, Mul, Div], unary: List[str | Symbol] = [Sqrt, Log, Abs, Neg, Inv, Sin, Cos, Tan], full_prob: float = 0.5, depth_range: Tuple[int, int] = (2, 6), const_range: Tuple[float, float] = None, rng: RandomState = None, edge_list: Tuple[List[int], List[int]] = None, num_nodes: int = None, scalar_number_only=True)[source]#
nd2py.generator.eq.metaai_generator module#
- class nd2py.generator.eq.metaai_generator.MetaAIGenerator(variables: List[Variable], binary: List[str | Symbol] = [Add, Sub, Mul, Div], unary: List[str | Symbol] = [Abs, Inv, Sqrt, Log, Exp, Sin, Arcsin, Cos, Arccos, Tan, Arctan, Pow2, Pow3], operators_to_downsample='Div:0,Arcsin:0,Arccos:0,Tan:0.2,Arctan:0.2,Sqrt:5,Pow2:3,Inv:3', rng: RandomState = None, edge_list: Tuple[List[int], List[int]] = None, num_nodes: int = None, scalar_number_only=True)[source]#
Bases:
object- __init__(variables: List[Variable], binary: List[str | Symbol] = [Add, Sub, Mul, Div], unary: List[str | Symbol] = [Abs, Inv, Sqrt, Log, Exp, Sin, Arcsin, Cos, Arccos, Tan, Arctan, Pow2, Pow3], operators_to_downsample='Div:0,Arcsin:0,Arccos:0,Tan:0.2,Arctan:0.2,Sqrt:5,Pow2:3,Inv:3', rng: RandomState = None, edge_list: Tuple[List[int], List[int]] = None, num_nodes: int = None, scalar_number_only=True)[source]#
- dist(n_op, n_emp)[source]#
max_ops: maximum number of operators Enumerate the number of possible unary-binary trees that can be generated from empty nodes. D[n][e] represents the number of different binary trees with n nodes that can be generated from e empty nodes, using the following recursion:
D(n, 0) = 0 D(0, e) = 1 D(n, e) = D(n, e - 1) + p_1 * D(n - 1, e) + D(n - 1, e + 1)
p1 = 0 if binary trees, or 1 if unary-binary trees
nd2py.generator.eq.snip_generator module#
- class nd2py.generator.eq.snip_generator.SNIPGenerator(max_var=5, min_unary=0, max_unary=4, min_binary_per_var=0, max_binary_per_var=1, max_binary_ops_offset=4, max_unary_depth=6, n_mantissa=4, max_exp=1, min_exp=0, **kwargs)[source]#
Bases:
MetaAIGenerator
- class nd2py.generator.eq.snip_generator.SNIPGenerator2(**kwargs)[source]#
Bases:
SNIPGenerator