Commit d6d9f4e2 authored by Guillaume Chérel's avatar Guillaume Chérel
Browse files

[Plugin] fix matrix C construction in SaltelliSampling.

parent c9298252
......@@ -467,7 +467,7 @@ lazy val abc = OsgiProject(pluginDir, "org.openmole.plugin.method.abc", imports
lazy val directSampling = OsgiProject(pluginDir, "org.openmole.plugin.method.directsampling", imports = Seq("*")) dependsOn(openmoleDSL, distributionDomain, pattern, modifierDomain, fileHook) settings (pluginSettings: _*)
lazy val sensitivity = OsgiProject(pluginDir, "org.openmole.plugin.method.sensitivity", imports = Seq("*")) dependsOn(exception, workflow, workspace, openmoleDSL, lhsSampling, directSampling) settings (pluginSettings: _*)
lazy val sensitivity = OsgiProject(pluginDir, "org.openmole.plugin.method.sensitivity", imports = Seq("*")) dependsOn(exception, workflow, workspace, openmoleDSL, lhsSampling, directSampling, collectionDomain % "test", boundsDomain % "test") settings (pluginSettings: _*)
/* Sampling */
......
......@@ -95,11 +95,18 @@ object SaltelliAggregation {
val fC: Array[Array[Array[Double]]] =
modelInputs.map { i reindex("c$" ++ i.prototype.name) }.toArray.transpose
// ftoi(o)._1(i) contains first order index for input i on output o.
// ftoi(o)._2(i) contains total order index for input i on output o.
val ftoi: Array[(Array[Double], Array[Double])] =
(fA zip fB zip fC).map { case ((fAo, fBo), fCo) firstAndTotalOrderIndices(fAo, fBo, fCo) }
// first order indices
// fosi(o)(i) contains first order index for input i on output o.
val fosi = ftoi.map { _._1.toArray }.toArray
// total order indices
// tosi(o)(i) contains total order index for input i on output o.
val tosi = ftoi.map { _._2.toArray }.toArray
val fosiv =
......
......@@ -19,7 +19,7 @@ object SaltelliSampling {
def buildLineOfC(i: Int, lineOfA: Array[Double], lineOfB: Array[Double]) =
(lineOfA zip lineOfB zipWithIndex) map {
case ((a, b), index) if (index == i) a else b
case ((a, b), index) if (index == i) b else a
}
val namespace = Namespace("saltelli")
......
package org.openmole.plugin.method.sensitivity
import org.scalatest.{FlatSpec, Matchers}
import org.openmole.core.dsl._
import org.openmole.core.workflow.test._
import scala.util.Random
import org.openmole.core.dsl._
import org.openmole.core.workflow.mole.Mole
import org.openmole.core.workflow.task.FromContextTask
import org.openmole.core.workflow.validation._
import org.openmole.plugin.domain.collection._
import org.scalatest._
import org.openmole.plugin.domain.bounds._
class Saltelli extends FlatSpec with Matchers {
import org.openmole.core.workflow.test.Stubs._
val rng = new Random()
val x1 = Val[Double]
val x2 = Val[Double]
val y1 = Val[Double]
val y2 = Val[Double]
/* Expected values of first order (SI) and total order (STI) sensitivity indices.
*
* - y1, x1: SI1 = 4/5, STI1 = 4/5
* - y1, x2: SI2 = 1/5, STI2 = 1/5
* - y2, x1: SI1 = (9 / 4) * (12 / 42) ~= 0.643,
* STI1 = (7.0 / 36.0) / (40.0 / 144.0) = 0.7
* - y2, x2: SI2 = 12 / 42 ~= 0.286,
* STI2 = (13.0 / 144.0) / (40.0 / 144.0) ~= 0.325
*/
val model = TestTask { context => context +
(y1 -> (context(x1) + 0.5 * context(x2) )) +
(y2 -> (context(x1) + 0.5 * context(x2) + context(x1) * context(x2)))
} set(
inputs += (x1, x2),
outputs += (y1, y2)
)
val sen = SensitivitySaltelli(
evaluation = model,
samples = 10000,
inputs = Seq(x1 in (0.0,1.0), x2 in (0.0,1.0)),
outputs = Seq(y1, y2)
)
"Saltelli" should "run" in {
sen run()
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment