rgp (version 0.4-1)

functionSet: Functions for defining the search space for Genetic Programming

Description

The GP search space is defined by a set of functions, a set of input variables, a set of constant constructor functions, and some rules how these functions, input variables, and constants may be combined to form valid symbolic expressions. The function set is simply given as a set of strings naming functions in the global environment. Input variables are also given as strings. Combination rules are implemented by a type system and defined by assigning sTypes to functions, input variables, and constant constructors.

Usage

functionSet(..., list = NULL, parentEnvironmentLevel = 1)
inputVariableSet(..., list = NULL)
constantFactorySet(..., list = NULL)
pw(x, pw)
hasPw(x)
getPw(x, default = 1)
"c"(..., recursive = FALSE)
"c"(..., recursive = FALSE)
"c"(..., recursive = FALSE)

Arguments

...
Names of functions or input variables given as strings.
list
Names of functions or input variables given as a list of strings.
parentEnvironmentLevel
Level of the parent environment used to resolve function names.
recursive
Ignored when concatenating function- or input variable sets.
x
An object (function name, input variable name, or constant factory) to tag with a probability pw.
pw
A probability weight.
default
A default probability weight to return iff no probability weight is associated with an object.

Value

A function set or input variable set.

Details

Function sets and input variable sets are S3 classes containing the following fields: \$all contains a list of all functions, or input variables, or constant factories. \$byRange contains a table of all input variables, or functions, or constant factories, indexed by the string label of their sTypes for input variables, or by the string label of their range sTypes for functions, or by the string label of their range sTypes for constant factories. This field exists mainly for quickly finding a function, input variable, or constant factory that matches a given type.

Multiple function sets, or multiple input variable sets, or multiple constant factory sets can be combined using the c function. functionSet creates a function set. inputVariableSet creates an input variable set. constantFactorySet creates a constant factory set.

Probability weight for functions, input variables, and constants can be given by tagging constant names, input variables, and constant factory functions via the pw function (see the examples). The predicate hasPw can be used to check if an object x has an associated probability weight. The function getPw returns the probability weight associated with an object x, if available.

Examples

Run this code
# creating an untyped search space description...
functionSet("+", "-", "*", "/", "exp", "log", "sin", "cos", "tan")
inputVariableSet("x", "y")
constantFactorySet(function() runif(1, -1, 1))
# creating an untyped function set with probability weights...
functionSet(pw("+", 1.2), pw("-", 0.8), pw("*", 1.0), pw("/", 1.0))

Run the code above in your browser using DataCamp Workspace