jacobian: Jacobian Matrix of Gradient Function for Training Datasets

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/jacobianS3.R

Description

Calculate the Jacobian matrix of gradient function for the training dataset. It takes input from neural network models and the gradient at each weight parameters. The matrix has dimension of R [nObs * nPara], nObs denotes the number of training observations and nPara denotes the number of weights parameters.

Usage

1
2
3
4
5
6
7
8
jacobian(object, ...)

## S3 method for class 'nnet'
jacobian(object, xTrain, funName = 'sigmoid',...)
## S3 method for class 'nn'
jacobian(object, xTrain, funName = 'sigmoid',...)
## S3 method for class 'rsnns'
jacobian(object, xTrain, funName = 'sigmoid',...)

Arguments

object

object of class: nnet as returned by 'nnet' package, nn as returned by 'neuralnet' package, rsnns as returned by 'RSNNS' package.

xTrain

matrix or data frame of input values for the training dataset.

funName

activation function name of neuron, e.g. 'sigmoid', 'tanh', etc. In default, it is set to 'sigmoid'.

...

additional arguments passed to the method.

Details

Jacobian matrix with gradient function, in which J[ij] element denotes the gradient function at the jth weight parameters for the ith training observation. The dimension is equal to nObs * nPara.

Value

matrix which denotes the Jacobian matrix for training datasets.

Author(s)

Xichen Ding <rockingdingo@gmail.com>

See Also

nnetPredInt

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
library(nnet)
xTrain <- rbind(cbind(runif(150,min = 0, max = 0.5),runif(150,min = 0, max = 0.5)) ,
		cbind(runif(150,min = 0.5, max = 1),runif(150,min = 0.5, max = 1))
		)
nObs <- dim(xTrain)[1]
yTrain <- 0.5 + 0.4 * sin(2* pi * xTrain %*% c(0.4,0.6)) +rnorm(nObs,mean = 0, sd = 0.05)
# Training nnet models
net <- nnet(yTrain ~ xTrain,size = 3, rang = 0.1,decay = 5e-4, maxit = 500)

# Calculating Jacobian Matrix of the training samples
library(nnetpredint)
jacobMat = jacobian(net,xTrain)
dim(jacobMat)

Example output

# weights:  13
initial  value 32.673914 
iter  10 value 7.407531
iter  20 value 4.632076
iter  30 value 3.080706
iter  40 value 2.627133
iter  50 value 2.510743
iter  60 value 2.071661
iter  70 value 1.724717
iter  80 value 1.468828
iter  90 value 1.407474
iter 100 value 1.366105
iter 110 value 1.318391
iter 120 value 1.315228
iter 130 value 1.289561
iter 140 value 1.224326
iter 150 value 1.164389
iter 160 value 1.111597
iter 170 value 1.073565
iter 180 value 1.000235
iter 190 value 0.956152
iter 200 value 0.912999
iter 210 value 0.904156
iter 220 value 0.892300
iter 230 value 0.889633
iter 240 value 0.888455
iter 250 value 0.888265
iter 260 value 0.888131
iter 270 value 0.887959
iter 280 value 0.887947
iter 290 value 0.887938
iter 300 value 0.887936
iter 300 value 0.887936
final  value 0.887936 
converged
[1] 300  13

nnetpredint documentation built on May 2, 2019, 6:12 p.m.