summarize.sims: Summarizes a collection of simulation files, by producing a...

View source: R/gather_simulation.r

summarize.simsR Documentation

Summarizes a collection of simulation files, by producing a data.frame each row of which contains the parameters and the data from the last generation of a single simulation file

Description

Summarizes a collection of simulation files, by producing a data.frame each row of which contains the parameters and the data from the last generation of a single simulation file

Usage

summarize.sims(
  simulations_path,
  simulation_file_pattern = "sim_.*",
  parameter_start_pattern = "^var",
  parameter_end_pattern = NA,
  data_start_pattern = "^generation",
  data_end_pattern = "^\n",
  sep = ";",
  recursive = T,
  callback_data = NULL,
  callback_parameters = NULL
)

Arguments

simulations_path

the directory in which all the simulations are collected

simulation_file_pattern

a regular expression that matches the simulation files

parameter_start_pattern

a regular expression that matches the start of the parameters

parameter_end_pattern

a regular expression that matches the end of the parameters. If parameters are at the end of the file anyway one can just write NA

data_start_pattern

a regular expression that matches the start of the data output for each timestep or generation

data_end_pattern

a regular expression that matches the end of the data output for each timestep or generation

sep

data separators, e.g., "," or "\t"

recursive

if recursive = TRUE, the search for simulation files recurses into subdirectories. If recursive = FALSE, only the current directory will be searched without descending into subdirectories

callback_data

function to perform additional processing of the data (variables) section. The function needs to accept a single argument x. For example, callback_data=some_func(x). This argument will be assigned a data.frame containing all the data The callback function needs to return a named list of values as in list(a=3,b=30.0,xk=-393) that will be appended to the final reuslt

callback_parameters

function to perform additional processing of the parameters section. The function needs to accept a single argument x. This argument will be assigned a data.frame containing the names of the parameters in the first columna and the corresponding parameter values in the second column. The callback function needs to return a named list of values as in list(a=3,b=30.0,xk=-393) that will be appended to the final result

Value

A data.frame, each row of which contains the parameters and last line of output of each simulation file and the corresponding file name in a column named file

Examples

# say the current directory "."
# contains the following files:
# ├── file_x.csv
# ├── parameters.txt
# ├── sim_cue_integration_23_06_2020_095246_1.csv
# ├── sim_cue_integration_23_06_2020_095246_10.csv
# ├── sim_cue_integration_23_06_2020_095246_10_dist.csv
# ├── sim_cue_integration_23_06_2020_095246_11.csv
# ├── sim_cue_integration_23_06_2020_095246_11_dist.csv
#
# we need to obtain the files
# ├── sim_cue_integration_23_06_2020_095246_1.csv
# ├── sim_cue_integration_23_06_2020_095246_10.csv
# ├── sim_cue_integration_23_06_2020_095246_11.csv
#
# hence we provide a simulation_file_pattern = "sim_.*\d\.csv"
# which is a regular expression mating sim_ followed by a series
# of any characters .* finalized by a digit \d followed by a
# dot \. and csv
#
data <- summarize.sims(simulations_path="."
                           ,simulation_file_pattern="sim_.*\\d\\.csv"
                           ,parameter_start_pattern="^sigmoid"
                           ,parameter_end_pattern="^sigmoid"
                           )
# collects the output from the files in the data.frame data
# sim_cue_integration_23_06_2020_095246_1.csv
# sim_cue_integration_23_06_2020_095246_10.csv
# sim_cue_integration_23_06_2020_095246_11.csv

# data will look like
str(data)
# 'data.frame':	150 obs. of  4 variables:
# generation: num 50000 500000 500000 ...
# var1: num 1 2 3 4 ...
# x: num 0.33 0.35 0.35...
# file: sim_cue_integration_23_06_2020_095246_1.csv ...

bramkuijper/simulation.utils documentation built on Jan. 29, 2024, 11:23 a.m.