lazy.nntools {lazy.nntools} | R Documentation |
This package provides some useful tools for learning supervised feed forward neural networks, which can be regarded as a non-linear regression or supervised classification models.
The first layer is the input matrix, X. The last layer is the output matrix, Yhat. In between the first and the last layers, there are hidden layers.
The size of the network is given as a vector of the # of layers,
nn
,
where nn[k]
is the # of neurons of layer k
.
nlayer
is the # of layers: nlayer=length(nn)
Using the list of output matrices, O
, and the list of
weight matrices, W
,
the output of the k
-th layer will be calculated as:
O[[k]] <- Psi( cbind( 1, O[[k-1]] ) %*% W[[k]] )
where Psi
is the logistic function.
The Weight Matrices are stored in a list W
of
length nlayer
.
W[[k]] is nn[k-1]+1 x nn[k]. W[[1]] is NULL. W[[2]] is nn[1]+1 x nn[2]. W[[k]] is nn[k-1] x nn[k]. W[[nlayer]] is nn[nlayer-1] x nn[nlayer].
The Output of each layer are stored in O
, a list of length
nlayer
.
O[[k]] is n x nn[k]. O[[1]] = X. O[[k]] is n x nn[k]. O[[nlayer]] is referred to as Yhat.
At the beginning of the session,
initialize_nn
must be called to create the storage lists
for the output O
and the weight W
.
output Given W, calculates the List of Output Matrices for each layer
It is assumed that O
exists.
on Given unlist(W)
, calculates Yhat
.
rss_nn_a Given unlist(W)
, calculates rss w.r.t unlist(W)
drss_nn_a Derivative of rss w.r.t unlist(W)
drss_nn_aJ Derivative of rss w.r.t unlist(W)
by Jac_nn_a
Jac_nn_a Jacobian of Yhat w.r.t unlist(W)
Jac_nn_a2 Jacobian of -Yhat w.r.t unlist(W)
ymyhat_nn Given unlist(W)
, calculates vec(Y)-vec(Yhat)
yhatmyh_nn Given unlist(W)
, calculates vec(Yhat)-vec(Y)
initialize_nn Initialize W
and O
.
getW_from_neuralnet Convert the list of weights from
neuralnet::neuralnet
to ours.
reshapeW Recovers W from unlist(W)
plot_nn Plots the Network
This function requires neuralnet
package or NeuralNetTools
packages with grid
packages.
summary_nn Given W
, calculates various quantities including,
rss, rmse, Yhat, gradient.
data_1_2 Nonlinear Regression Data
data_2_3 Supervised Classification Data
ExamplesOfnn Tow Example Codes