Commit 02f5d23b authored by Chris Jewell's avatar Chris Jewell
Browse files

Factored out R6 class definitions for Acceptance, Inits and Priors from...

Factored out R6 class definitions for Acceptance, Inits and Priors from interface.R.  Code could do with further streamlining (incorporation of sanity checking code into these classes, for example), but okay for now.
parent 530483c9
HaldDP_inits = R6::R6Class(
"inits_class",
public = list(
theta = NULL,
s = NULL,
alpha = NULL,
r = NULL,
initialize = function(inits) {
self$theta <-
inits$theta ## vector of length number of groups (i.e. no of unique values in s)
self$s <- inits$s
self$alpha <-
inits$alpha ## 3D array [source, time, location]
self$r <-
inits$r ## 3D array [source, type, time] giving the relative prevalences
}
)
)
HaldDP_priors = R6::R6Class(
"priors",
public = list(
a_theta = NULL,
b_theta = NULL,
a_r = NULL,
a_alpha = NULL,
initialize = function(priors) {
self$a_theta <- priors$a_theta ## single number
self$b_theta <- priors$b_theta ## single number
self$a_r <-
priors$a_r ## DP prior for each type, source, time, location
self$a_alpha <-
priors$a_alpha ## DP prior for each source, time, location
}
)
)
Acceptance = R6::R6Class(
"acceptance",
public = list(
alpha = NULL,
r = NULL,
initialize = function(nSources = private$nSources,
nTimes = private$nTimes,
nLocations = private$nLocations,
nTypes = private$nTypes,
namesSources = private$namesSources,
namesTimes = private$namesTimes,
namesLocations = private$namesLocations,
namesTypes = private$namesTypes) {
self$alpha <- array(
dim = c(nSources,
nTimes,
nLocations),
dimnames = list(
source = namesSources,
time = namesTimes,
location = namesLocations
)
)
self$r <- array(
dim = c(nTypes,
nSources,
nTimes),
dimnames = list(
type = namesTypes, source = namesSources, time = namesTimes
)
)
}
)
)
Acceptance = R6::R6Class("acceptance",
public = list(
alpha = NULL,
r = NULL,
initialize = function(nSources,
nTimes,
nLocations,
nTypes,
namesSources,
namesTimes,
namesLocations,
namesTypes,
paramsFix) {
if (paramsFix$alpha == FALSE) {
self$alpha <- array(
dim = c(nSources,
nTimes,
nLocations),
dimnames = list(
source = namesSources,
time = namesTimes,
location = namesLocations
)
)
}
if (paramsFix$r == FALSE) {
self$r <- array(
dim = c(nTypes,
nSources,
nTimes),
dimnames = list(
type = namesTypes,
source = namesSources,
time = namesTimes
)
)
}
}
))
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment