File: step_relu.Rd

package info (click to toggle)
r-cran-recipes 0.1.15%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 2,496 kB
  • sloc: sh: 37; makefile: 2
file content (114 lines) | stat: -rw-r--r-- 3,925 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/relu.R
\name{step_relu}
\alias{step_relu}
\alias{tidy.step_relu}
\title{Apply (Smoothed) Rectified Linear Transformation}
\usage{
step_relu(
  recipe,
  ...,
  role = "predictor",
  trained = FALSE,
  shift = 0,
  reverse = FALSE,
  smooth = FALSE,
  prefix = "right_relu_",
  columns = NULL,
  skip = FALSE,
  id = rand_id("relu")
)

\method{tidy}{step_relu}(x, ...)
}
\arguments{
\item{recipe}{A recipe object. The step will be added to the sequence of
operations for this recipe.}

\item{...}{One or more selector functions to choose which variables are
affected by the step. See \code{\link[=selections]{selections()}} for more details.}

\item{role}{Defaults to "predictor".}

\item{trained}{A logical to indicate if the quantities for preprocessing
have been estimated.}

\item{shift}{A numeric value dictating a translation to apply to the data.}

\item{reverse}{A logical to indicate if the left hinge should be used as
opposed to the right hinge.}

\item{smooth}{A logical indicating if the softplus function, a smooth
approximation to the rectified linear transformation, should be used.}

\item{prefix}{A prefix for generated column names, default to "right_relu_"
when right hinge transformation and "left_relu_" for reversed/left hinge
transformations.}

\item{columns}{A character string of variable names that will
be populated (eventually) by the \code{terms} argument.}

\item{skip}{A logical. Should the step be skipped when the
recipe is baked by \code{\link[=bake.recipe]{bake.recipe()}}? While all operations are baked
when \code{\link[=prep.recipe]{prep.recipe()}} is run, some operations may not be able to be
conducted on new data (e.g. processing the outcome variable(s)).
Care should be taken when using \code{skip = TRUE} as it may affect
the computations for subsequent operations}

\item{id}{A character string that is unique to this step to identify it.}

\item{x}{A \code{step_relu} object.}
}
\value{
An updated version of \code{recipe} with the
new step added to the sequence of existing steps (if any).
}
\description{
\code{step_relu} creates a \emph{specification} of a recipe step that
will apply the rectified linear or softplus transformations to numeric
data. The transformed data is added as new columns to the data matrix.
}
\details{
The rectified linear transformation is calculated as
\deqn{max(0, x - c)} and is also known as the ReLu or right hinge function.
If \code{reverse} is true, then the transformation is reflected about the
y-axis, like so: \deqn{max(0, c - x)} Setting the \code{smooth} option
to true will instead calculate a smooth approximation to ReLu
according to \deqn{ln(1 + e^(x - c)} The \code{reverse} argument may
also be applied to this transformation.
}
\section{Connection to MARS}{


The rectified linear transformation is used in Multivariate Adaptive
Regression Splines as a basis function to fit piecewise linear functions to
data in a strategy similar to that employed in tree based models. The
transformation is a popular choice as an activation function in many
neural networks, which could then be seen as a stacked generalization of
MARS when making use of ReLu activations. The hinge function also appears
in the loss function of Support Vector Machines, where it penalizes
residuals only if they are within a certain margin of the decision boundary.
}

\examples{
library(modeldata)
data(biomass)

biomass_tr <- biomass[biomass$dataset == "Training",]
biomass_te <- biomass[biomass$dataset == "Testing",]

rec <- recipe(HHV ~ carbon + hydrogen + oxygen + nitrogen + sulfur,
              data = biomass_tr)

transformed_te <- rec \%>\%
  step_relu(carbon, shift = 40) \%>\%
  prep(biomass_tr) \%>\%
  bake(biomass_te)

transformed_te

}
\seealso{
\code{\link[=recipe]{recipe()}} \code{\link[=prep.recipe]{prep.recipe()}}
\code{\link[=bake.recipe]{bake.recipe()}}
}