A bru_mapper
sub-class implementation must provide an
ibm_jacobian()
method. If the model size 'n' and definition
values 'values' are stored in the object itself, default methods are
available (see Details). Otherwise the
ibm_n()
and ibm_values()
methods also need to be provided.
Usage
ibm_n(mapper, inla_f = FALSE, ...)
ibm_n_output(mapper, input, state = NULL, inla_f = FALSE, ...)
ibm_values(mapper, inla_f = FALSE, ...)
ibm_is_linear(mapper, ...)
ibm_jacobian(mapper, input, state = NULL, inla_f = FALSE, ...)
ibm_linear(mapper, input, state = NULL, ...)
ibm_simplify(mapper, input = NULL, state = NULL, ...)
ibm_eval(mapper, input, state = NULL, ...)
ibm_eval2(mapper, input, state = NULL, ...)
ibm_names(mapper)
ibm_names(mapper) <- value
ibm_inla_subset(mapper, ...)
ibm_invalid_output(mapper, input, state, ...)
# Default S3 method
ibm_n(mapper, inla_f = FALSE, ...)
# Default S3 method
ibm_n_output(mapper, input, state = NULL, inla_f = FALSE, ...)
# Default S3 method
ibm_values(mapper, inla_f = FALSE, ...)
# Default S3 method
ibm_is_linear(mapper, ...)
# Default S3 method
ibm_jacobian(mapper, input, state, ...)
# Default S3 method
ibm_linear(mapper, input, state, ...)
# Default S3 method
ibm_simplify(mapper, input = NULL, state = NULL, ...)
# Default S3 method
ibm_eval(mapper, input, state = NULL, ..., jacobian = NULL)
# Default S3 method
ibm_eval2(mapper, input, state, ...)
# Default S3 method
ibm_names(mapper, ...)
# Default S3 method
ibm_inla_subset(mapper, ...)
# Default S3 method
ibm_invalid_output(mapper, input, state, ...)
Arguments
- mapper
A mapper S3 object, inheriting from
bru_mapper
.- inla_f
logical; when
TRUE
foribm_n()
andibm_values()
, the result must be compatible with theINLA::f(...)
and correspondingINLA::inla.stack(...)
constructions. Foribm_{eval,jacobian,linear}
, theinput
interpretation may be different. Implementations do not normally need to do anything different, except for mappers of the type needed for hidden multicomponent models such as "bym2", which can be handled bybru_mapper_collect
.- ...
Arguments passed on to other methods
- input
Data input for the mapper.
- state
A vector of latent state values for the mapping, of length
ibm_n(mapper, inla_f = FALSE)
- value
a character vector of the same length as the number of sub-mappers in the mapper
- jacobian
For
ibm_eval()
methods, an optional pre-computed Jacobian, typically supplied by internal methods that already have the Jacobian.
Functions
ibm_n()
: Implementations must return the size of the latent vector being mapped to.ibm_n_output()
: Implementations must return an integer denoting the mapper output length. The default implementation returnsNROW(input)
. Mappers such asbru_mapper_multi
andbru_mapper_collect
, that can acceptlist()
inputs require their own methods implementations.ibm_values()
: Wheninla_f=TRUE
, implementations must return a vector that would be interpretable by anINLA::f(..., values = ...)
specification. The exception is the method forbru_mapper_multi
, that returns a multi-column data frame.ibm_is_linear()
: Implementations must returnTRUE
orFALSE
. IfTRUE
(returned by the default method unless the mapper contains anis_linear
variable), users of the mapper may assume the mapper is linear.ibm_jacobian()
: Implementations must return a (sparse) matrix of sizeibm_n_output(mapper, input, inla_f)
byibm_n(mapper, inla_f = FALSE)
. Theinla_f=TRUE
argument should only affect the allowed type of input format.ibm_linear()
: Implementations must return a bru_mapper_taylor object The linearisation information includesoffset
,jacobian
, andstate0
. The state information indicates for which state theoffset
was evaluated, withNULL
meaning all-zero. The linearised mapper output is defined asThe default method calls
ibm_eval()
andibm_jacobian()
to generate the needed information.ibm_simplify()
: Implementations must return a bru_mapper object. The default method returnsibm_linear(...)
for linear mappers, and the originalmapper
for non-linear mappers.ibm_eval()
: Implementations must return a vector of lengthibm_n_output(...)
. Theinput
contents must be in a format accepted byibm_jacobian(...)
for the mapper.ibm_eval2()
: Implementations must return a list with elementsoffset
andjacobian
. Theinput
contents must be in a format accepted byibm_jacobian(...)
for the mapper.ibm_names()
: Implementations must return a character vector of sub-mapper names, orNULL
. Intended for providing information about multi-mappers and mapper collections.ibm_names(mapper) <- value
: Set mapper names.ibm_inla_subset()
: Implementations must return a logical vector ofTRUE/FALSE
for the subset such that, given the full A matrix and values output,A[, subset, drop = FALSE]
andvalues[subset]
(orvalues[subset, , drop = FALSE]
for data.frame values) are equal to theinla_f = TRUE
version of A and values. The default method uses theibm_values
output to construct the subset indexing.ibm_invalid_output()
: Implementations should return a logical vector of lengthibm_n_output(mapper, input, state, ...)
indicating which, if any, output elements ofibm_eval(mapper, input, state, ...)
are known to be invalid. For for multi/collect mappers, a list, when given amulti=TRUE
argument.ibm_n(default)
: Returns a non-null element 'n' from the mapper object, and gives an error if it doesn't exist. Ifinla_f=TRUE
, first checks for a 'n_inla' element.ibm_n_output(default)
: ReturnsNROW(input)
ibm_values(default)
: Returns a non-null element 'values' from the mapper object, andseq_len(ibm_n(mapper))
if it doesn't exist.ibm_is_linear(default)
: Returns logicalis_linear
from the mapper object if it exists, and otherwiseTRUE
.ibm_jacobian(default)
: Mapper classes must implement their ownibm_jacobian
method.ibm_linear(default)
: Callsibm_eval()
andibm_jacobian()
and returns abru_mapper_taylor
object. Thestate0
information in the affine mapper indicates for which state theoffset
was evaluated; The affine mapper output is defined asibm_simplify(default)
: Callsibm_linear()
for linear mappers, and returns the original mapper for non-linear mappers.ibm_eval(default)
: Verifies that the mapper is linear withibm_is_linear()
, and then computes a linear mapping asibm_jacobian(...) %*% state
. Whenstate
isNULL
, a zero vector of lengthibm_n_output(...)
is returned.ibm_eval2(default)
: Callsjacobian <- ibm_jacobian(...)
andoffset <- ibm_eval(..., jacobian = jacobian)
and returns a list with elementsoffset
andjacobian
, as needed byibm_linear.default()
and similar methods. Mapper classes can implement their ownibm_eval2
method if joint construction of evaluation and Jacobian is more efficient than separate or sequential construction.ibm_names(default)
: ReturnsNULL
ibm_inla_subset(default)
: Uses theibm_values
output to construct the inla subset indexing, passing extra arguments such asmulti
on to the methods (this means it supports both regular vector values andmulti=1
data.frame values).ibm_invalid_output(default)
: Returns an all-FALSE
logical vector.
See also
bru_mapper for constructor methods, and bru_get_mapper for hooks to extract mappers from latent model object class objects.
Other mappers:
bru_get_mapper()
,
bru_mapper()
,
bru_mapper.fm_mesh_1d()
,
bru_mapper.fm_mesh_2d()
,
bru_mapper_aggregate()
,
bru_mapper_collect()
,
bru_mapper_const()
,
bru_mapper_factor()
,
bru_mapper_fmesher()
,
bru_mapper_harmonics()
,
bru_mapper_index()
,
bru_mapper_linear()
,
bru_mapper_logsumexp()
,
bru_mapper_marginal()
,
bru_mapper_matrix()
,
bru_mapper_mesh_B()
,
bru_mapper_multi()
,
bru_mapper_pipe()
,
bru_mapper_repeat()
,
bru_mapper_scale()
,
bru_mapper_shift()
,
bru_mapper_taylor()
Examples
# ibm_names
mapper <- bru_mapper_multi(list(
A = bru_mapper_index(2),
B = bru_mapper_index(2)
))
ibm_names(mapper)
#> [1] "A" "B"
ibm_names(mapper) <- c("new", "names")
ibm_names(mapper)
#> [1] "new" "names"