SEAL Functions

From DiLab
Revision as of 01:02, 2 October 2012 by Atis (talk | contribs)
Jump to: navigation, search

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:

  1. sum(Light, Humidity, -12) -- calculates sum of last light sensor reading with last humidity sensor reading and -12 (i.e. subtracts 12).
  2. 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:

  1. min(Light, 10) -- calculate the minimum of light sensor reading and the number 10;
  2. 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:

  1. max(Light, 10) -- calculate the maximum of the light sensor reading and the number 10;
  2. 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:

  1. average(Light) -- calculate the average of light sensor readings during program's execution;
  2. 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:

  1. stdev(Light) -- calculate the standard deviation of light sensor readings during program's execution;
  2. 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:

  1. variance(Light) -- calculate the variance of light sensor readings during program's execution;
  2. 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:

  1. ewma(Light, 0.5) -- calculate the exponential moving average of light sensor readings during program's execution with coefficient 0.5;
  2. 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:

  1. changed(Light) -- true if light sensor reading have changed during program's execution.
  2. changed(take(Light, 100)) -- true if light sensor reading have changed during last 100 readings.
  3. 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: