Datafilter - bool()

.. bool(expr) - returns 0 or 1 for the expression passed. This allows a
   logical expression to be used in a formula (which is useful when
   fitting models).

   e.g a*(x>1) is invalid, whilst a*bool(x>1) is not.
This commit is contained in:
Mark Liversedge
2020-03-19 11:31:20 +00:00
parent a4727c8a46
commit 917bbab173

View File

@@ -181,6 +181,11 @@ static struct {
// diagnostics goodness of fit measures [ success, RMSE, CV ] where a non-zero value
// for success means true, if it is false, RMSE and CV will be set to -1
{ "bool", 1 }, // bool(e) - will turn the passed parameter into a boolean with value 0 or 1
// this is useful for embedding logical expresissions into formulas. Since the
// grammar does not support (a*x>1), instead we can use a*bool(x>1). All non
// zero expressions will evaluate to 1.
// add new ones above this line
{ "", -1 }
};
@@ -2416,6 +2421,13 @@ Result Leaf::eval(DataFilterRuntime *df, Leaf *leaf, float x, long it, RideItem
}
}
// bool(expr)
if (leaf->function == "bool") {
Result r=eval(df, leaf->fparms[0],x, it, m, p, c, s, d);
if (r.number != 0) return Result(1);
else return Result(0);
}
// c (concat into a vector)
if (leaf->function == "c") {