Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Rapidsai Cuml Genetic Node

From Leeroopedia
Revision as of 16:27, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Rapidsai_Cuml_Genetic_Node.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Knowledge Sources
Domains Machine_Learning, Genetic_Programming
Last Updated 2026-02-08 12:00 GMT

Overview

Defines the node structure used to represent individual elements in abstract syntax trees (ASTs) for the cuML genetic programming module, supporting terminal (variable, constant) and non-terminal (function) node types.

Description

The node.h header declares the cuml::genetic::node struct, which is the fundamental building block of program ASTs in the genetic programming framework.

Node Type Enum (node::type):

An extensive enumeration covering all supported node kinds:

  • Terminals: variable (references a feature column by index) and constant (holds a float value).
  • Binary functions: add, atan2, div, fdim, max, min, mul, pow, sub.
  • Unary functions: abs, acos, acosh, asin, asinh, atan, atanh, cbrt, cos, cosh, cube, exp, inv, log, neg, rcbrt, rsqrt, sin, sinh, sq, sqrt, tan, tanh.

Node Members:

  • t: The node type.
  • u.fid: Feature column ID (for variable nodes).
  • u.val: Constant value (for constant nodes).

Constructors:

  • Default constructor.
  • Function node: node(type ft).
  • Variable node: node(int fid).
  • Constant node: node(float val).
  • Copy constructor and assignment operator.

Methods:

  • is_terminal(): Returns true for variable or constant nodes.
  • is_nonterminal(): Returns true for function nodes.
  • arity(): Returns 0 for terminals, 1 for unary, 2 for binary functions.
  • from_str(): Static method to parse a node type from a string.

Usage

Use this struct when constructing, manipulating, or inspecting program ASTs in the genetic programming framework. Nodes are the elements stored in program::nodes arrays and are used internally by the evolution, mutation, and evaluation functions.

Code Reference

Source Location

Signature

namespace cuml {
namespace genetic {

struct node {
  enum class type : uint32_t {
    variable = 0, constant,
    functions_begin,
    binary_begin = functions_begin,
    add = binary_begin, atan2, div, fdim, max, min, mul, pow, sub,
    binary_end = sub,
    unary_begin,
    abs = unary_begin, acos, acosh, asin, asinh, atan, atanh,
    cbrt, cos, cosh, cube, exp, inv, log, neg, rcbrt, rsqrt,
    sin, sinh, sq, sqrt, tan, tanh,
    unary_end = tanh,
    functions_end = unary_end,
  };

  explicit node();
  explicit node(type ft);
  explicit node(int fid);
  explicit node(float val);
  explicit node(const node& src);
  node& operator=(const node& src);

  bool is_terminal() const;
  bool is_nonterminal() const;
  int arity() const;
  static type from_str(const std::string& ntype);

  static const int kInvalidFeatureId;

  type t;
  union {
    int fid;
    float val;
  } u;
};

} // namespace genetic
} // namespace cuml

Import

#include <cuml/genetic/node.h>

I/O Contract

Inputs

Name Type Required Description
ft node::type Yes (function ctor) Function type for non-terminal nodes
fid int Yes (variable ctor) Feature column index for variable nodes
val float Yes (constant ctor) Constant value for constant nodes
ntype const std::string& Yes (from_str) String name of the node type

Outputs

Name Type Description
is_terminal() bool True if the node is a variable or constant
is_nonterminal() bool True if the node is a function
arity() int 0 for terminals, 1 for unary, 2 for binary functions
from_str() node::type Parsed node type enum value from string

Usage Examples

#include <cuml/genetic/node.h>

using cuml::genetic::node;

// Create a function node (subtraction)
node func_node{node::type::sub};
// func_node.is_nonterminal() == true
// func_node.arity() == 2

// Create a constant node
node const_node{2.5f};
// const_node.is_terminal() == true
// const_node.u.val == 2.5f

// Create a variable node (feature column 3)
node var_node{3};
// var_node.is_terminal() == true
// var_node.u.fid == 3

// Parse from string
node::type t = node::from_str("add");
// t == node::type::add

// Build a simple expression: X[0] + 2.0
// AST representation: [add, X[0], 2.0]
node expr[3];
expr[0] = node{node::type::add};
expr[1] = node{0};       // feature 0
expr[2] = node{2.0f};    // constant 2.0

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment