makeinputfiles           package:emulator           R Documentation

_M_a_k_e_s _i_n_p_u_t _f_i_l_e_s _f_o_r _c_o_n_d_o_r _r_u_n_s _o_f _g_o_l_d_s_t_e_i_n

_D_e_s_c_r_i_p_t_i_o_n:

     Wrapper to create arbitrary numbers of condor-compatible goldstein
     runnable input files.  Function 'sample.from.exp.est()' samples
     from the appropriate distribution.

     This function is not designed for the general user: it is tailored
     for use in the environment of the National Oceanographic Centre,
     with a particular version of the specialist model "goldstein".

_U_s_a_g_e:

     makeinputfiles(number.of.runs = 100, gaussian = TRUE,
     directoryname="~/goldstein/genie-cgoldstein/", filename="QWERTYgoin", expert.estimates, area.outside=0.05)
     sample.from.exp.est(number.of.runs, expert.estimates, gaussian=TRUE, area.outside=0.05)

_A_r_g_u_m_e_n_t_s:

number.of.runs: Number of condor runs to generate

gaussian: Boolean variable with default TRUE meaning use a lognormal
          distribution, and FALSE meaning a uniform distribution.  In
          the case of a Gaussian distribution, only the 'upper' and
          'lower' columns are used: here these values are interpreted
          as the 2.5%ile and 97.5%ile respectively and a lognormal
          distribution with the appropriate parameters is used.

          Note that this approach discards the "best" value, but OTOH
          it seemed to me that my expert chose his "best" value as an
          arithmetic (sic) mean of his high and low values, and thus
          has limited information content. 

directoryname: Name of directory to which input files are written

filename: Basename of input files

expert.estimates: Dataframe holding expert estimates (supplied by a
          climate scientist).   Use 'data(expert.estimates)' to load a
          sample dataset that was supplied by Bob Marsh

area.outside: Area of tails of the lognormal distribution (on a log
          scale) that fall  outside the expert ranges.  Default value
          of 0.05 means interpret 'a' and 'b' as the 2.5%ile and
          97.5%ile respectively.

_D_e_t_a_i_l_s:

     This function creates condor-compatible goldstein runnable input
     files that are placed in directory
     '/working/jrd/sat/rksh/goldstein'.  The database 'results.table'
     is made using the shell scripts currently in
     '/users/sat/rksh/goldstein/emulator'.

     Note that 'makeinputfiles(number.of.runs=n)' creates files
     numbered from 0 to n-1: so be careful of off-by-one errors.  It's
     probably best to avoid reference to the "first", "second" file
     etc.  Instead, refer to files using their suffix number.  Note
     that the suffix number is not padded with zeros due to the
     requirements of Condor.

     The suffix number of a file matches the name of its 'tmp' file
     (so, for example, file with suffix number 15 writes output to
     files 'tmp/tmp.15' and 'tmp/tmp.avg.15').

_V_a_l_u_e:

     Returns zero on successful completion.  The function is used for
     its side-effect of creating a bunch of Goldstein input files.

_A_u_t_h_o_r(_s):

     Robin K. S. Hankin

_S_e_e _A_l_s_o:

     'expert.estimates', 'results.table'

_E_x_a_m_p_l_e_s:

     ## Not run: 
       data(expert.estimates) system("mkdir /users/sat/rksh/tmp",ignore=TRUE)
       makeinputfiles(number.of.runs = 100, gaussian = TRUE,
       directoryname="~/tmp/", expert.estimate=expert.estimates)
     ## End(Not run)
     data(results.table)
     data(expert.estimates)

     output.col <- 25
     wanted.row <- 1:27
     wanted.cols <- c(2:9,12:19)

     val <- results.table[wanted.row , wanted.cols]

     mins  <- expert.estimates$low 
     maxes <- expert.estimates$high

     normalize <- function(x){(x-mins)/(maxes-mins)}
     unnormalize <- function(x){mins + (maxes-mins)*x}

     jj <- t(apply(val,1,normalize))

     jj <- as.data.frame(jj)
     names(jj) <- names(val)
     val <- jj

     scales.optim <- exp(c( -2.63, -3.03, -2.24, 2.61,
     -1.65, -3.13, -3.52, 3.16, -3.32, -2.53, -0.25,  -2.55, -4.98, -1.59,
     -4.40, -0.81))

     d  <- results.table[wanted.row ,  output.col]
     A <- corr.matrix(val, scales=scales.optim, power=1.5)
     Ainv <- solve(A)

     x <- sample.from.exp.est(1000,exp=expert.estimates)
     x <- t(apply(x,1,normalize))
     ensemble <- interpolant.quick(x , d , val , Ainv, scales=scales.optim, power=1.5) 
     hist(ensemble)

