R神经网络置信区间工具nnetpredint

Package‘nnetpredint’
December21,2015
Type Package
Title Prediction Intervals of Multi-Layer Neural Networks
Version1.2
Date2015-12-21
Suggests MASS,nnet,neuralnet
大田西瓜种植技术Imports stats,RSNNS
Author Xichen Ding<rockingdingo@gmail>
Maintainer Xichen Ding<rockingdingo@gmail>
Description Computing prediction intervals of neural network backpropagation)at cer-tain confidence level.It can take the output from models trained by other pack-
贝雷梁
ages like'nnet','neuralnet','RSNNS',etc.
License GPL(>=2)
Repository CRAN
Repository/R-Forge/Project nnetpredint
Repository/R-Forge/Revision7
Repository/R-Forge/DateTimeStamp2015-12-2112:31:51
Date/Publication2015-12-2121:35:34
NeedsCompilation no
R topics documented:
activate (2)
jacobian (2)
nnetPredInt (4)
transWeightListToVect (7)
Index9
1
activate Neuron Activation Function
Description
activation function for each neuron node,we provide the popular activation functions including ’sigmoid’,’tanh’,etc.
Usage
activate(x,funName)
Arguments
x input value to the activation function
funName This package provides the most popular activation functions which can be used by setting the funName parameter to the following strings:’sigmoid’,’tanh’.
’sigmoid’sigmoid function1/(1+exp(-x)).
’tanh’tanh is the hyperbolic tangent function equal to(exp(x)-exp(-x))/(exp(x)
+exp(-x)).
Examples
x<-c(-5:5)
y1<-activate(x,funName= sigmoid )
y2<-activate(x,funName= tanh )
jacobian Jacobian Matrix of Gradient Function for Training Datasets
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
jacobian(object,...)
##S3method for class nnet
jacobian(object,xTrain,funName= sigmoid ,...)
##S3method for class nn
jacobian(object,xTrain,funName= sigmoid ,...)
##S3method 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 ’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>
See Also
nnetPredInt
Examples
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)
nnetPredInt Prediction Intervals of Neural Networks
Description
Get the prediction intervals of new dataset at certain confidence level based on the training datasets and the gradient at weight parameters of the neural network model.
Usage
nnetPredInt(object,...)
##Default S3method:
nnetPredInt(object=NULL,xTrain,yTrain,yFit,node,wts,newData, alpha=0.05,lambda=0.5,funName= sigmoid ,...)
##S3method for class nnet
nnetPredInt(object,xTrain,yTrain,newData,alpha=0.05,lambda=0.5, funName= sigmoid ,...)
##S3method for class nn
nnetPredInt(object,xTrain,yTrain,newData,alpha=0.05,lambda=0.5, funName= sigmoid ,...)
##S3method for class rsnns
nnetPredInt(object,xTrain,yTrain,newData,alpha=0.05,lambda=0.5, 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.Object set as NULL will use
the default method which takes the weight parameters as the input from user.
xTrain matrix or data frame of input values for the training dataset.
yTrain vector of target values for the training dataset.
newData matrix or data frame of the prediction dataset.
yFit vector of thefitted values,as the output produced by the training
nnet$fitted.values(’nnet’),sult[[1]](’neuralnet’)and rsnns$fitted.values
(’RSNNS’)
node a vector of integers specifying the number of hidden nodes in each layer.Multi-layer network has the structure(s0,s1,...,sm),in which s0denotes the dimen-
sion for input layer and sm denotes the dimension of the output layer.sm is
usually set as1.
wts a numeric vector of optimal weight parameters as the output of the neural net-work training model.The order of wts parameter is as follows:For any node i
in layer k:c(bias ik,wi1k,wi2k,...wijk).
nnet object,returned by’nnet’package.We can directly set the wts as:wts=
nnet$wts
nn object,returned by’neuralnet’package.We need to use transWeightList-
多功能折叠椅ToVect function to transform the list of weights to a single vectorfirst:wts=
transWeightListToVect(wtsList,m).
rsnns object,returned by’RSNNS’package.We need to transform and combine
the weight and bias parameters to a single vector:weightMatrix(object)and
extractNetInfo(object)$unitDefinitions$unitBias.
alpha confidence level.The confidence level is set to(1-alpha).In default,alpha=
0.05.
lambda decay parameter of weights when the Jacobian matrix of training dataset is sin-gular.In default,lamda is set to0.5.
funName activation function name of ’sigmoid’,’tanh’,etc.In default,it is set to’sigmoid’.
...additional arguments passed to the method.
Value
data frame of the prediction intervals,including prediction value,lower and upper bounds of the interval.
yPredValue the column of prediction value in the data frame.
lowerBound the column of prediction lower bounds in the data frame.
upperBound the column of prediction upper bounds in the data frame.
Author(s)
Xichen Ding<rockingdingo@gmail>
References
De Veaux R.D.,Schumi J.,Schweinsberg J.,Ungar L.H.,1998,"Prediction intervals for neural networks via nonlinear regression",Technometrics40(4):273-282.
Chryssolouris G.,Lee M.,Ramsey A.,"Confidence interval prediction for neural networks models", IEEE Trans.Neural Networks,7(1),1996,pp.229-232.
’neuralnet’package by Stefan Fritsch,Frauke Guenther.
’nnet’package by Brian Ripley,William Venables.
’RSNNS’package by Christoph Bergmeir,Jose M.Benitez.
See Also
transWeightListToVect jacobian
Examples
#Example1:Using the nn object trained by neuralnet package
set.seed(500)
汽车脚垫制造设备library(MASS)
data<-Boston
maxs<-apply(data,2,max)
mins<-apply(data,2,min)
scaled<-as.data.frame(scale(data,center=mins,scale=maxs-mins))#normalization index<-sample(1:nrow(data),round(0.75*nrow(data)))
train_<-scaled[index,]
test_<-scaled[-index,]
library(neuralnet)#Training
n<-names(train_)
f<-as.formula(paste("medv~",paste(n[!n%in%"medv"],collapse="+")))
nn<-neuralnet(f,data=train_,hidden=c(5,3),linear.output=FALSE)
plot(nn)
library(nnetpredint)#Getting prediction confidence interval
x<-train_[,-14]
y<-train_[,14]
newData<-test_[,-14]
#S3generic method:Object of nn
yPredInt<-nnetPredInt(nn,x,y,newData)
print(yPredInt[1:20,])
#S3default method for user defined weights input,without model object trained:
yFit<-c(sult[[1]])
nodeNum<-c(13,5,3,1)
m<-3
百花仙酒
wtsList<-nn$weights[[1]]
wts<-transWeightListToVect(wtsList,m)
yPredInt2<-nnetPredInt(object=NULL,x,y,yFit,nodeNum,wts,newData,alpha=0.05) print(yPredInt2[1:20,])
#Compare to the predict values from the neuralnet Compute method
predValue<-compute(nn,newData)
print(matrix(sult[1:20]))
#Example2:Using the nnet object trained by nnet package
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) plot(xTrain%*%c(0.4,0.6),yTrain)
#Training nnet models

本文发布于:2024-09-22 19:24:05,感谢您对本站的认可!

本文链接:https://www.17tex.com/tex/4/252728.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

上一篇:NumPy求范数
下一篇:差生拼音补习
标签:设备   西瓜   百花   脚垫
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议