Movatterモバイル変換


[0]ホーム

URL:


Title:Parameter Space Partitioning MCMC for Global Model Evaluation
Version:1.0.2
Date:2024-07-24
Description:Implements an n-dimensional parameter space partitioning algorithm for evaluating the global behaviour of formal computational models as described by Pitt, Kim, Navarro and Myung (2006) <doi:10.1037/0033-295X.113.1.57>.
License:GPL (≥ 3)
URL:https://github.com/lenarddome/psp
BugReports:https://github.com/lenarddome/psp/issues
Imports:Rcpp (≥ 1.0.8.3), parallel, data.table, methods
LinkingTo:Rcpp, RcppArmadillo
Encoding:UTF-8
Suggests:testthat (≥ 3.0.0)
Config/testthat/edition:3
NeedsCompilation:yes
Packaged:2024-07-24 09:09:21 UTC; lenarddome
Author:Lenard Dome [aut, cre], Andy Wills [aut]
Maintainer:Lenard Dome <lenarddome@gmail.com>
Repository:CRAN
Date/Publication:2024-07-24 10:00:02 UTC

Parameter Space Partitioning MCMC for Global Model Evaluation

Description

Implements an n-dimensional parameter space partitioning algorithm for evaluatingthe global behaviour of formal computational models as described by Pitt, Kim,Navarro and Myung (2006) <doi:10.1037/0033-295X.113.1.57>.

Please cite the package in publications. Usecitation("psp").

Author(s)

Lenard Dome

Maintainer: Lenard Domelenarddome@gmail.com

References

Pitt, M. A., Kim, W., Navarro, D. J., & Myung, J. I. (2006). Global model analysis by parameter space partitioning. Psychological Review, 113(1), 57.


Parameter Space Partitioning

Description

An all-purpose C++ implementation of the Parameter Space Partitioning MCMCAlgorithm described by Pitt, Kim, Navarro, Myung (2006).

Usage

pspGlobal(model, discretize, control, save = FALSE, path = ".",          extension = ".csv", quiet = FALSE)

Arguments

model

It should take a numeric vector (parameter set)as its argument, and return a numeric vector of continuous variables.

discretize

The inequality matrix constructor. It should take a numericvector of probabilities. It must return a matrix in amatrix formatwith 'type=double'. NA values are not allowed, see Note 1.

control

Alist() of control arguments that tunes the behaviorof the parameter space partitioning routine. See Details for more informationon what to include.

save

ifsave = TRUE, all evaluated parameters and continuousmodel outputs will be saved to disk. The default isFALSE.

path

If 'save = TRUE', the path to the file that will store allevaluated parameters and continuous model outputs. The default path is thecurrent working directory. Evaluated parameters and continuous model outputsare save separately, see Details.

extension

If 'save = TRUE', the extension of the file will storeall evaluated parameters and continuous model outputs. The default extensionis.csv.

quiet

IfFALSE (default), print the number of the currentiteration. IfTRUE, do not print anything.

Details

Overview:

This function implements the Parameter Space Partitioning algorithmdescribed by Pitt et al. (2006). The brief overview of the algorithm is as follows:

0. Initialize parameter space.

0. Select the first set of parameters, and evaluate the model on this set. Itsordinal output will become the first ordinal pattern and the first regionin the parameter space.

1. Pick a random jumping distribution for each ordinal pattern from thesampling region defined by a hypersphere with a center of the last recordedparameter set for a given pattern. Clamp parameter values with theirrespective lower and upper bounds.

2. Evaluate the model on all new parameter sets.

3. Record new patterns and their corresponding parameter sets. If theparameter sets return an already discovered pattern, add the parameter setto their records. Return to Step 1.

Tuning the behaviour of the algorithm viacontrol:

This behavior is further tuned by 'control', which needs to contain a list of the following values:

Saving files to disk:

The evaluated parameter sets and their corresponding continuous model outputsare saved to disk ifsave = TRUE. The evaluated parameter sets are saved ina file with the namepath_parameters and the extension specified,whereas continuous model outputs are saved in a file with the namepath_continuousand the extension specified.

Value

The output is a list with the following items:

ordinal_patterns

A 3D array with the ordinal patterns found.The place of the ordinal pattern corresponds to ordinal_counts.

ordinal_counts

A table with the ordinal patterns discovered and thepopulation of their corresponding region - the number of parameter setsdiscovered to produce the ordinal pattern.

iterations

Number of iterations completed before reaching a set threshold.

Note

1. NA values are usually a result of some parameter combination falling outside of what the model implementation can handle. It is best handled outside of the PSP routine, e.g. during the inequality matrix construction. For example, if NA is detected in the matrix, change all values to 99 before returning the output.2. Ideally, responses and dimensionality should be the same, but we can imagine a scenario where the dimensionality of the inequality matrix will be smaller than the number of responses. For example, when continuous variables are compressed into a more compact format via clustering.

References

Dome, L., Wills, A. J. (2023) g-distance: On the comparison of model and human heterogeneity. PsyArxiv.doi:10.31234/osf.io/ygmcj.

Pitt, M. A., Kim, W., Navarro, D. J., & Myung, J. I. (2006). Global model analysis by parameter space partitioning. Psychological Review, 113(1), 57.doi:10.1037/0033-295X.113.1.57.

Weisstein, Eric W. "Hypersphere Point Picking." From MathWorld–A Wolfram Web Resource.https://mathworld.wolfram.com/HyperspherePointPicking.html. Accessed 2021-09-30.


Control the behaviour of the psp_global implementation

Description

psp_control allows users to define characteristics of theparameter space partitioning MCMC algorithm as implemented inpsp_global.

Usage

psp_control(radius = 0.1, init, lower, upper,           pop = 400, cl = NULL,           param_names = NULL,           parallel = FALSE,           cluster_names = NULL,           export_objects = NULL,           export_libs = NULL,           iterations = 1000)

Arguments

radius

The radius of the hypershere with n-dimensions to sample from.Must be a double or a numeric vector, where elements correspond toparameters in 'init, lower, upper'. Default is 0.1.

init

A vector of parameters to use as the first jumpingdistribution.

lower,upper

Vectors specifiying the lower and upper boundaries ofthe parameter space for each parameter. The i-th element of lower andupper bounds applies to the i-th parameter.

pop

The minimum population psp_global aims to find for each ordinalpattern discovered. This can stop the parameter search early in casethe population of all ordinal pattern are equal to or larger thanpop. If you do not want to use this option, set it toNULLorInf. Default is400.

parallel

If TRUE, uses the parallel package to run evaluations ofjumping distributions for each chain parallel. Default value isFALSE.

cl

If parallel is TRUE, the number of cores to use formakeCluster from theparallel package. If null(default), use all cores.

param_names

A character vector that includes the names of eachparameter. IfNULL (default), a character vector is generated withparameter_1, parameter_2, parameter_3, ...

cluster_names

Maintained for backwards-compatibility. Seeexport_objects below.

export_objects

A character vector that includes all of the objectsto be loaded into each cluster. It is handled byparallel::clusterExports. Default isNULL.

export_libs

A character vector that includes all the packages tobe loaded into each cluster. It is handled byparallel::clusterExports. Default isNULL.

iterations

The number of global iterations for psp_global. Default is1000.

Value

Returns a control list suitable forpsp_global with the aboveelements.

Examples

# two parameter modelpsp_control(lower = rep(0, 2), upper = rep(1, 2), init = rep(0.5, 2),           radius = rep(0.25, 2), cluster_names = NULL,           parallel = FALSE, iterations = 500)

Parameter Space Partitioning

Description

An all-purpose implementation of the Parameter Space Partitioning MCMCAlgorithm described by Pitt, Kim, Navarro, Myung (2006).

Usage

psp_global(fn, control = psp_control(), ..., quiet = FALSE)

Arguments

fn

The ordinal function. It should take a numeric vector (parameter set)as its argument, and return an ordinal response pattern as character (e.g."A > B"). NA values are not currently allowed.

control

a list of control parameters, seepsp_control

...

Additional arguments passed tofn.

quiet

IfFALSE (default), print the total number of patternsfound up to the current iteration. IfTRUE, do not print anything.

Details

This function implements the Parameter Space Partitioning algorithmdesribed by Pitt et al. (2006). The algorithm is as follows:

0. Initialize parameter space.

0. Select first set of parameters, and evaluate the model on this set. Itsordinal output will become the first ordinal pattern and the first regionin the parameter space.

1. Pick a random jumping distribution from for each ordinal pattern from thesampling region defined by a hypershere with a center of the last recordedparameter set for a given pattern.

2. Evaluate model on all new parameter sets.

3. Record new patterns and their corresponding parameter sets. If theparameter sets returns an already discovered pattern, add parameter setto their records. Return to Step 1.

This process runs can run in parallel for each discovered pattern.

Value

The output of functionpsp is a member of theS3 classofPSP. APSP object is a list with the following items:

ps_partitions

Adata.table containing coordinates from theparameter space and their corresponding ordinal response pattern output byfn. Columns include (in this order): parameter coordinates,their ordinal pattern output byfn, the global iteration of theMCMC. Each row corresponds with the evaluation of a single set ofparameters.

ps_patterns

A table with the ordinal patterns discovered and thepopulation of their corresponding region - the number of parameter setsdiscovered to produce the ordinal pattern.

ps_ordinal

A list (if ordinal patterns are multidimensional objects)or character vector (if ordinal patterns are strings or other single values)with the ordinal patterns found. The place of the ordinal patterncorresponds to the names in ps_patterns.

References

Pitt, M. A., Kim, W., Navarro, D. J., & Myung, J. I. (2006). Global model analysis by parameter space partitioning. Psychological Review, 113(1), 57.

Weisstein, Eric W. "Hypersphere Point Picking." From MathWorld–A Wolfram Web Resource. https://mathworld.wolfram.com/HyperspherePointPicking.html

Examples

library(psp)#' euclidean distance#'#' @param a vector coordinate 1#' @param b vector coordinate 2#' @return euclidean distance between coordinateseuclidean <- function(a, b) sqrt(sum((a - b)^2))# define center points for the 10 regions in a two-dimensional spacepositions <- NULLfor (i in seq_len(2)) positions <- cbind(positions, sample(500, 10))#' dummy hypercube model to test the PSP function#' The model takes in a set of coordinates, calculates its distance from all#' all of available coordinates, then return closest region number.#' This model generalizes to n-dimensions#'#' @param x a vector of coordinates#' @return The number of the region as character#' @examples#' model(runif(5))model <- function(par) {    areas <- NULL    for (i in seq_along(par)) {        range <- c(1, 0)        if (i %% 2 == 0) {            range <- c(0, 1)        }        areas <- cbind(areas,                       seq(range[1], range[2], length.out = 500)[positions[,i]])    }    dist <- apply(areas, 1, function(x) euclidean(par, x))    return(as.character(which.min(dist)))}# run Parameter Space Partitioning with some default settings# Here we run the MCMC for 400 iterations, but the partitioning# will stop if the population of all regions reach 200.# Note that we have to load our utility function into# the clusters, because PSPglobal is currently parallelized.out <- psp_global(model, psp_control(lower = rep(0, 2),                                   upper = rep(1, 2),                                   init = rep(0.5, 2),                                   radius = rep(0.25, 2),                                   pop = 100,                                   parallel = FALSE,                                   iterations = 100))print(out)

[8]ページ先頭

©2009-2025 Movatter.jp