Scala Functions

Suggest edits
Documentation > Language

Contents

Some useful functions are usable anywhere in OpenMOLE where you would use scala code. For instance you can use them in:
  • ScalaTask code,
  • string expanded by OpenMOLE (${scala code}),
  • OpenMOLE scripts.

Data processing đź”—

OpenMOLE provides a useful function to aggregate data. This function 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.

File creation đź”—

It might be useful to create files and folders in ScalaTask code. To do that use one of the folowing 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 called newFile().
  • 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 called newDir(). 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 called mkDir(). This function creates the directory.

Random number generator đź”—

In scala code you may use a properly initialised random generator by calling random(). 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().