SymbolicLoss: Symbolic Gradient/Hessian Loss computation

Description Usage Arguments Details Value Examples

Description

This function computes the 1st and 2nd symbolic derivatives of the loss function (gradient/hessian) provided.

Usage

1
2
SymbolicLoss(fc, fc_ref = NULL, verbose = TRUE, plotting = TRUE,
  xmin = -10, xmax = 10, xpoint = 20, ...)

Arguments

fc

The loss function to derivate twice. Gradient and hessian are computed and returned into a list to the user.

fc_ref

The loss function for reference to compare when using plotting = TRUE. Defaults to NULL.

verbose

Whether the functions should be printed to the console while being returned. Defaults to TRUE.

plotting

Whether the functions should be plotted for debugging purposes. Defaults to TRUE.

xmin

The x-axis minimum when plotting data when plotting = TRUE. Defaults to -10.

xmax

The x-axis maximum when plotting data when plotting = TRUE. Defaults to 10.

xpoint

How many poitns to plot when plotting = TRUE. Defaults to 20.

...

Arguments to pass to fc and fc_ref.

Details

This function cannot handle any type of input. It cannot handle sums or loops in the function code. It handles the following, in the alphabetic order:

\*

Multiplication

/

Division

^

Power

abs

Absolute value function

acos

Arcosine function

acosh

Hyperbolic Arcosine function

asin

Arsine function

asinh

Hyperbolic Arcsine function

atan

Arctangent function

atan2

Arctangent angle function between the x-axis and the vector from the origin (x,y), atan=y/x if x>0 and y>0

atanh

Hyperbolic Arctangent function

besselI

Modified Bessel function of the first kind

besselJ

Bessel function of the first kind

besselK

Modified Bessel function of the second kind

besselY

Sphereical Bessel function

beta

Beta function (Eulerian integral of the first kind)

cos

Cosine function

cosh

Hyperbolic cosine function

cospi

Cosine function with argument multiplicand pi

dbinom

Density binomial function

digamma

First derivative of the logarithm of the gamma function

dnorm

Density normal function

exp

Exponential function

expm1

Exponential function minus 1

gamma

Gamma function (Mellin transform of the negative exponential function)

lbeta

Natural logarithm of the beta function

lgamma

Natural logarithm of the absolute value of the gamma function

log

Natural (e) logarithm function

log10

Common (10) logarithm function

log1p

Natural (e) logarithm function with 1 added to the argument

log2

Binary (2) logarithm function

logb

Logarithm function of base b (base)

pnorm

Normal distribution function

psigamma

Polygamma function (degree specified by deriv)

rep.int

Replicate "times" elements of vectors and lists

rep_len

Replicate "length.out" elements of vectors and lists

sign

Sign function

sin

Sine function

sinh

Hyperbolic sine function

sinpi

Sine function with argument multiplicand pi

sqrt

Square root function

tan

Tangent function

tanh

Hyperbolic tangent function

tanpi

Tangent function with argument multiplicand pi

trigamma

Second derivative of the logarithm of the gamma function

Value

A list with grad as the gradient of the loss function and hess as the hessian of the loss function.

Examples

1
2
3
4
5
6
7
8
9
# Median Fair loss (just the Fair loss...)
library(Deriv) # loads the required library
fc <- function(x, c=2, t=0.5)
{(c^2) * ((abs(x) / c) - log(1 + (abs(x) / c))) * ifelse(x > 0, 2 * t, 2-2*t)}
fc_ref <- function(x) {x^2} # Quadratic loss, aka Mean Squared Error
SymbolicLoss(fc = fc,
             fc_ref = fc_ref,
             verbose = TRUE,
             plotting = TRUE)

Laurae2/Laurae documentation built on May 8, 2019, 7:59 p.m.