Skip to content

trying out model parameters

erindb edited this page Oct 17, 2014 · 1 revision

for small, fast church models

Church models that run fairly quickly and return one or two values per run of the model are good for writing to a single CSV file, as described in this section. Larger models with more return values or longer run times might need more incremental writing to files, so that the program doesn't run out of memory or go on for too long without producing output.

Define a function around all of your model code that takes in the parameters you want to vary and returns whatever values you are interested in. Return this as a list of values, which will eventually be a row of your csv file.

(define model
  (lambda (parameter1 parameter2 parameter3)
    (define result1 (+ parameter1 parameter2 parameter3))
    (define result2 (* parameter1 parameter2 parameter3))
    (list parameter1 parameter2 parameter3 result1 result2)))

Define the ranges of values of your parameters:

(define parameter1-values '(1 2 3 4 5))
(define parameter2-values '(10 100))
(define parameter3-values '(-1 0 1))

Write to a csv file (note: this will only work when run on the command line).

(define data
  (apply append
         (map (lambda (parameter1)
                (apply append
                       (map (lambda (parameter2)
                              (map (lambda (parameter3)
                                     (model parameter1 parameter2 parameter3))
                                   parameter3-values))
                            parameter2-values)))
              parameter1-values)))

(write-csv data "data.csv")
Clone this wiki locally