ann {validann} | R Documentation |
Fit Artificial Neural Networks.
Description
Fits a single hidden layer ANN model to input data x
and output data
y
.
Usage
ann(x, y, size, act_hid = c("tanh", "sigmoid", "linear", "exp"),
act_out = c("linear", "sigmoid", "tanh", "exp"), Wts = NULL, rang = 0.5,
objfn = NULL, method = "BFGS", maxit = 1000, abstol = 1e-04,
reltol = 1e-08, trace = TRUE, ...)
Arguments
x |
matrix, data frame or vector of numeric input values, with
|
y |
matrix, data frame or vector of target values for examples. |
size |
number of hidden layer nodes. Can be zero. |
act_hid |
activation function to be used at the hidden layer. See ‘Details’. |
act_out |
activation function to be used at the output layer. See ‘Details’. |
Wts |
initial weight vector. If |
rang |
initial random weights on [-rang,rang]. Default value is 0.5. |
objfn |
objective function to be minimised when fitting
weights. This function may be user-defined with the first two arguments
corresponding to |
method |
the method to be used by |
maxit |
maximum number of iterations used by |
abstol |
absolute convergence tolerance (stopping criterion)
used by |
reltol |
relative convergence tolerance (stopping criterion)
used by |
trace |
logical. Should optimization be traced? Default = TRUE. |
... |
arguments to be passed to user-defined |
Details
The “linear” activation, or transfer, function is the
identity function where the output of a node is equal to its input
f(x) = x
.
The “sigmoid” function is the standard logistic sigmoid function given
by f(x) = \frac{1}{1+e^{-x}}
.
The “tanh” function is the hyperbolic tangent function given by
f(x) = \frac{e^{x}-e^{-x}}{e^{x}+e^{-x}}
The “exp” function is the exponential function given by
f(x) = e^{x}
The default configuration of activation functions is
act_hid = "tanh"
and act_out = "linear"
.
Optimization (minimization) of the objective function (objfn
) is
performed by optim
using the method specified.
Derivatives returned are first-order partial derivatives of the hidden and output nodes with respect to their inputs. These may be useful for sensitivity analyses.
Value
object of class ‘ann’ with components describing the ANN structure and the following output components:
wts |
best set of weights found. |
par_of |
best values of additional |
value |
value of objective function. |
fitted.values |
fitted values for the training data. |
residuals |
residuals for the training data. |
convergence |
integer code returned by |
derivs |
matrix of derivatives of hidden (columns |
See Also
Examples
## fit 1-hidden node ann model with tanh activation at the hidden layer and
## linear activation at the output layer.
## Use 200 random samples from ar9 dataset.
## ---
data("ar9")
samp <- sample(1:1000, 200)
y <- ar9[samp, ncol(ar9)]
x <- ar9[samp, -ncol(ar9)]
x <- x[, c(1,4,9)]
fit <- ann(x, y, size = 1, act_hid = "tanh", act_out = "linear", rang = 0.1)
## fit 3-hidden node ann model to ar9 data with user-defined AR(1) objective
## function
## ---
ar1_sse <- function(y, y_hat, par_of) {
err <- y - y_hat
err[-1] <- err[-1] - par_of * err[-length(y)]
sum(err ^ 2)
}
fit <- ann(x, y, size = 3, act_hid = "tanh", act_out = "linear", rang = 0.1,
objfn = ar1_sse, par_of = 0.7)