Skip to content
kvcalvin edited this page May 24, 2018 · 5 revisions

Welcome to the gcamland wiki!

Basic usage

To run an individual scenario, first generate a structure to hold the scenario parameters. The scenario structure can be passed directly to the main model function.

sceninfo <- ScenarioInfo(aScenarioType = "Hindcast")   # see helpfile for arguments 
outdir <- run_model(sceninfo)

The results will be written as a series of csv files in the outdir directory. Subdirectories under that top-level directory will contain model outputs including price and yield expectations and land allocation.

Running ensembles

The run_ensemble function will generate and run a collection of scenarios with varying parameters. The parameters are sampled quasi-randomly using a Sobol sequence. The arguments to run_ensemble are the number of samples (for each expectation model, so 3 times that many will actually be run), output directory, and (optionally) scenario type.

registerDoParallel(cores=6)
ensemble_scenarios <- run_ensemble(1000, './ensemble-output')

The run_ensemble function is parallel enabled using the doParallel package. The return value is a list of the ScenarioInfo structures created. These structures have the parameter values, as well as the file names for the output.

For really large ensembles you will probably want to run them in parallel on a cluster. There is an example batch script (for the SLURM cluster resource manager) in inst/scripts/jobrun.zsh. You will want to customize the output directory and number of iterations to your needs, then submit it with sbatch.

Calculating Bayesian Posteriors

The run_bayes function will compute a Bayesian log-posterior probability density for a list of models returned from run_ensemble. The results of this calculation are stored in the list of modified ScenarioInfo structures returned from the function, but the grand_table function will turn these into a table with parameter values and log-posteriors.

ensemble_scenarios <- run_bayes(ensemble_scenarios)
post_table <- grand_table(ensemble_scenarios)
Clone this wiki locally