Constructs a mapper for cos/sin functions of orders 1 (if intercept is TRUE, otherwise 0) through order. The total number of basis functions is intercept + 2 * order.

Optionally, each order can be given a non-unit scaling, via the scaling vector, of length intercept + order. This can be used to give an effective spectral prior. For example, let

scaling = 1 / (1 + (0:4)^2)
x <- seq(0, 1, length.out = 11)
bmh1 = bru_mapper_harmonics(order = 4, interval = c(0, 1))
u1 <- ibm_eval(
bmh1,
input = x,
state = rnorm(9, sd = rep(scaling, c(1, 2, 2, 2, 2)))
)

Then, with

bmh2 = bru_mapper_harmonics(order = 4, scaling = scaling)
u2 = ibm_eval(bmh2, input = x, state = rnorm(9))

the stochastic properties of u1 and u2 will be the same, with scaling^2 determining the variance for each frequency contribution.

The period for the first order harmonics is shifted and scaled to match interval.

## Usage

bru_mapper_harmonics(
order = 1,
scaling = 1,
intercept = TRUE,
interval = c(0, 1)
)

# S3 method for bru_mapper_harmonics
ibm_n(mapper, inla_f = FALSE, ...)

# S3 method for bru_mapper_harmonics
ibm_jacobian(mapper, input, state = NULL, inla_f = FALSE, ...)

## Arguments

order

For bru_mapper_harmonics, specifies the maximum cos/sin order. (Default 1)

scaling

For bru_mapper_harmonics, specifies an optional vector of scaling factors of length intercept + order, or a common single scalar.

intercept

logical; For bru_mapper_harmonics, if TRUE, the first basis function is a constant. (Default TRUE)

interval

numeric length-2 vector specifying a domain interval. Default c(0, 1).

mapper

A mapper S3 object, inheriting from bru_mapper.

inla_f

logical; when TRUE for ibm_n() and ibm_values(), the result must be compatible with the INLA::f(...) and corresponding INLA::inla.stack(...) constructions. For ibm_{eval,jacobian,linear}, the input 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 by bru_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)

Other mappers: bru_get_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_generics, 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_scale(), bru_mapper_shift(), bru_mapper_taylor(), bru_mapper()

## Examples

m <- bru_mapper_harmonics(2)
ibm_eval2(m, input = c(0, pi / 4, pi / 2, 3 * pi / 4), 1:5)
#> $offset #>  7.000000 -7.247183 4.306719 -3.678570 #> #>$jacobian
#> 4 x 5 Matrix of class "dgeMatrix"
#>      [,1]       [,2]       [,3]       [,4]       [,5]
#> [1,]    1  1.0000000  0.0000000  1.0000000  0.0000000
#> [2,]    1  0.2205840 -0.9753680 -0.9026854 -0.4303012
#> [3,]    1 -0.9026854 -0.4303012  0.6296817  0.7768532
#> [4,]    1 -0.6188200  0.7855328 -0.2341236 -0.9722068
#>