-
Notifications
You must be signed in to change notification settings - Fork 45
Baby BehaviorSpace
Jeremy B edited this page Oct 10, 2018
·
2 revisions
This feature is experimental and should be used with caution.
Example usage of Baby BehaviorSpace:
// Log the results from BBS when they come in
window.addEventListener("message", function (e) {
if (e.data.type === "baby-behaviorspace-results") {
console.log(JSON.stringify(e.data.data));
}
});
// Build a parameter set for Wolf-Sheep Predation
args = {
experimentName: "BBS Wolf-Sheep example",
parameterSet: {
type: "cartesianProduct"
, variables: [{
name: "grass?"
, parameterSpace: {
type: "discreteValues"
, values: [true, false]
}
}, {
name: "grass-regrowth-time"
, parameterSpace: {
type: "range"
, min: 0
, max: 30
, interval: 7
}
}]
}
, repetitionsPerCombo: 3
, metrics: [{ reporter: "count wolves", interval: 5 }, { reporter: "count sheep + 1", interval: 10 }, { reporter: "one-of turtles", interval: 7 }]
, setupCode: "setup"
, goCode: "go"
, stopConditionCode: ""
, iterationLimit: 20
}
// Tell the `iframe`—this assumes that we're on netlogoweb.org/launch —to launch BBS with our config
document.getElementById('model-container').contentWindow.postMessage({ type: "run-baby-behaviorspace", config: args }, "*")The config object should fit this type:
type Metric = {
interval: Number
, reporter: String // NetLogo code that is () => Any
}
type VariableConfig = {
name: String
parameterSpace: { type: "discreteValues", values: Array[Any] }
| { type: "range", min: Number, max: Number, interval: Number }
}
type BehaviorSpaceConfig =
{
experimentName: String
parameterSet: { type: "discreteCombos", combos: Array[Object[Any]] }
| { type: "cartesianProduct", variables: Array[VariableConfig] }
repetitionsPerCombo: Number
metrics: Object[Metric]
setupCode: String // NetLogo code that is () => Unit
goCode: String // NetLogo code that is () => Unit
stopConditionCode: String // NetLogo code that is () => Boolean
iterationLimit: Number
}