Difference between revisions of "SEAL Functions"
 (New page: == Arithmetic functions ==  === sum ===  '''Argument:''' sensor value or scalar.  Argument can be repeated zero to many times.  Is aggregate function (i.e. can have <code>take()</code> as ...)  | 
				|||
| Line 1: | Line 1: | ||
== Overview ==  | 
|||
The following functions are available and can be called from SEAL code.  | 
|||
Naming convention used in this document:  | 
|||
* Sensor value -- name of a SEAL sensor.  | 
|||
* A scalar -- a predefined constant, a variable, or an integer literal.  | 
|||
== Arithmetic functions ==  | 
  == Arithmetic functions ==  | 
||
=== sum ===  | 
  === sum(value, ...) ===  | 
||
Sum.  | 
|||
'''Argument:''' sensor value or scalar.  | 
  |||
'''Argument:''' a sensor value or a scalar.  | 
|||
Argument can be repeated zero to many times.  | 
  Argument can be repeated zero to many times.  | 
||
Aggregate function (i.e. can have <code>take()</code> as parameter).  | 
|||
'''Example syntax:'''  | 
|||
'''Example syntax:''' <code>sum(Light, 1, -12)</code> -- calculates sum of light sensor readings with +1 and -12 (i.e. adds one and subtracts 12).  | 
  |||
# <code>sum(Light, Humidity, -12)</code> -- calculates sum of last light sensor reading with last humidity sensor reading and -12 (i.e. subtracts 12).  | 
|||
# <code>sum(take(Light, 10))</code> -- calculates sum of last 10 light sensor readings  | 
|||
=== plus ===  | 
  === plus(value1, value2) ===  | 
||
Addition.  | 
|||
'''Argument:'''   | 
  |||
'''Arguments:''' sensor values or scalars.  | 
|||
'''Synonym:''' <code>add</code>  | 
  '''Synonym:''' <code>add</code>  | 
||
'''Example syntax:''' <code>plus(Light, Humidity)</code> -- calculates sum of light and humidity sensor readings  | 
|||
'''Example syntax:'''   | 
  |||
=== minus ===  | 
  === minus(value1, value2)  ===  | 
||
Subtraction.  | 
|||
'''Argument:'''   | 
  |||
'''Arguments:''' sensor values or scalars.  | 
|||
'''Synonym:''' <code>subtract</code>  | 
  '''Synonym:''' <code>subtract</code>  | 
||
'''Example syntax:''' <code>minus(Light, Humidity)</code> -- calculates value of the expression: light sensor reading - humidity sensor reading.  | 
|||
'''Example syntax:'''   | 
  |||
=== times ===  | 
  === times(value1, value2)  ===  | 
||
Multiplication.  | 
|||
'''Argument:'''   | 
  |||
'''Arguments:''' sensor values or scalars.  | 
|||
'''Synonym:''' <code>multiply</code>  | 
  '''Synonym:''' <code>multiply</code>  | 
||
'''Example syntax:''' <code>times(Light, 3)</code> -- calculates value of light sensor reading multiplied by three.  | 
|||
'''Example syntax:'''   | 
  |||
=== divide ===  | 
  === divide(value1, value2)  ===  | 
||
Division.  | 
|||
'''Argument:'''   | 
  |||
'''Arguments:''' sensor values or scalars.  | 
|||
'''Example syntax:'''   | 
  |||
'''Example syntax:''' <code>divide(Light, 3)</code> -- calculates value of light sensor reading divided by three and rounded down to the nearest integer.  | 
|||
=== modulo ===  | 
  |||
=== modulo(value1, value2) ===  | 
|||
'''Argument:'''   | 
  |||
The remainder in division.  | 
|||
'''Example syntax:'''   | 
  |||
'''Arguments:''' sensor values or scalars.  | 
|||
=== difference ===  | 
  |||
'''Example syntax:''' <code>modulo(Random, 3)</code> -- calculates the remainder of a random number value divided by three.  | 
|||
'''Argument:'''   | 
  |||
=== difference(value1, value2) ===  | 
|||
'''Example syntax:'''   | 
  |||
Symmetrical difference.  | 
|||
=== abs ===  | 
  |||
'''Argument:'''   | 
  '''Argument:''' sensor values or scalars.  | 
||
'''Example syntax:''' <code>difference(13, 14)</code> calculates the absolute value of the difference between two values 13 and 14. Same as <code>abs(minus(13, 14))</code>.  | 
|||
'''Example syntax:'''   | 
  |||
===   | 
  === abs(value) ===  | 
||
Absolute value  | 
|||
'''Argument:'''   | 
  |||
'''Argument:''' a sensor value or a scalar.  | 
|||
'''Example syntax:'''   | 
  |||
'''Example syntax:''' <code>abs(Temperature)</code> -- calculate the absolute valute of temperature sensor reading  | 
|||
=== invert ===  | 
  |||
=== neg(value) ===  | 
|||
'''Argument:'''   | 
  |||
Negation.  | 
|||
'''Example syntax:'''   | 
  |||
'''Argument:''' a sensor value or a scalar.  | 
|||
=== square ===  | 
  |||
'''Example syntax:''' <code>neg(Humidity)</code> -- calculate the negation valute of humidity sensor reading  | 
|||
'''Argument:'''   | 
  |||
=== invert(value) ===  | 
|||
'''Example syntax:'''   | 
  |||
Return the Boolean inverse of the value passed: True if the value zero, False otherwise.   | 
|||
=== sqrt ===  | 
  |||
'''Argument:'''   | 
  '''Argument:''' a sensor value or a scalar.  | 
||
'''Example syntax:'''   | 
  '''Example syntax:''' <code>invert(Random)</code> -- evaluates to true if the last random number is zero.  | 
||
===   | 
  === square(value) ===  | 
||
Square -- second power.  | 
|||
'''Argument:'''   | 
  |||
'''Argument:''' a sensor value or a scalar.  | 
|||
'''Example syntax:'''   | 
  |||
'''Example syntax:''' <code>square(Random)</code> -- calculate the square of the last random number.  | 
|||
=== sqrt(value) ===  | 
|||
Square root.  | 
|||
'''Argument:''' a sensor value or a scalar.  | 
|||
'''Example syntax:''' <code>sqrt(Random)</code> -- calculates the square root of the last random number rounded to the nearest integer. Depending on the implmentation, approximate values may be returned!  | 
|||
=== power(base, exponent) ===  | 
|||
Exponentiation.  | 
|||
'''Arguments:''' base is a sensor value or a scalar, exponent must be scalar.  | 
|||
'''Example syntax:''' <code>power(Random, 3)</code> -- calculate the cube of the last random number.  | 
|||
== Data aggregation functions ==  | 
  == Data aggregation functions ==  | 
||
=== min ===  | 
  === min(value, ...) ===  | 
||
Minimal value.  | 
|||
'''Argument:'''   | 
  |||
'''Argument:''' a sensor value or a scalar  | 
|||
Argument can be repeated one to many times.  | 
|||
Aggregate function (i.e. can have <code>take()</code> as parameter).  | 
|||
'''Example syntax:'''   | 
  '''Example syntax:'''   | 
||
# <code>min(Light, 10)</code> -- calculate the minimum of light sensor reading and the number 10;  | 
|||
# <code>min(take(Light, 100))</code> -- calculate the minimum of the last 100 light sensor readings.  | 
|||
=== max(value, ...) ===  | 
|||
Maximal value.  | 
|||
'''Argument:''' a sensor value or a scalar  | 
|||
Argument can be repeated one to many times.  | 
|||
=== max ===  | 
  |||
Aggregate function (i.e. can have <code>take()</code> as parameter).  | 
|||
'''Argument:'''   | 
  |||
'''Example syntax:'''   | 
  '''Example syntax:'''   | 
||
# <code>max(Light, 10)</code> -- calculate the maximum of the light sensor reading and the number 10;  | 
|||
# <code>max(take(Light, 100))</code> -- calculate the maximum of the last 100 light sensor readings.  | 
|||
=== average ===  | 
  === average(value) ===  | 
||
Average value (the mean).  | 
|||
'''Argument:'''   | 
  |||
'''Argument:''' a sensor value or a scalar  | 
|||
Aggregate function (i.e. can have <code>take()</code> as parameter).  | 
|||
'''Synonym:''' <code>avg</code>  | 
  '''Synonym:''' <code>avg</code>  | 
||
'''Example syntax:'''   | 
  '''Example syntax:'''   | 
||
# <code>average(Light)</code> -- calculate the average of light sensor readings during program's execution;  | 
|||
# <code>average(take(Light, 100))</code> -- calculate the average of the last 100 light sensor readings.  | 
|||
=== stdev(value) ===  | 
|||
Standard deviation.  | 
|||
'''Argument:''' a sensor value or a scalar  | 
|||
=== stdev ===  | 
  |||
Aggregate function (i.e. can have <code>take()</code> as parameter).  | 
|||
'''Argument:'''   | 
  |||
'''Synonym:''' <code>std</code>  | 
  '''Synonym:''' <code>std</code>  | 
||
'''Example syntax:'''   | 
  '''Example syntax:'''   | 
||
# <code>stdev(Light)</code> -- calculate the standard deviation of light sensor readings during program's execution;  | 
|||
# <code>stdev(take(Light, 100))</code> -- calculate the standard deviation of the last 100 light sensor readings.  | 
|||
=== variance ===  | 
  === variance(value) ===  | 
||
Signal variance.  | 
|||
'''Argument:'''   | 
  |||
'''Argument:''' a sensor value or a scalar  | 
|||
'''Example syntax:'''   | 
  '''Example syntax:'''   | 
||
# <code>variance(Light)</code> -- calculate the variance of light sensor readings during program's execution;  | 
|||
# <code>variance(take(Light, 100))</code> -- calculate the variance of the last 100 light sensor readings.  | 
|||
=== ewma ===  | 
  === ewma(value, alpha) ===  | 
||
Exponential moving average with coefficient ''alpha''.  | 
|||
'''Argument:'''   | 
  |||
'''Arguments:''' 'value' is a sensor value or a scalar, 'alpha' is a scalar (including floating point) value.  | 
|||
'''Example syntax:'''   | 
  '''Example syntax:'''   | 
||
# <code>ewma(Light, 0.5)</code> -- calculate the exponential moving average of light sensor readings during program's execution with coefficient 0.5;  | 
|||
# <code>ewma(take(Light, 100), 0.5)</code> -- calculate the same, but for the last 100 light sensor readings.  | 
|||
=== changed ===  | 
  === changed(value) ===  | 
||
Boolean value that describes whether the value has changed.  | 
|||
'''Argument:'''   | 
  |||
'''Example syntax:'''   | 
  |||
'''Argument:''' a sensor value or a scalar  | 
|||
'''Example syntax:'''   | 
|||
#<code>changed(Light)</code> -- true if light sensor reading have changed during program's execution.  | 
|||
#<code>changed(take(Light, 100))</code> -- true if light sensor reading have changed during last 100 readings.  | 
|||
#<code>changed(13)</code> -- always false, because the value is constant.  | 
|||
== Signal processing functions ==  | 
  == Signal processing functions ==  | 
||
Revision as of 00:02, 2 October 2012
Contents
Overview
The following functions are available and can be called from SEAL code.
Naming convention used in this document:
- Sensor value -- name of a SEAL sensor.
 - A scalar -- a predefined constant, a variable, or an integer literal.
 
Arithmetic functions
sum(value, ...)
Sum.
Argument: a sensor value or a scalar.
Argument can be repeated zero to many times.
Aggregate function (i.e. can have take() as parameter).
Example syntax:
sum(Light, Humidity, -12)-- calculates sum of last light sensor reading with last humidity sensor reading and -12 (i.e. subtracts 12).sum(take(Light, 10))-- calculates sum of last 10 light sensor readings
plus(value1, value2)
Addition.
Arguments: sensor values or scalars.
Synonym: add
Example syntax: plus(Light, Humidity) -- calculates sum of light and humidity sensor readings
minus(value1, value2)
Subtraction.
Arguments: sensor values or scalars.
Synonym: subtract
Example syntax: minus(Light, Humidity) -- calculates value of the expression: light sensor reading - humidity sensor reading.
times(value1, value2)
Multiplication.
Arguments: sensor values or scalars.
Synonym: multiply
Example syntax: times(Light, 3) -- calculates value of light sensor reading multiplied by three.
divide(value1, value2)
Division.
Arguments: sensor values or scalars.
Example syntax: divide(Light, 3) -- calculates value of light sensor reading divided by three and rounded down to the nearest integer.
modulo(value1, value2)
The remainder in division.
Arguments: sensor values or scalars.
Example syntax: modulo(Random, 3) -- calculates the remainder of a random number value divided by three.
difference(value1, value2)
Symmetrical difference.
Argument: sensor values or scalars.
Example syntax: difference(13, 14) calculates the absolute value of the difference between two values 13 and 14. Same as abs(minus(13, 14)).
abs(value)
Absolute value
Argument: a sensor value or a scalar.
Example syntax: abs(Temperature) -- calculate the absolute valute of temperature sensor reading
neg(value)
Negation.
Argument: a sensor value or a scalar.
Example syntax: neg(Humidity) -- calculate the negation valute of humidity sensor reading
invert(value)
Return the Boolean inverse of the value passed: True if the value zero, False otherwise.
Argument: a sensor value or a scalar.
Example syntax: invert(Random) -- evaluates to true if the last random number is zero.
square(value)
Square -- second power.
Argument: a sensor value or a scalar.
Example syntax: square(Random) -- calculate the square of the last random number.
sqrt(value)
Square root.
Argument: a sensor value or a scalar.
Example syntax: sqrt(Random) -- calculates the square root of the last random number rounded to the nearest integer. Depending on the implmentation, approximate values may be returned!
power(base, exponent)
Exponentiation.
Arguments: base is a sensor value or a scalar, exponent must be scalar.
Example syntax: power(Random, 3) -- calculate the cube of the last random number.
Data aggregation functions
min(value, ...)
Minimal value.
Argument: a sensor value or a scalar
Argument can be repeated one to many times.
Aggregate function (i.e. can have take() as parameter).
Example syntax:
min(Light, 10)-- calculate the minimum of light sensor reading and the number 10;min(take(Light, 100))-- calculate the minimum of the last 100 light sensor readings.
max(value, ...)
Maximal value.
Argument: a sensor value or a scalar
Argument can be repeated one to many times.
Aggregate function (i.e. can have take() as parameter).
Example syntax:
max(Light, 10)-- calculate the maximum of the light sensor reading and the number 10;max(take(Light, 100))-- calculate the maximum of the last 100 light sensor readings.
average(value)
Average value (the mean).
Argument: a sensor value or a scalar
Aggregate function (i.e. can have take() as parameter).
Synonym: avg
Example syntax:
average(Light)-- calculate the average of light sensor readings during program's execution;average(take(Light, 100))-- calculate the average of the last 100 light sensor readings.
stdev(value)
Standard deviation.
Argument: a sensor value or a scalar
Aggregate function (i.e. can have take() as parameter).
Synonym: std
Example syntax:
stdev(Light)-- calculate the standard deviation of light sensor readings during program's execution;stdev(take(Light, 100))-- calculate the standard deviation of the last 100 light sensor readings.
variance(value)
Signal variance.
Argument: a sensor value or a scalar
Example syntax:
variance(Light)-- calculate the variance of light sensor readings during program's execution;variance(take(Light, 100))-- calculate the variance of the last 100 light sensor readings.
ewma(value, alpha)
Exponential moving average with coefficient alpha.
Arguments: 'value' is a sensor value or a scalar, 'alpha' is a scalar (including floating point) value.
Example syntax:
ewma(Light, 0.5)-- calculate the exponential moving average of light sensor readings during program's execution with coefficient 0.5;ewma(take(Light, 100), 0.5)-- calculate the same, but for the last 100 light sensor readings.
changed(value)
Boolean value that describes whether the value has changed.
Argument: a sensor value or a scalar
Example syntax:
changed(Light)-- true if light sensor reading have changed during program's execution.changed(take(Light, 100))-- true if light sensor reading have changed during last 100 readings.changed(13)-- always false, because the value is constant.
Signal processing functions
map
Argument:
Example syntax:
sharpen
Argument:
Synonym: contrast
Example syntax:
smoothen
Argument:
Synonym: blur
Example syntax:
Filtering functions
match
Argument:
Example syntax:
filterRange
Argument:
Example syntax:
filterEqual
Argument:
Example syntax:
filterNotEqual
Argument:
Example syntax:
filterLess
Argument:
Example syntax:
filterLessOrEqual
Argument:
Example syntax:
filterMore
Argument:
Example syntax:
filterMoreOrEqual
Argument:
Example syntax:
invertFilter
Argument:
Example syntax:
Subset selection & special purpose functions
take
Argument:
Example syntax:
tuple
Argument:
Example syntax:
sync
Argument:
Example syntax: