Documentation > Language
Some useful functions are usable anywhere in OpenMOLE where you would use Scala code.
For instance you can use them in:
It might sometimes be useful to create a new random number generator. To do that use
- ScalaTask code,
- string expanded by OpenMOLE (${scala code}),
- OpenMOLE scripts.
Data processing 🔗
OpenMOLE provides a useful functions to aggregate data. Theses functions can be called on array and vectors. For instance:val pi = Val[Double]
val piAvg = Val[Double]
// Define the average task that average several estimation of pi
val average =
ScalaTask("val piAvg = pi.average") set (
inputs += pi.toArray,
outputs += piAvg
)
This task takes place after an exploration and compute the average of many values of pi.
The presently available functions are:
-
def median: Double
, compute the median of the vector, -
def medianAbsoluteDeviation: Double
, compute the median absolute deviation of the vector, -
def average: Double
, compute the average of the vector, -
def meanSquaredError: Double
, compute the mean square error of the vector, -
def rootMeanSquaredError: Double
, compute the root of the mean square error of the vector.
Data comparison 🔗
OpenMOLE provides useful functions to compare data series. This function can be called on array and vectors. For instance:-
def absoluteDistance(s1: Seq[Double], s2: Seq[Double]): Double
, compute the sum of the absolute distance between the respective elements of s1 and s2, -
def squareDistance(s1: Seq[Double], s2: Seq[Double]): Double
, compute the sum of the squared distance between the respective elements of s1 and s2. -
def dynamicTimeWarpingDistance(s1: Seq[Double], s2: Seq[Double]): Double
, compute the dynamic time warping distance between s1 and s2.
File creation 🔗
It might be useful to create files and folders in ScalaTask code. To do that, use one of the following functions:-
def newFile(prefix: String, suffix: String): File
, this function creates a new file in the OpenMOLE workspace. You may optionally provide a prefix and suffix for the file name. It would generally be callednewFile()
. -
def newDir(prefix: String): File
, this function creates a new directory in the OpenMOLE workspace. You may optionally provide a prefix for the directory name. It would generally be callednewDir()
. This function doesn't create the directory. -
def mkDir(prefix: String): File
, this function creates a new directory in the OpenMOLE workspace. You may optionally provide a prefix for the directory name. It would generally be calledmkDir()
. This function creates the directory.
Random number generator 🔗
In Scala code you may use a properly initialised random generator by callingrandom()
.
For instance you may call random().nextInt
.
It might sometimes be useful to create a new random number generator. To do that use
def newRandom(seed: Long): Random
.
The seed is optional.
If it is not provided OpenMOLE will take care of the generator initialisation in a sound manner.
It would generally be called newRNG()
.