Skip to content

Commit

Permalink
Merge branch 'release/v0.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
chasset committed May 16, 2013
2 parents c5ee8f7 + 21fc715 commit 24557c4
Show file tree
Hide file tree
Showing 15 changed files with 254 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.Rproj.user
.Rhistory
.RData
16 changes: 16 additions & 0 deletions DESCRIPTION
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'
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export(guess)
export(learn)
export(smooth)
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
grnn 0.1
========

* Package structure implemented.
7 changes: 7 additions & 0 deletions R/create.R
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)
}
13 changes: 13 additions & 0 deletions R/grnn-package.r
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
30 changes: 30 additions & 0 deletions R/guess.r
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)
}
20 changes: 20 additions & 0 deletions R/kernel.R
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)
}
24 changes: 24 additions & 0 deletions R/learn.R
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)
}
15 changes: 15 additions & 0 deletions R/smooth.R
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()
}
15 changes: 15 additions & 0 deletions inst/CITATION
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 = " ")
)
23 changes: 23 additions & 0 deletions man/grnn-package.Rd
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,}

38 changes: 38 additions & 0 deletions man/guess.Rd
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}}
}

25 changes: 25 additions & 0 deletions man/learn.Rd
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}}
}

18 changes: 18 additions & 0 deletions man/smooth.Rd
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}}
}

0 comments on commit 24557c4

Please sign in to comment.