Learn R Programming

nnlib2Rcpp (version 0.1.8)

LVQs-class: Class "LVQs"

Description

Supervised Learning Vector Quantization (LVQ) NN module, for data classification.

Arguments

Extends

Class "'>RcppClass", directly.

All reference classes extend and inherit methods from "'>envRefClass".

Fields

.CppObject:

Object of class C++Object ~~

.CppClassDef:

Object of class activeBindingFunction ~~

.CppGenerator:

Object of class activeBindingFunction ~~

Methods

encode(data, desired_class_ids, training_epochs):

Encode input and output (classification) for a dataset using LVQ NN. Parameters are:

data: training data, a numeric matrix, (2d, cases in rows, variables in columns). Data should be in 0 to 1 range. desired_class_ids : vector of integers containing a desired class id for each training data case (row). Should contain integers in 0 to n-1 range, where n is the number of classes. training_epochs: integer, number of training epochs, aka presentations of all training data to the NN during training.

recall(data_in):

Get output (classification) for a dataset (numeric matrix data_in) from the (trained) LVQ NN. The data_in dataset should be 2-d containing data cases (rows) to be presented to the NN and is expected to have same number or columns as the original training data. Returns a vector of integers containing a class id for each case (row).

print():

print NN structure.

load(filename):

retrieve the NN from specified file.

save(filename):

save the NN to specified file.

The following methods are inherited (from the corresponding class): objectPointer ("RcppClass"), initialize ("RcppClass"), show ("RcppClass")

References

Simpson, P. K. (1991). Artificial neural systems: Foundations, paradigms, applications, and implementations. New York: Pergamon Press.

See Also

LVQu (unsupervised LVQ function).

Examples

Run this code
# NOT RUN {
# LVQ expects data in 0 to 1 range, so scale some numeric data...
iris_s<-as.matrix(iris[1:4])
c_min<-apply(iris_s,2,FUN = "min")
c_max<-apply(iris_s,2,FUN = "max")
c_rng<-c_max-c_min
iris_s<-sweep(iris_s,2,FUN="-",c_min)
iris_s<-sweep(iris_s,2,FUN="/",c_rng)

# create a vector of desired class ids (starting from 0):
iris_desired_class_ids<-as.integer(iris$Species)-1;

# now create the NN:
lvq<-new("LVQs")

# and train it:
lvq$encode(iris_s,iris_desired_class_ids,100)

# recall the same data (a simple check of how well the LVQ was trained):
lvq_recalled_class_ids<-lvq$recall(iris_s);
plot(iris_s, pch=lvq_recalled_class_ids, main="LVQ recalled clusters (module)")
# }

Run the code above in your browser using DataLab