Description Usage Arguments Value Author(s) References See Also Examples
View source: R/predict.elmNN.R
Calculate the output predictions from a neural network trained using elmtrain
. It is possible to calculate output predictions from a new data set or returns the output predictions from the previous training data set ( fitted
data ).
1 2 |
object |
an object of class |
newdata |
(optional) a new data set to calculate output from the model. If missing, |
... |
not used. |
returns a vector containing the output predictions.
Alberto Gosso
see elmNN-package
documentation.
elmtrain.default
,elmtrain.formula
,elmNN-package
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 | set.seed(1234)
Var1 <- runif(50, 0, 100)
sqrt.data <- data.frame(Var1, Sqrt=sqrt(Var1))
model <- elmtrain.formula(Sqrt~Var1, data=sqrt.data, nhid=10, actfun="sig")
new <- data.frame(Sqrt=0,Var1 = runif(50,0,100))
p <- predict(model,newdata=new)
## The function is currently defined as
function (object, newdata = NULL, ...)
{
if (is.null(newdata))
predictions <- fitted(object)
else {
if (!is.null(object$formula)) {
x <- model.matrix(object$formula, newdata)
}
else {
x <- newdata
}
inpweight <- object$inpweight
biashid <- object$biashid
outweight <- object$outweight
actfun <- object$actfun
nhid <- object$nhid
TV.P <- t(x)
tmpHTest = inpweight %*% TV.P
biasMatrixTE <- matrix(rep(biashid, ncol(TV.P)), nrow = nhid,
ncol = ncol(TV.P), byrow = F)
tmpHTest = tmpHTest + biasMatrixTE
if (actfun == "sig")
HTest = 1/(1 + exp(-1 * tmpHTest))
else {
if (actfun == "sin")
HTest = sin(tmpHTest)
else {
if (actfun == "radbas")
HTest = exp(-1 * (tmpHTest^2))
else {
if (actfun == "hardlim")
HTest = hardlim(tmpHTest)
else {
if (actfun == "hardlims")
HTest = hardlims(tmpHTest)
else {
if (actfun == "satlins")
HTest = satlins(tmpHTest)
else {
if (actfun == "tansig")
HTest = 2/(1 + exp(-2 * tmpHTest)) -
1
else {
if (actfun == "tribas")
HTest = tribas(tmpHTest)
else {
if (actfun == "poslin")
HTest = poslin(tmpHTest)
else {
if (actfun == "purelin")
HTest = tmpHTest
else stop(paste("ERROR: ", actfun,
" is not a valid activation function.",
sep = ""))
}
}
}
}
}
}
}
}
}
TY = t(t(HTest) %*% outweight)
predictions <- t(TY)
}
predictions
}
|
Loading required package: MASS
function (object, newdata = NULL, ...)
{
if (is.null(newdata))
predictions <- fitted(object)
else {
if (!is.null(object$formula)) {
x <- model.matrix(object$formula, newdata)
}
else {
x <- newdata
}
inpweight <- object$inpweight
biashid <- object$biashid
outweight <- object$outweight
actfun <- object$actfun
nhid <- object$nhid
TV.P <- t(x)
tmpHTest = inpweight %*% TV.P
biasMatrixTE <- matrix(rep(biashid, ncol(TV.P)), nrow = nhid,
ncol = ncol(TV.P), byrow = F)
tmpHTest = tmpHTest + biasMatrixTE
if (actfun == "sig")
HTest = 1/(1 + exp(-1 * tmpHTest))
else {
if (actfun == "sin")
HTest = sin(tmpHTest)
else {
if (actfun == "radbas")
HTest = exp(-1 * (tmpHTest^2))
else {
if (actfun == "hardlim")
HTest = hardlim(tmpHTest)
else {
if (actfun == "hardlims")
HTest = hardlims(tmpHTest)
else {
if (actfun == "satlins")
HTest = satlins(tmpHTest)
else {
if (actfun == "tansig")
HTest = 2/(1 + exp(-2 * tmpHTest)) -
1
else {
if (actfun == "tribas")
HTest = tribas(tmpHTest)
else {
if (actfun == "poslin")
HTest = poslin(tmpHTest)
else {
if (actfun == "purelin")
HTest = tmpHTest
else stop(paste("ERROR: ", actfun,
" is not a valid activation function.",
sep = ""))
}
}
}
}
}
}
}
}
}
TY = t(t(HTest) %*% outweight)
predictions <- t(TY)
}
predictions
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.