R/stop-conditions.R

Defines functions minimize_ratio n_metamers n_tries

Documented in minimize_ratio n_metamers n_tries

#' Stop conditions
#'
#' @param n integer number of tries or metamers.
#' @param r Ratio of minimize value to shoot for. If `0.5`,
#' the stop condition is that the iteration will stop if the value
#' to minimize gets to one-half of the starting value.
#'
#' @export
#' @rdname stop_conditions
n_tries <- function(n) {
  force(n)
  function() {
    get("n_tries", envir = parent.frame()) >= n

  }
}

#' @export
#' @rdname stop_conditions
n_metamers <- function(n) {
  force(n)
  function() {
    get("n_metamers", envir = parent.frame()) >= n
  }
}

#' @export
#' @rdname stop_conditions
minimize_ratio <- function(r) {
  force(r)
  function() {
    get("minimize_ratio", parent.frame()) <= r
  }
}

Try the metamer package in your browser

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

metamer documentation built on June 24, 2022, 1:06 a.m.