activation_curve {nndiagram}R Documentation

Producing 'LaTeX' Code for Drawing Activation Functions

Description

The activation_curve command is used to produce 'LaTeX' code for drawing well-formatted activation functions, which are crucial in neural network analysis. To make the code work in a 'LaTeX' editor, users need to install and import two 'TeX' packages TikZ and pgfplots in the setting of 'TeX' file. Syntax of importing these packages is included in the output of function.

Usage

activation_curve(
  expr = "ReLU",
  title = NULL,
  xlabel = NULL,
  ylabel = NULL,
  xmin = -10,
  xmax = 10,
  ymin = NULL,
  ymax = NULL,
  suppress = FALSE
)

Arguments

expr

an optional character that specifies the activation function. It could be "ReLU", "sigmoid" or "step", which are commonly used activation functions. Or, it can be a call or an expression written as a function of x that will evaluate to an object of the same length as x. Default is "ReLU".

title

an optional character that specifies the main title of diagram. Default is NULL.

xlabel

an optional character that specifies the label of x-axis. Default is NULL.

ylabel

an optional character that specifies the label of y-axis. Default is NULL.

xmin

an optional numeric value that specifies the minimum value of x-axis. Default is -10.

xmax

an optional numeric value that specifies the maximum value of x-axis. Default is 10.

ymin

an optional numeric value that specifies the minimum value of y-axis. Default is NULL.

ymax

an optional numeric value that specifies the maximum value of y-axis. Default is NULL.

suppress

an optional logical value that specifies whether activation_curve should suppress the output of 'LaTeX' code to be directly printed on console. Default is FALSE.

Value

activation_curve uses cat() to print out 'LaTeX' code on console, if not suppressed. Also, activation_curve saves the same output as a character vector invisibly, so users could use cat() to print it out later at their demand, as shown in Examples. The activation_curve 'LaTeX' output can be directly copied and pasted to produce activation curve in any 'LaTeX' editor.

Author(s)

Chencheng Fang, Bonn Graduate School of Economics, University of Bonn. Email: ccfang@uni-bonn.de

See Also

nndiagram; nndiagram_oversize; nndiagram_nodeCoverup.

Examples

# Rectified Linear Unit Function with all arguments default
activation_curve()

# Sigmoid function with domain from -5 to 5.
activation_curve(expr="sigmoid", title="Sigmoid Function", xmin=-5, xmax=5)

# Define a parametric ReLU in the argument of \code{expr}.
activation_curve(expr="(x>=0)*x+0.2*x*(x<0)", title="Parametric Rectified Linear Unit Function")

# Suppress the output of 'LaTeX' code to be directly printed on the console and save the output
# to an object, which can be printed later at demand.
nnd_activation <- activation_curve(suppress=TRUE)
cat(paste(nnd_activation,"\n"))

[Package nndiagram version 1.0.0 Index]