Produces an object that may be used in place of a vector or matrix in the creation of arguments to spec_rescomp()
.
Linearly interpolates between two sets of coefficients according to the value of a time-dependent parameter.
rescomp_coefs_lerp(coefs0, coefs1, param_name, param0 = 0, param1 = 1)
Vectors, matrices, or objects of class rescomp_coefs_vector
or rescomp_coefs_matrix
to be interpolated between. Either both must be vectors, or both must be matrices.
A character vector of length 1; the name of the parameter to be interpolated according to.
The values of the parameter to take as the fixed points for interpolation.
S3 object of class rescomp_coefs_vector
or rescomp_coefs_matrix
, according to the types of coefs0
and coefs1
.
Coefficients are taken to have the values in coef0
at param = param0
, and the values in coef1
at param = param1
, and are linearly interpolated between.
Each parameter in the vector/matrix is interpolated independently.
coefs_vec <- rescomp_coefs_lerp(
c(0, 0, 0),
c(2, 3, 5),
"scale"
)
get_coefs(coefs_vec, list(scale = 0))
#> [1] 0 0 0
get_coefs(coefs_vec, list(scale = 0.5))
#> [1] 1.0 1.5 2.5
get_coefs(coefs_vec, list(scale = 1))
#> [1] 2 3 5
get_coefs(coefs_vec, list(scale = 1.5))
#> [1] 3.0 4.5 7.5
coefs_mat1 <- rescomp_coefs_lerp(
matrix(c(0.2, 0.4, 0.3, 0.2), nrow = 2),
matrix(c(0.2, 0.1, 0.3, 0.1), nrow = 2),
"antibiotic1_concentration",
param0 = 0,
param1 = 200
)
get_coefs(coefs_mat1, list(antibiotic1_concentration = 0))
#> [,1] [,2]
#> [1,] 0.2 0.3
#> [2,] 0.4 0.2
get_coefs(coefs_mat1, list(antibiotic1_concentration = 100))
#> [,1] [,2]
#> [1,] 0.20 0.30
#> [2,] 0.25 0.15
get_coefs(coefs_mat1, list(antibiotic1_concentration = 200))
#> [,1] [,2]
#> [1,] 0.2 0.3
#> [2,] 0.1 0.1
coefs_mat2 <- rescomp_coefs_lerp(
coefs_mat1,
matrix(c(0.0, 0.0, 0.0, 0.0), nrow = 2),
"antibiotic2_concentration",
param0 = 0,
param1 = 100
)
get_coefs(coefs_mat2, list(antibiotic1_concentration = 100, antibiotic2_concentration = 50))
#> [,1] [,2]
#> [1,] 0.100 0.150
#> [2,] 0.125 0.075