fn_get_optimal_param_idx: Get the index of parameters that optimize the log joint...

View source: R/tulip.R

fn_get_optimal_param_idxR Documentation

Get the index of parameters that optimize the log joint distribution

Description

Since we allow multiple familys to be evaluated at once with the same grid of parameter values, we first need to identify the 'raw' index that tells us the optimal family choice. Then we can within this family identify the 'wrapped' optimum index that gives the optimal params choice.

Usage

fn_get_optimal_param_idx(log_joint, idx_wrap)

Arguments

log_joint

A vector of length dim(param_grid)[1] multiplied by the number of evaluated familys

idx_wrap

The number of params (same for each family); used to indicate at which index the log_joint repeats the parameters for the next family

Details

When only a single family is evaluated, the 'raw' and 'wrapped' indices are the same.

Value

A list of two scalar integers, named raw and wrapped

Examples

# let's say there are 5 parameter sets being evaluated
log_joint_params <- rnorm(n = 5, sd = 5)
idx_wrap <- length(log_joint_params)

# we evaluate the parameter sets for three different family choices, which
# creates 3 * 5 different sets of models to be evaluated
log_joint <- c(
  log_joint_params + rnorm(n = 1, sd = 5),
  log_joint_params + rnorm(n = 1, sd = 5),
  log_joint_params + rnorm(n = 1, sd = 5)
)

ls_opt_idx <- tulip:::fn_get_optimal_param_idx(
  log_joint = log_joint,
  idx_wrap = idx_wrap
)

plot(x = 1:idx_wrap,
     y = seq(-30, 30, length.out = idx_wrap),
     type = "n", xlab = "idx", ylab = "log joint")

for (i in 1:(length(log_joint) / idx_wrap)) {
  lines(
    x = 1:idx_wrap,
    y = log_joint[(i*idx_wrap - 4):(i*idx_wrap)],
    lty = i
  )
}

points(ls_opt_idx$wrapped, log_joint[ls_opt_idx$raw], pch = 19)


timradtke/heuristika documentation built on April 24, 2023, 1:55 a.m.