Skip to content
Clifford Bohm edited this page Sep 8, 2021 · 8 revisions

MTrees are data structures that define mathematical functions.

One particularly useful aspect of MTrees is that they can be defined by and converted into strings.

Some Parameters will use MTrees so that the user can define complex behavior.

for example...

optimizeValue = POW[1.05,DM_AVE[score]]

... sets optimizeValue to 1.05 raised to the power of the score in the DataMap of the organism being evaluated.

another example...

optimizeValue = (DM_AVE[score]*(10-DM_AVE[gates]))

... sets optimizeValue to the score in the DataMap of the organism being evaluated times 10 minus the number of gates in that organism (assumes that the organism has gates - i.e. markov brains). That is optimization should be based on score and having fewer gates.

using an MTree in code

You can construct an MTree from a string with:

myMT= stringToMTree("DM_AVE[score]*(10-DM_AVE[gates])");

When you want to evaluate an MTree, you call the eval function on the MTree.

double opVal = myMT->eval(dataMap, PT, vect)[0];

where dataMap is some DataMap, PT is a parameters table, and vect is a vector<vector<double>>.

You can leave out any of the parameters if they are not needed (see below for how dataMap, PT, and vect are used in an MTree.)

available functions

CONST[x]
returns x. x without CONST[] can be used in place of CONST[x]
SUM[x,y,x,...]
sums all elements in brackets
MULT[x,y,x,...]
multiples all elements in brackets
SUBTRACT[x,y]
subract y from x
DIVIDE[x,y]
divide x by y
POW[x,y]
x to the y power
SIN[x]
return sine of x
COS[x]
return cosine of x
RANDOM[x,y]
generate a random number between x and y
UPDATE[]
return the current value of GLOBAL::update
DM_AVE["key_name"]
if a (DataMap)[DataMap] is passed when MTree.evaluate is called then return the average of the values associated with "key_name"
DM_SUM["key_name"]
if a (DataMap)[DataMap] is passed when MTree.evaluate is called then return the sum of the values associated with "key_name"
MANY[x,y,z,...]
returns a vector with the values of {x,y,z,...}
VECT[x,y]
if a Vector> is passed when MTree.evaluate is called, then return the value in vect[x][y] (this can be used to provide access to values that are only known at runtime.)
IF[x,y,z]
if x > 0 then y else z
MIN[x,y]
lesser of x and y
MAX[x,y]
greaterof x and y
REMAP[x,y,z,a,b]
if one argument, return x clamped [0,1]
if three arguments, return x clamped [y,z] and scaled to [0,1]
if five arguments, return x clamped [y,z] and scaled to [a,b]
SIGMOID[x,y,z,a]
returns value in range [0,1]
with 2 arguments, x is value to remap, y is strength of sigmoid function
with 4 arguments, x will be bounded and scaled to [0,1] by [z,a] before sigmod function is applied.
MOD[x,y]
x % y
ABS[x]
absolute value of x

shorthand for MULT and SUM

MULT[x,y,z...] and SUM[x,y,z...] can be replaced by (xyz...) and (x+y+z...) respectively.
x,y,z, etc. can be other functions but within parathesis, there can only be one type of operator. MTree has no definition of order of operations, the user must resolve this with parathesis.

shorthand for SUB, DIVIDE, and POW

SUB[x,y], DIVIDE[x,y] and POW[x,y] can be replaced by (x-y), (x/y) and, (x^y) respectively as in MULT and SUM, with the exception that only two terms are allowed.

Clone this wiki locally