addGpFunction
Note: This function is not supported by Community Edition. You can
get a trial of Shark from DolphinDB official website.
Syntax
addGpFunction(engine, func)
Arguments
engine is the engine object returned by
createGPLearnEngine
.
func is a user-defined function. Currently it does not support complex
assignment,
if
or for
statement. Only
return
statement can be used to return a combination of the
training functions (see Appendix for supported functions). For example:
def f(x, y){
return cos(x+y)
}
Details
Add a user-defined training function to the GPLearn engine.
Examples
def f(x, y){
return cos(x+y)
}
addGpFunction(engine,f)
Appendix
The following table lists available functions for building and evolving programs. The parameter n indicates the sliding window size taken from windowRange. For all m-functions, if the current window is smaller than n, 0 is returned.
Function | Number of Inputs | Description |
---|---|---|
add(x,y) | 2 | Addition |
sub(x,y) | 2 | Subtraction |
mul(x,y) | 2 | Multiplication |
div(x,y) | 2 | Division, returns 1 if the absolute value of the divisor is less than 0.001 |
max(x,y) | 2 | Maximum value |
min(x,y) | 2 | Minimum value |
sqrt(x) | 1 | Square root based on absolute value |
log(x) | 1 | If x < 0.001, returns 0, otherwise returns log(abs(x)) |
neg(x) | 1 | Negation |
reciprocal(x) | 1 | Reciprocal, returns 0 if the absolute value of x is less than 0.001 |
abs(x) | 1 | Absolute value |
sin(x) | 1 | Sine function |
cos(x) | 1 | Cosine function |
tan(x) | 1 | Tangent function |
sig(x) | 1 | Sigmoid function |
mdiff(x, n) | 1 | n-th order difference of x |
mcovar(x, y, n) | 2 | Covariance of x and y with a sliding window of size n |
mcorr(x, y, n) | 2 | Correlation of x and y with a sliding window of size n |
mstd(x, n) | 1 | Sample standard deviation of x with a sliding window of size n |
mmax(x, n) | 1 | Maximum value of x with a sliding window of size n |
mmin(x, n) | 1 | Minimum value of x with a sliding window of size n |
msum(x, n) | 1 | Sum of x with a sliding window of size n |
mavg(x, n) | 1 | Average of x with a sliding window of size n |
mprod(x, n) | 1 | Product of x with a sliding window of size n |
mvar(x, n) | 1 | Sample variance of x with a sliding window of size n |
mvarp(x, n) | 1 | Population variance of x with a sliding window of size n |
mstdp(x, n) | 1 | Population standard deviation of x with a sliding window of size n |
mimin(x, n) | 1 | Index of the minimum value of x with a sliding window of size n |
mimax(x, n) | 1 | Index of the maximum value of x with a sliding window of size n |
mbeta(x, y, n) | 2 | Least squares estimate of the regression coefficient of x on y with a sliding window of size n |
mwsum(x, y, n) | 2 | Inner product of x and y with a sliding window of size n |
mwavg(x, y, n) | 2 | Weighted average of x using y as weights with a sliding window of size n |