View source: R/generateReferenceDistribution.R
| generateReferenceDistribution2IFC | R Documentation |
Generates the reference distribution of norms for a stimulus set.
generateReferenceDistribution2IFC(
rdata,
iter = 10000,
ncores = default_ncores(),
response_seed = NULL,
save_rdata = TRUE,
baseimage = NULL
)
rdata |
Path to the |
iter |
Number of simulated classification images, each built from random responses; the distribution holds one norm per image. |
ncores |
Number of CPU cores used to rebuild the saved noise (default: |
response_seed |
Optional seed for the simulated random responses. The default,
|
save_rdata |
Boolean: write the reference distribution into the |
baseimage |
Base-image label, the same key passed to |
computeInfoVal2IFC scores a classification image against this distribution. By
default the result is saved in the rdata file for later reuse.
The reference distribution, invisibly, as a numeric vector of iter norms.
Unless save_rdata = FALSE, it is also added to the rdata file as
reference_norms, with reference_norms_seed recording the response_seed
it was drawn with. A later computeInfoVal2IFC call on the same file then reuses
it instead of simulating again. For independent base images it goes in
reference_norms_by_base instead, as described above.
With the default response_seed = NULL, the reference distribution depends only on the
stimulus .Rdata file and the session's RNGkind: not on the current
random state, and not on ncores. Two researchers computing InfoVal from the same
stimulus file get the same reference distribution, and the same number, on any machine and in
any session, provided both use the same RNG kind.
This needs the stimulus seed saved in the file. A file without one (made with
generateStimuli2IFC(seed = NULL), or with the field removed) has no stream to continue,
so the default stops with an error; pass a response_seed instead.
The RNG kind is the one gap. set.seed() keeps whatever kind the session already has,
and no stimulus file records which kind was in use. A session with a different
RNGkind() therefore draws different simulated responses, and so a different null; the
saved noise basis and stimulus parameters stay the same. To reproduce an earlier reference, use
the RNG kind that built it; see https://github.com/rdotsch/rcicr/issues/315.
The noise is rebuilt from the basis and parameters saved in the stimulus file, so the base images are never reopened and a moved or archived experiment can still be scored. The simulated responses continue the random stream from the saved stimulus seed, after the draws for one parameter matrix, which reproduces the historical default reference.
Pass a response_seed to draw a different null from the same stimuli, for
instance to check how much Monte Carlo error a given iter leaves in your InfoVal. This
changes only the simulated responses, not the stimuli or the noise basis the null is built on.
When the base images have different parameter matrices, baseimage says whose noise to
use. The distributions are then stored in reference_norms_by_base, one entry per base
label, each holding norms and response_seed. A shared reference_norms
in such a file is neither used nor overwritten. Files whose base images share one parameter
matrix keep using reference_norms.
# a synthetic square grayscale image stands in for a real base face photo
base_face <- tempfile(fileext = ".png")
png::writePNG(matrix(runif(32 * 32), 32, 32), base_face)
stimulus_path <- tempfile("stimuli")
generateStimuli2IFC(
base_face_files = list(face = base_face),
n_trials = 6,
img_size = 32,
stimulus_path = stimulus_path,
seed = 1,
ncores = 1,
nscales = 1,
save_as_png = FALSE
)
rdata_file <- list.files(stimulus_path, pattern = "\\.Rdata$", full.names = TRUE)[1]
# iter is kept tiny here for a fast example; in practice use iter >= 10000.
suppressWarnings(generateReferenceDistribution2IFC(rdata_file, iter = 3, ncores = 1))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.