Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
openmole
openmole
Commits
6b7eb10e
Commit
6b7eb10e
authored
Mar 22, 2019
by
Juste Raimbault
Browse files
[Plugin] First version OneFactorSampling
parent
7c77acc3
Changes
4
Hide whitespace changes
Inline
Side-by-side
openmole/build.sbt
View file @
6b7eb10e
...
...
@@ -468,7 +468,7 @@ lazy val sensitivity = OsgiProject(pluginDir, "org.openmole.plugin.method.sensit
/* Sampling */
def
allSampling
=
Seq
(
combineSampling
,
csvSampling
,
lhsSampling
,
quasirandomSampling
)
def
allSampling
=
Seq
(
combineSampling
,
csvSampling
,
oneFactorSampling
,
lhsSampling
,
quasirandomSampling
)
lazy
val
combineSampling
=
OsgiProject
(
pluginDir
,
"org.openmole.plugin.sampling.combine"
,
imports
=
Seq
(
"*"
))
dependsOn
(
exception
,
modifierDomain
,
collectionDomain
,
workflow
)
settings
(
pluginSettings
:
_
*
)
...
...
@@ -476,6 +476,8 @@ lazy val csvSampling = OsgiProject(pluginDir, "org.openmole.plugin.sampling.csv"
libraryDependencies
+=
Libraries
.
scalatest
)
settings
(
pluginSettings
:
_
*
)
lazy
val
oneFactorSampling
=
OsgiProject
(
pluginDir
,
"org.openmole.plugin.sampling.onefactor"
,
imports
=
Seq
(
"*"
))
dependsOn
(
exception
,
workflow
,
openmoleDSL
)
settings
(
pluginSettings
:
_
*
)
lazy
val
lhsSampling
=
OsgiProject
(
pluginDir
,
"org.openmole.plugin.sampling.lhs"
,
imports
=
Seq
(
"*"
))
dependsOn
(
exception
,
workflow
,
workspace
,
openmoleDSL
)
settings
(
pluginSettings
:
_
*
)
lazy
val
quasirandomSampling
=
OsgiProject
(
pluginDir
,
"org.openmole.plugin.sampling.quasirandom"
,
imports
=
Seq
(
"*"
))
dependsOn
(
exception
,
workflow
,
workspace
)
settings
(
...
...
openmole/plugins/org.openmole.plugin.sampling.onefactor/src/main/scala/org/openmole/plugin/sampling/onefactor/Activator.scala
0 → 100644
View file @
6b7eb10e
package
org.openmole.plugin.sampling.onefactor
import
org.openmole.core.pluginmanager._
import
org.openmole.core.preference.ConfigurationInfo
import
org.osgi.framework.BundleContext
class
Activator
extends
PluginInfoActivator
{
override
def
stop
(
context
:
BundleContext
)
:
Unit
=
{
PluginInfo
.
unregister
(
this
)
ConfigurationInfo
.
unregister
(
this
)
}
override
def
start
(
context
:
BundleContext
)
:
Unit
=
{
import
org.openmole.core.pluginmanager.KeyWord._
val
keyWords
:
Vector
[
KeyWord
]
=
Vector
(
Sampling
(
classOf
[
OneFactorSampling
])
)
PluginInfo
.
register
(
this
,
Vector
(
this
.
getClass
.
getPackage
),
keyWords
=
keyWords
)
ConfigurationInfo
.
register
(
this
,
ConfigurationInfo
.
list
()
)
}
}
\ No newline at end of file
openmole/plugins/org.openmole.plugin.sampling.onefactor/src/main/scala/org/openmole/plugin/sampling/onefactor/OneFactorSampling.scala
0 → 100644
View file @
6b7eb10e
package
org.openmole.plugin.sampling.onefactor
import
org.openmole.core.context.
{
PrototypeSet
,
Val
,
Variable
}
import
org.openmole.core.expansion.FromContext
import
org.openmole.core.workflow.domain.Finite
import
org.openmole.core.workflow.sampling.
{
ExplicitSampling
,
Factor
,
FactorSampling
,
Sampling
}
case
class
NominalFactor
[
D
,
T
](
factor
:
Factor
[
D
,
T
],
nominalValue
:
T
,
values
:
Finite
[
D
,
T
])
{
def
inputs
:
PrototypeSet
=
Seq
(
factor
.
value
)
def
prototype
:
Val
[
T
]
=
factor
.
value
def
toValuesSampling
:
Sampling
=
FactorSampling
[
D
,
T
](
factor
)(
values
)
def
toNominalSampling
:
Sampling
=
ExplicitSampling
[
T
](
prototype
,
Seq
(
nominalValue
))
}
object
OneFactorSampling
{
def
apply
(
factors
:
NominalFactor
[
_
,
_
]*)
=
new
OneFactorSampling
(
factors
:
_
*
)
}
case
class
OneFactorSampling
(
factors
:
NominalFactor
[
_
,
_
]*)
extends
Sampling
{
override
def
inputs
:
PrototypeSet
=
PrototypeSet
.
empty
++
factors
.
toSeq
.
flatMap
{
_
.
inputs
}
override
def
prototypes
:
Iterable
[
Val
[
_
]]
=
factors
.
map
{
_
.
prototype
}
override
def
apply
()
:
FromContext
[
Iterator
[
Iterable
[
Variable
[
_
]]]]
=
FromContext
{
p
⇒
import
p._
if
(
factors
.
isEmpty
)
Iterator
.
empty
else
factors
.
toIterator
.
flatMap
(
oneFactorSampling
(
_
).
from
(
context
))
}
/**
* Sampling along one of parameters
* (the FromContext is needed as NominalFactor function return Sampling, since they use core sampling primitive)
* @param n
* @return
*/
def
oneFactorSampling
(
n
:
NominalFactor
[
_
,
_
])
:
FromContext
[
Iterator
[
Iterable
[
Variable
[
_
]]]]
=
FromContext
{
p
=>
import
p._
complete
(
Seq
(
n
.
toValuesSampling
().
from
(
context
))
++
factors
.
filter
(!
_
.
equals
(
n
)).
map
(
_
.
toNominalSampling
().
from
(
context
)))
}
/**
* complete sampling
* @param samplings
* @return
*/
def
complete
(
samplings
:
Seq
[
Iterator
[
Iterable
[
Variable
[
_
]]]])
:
Iterator
[
Iterable
[
Variable
[
_
]]]
=
samplings
.
reduceLeft
(
combine
)
/**
* combination for the complete sampling
* @param s1
* @param s2
* @return
*/
def
combine
(
s1
:
Iterator
[
Iterable
[
Variable
[
_
]]],
s2
:
Iterator
[
Iterable
[
Variable
[
_
]]])
:
Iterator
[
Iterable
[
Variable
[
_
]]]
=
for
(
x
←
s1
;
y
←
s2
)
yield
x
++
y
}
openmole/plugins/org.openmole.plugin.sampling.onefactor/src/main/scala/org/openmole/plugin/sampling/onefactor/package.scala
0 → 100644
View file @
6b7eb10e
package
org.openmole.plugin.sampling
package
onefactor
{
import
org.openmole.core.workflow.domain.Finite
import
org.openmole.core.workflow.sampling.Factor
trait
OneFactorDSL
{
implicit
class
SamplingIsNominalFactor
[
D
,
_
](
f
:
Factor
[
D
,
Any
])(
implicit
domain
:
Finite
[
D
,
Any
])
{
def
nominal
[
T
](
t
:
T
)
=
NominalFactor
(
f
,
t
,
domain
)
}
}
}
package
object
onefactor
extends
OneFactorDSL
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment