This example is using NetLogo Flocking model (Wilensky, 1998) to demonstrate exploring parameter space with categorical evaluation.

See also Thiele, Kurth & Grimm (2014) for categorical criteria example.

Measures and Evaluation Criteria

As in previous example two measures of self-organization were defined:

Additionaly

experiment <- nl_experiment( 
  model_file = "models/Sample Models/Biology/Flocking.nlogo",
  setup_commands = c("setup", "repeat 100 [go]"),
  iterations = 5,

  param_values = list(
    world_size = 50,
    population = 80,
    vision = c(3,6),
    min_separation = seq(from = 0, to = 4, by = 0.5),
    max_align_turn = seq(from = 0, to = 20, by = 2.5)
  ),
  mapping = c(
    min_separation = "minimum-separation",
    max_align_turn = "max-align-turn"),

  step_measures = measures(
    converged = "1 - 
      (standard-deviation [dx] of turtles + 
       standard-deviation [dy] of turtles) / 2",
    mean_crowding = 
      "mean [count flockmates + 1] of turtles"
  ),
  eval_criteria = criteria(
    c_converged = mean(step$converged),
    c_mcrowding = mean(step$mean_crowding)
  ),

  repetitions = 10,                        # repeat simulations 10 times
  random_seed = 1:10,
  
  eval_aggregate_fun = mean                # aggregate over repetitions
)

result3 <- nl_run(experiment, parallel = TRUE) 

Add Categorical Criteria

If we were interested in parameters where the model will produce medium sized flocks which fly in same direction we could define criteria based on crowding and direction convergence like this:

Crowding criteria:

\[ 5 \leq crowding < 11 \]

Alignment criteria:

\[ converged > 0.7 \]

dat <- nl_get_criteria_result( 
  result3,
  are_grouped = c_mcrowding >= 5 & c_mcrowding < 11,
  are_aligned = c_converged > 0.7
)

library(ggplot2)
ggplot( dat, aes(x = min_separation, y = max_align_turn) ) +
  geom_point() +
  geom_point(data=subset(dat,are_aligned),color="red",size=5,shape=2) +
  geom_point(data=subset(dat,are_grouped),color="blue",size=5,shape=3) +
  coord_equal(ratio = 1/5) +
  facet_grid(. ~ vision, labeller = label_both) +
  theme_minimal() +
  theme(panel.margin = grid::unit(0.07,"npc"))
#> Warning: `panel.margin` is deprecated. Please use `panel.spacing` property
#> instead