R/helpers.R

Defines functions eval_gr_obj_fn eval_gr_p_fn eval_gr_d_fn eval_obj_fn eval_p_fn eval_d_fn

#' Objective function in the optimization problem for exponentially tilted
#' empirical likelihood
#'
#' Computes the objective function in the optimization problem for exponentially
#' tilted empirical likelihood.
#'
#' @param l
#'   A numeric vector.
#' @param g
#'   A numeric matrix.
#' @param n
#'   A single integer.
#' @param tau
#'   A single numeric.
#' @return
#'   A single numeric.
#' @noRd
eval_d_fn <- function(l, g, n, tau) {
  sum(exp(g %*% l)) / (n + tau)
}

#' Penalty function in the optimization problem for regularized exponentially
#' tilted empirical likelihood
#'
#' Computes the penalty function in the optimization problem for regularized
#' exponentially tilted empirical likelihood.
#'
#' @param l
#'   A numeric vector.
#' @param mu
#'   A numeric vector.
#' @param Sigma
#'   A numeric matrix.
#' @param n
#'   A single integer.
#' @param tau
#'   A single numeric.
#' @return
#'   A single numeric.
#' @noRd
eval_p_fn <- function(l, mu, Sigma, n, tau) {
  tau * exp(as.numeric(l %*% mu) + colSums(l * (Sigma %*% l)) / 2) / (n + tau)
}

#' Objective function in the optimization problem for regularized exponentially
#' tilted empirical likelihood
#'
#' Computes the objective function in the optimization problem for regularized
#' exponentially tilted empirical likelihood.
#'
#' @param l
#'   A numeric vector.
#' @param g
#'   A numeric matrix.
#' @param mu
#'   A numeric vector.
#' @param Sigma
#'   A numeric matrix.
#' @param n
#'   A single integer.
#' @param tau
#'   A single numeric.
#' @return
#'   A single numeric.
#' @noRd
eval_obj_fn <- function(l, g, mu, Sigma, n, tau) {
  eval_d_fn(l, g, n, tau) + eval_p_fn(l, mu, Sigma, n, tau)
}

#' Gradient of the objective function in the optimization problem for
#' exponentially tilted empirical likelihood
#'
#' Computes the gradient of the objective function in the optimization problem
#' for exponentially tilted empirical likelihood.
#'
#' @param l
#'   A numeric vector.
#' @param g
#'   A numeric matrix.
#' @param n
#'   A single integer.
#' @param tau
#'   A single numeric.
#' @return
#'   A numeric vector.
#' @noRd
eval_gr_d_fn <- function(l, g, n, tau) {
  colSums(as.numeric(exp(g %*% l)) * g) / (n + tau)
}

#' Gradient of the penalty function in the optimization problem for regularized
#' exponentially tilted empirical likelihood
#'
#' Compute the gradient of the penalty function in the optimization problem
#' for regularized exponentially tilted empirical likelihood.
#'
#' @param l
#'   A numeric vector.
#' @param mu
#'   A numeric vector.
#' @param Sigma
#'   A numeric matrix.
#' @param n
#'   A single integer.
#' @param tau
#'   A single numeric.
#' @return
#'   A numeric vector.
#' @noRd
eval_gr_p_fn <- function(l, mu, Sigma, n, tau) {
  eval_p_fn(l, mu, Sigma, n, tau) * (mu + as.numeric(Sigma %*% l))
}

#' Gradient of the objective function in the optimization problem for
#' regularized exponentially tilted empirical likelihood
#'
#' Compute the gradient of the objective function in the optimization problem
#' for regularized exponentially tilted empirical likelihood.
#'
#' @param l
#'   A numeric vector.
#' @param g
#'   A numeric matrix.
#' @param mu
#'   A numeric vector.
#' @param Sigma
#'   A numeric matrix.
#' @param n
#'   A single integer.
#' @param tau
#'   A single numeric.
#' @return
#'   A numeric vector.
#' @noRd
eval_gr_obj_fn <- function(l, g, mu, Sigma, n, tau) {
  eval_gr_d_fn(l, g, n, tau) + eval_gr_p_fn(l, mu, Sigma, n, tau)
}

Try the retel package in your browser

Any scripts or data that you put into this service are public.

retel documentation built on May 29, 2024, 10:40 a.m.