the problem here is more about scala than openmole, I need to calculate the mean and variance of a vector. Here is a working code for this :
val meanAndVar =
ScalaTask("""val meanValue = doubleValue.sum/doubleValue.size
doubleValue = doubleValue.map(_ - meanValue)
doubleValue = doubleValue.map(math.pow(_, 2))
val varValue = doubleValue.sum/doubleValue.size
""") set (
inputs += VectorValue,
outputs += (meanValue, varValue)
As you can see it's not very good, I'm doing three iterations over the doubleValue vector and I'm certain I can do it in only one (using an accumulator or something like this ?) but scala and functional programming/lambda calculus are really not my area of expertise.
Does someone know where to find such a code or how to achieve this task in a better way?