-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
254 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.Rproj.user | ||
.Rhistory | ||
.RData |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
Package: grnn | ||
Title: General regression neural network | ||
Description: The program GRNN implements the algorithm proposed by Specht | ||
(1991). | ||
URL: http://flow.chasset.net/r-grnn/ | ||
Version: 0.1.0 | ||
Author: Pierre-Olivier Chasset | ||
Maintainer: Pierre-Olivier Chasset <[email protected]> | ||
License: AGPL | ||
Collate: | ||
'create.R' | ||
'grnn-package.r' | ||
'guess.r' | ||
'kernel.R' | ||
'learn.R' | ||
'smooth.R' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export(guess) | ||
export(learn) | ||
export(smooth) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
grnn 0.1 | ||
======== | ||
|
||
* Package structure implemented. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
create.grnn <- function() { | ||
nn <- list( | ||
model="General regression neural network", | ||
set=NULL | ||
) | ||
return(nn) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#' GRNN | ||
#' | ||
#' General regression neural network. | ||
#' | ||
#' The program GRNN implements the algorithm proposed by Specht (1991). | ||
#' | ||
#' @author Pierre-Olivier Chasset | ||
#' @docType package | ||
#' @keywords Neural network, Regression | ||
#' @references Specht D.F. (1991). A general regression neural network. IEEE Transactions on Neural Networks, 2(6):568-576. | ||
#' @aliases grnn | ||
#' @name grnn-package | ||
NULL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#' Guess | ||
#' | ||
#' Infers the value of a new observation. | ||
#' | ||
#' @examples | ||
#' n <- 100 | ||
#' set.seed(1) | ||
#' x <- runif(n, -2, 2) | ||
#' y0 <- x^3 | ||
#' epsilon <- rnorm(n, 0, .1) | ||
#' y <- y0 + epsilon | ||
#' grnn <- learn(data.frame(y,x)) | ||
#' grnn <- smooth(grnn, sigma=0.1) | ||
#' guess(grnn, -2) | ||
#' guess(grnn, -1) | ||
#' guess(grnn, -0.2) | ||
#' guess(grnn, -0.1) | ||
#' guess(grnn, 0) | ||
#' guess(grnn, 0.1) | ||
#' guess(grnn, 0.2) | ||
#' guess(grnn, 1) | ||
#' guess(grnn, 2) | ||
#' @param nn A trained and smoothed General regression neural network. | ||
#' @param X A vector describing a new observation. | ||
#' @seealso \code{\link{grnn-package}} | ||
#' @export | ||
guess <- function(nn, X) { | ||
results <- Y(nn$Xa, nn$Ya, X, nn$sigma) | ||
return(results) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
ds <- function(Xa, X) { | ||
value <- (X - Xa) %*% t(X - Xa) | ||
return(as.numeric(value)) | ||
} | ||
|
||
pattern <- function(Xa, X, sigma) { | ||
res <- exp( - ds(Xa, X) / (2 * sigma ^ 2) ) | ||
return(as.numeric(res)) | ||
} | ||
|
||
patterns <- function(Xa, X, sigma) | ||
apply(Xa, 1, pattern, X, sigma) | ||
|
||
Y <- function(Xa, Ya, X, sigma) { | ||
p <- length(X) # Dimensionality of measurement space | ||
m <- length(Xa[,1]) # Total number of training patterns from category A | ||
patterns1 <- patterns(Xa, X, sigma) | ||
f <- sum(Ya * patterns1) / sum(patterns1) | ||
return(f) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#' Learn | ||
#' | ||
#' Create or update a General regression neural network. | ||
#' | ||
#' @param set Data frame representing the training set. The first column is used to define the category of each observation (set \code{category.column} if it is not the case). | ||
#' @param nn A General regression neural network with or without training. | ||
#' @param variable.column The field number of the variable (1 by default). | ||
#' @seealso \code{\link{grnn-package}} | ||
#' @export | ||
learn <- function(set, nn, variable.column=1) { | ||
if(missing(set)) stop("Set is missing!") | ||
if(missing(nn)) nn <- create.grnn() | ||
if(is.null(nn$set)) { | ||
nn$variable.column <- variable.column | ||
nn$set <- set | ||
} else { | ||
nn$set <- rbind(nn$set, set) | ||
} | ||
nn$Xa <- as.matrix(nn$set[,-nn$variable.column]) | ||
nn$Ya <- as.matrix(nn$set[,nn$variable.column]) | ||
nn$k <- length(nn$set[1,]) - 1 | ||
nn$n <- length(nn$set[,1]) | ||
return(nn) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#' Smooth | ||
#' | ||
#' Smooth a General regression neural network. | ||
#' | ||
#' @param nn A trained General regression neural network. | ||
#' @param sigma A scalar. | ||
#' @seealso \code{\link{grnn-package}} | ||
#' @export | ||
smooth <- function(nn, sigma) { | ||
if(!missing(sigma)) { | ||
nn$sigma <- sigma | ||
return(nn) | ||
} | ||
stop() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
bibentry("Manual", | ||
title = "GRNN: General regression neural network for the statistical software R", | ||
author = person("P.-O. Chasset"), | ||
organization = "Independant scientist", | ||
address = "Nancy, France", | ||
year = 2013, | ||
note = "Software", | ||
url = "http://flow.chasset.net/r-grnn/", | ||
|
||
mheader = "To cite the library GRNN in publications use:", | ||
|
||
mfooter = | ||
paste("We have invested a lot of time and effort in creating GRNN,", | ||
"please cite it when using it for data analysis.", sep = " ") | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
\docType{package} | ||
\name{grnn-package} | ||
\alias{grnn} | ||
\alias{grnn-package} | ||
\title{GRNN} | ||
\description{ | ||
General regression neural network. | ||
} | ||
\details{ | ||
The program GRNN implements the algorithm proposed by | ||
Specht (1991). | ||
} | ||
\author{ | ||
Pierre-Olivier Chasset | ||
} | ||
\references{ | ||
Specht D.F. (1991). A general regression neural network. | ||
IEEE Transactions on Neural Networks, 2(6):568-576. | ||
} | ||
\keyword{Neural} | ||
\keyword{Regression} | ||
\keyword{network,} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
\name{guess} | ||
\alias{guess} | ||
\title{Guess} | ||
\usage{ | ||
guess(nn, X) | ||
} | ||
\arguments{ | ||
\item{nn}{A trained and smoothed General regression | ||
neural network.} | ||
|
||
\item{X}{A vector describing a new observation.} | ||
} | ||
\description{ | ||
Infers the value of a new observation. | ||
} | ||
\examples{ | ||
n <- 100 | ||
set.seed(1) | ||
x <- runif(n, -2, 2) | ||
y0 <- x^3 | ||
epsilon <- rnorm(n, 0, .1) | ||
y <- y0 + epsilon | ||
grnn <- learn(data.frame(y,x)) | ||
grnn <- smooth(grnn, sigma=0.1) | ||
guess(grnn, -2) | ||
guess(grnn, -1) | ||
guess(grnn, -0.2) | ||
guess(grnn, -0.1) | ||
guess(grnn, 0) | ||
guess(grnn, 0.1) | ||
guess(grnn, 0.2) | ||
guess(grnn, 1) | ||
guess(grnn, 2) | ||
} | ||
\seealso{ | ||
\code{\link{grnn-package}} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
\name{learn} | ||
\alias{learn} | ||
\title{Learn} | ||
\usage{ | ||
learn(set, nn, variable.column = 1) | ||
} | ||
\arguments{ | ||
\item{set}{Data frame representing the training set. The | ||
first column is used to define the category of each | ||
observation (set \code{category.column} if it is not the | ||
case).} | ||
|
||
\item{nn}{A General regression neural network with or | ||
without training.} | ||
|
||
\item{variable.column}{The field number of the variable | ||
(1 by default).} | ||
} | ||
\description{ | ||
Create or update a General regression neural network. | ||
} | ||
\seealso{ | ||
\code{\link{grnn-package}} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
\name{smooth} | ||
\alias{smooth} | ||
\title{Smooth} | ||
\usage{ | ||
smooth(nn, sigma) | ||
} | ||
\arguments{ | ||
\item{nn}{A trained General regression neural network.} | ||
|
||
\item{sigma}{A scalar.} | ||
} | ||
\description{ | ||
Smooth a General regression neural network. | ||
} | ||
\seealso{ | ||
\code{\link{grnn-package}} | ||
} | ||
|