weighted_trajectory_variation_multivariate: Calculate approximation to expectation of nu_j (multivariate)

View source: R/RcppExports.R

weighted_trajectory_variation_multivariateR Documentation

Calculate approximation to expectation of nu_j (multivariate)

Description

Calculation of the scaled/weighted average variation of the C trajectories with respect to their individual sub-posterior means

Usage

weighted_trajectory_variation_multivariate(
  x_samples,
  normalised_weights,
  sub_posterior_means,
  inv_precondition_matrices
)

Arguments

sub_posterior_means

matrix with C rows of sub-posterior means

inv_precondition_matrices

list of length m of inverse preconditioning matrices

list

where x_samples[[i]] ith collection of the C trajectories

Value

the approximated expectation of nu_j

Examples

N <- 10
C <- 4
d <- 3
x_samples <- lapply(1:N, function(i) mvrnormArma(C, rep(0,d), diag(1,d)))
normalised_weights <- rep(1/N, N)
sub_posterior_means <- mvrnormArma(C, rep(0,d), diag(1,d))
precond <- lapply(1:C, function(c) diag(c, d))
inv_precond <- lapply(precond, solve)
weighted_trajectory_variation_multivariate(x_samples = x_samples,
                                           normalised_weights = normalised_weights,
                                           sub_posterior_means = sub_posterior_means,
                                           inv_precondition_matrices = inv_precond)
# should be equal to the result of this:
sum(sapply(1:N, function(i) {
  sum(sapply(1:C, function(c) {
    diff <- x_samples[[i]][c,]-sub_posterior_means[c,]
    return(t(diff) %*% inv_precond[[c]] %*% diff)
  }))/C
}))/N

rchan26/hierarchicalFusion documentation built on Sept. 11, 2022, 10:30 p.m.