Constructs a mapper
that aggregates elements of exp(state)
, with optional non-negative
weighting, and then takes the log()
, so it can be used e.g.
for \(v_k=\log[\sum_{i\in I_k} w_i \exp(u_i)]
\)
and \(v_k=\log[\sum_{i\in I_k} w_i \exp(u_i) / \sum_{i\in I_k} w_i]
\)
calculations. Relies on the input handling methods for
bm_aggregate
, but also allows the weights to be supplied on a
logarithmic scale as log_weights
. To avoid numerical overflow, it uses the
common method of internally shifting the state blockwise;
\(v_k=s_k+\log[\sum_{i\in I_k} \exp(u_i + \log(w_i)- s_k)]
\),
where \(s_k=\max_{i\in I_k} u_i + \log(w_i)\) is the
shift for block \(k\).
Arguments
- rescale
logical; For
bm_aggregate
andbm_logsumexp
, specifies if the blockwise sums should be normalised by the blockwise weight sums or not:FALSE
: (default) Straight weighted sum, no rescaling.TRUE
: Divide by the sum of the weight values within each block. This is useful for integration averages, when the given weights are plain integration weights. If the weights areNULL
or all ones, this is the same as dividing by the number of entries in each block.
- n_block
Predetermined number of output blocks. If
NULL
, overrides the maximum block index in the inputs. The priority order isinput$n_block
, the mapper definitionn_block
, thenmax(input$block)
.- ...
Arguments passed on to
bm_logsumexp()
See also
bru_mapper, bru_mapper_generics
Other mappers:
bm_aggregate()
,
bm_collect()
,
bm_const()
,
bm_factor()
,
bm_fm_mesh_1d
,
bm_fmesher()
,
bm_harmonics()
,
bm_index()
,
bm_linear()
,
bm_marginal()
,
bm_matrix()
,
bm_mesh_B()
,
bm_multi()
,
bm_pipe()
,
bm_repeat()
,
bm_scale()
,
bm_shift()
,
bm_sum()
,
bm_taylor()
,
bru_get_mapper()
,
bru_mapper()
Other specific bm_logsumexp method implementations:
ibm_eval()
,
ibm_jacobian()
Examples
m <- bm_logsumexp()
ibm_eval2(m, list(block = c(1, 2, 1, 2), weights = 1:4), 11:14)
#> $offset
#> [1] 14.14274 15.45177
#>
#> $jacobian
#> 2 x 4 sparse Matrix of class "dgCMatrix"
#>
#> [1,] 0.04316453 . 0.9568355 .
#> [2,] . 0.06337894 . 0.9366211
#>
ibm_eval2(m, list(block = c(1, 2, 1, 2), weights = 1:4, n_block = 3), 11:14)
#> $offset
#> [1] 14.14274 15.45177 -Inf
#>
#> $jacobian
#> 3 x 4 sparse Matrix of class "dgCMatrix"
#>
#> [1,] 0.04316453 . 0.9568355 .
#> [2,] . 0.06337894 . 0.9366211
#> [3,] . . . .
#>