Types

Equations

Equations are specified as binary trees with the Node type, defined as follows:

SymbolicRegression.CoreModule.EquationModule.NodeType
Node{T<:Real}

Node defines a symbolic expression stored in a binary tree. A single Node instance is one "node" of this tree, and has references to its children. By tracing through the children nodes, you can evaluate or print a given expression.

Fields

  • degree::Int: Degree of the node. 0 for constants, 1 for unary operators, 2 for binary operators.
  • constant::Bool: Whether the node is a constant.
  • val::T: Value of the node. If degree==0, and constant==true, this is the value of the constant. It has a type specified by the overall type of the Node (e.g., Float64).
  • feature::Int (optional): Index of the feature to use in the case of a feature node. Only used if degree==0 and constant==false. Only defined if degree == 0 && constant == false.
  • op::Int: If degree==1, this is the index of the operator in options.unaops. If degree==2, this is the index of the operator in options.binops. In other words, this is an enum of the operators, and is dependent on the specific Options object. Only defined if degree >= 1
  • l::Node{T}: Left child of the node. Only defined if degree >= 1. Same type as the parent node.
  • r::Node{T}: Right child of the node. Only defined if degree == 2. Same type as the parent node. This is to be passed as the right argument to the binary operator.
source

There are a variety of constructors for Node objects, including:

SymbolicRegression.CoreModule.EquationModule.NodeMethod
Node(; val::Real=nothing, feature::Integer=nothing)

Create a leaf node: either a constant, or a variable.

Arguments:

  • val::Real, if you are specifying a constant, pass the value of the constant here.
  • feature::Integer, if you are specifying a variable, pass the index of the variable here.
source

When you create an Options object, the operators passed are also re-defined for Node types. This allows you use, e.g., t=Node("x1") * 3f0 to create a tree, so long as * was specified as a binary operator.

When using these node constructors, types will automatically be promoted. You can convert the type of a node using convert:

Base.convertMethod
convert(::Type{Node{T1}}, n::Node{T2}) where {T1,T2}

Convert a Node{T2} to a Node{T1}. This will recursively convert all children nodes to Node{T1}, using convert(T1, tree.val) at constant nodes.

source

Population

Groups of equations are given as a population, which is an array of trees tagged with score, loss, and birthdate–-these values are given in the PopMember.

Population members

SymbolicRegression.PopMemberModule.PopMemberMethod
PopMember(t::Node, score::T, loss::T)

Create a population member with a birth date at the current time.

Arguments

  • t::Node: The tree for the population member.
  • score::T: The score (normalized to a baseline, and offset by a complexity penalty)
  • loss::T: The raw loss to assign.
source
SymbolicRegression.PopMemberModule.PopMemberMethod
PopMember(dataset::Dataset{T}, baseline::T,
          t::Node, options::Options)

Create a population member with a birth date at the current time. Automatically compute the score for this tree.

Arguments

  • dataset::Dataset{T}: The dataset to evaluate the tree on.
  • baseline::T: The baseline loss.
  • t::Node: The tree for the population member.
  • options::Options: What options to use.
source

Hall of Fame

SymbolicRegression.HallOfFameModule.HallOfFameMethod
HallOfFame(options::Options, ::Type{T}) where {T<:Real}

Create empty HallOfFame. The HallOfFame stores a list of PopMember objects in .members, which is enumerated by size (i.e., .members[1] is the constant solution). .exists is used to determine whether the particular member has been instantiated or not.

Arguments:

  • options: Options containing specification about deterministic.
  • T: Type of Nodes to use in the population. e.g., Float64.
source

Dataset