Expression evaluation

From Knowledge Base
Revision as of 17:05, 25 October 2023 by Andy (talk | contribs) (Created page with "== Feature references == An expression may reference any feature inspection so far in the workflow for the current part. *To reference the entered value of a numeric feature (or the numeric field of a categorical feature), use <code>$x</code>, where <code>x</code> is the balloon label of the feature. *To reference the selected value of a categorical feature (even if it has a numeric value as well), use <code>$$x</code>, where <code>x</code> is the balloon label of the f...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Feature references

An expression may reference any feature inspection so far in the workflow for the current part.

  • To reference the entered value of a numeric feature (or the numeric field of a categorical feature), use $x, where x is the balloon label of the feature.
  • To reference the selected value of a categorical feature (even if it has a numeric value as well), use $$x, where x is the balloon label of the feature.
  • Features without balloon labels cannot be referenced.

Logical operations

The following logical operations are supported:
Operator Evaluates to true only when... Example
== Both arguments are equal 1 == 2false
!= Both arguments are not equal 1 != 2true
< Left argument is smaller 1 < 2true
> Right argument is smaller 1 > 2false
<= Left argument is smaller or equal 1 <= 2true
>= Right argument is smaller or equal 1 >= 2false
or Either input is true (1 > 2) or (4 > 3)true
and Both inputs are true (1 > 2) and (2 >= 3)false
xor Exactly one input is true true xor truefalse
not The input is false not truefalse

Logical operations can be infinitely nested. For example, ((1 == 1) and (1 < 2)) or not ((3 > 4) and (2 > 1)) evaluates to true.

Mathematical operations

The following mathematical operations are supported:
Operator Description Example
+ Addition 1 + 23
- Subtraction 2 - 0.51.5
* Multiplication 2 * 36
/ Division 9 / 24.5
^ Exponentiation 4 ^ 216
% Remainder 12 % 52
! Factorial 4!24

Functions

The following functions are supported:
Name Description Example
abs(x) Returns the absolute value of x abs(-3)3
round(x) Round x to the nearest integer round(1.5)2
ceil(x) Rounds x up ceil(1.1)2
floor(x) Rounds x down ceil(2.9)2
log(x) Computes the logarithm base e of x log(5)1.60944...
log(x, b) Computes the logarithm base b of x log(5, 10)0.69897...
sqrt(x) Returns the square root of x sqrt(64)8
min(...) Returns the smallest of its arguments min(1, 2, 3)1
max(...) Returns the largest of its arguments max(1, 2, 3)3
mean(...) Returns the average of its arguments mean(1, 5, 10)2.666...
median(...) Returns the middle of its arguments.

If there are an even number of arguments, it returns the average of the middle two.

median(2, 5, 7)5
std(...) Returns the standard deviation of its arguments. mode(1, 5, 13, 20)8
sum(...) Returns the sum of its arguments. sum(1, 2, 3, 4)10

The following trigonometry functions are also available and operate in radians:

  • sin, sinh, asin, asinh
  • cos, cosh, acos, acosh
  • tan, tanh, atan, atanh
  • sec, sech, asec, asech
  • csc, csch, acsc, acsch
  • cot, coth, acot, acoth

Where a indicates an inverse function and h indicates a hyperbolic function.

Constants

The following constants are predefined:
Name Description Value
pi or PI Pi (π) 3.141592653589793
e or E Euler's number (e) 2.718281828459045
phi Golden ratio (φ) 1.618033988749895