skSymbolFit
First introduced in version 3.00.6
Syntax
skSymbolFit(symbolRegressor, inputs, target, config)
Details
Runs symbolic regression training based on input variables, a target variable, and the training configuration. The target variable represents the output to be fitted, and its values are determined by the input variables. The goal of symbolic regression training is to discover a mathematical expression that describes the relationship between the input variables and the target variable.
The Community Edition license does not support Shark. To use Shark, go to the official download page and click Request a free trial in the Shark section.
Parameters
symbolRegressor is a handle that specifies the symbolic regressor used for training. It is created by the skSymbolRegressor function.
inputs is a dictionary that specifies the input variables used for training and includes the following keys:
- "varTerminalSet": Required. An tuple that specifies the set of input variables available in expressions, for example, [a,b,c,d]. All variables must be vectors of the same length. Variable names are used to construct expressions and are preserved in the final generated expression. During expression evaluation (
skSymbolEval), the column names in the input table must match the variable names specified here. - "groupTerminalSet": An tuple that specifies the grouping variables for the training data, for example, [g1,g2]. All variables must be vectors whose lengths match the variables in "varTerminalSet". If this field is specified, the system constructs a group context based on the grouping variables, and the length of the target variable target must equal the number of groups.
target is a vector that specifies the target variable used for training. If "groupTerminalSet" is not specified, its length must match the length of the input variables. If "groupTerminalSet" is specified, its length must match the number of groups.
config is a dictionary that specifies the symbolic regression training configuration and includes the following keys:
- "fitnessFunction": Required. A function definition that specifies the fitness
function used to evaluate expression quality. For example, the following fitness
function calculates the mean squared error between the expression predictions x
and the target values y. A smaller error indicates a higher-quality
expression.
@gpu def fit_mse(x, y){ a = x - y return mean(a * a) } - "initializer": A dictionary that specifies the method for initializing
expression trees and includes the following keys:
- "name": A STRING scalar that specifies the strategy name. Valid values:
- "half": The default value. Each subtree of the expression tree has a 50% probability of being generated by either the grow method or the full method.
- "full": Only leaf nodes in the expression tree can be constants or variables.
- "grow": Each node in the expression tree can be randomly selected from functions, constants, and variables.
- "param": A dictionary that specifies the strategy parameters and
includes the following keys:
- "minDepth": An INT scalar that specifies the minimum depth of the initial expression tree. Only the half strategy supports this key.
- "maxDepth": An INT scalar that specifies the maximum depth of the initial expression tree.
- "probConstant": A DOUBLE scalar that specifies the probability of selecting a constant when generating a leaf node.
- "name": A STRING scalar that specifies the strategy name. Valid values:
- "constantRange": A dictionary that specifies random constant ranges and
sampling weights, and includes the following keys:
- "floatRange": A dictionary that specifies the sampling range for
floating-point constants and includes the following keys:
- "min": A DOUBLE scalar that specifies the minimum value of floating-point constants. The default value is -1.0.
- "max": A DOUBLE scalar that specifies the maximum value of the floating-point constants. The default value is 1.0.
- "weight": An INT scalar that specifies the probability of generating a floating-point constant. The default value is 1.
- "intRange": A dictionary that specifies the sampling range for integer
constants. It includes the following keys:
- "min": A DOUBLE scalar that specifies the minimum value of the integer constants. The default value is -10.0.
- "max": A DOUBLE scalar that specifies the maximum value of the integer constants. The default value is 10.0.
- "weight": An INT scalar that specifies the probability of generating an integer constant. The default value is 1.
Note:The system determines whether to generate a floating-point constant or an integer constant based on the relative values of
floatRange.weightandintRange.weight. Weights less than or equal to 0 are treated as 0. If both weights are not greater than 0, the system selects between the two constant types with equal probability.
- "floatRange": A dictionary that specifies the sampling range for
floating-point constants and includes the following keys:
- "epsilon": A DOUBLE scalar that specifies the threshold for early termination of training. Training stops early when the fitness of the best expression reaches this threshold. The default value is 1e-3.
- "parsimony": A DOUBLE scalar that specifies the expression complexity penalty coefficient, used to balance fitting accuracy against expression complexity. A larger value favors simpler expressions. The default value is 0.0.
- "seed": A LONG scalar that specifies the random seed used to initialize the random number generator during training. Using the same random seed can improve the reproducibility of training results when the input data and training configuration are the same. If this parameter is not specified, the system automatically generates a random seed.
- "population": An INT scalar that specifies the number of individuals in each generation, that is, the number of candidate expressions that participate in evolution in each generation. The default value is 1000.
- "generation": An INT scalar that specifies the maximum number of generations for population evolution. Selection, crossover, mutation, and fitness evaluation are performed in each generation. The default value is 20.
- "maxDepth": An INT scalar that specifies the maximum allowed depth of a candidate expression, that is, the maximum number of levels from the root node to the deepest leaf node. All expressions generated during training, including mutation results, are subject to this limit. The default value is 6.
- "elites": An INT scalar that specifies the number of expressions with the best fitness to retain directly in each generation. These expressions do not participate in crossover or mutation. They are carried directly into the next generation to ensure that the best solutions are not lost. The default value is 0.
- "simplify": A BOOL scalar that specifies whether to perform symbolic simplification before returning the final expression. The default value is false.
- "verbose": A BOOL scalar that specifies whether to output the training configuration and training statistics. The default value is true.
Returns
Returns two objects:
- syms: A vector of symbol handles that represents the deduplicated symbolic expressions obtained from training, sorted by fitness in ascending order. You can use
string(syms)to view the expression text, or pass syms toskSymbolEvalfor evaluation. - info: A training result summary table that contains the columns fitness, height, and hash, which represent fitness, expression depth, and expression hash value, respectively.
Examples
See Shark Symbolic Regression.
Related functions: getGlobalSharkEngine, skSymbolRegressor, skSymbolEvalContext, skSymbolEval
