R/Csn.R

Defines functions Csn

Documented in Csn

source("R/Tay.R")

#' @title Csn
#' @description The function that returns \eqn{\mathsf{Csn}}.
#'
#' @param n The number of Taylor iterations. Accuracy as well as computation
#' time increases as \eqn{n} increases
#' @param q a real number in \eqn{(2,\infty)}. Accuracy as well as computation
#' time increases as \eqn{q} gets closer to \eqn{2} increases
#' @param eps a real number in \eqn{(0,\infty)}. ccuracy as well as computation
#' time increases as \eqn{\varepsilon} gets closer to \eqn{0} increases
#'
#' \emph{Note: } In practice for most desktop uses
#' \eqn{q < 2.05} and \eqn{\varepsilon< 0.05} tends to cause problems in
#' "too long a vector", atleaast as tested on my computer.
#'
#' @return A neural network that approximates \eqn{\cos} under instantiation
#' with ReLU activation. See also \code{\link{Sne}}.
#'
#' @references Definition 2.29 in Rafi S., Padgett, J.L., Nakarmi, U. (2024) Towards an Algebraic Framework For
#' Approximating Functions Using Neural Network Polynomials
#' \url{https://arxiv.org/abs/2402.01058}
#'
#' @examples
#' Csn(2, 2.5, 0.5) # this may take some time
#'
#' Csn(2, 2.5, 0.5) |> inst(ReLU, 1.50)
#'
#' @export

Csn <- function(n, q, eps) {
  if (q <= 2 || eps <= 0) {
    stop("q must be > 2 and eps must be > 0")
  } else if (n %% 1 != 0 || n < 0) {
    stop("The number of Taylor iterations must be non negative integer")
  } else {
    Tay("cos", n, q, eps) -> return_network
    return(return_network)
  }
}

Vectorize(Csn) -> Csn

Try the nnR package in your browser

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

nnR documentation built on May 29, 2024, 2:02 a.m.