ANFIS-class: ANFIS S4 class implementation in R

Description Slots Features Functions Author(s) See Also Examples

Description

Represent a concrete S4 class that represents an Adaptive Neuro Fuzzy Inference System in R, using type 3 Takagi and Sugeno's fuzzy if-then rule with multiple outputs.

Slots

premises

list with the MembershipFunctions for each input.

consequents

numeric matrix with nrow= #rules, ncol= #outputs.

rules

matrix with the connectivity of the membership functions to the rules.

X

input matrix with ncol=#inputs and nrow=#individuals.

Y

output matrix with ncol=#output and nrow=#individuals.

errors

numeric vector with training errors.

trainingType

character describing the training algorithm used: trainHybridJangOffLine, trainHybridOffLine or trainHybridJangOnLine.

fitted.values

numeric matrix with predicted values for training data X.

residuals

numeric matrix with residuals values for training data X.

call

call class object with training call.

Features

  1. Membership Functions (MF) flexible framework:

    • Flexible user-defined membership functions(MF) extensible class.

    • Independent number of (MF) for each input.

    • Different MF types, if required, for each input.

  2. Type 3 Takagi and Sugeno's fuzzy if-then rule

  3. Full Rule combinations, e.g. 2 inputs 2 membership functions this means that 4 fuzzy rules will be created.

  4. Different learning strategies:

    trainHybridJangOffLine

    Hybrid learning, i.e. Descent Gradient for precedents and Least Squares Estimation for consequents.

    trainHybridJangOnLine

    on-line version with hybrid learning.

    trainHybridOffLine

    Adaptive learning coefficient and momentum term.

  5. Multiple outputs support, i.e., the same input partition can be used to predict more than one output variable.

Functions

ANFIS S4 class includes the following functions:

initialize

constructor of ANFIS Architecture to generate the rule set and consequents

show/print

generic output of the object

getRules, getPremises, getConsequents, getErrors, getTrainingType

return the respective ANFIS slots

plotMF

plot MembershipFunctions domain

plotMFs

plot all the MembershipFunctions for the input domain

plot

plot training error according with training Type

LSE

auxiliary function for Least Square Estimation to avoid singular matrix system in off-line training

trainHybridJangOffLine

Jang's Hybrid off-line training

trainHybridJangOnLine

Jang's Hybrid on-line training

trainHybridOffLine

Hybrid off-line training with momentum and adaptive learning rate

summary, fitted, fitted.values, coef, coefficients, resid, residuals

wrappers for traditional model functions

Author(s)

Cristobal Fresno cfresno@bdmg.com.ar, Andrea S. Llera ALlera@leloir.org.ar and Elmer A. Fernandez efernandez@bdmg.com.ar

See Also

BellMF-class, GaussianMF-class and NormalizedGaussianMF-class

Other ANFIS: LSE, LSE, LSE,ANFIS-method, LSE-methods, trainHybridJangOffLine, trainHybridJangOffLine, trainHybridJangOffLine,ANFIS-method, trainHybridJangOffLine-methods, trainHybridJangOnLine, trainHybridJangOnLine, trainHybridJangOnLine,ANFIS-method, trainHybridJangOnLine-methods, trainHybridOffLine, trainHybridOffLine, trainHybridOffLine,ANFIS-method, trainHybridOffLine-methods; anfis3; coef, coef,ANFIS-method, coefficients, coefficients,ANFIS-method, fitted, fitted,ANFIS-method, fitted.values, fitted.values,ANFIS-method, resid, resid,ANFIS-method, residuals, residuals,ANFIS-method, summary, summary,ANFIS-method; getConsequents, getConsequents, getConsequents,ANFIS-method, getConsequents,ANFIS-method, getErrors, getErrors, getErrors,ANFIS-method, getErrors,ANFIS-method, getPremises, getPremises, getPremises,ANFIS-method, getPremises-methods, getRules, getRules, getRules,ANFIS-method, getRules-methods, getTrainingType, getTrainingType, getTrainingType,ANFIS-method, getTrainingType,ANFIS-method; initialize, initialize,ANFIS-method; plotMF, plotMF, plotMF,ANFIS-method, plotMF-methods, plotMFs, plotMFs, plotMFs,ANFIS-method, plotMFs-methods; plot, plot,ANFIS-method; predict, predict,ANFIS-method; print, print,ANFIS-method, show, show,ANFIS-method; trainSet

Examples

 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 2 cores using global options for parallel library
require("parallel")
if(.Platform$OS.type == "windows"){
 options(mc.cores=1)
}else{
 options(mc.cores=2) ##You could use all calling detectCores()
}

##Example domain for bidimentional sinc(x,y) function
x <- seq(-10, 10, length= 11)
trainingSet <- trainSet(x,x)
Z <- matrix(trainingSet[,"z"],ncol=length(x),nrow=length(x))
persp(x,x,Z,theta = 45, phi = 15, expand = 0.8, col = "lightblue",
 ticktype="detailed",main="sinc(x)*sinc(y)")

##Training domain patterns
X <- trainingSet[,1:2]
Y <- trainingSet[,3,drop=FALSE]

##Defining the required MembershipFunctions for the ANFIS
membershipFunction<-list(
 x=c(new(Class="NormalizedGaussianMF",parameters=c(mu=-10,sigma=2)),
   new(Class="NormalizedGaussianMF",parameters=c(mu=-5,sigma=2)),
   new(Class="NormalizedGaussianMF",parameters=c(mu=0,sigma=2)),
   new(Class="NormalizedGaussianMF",parameters=c(mu=5,sigma=2)),
   new(Class="NormalizedGaussianMF",parameters=c(mu=10,sigma=2))),
 y=c(new(Class="NormalizedGaussianMF",parameters=c(mu=-10,sigma=2)),
   new(Class="NormalizedGaussianMF",parameters=c(mu=-5,sigma=2)),
   new(Class="NormalizedGaussianMF",parameters=c(mu=0,sigma=2)),
   new(Class="NormalizedGaussianMF",parameters=c(mu=5,sigma=2)),
   new(Class="NormalizedGaussianMF",parameters=c(mu=10,sigma=2))))

##Creating the ANFIS network with 2 inputs and 4 MembershipFunctions in
##each input
anfis3 <- new(Class="ANFIS",X,Y,membershipFunction)
anfis3

##Check for epsilon-completeness in each input
plotMFs(anfis3)

##Training the ANFIS network.
trainOutput <- trainHybridJangOffLine(anfis3, epochs=10)
##We will use instead an already trained object to reduce example time.
data(anfis3)

##How the training went. You can keep on training as the training error
##is still descending.
plot(anfis3)

##Test the fit, i. e., how the MembershipFunctions partition the input space
plotMFs(anfis3)

##Just to see if premises, consequents and errors were updated
getPremises(anfis3)[[input=1]][[mf=1]]
getConsequents(anfis3)[1:2,]
getErrors(anfis3) #Training errors
getTrainingType(anfis3)
names(coef(anfis3))
##An alternative to get premises and/or consequents ...
coef(anfis3)$premises[[input=1]][[mf=1]]
coef(anfis3)$consequents[1:2,]

##First five train pattern associated values for the training process
fitted(anfis3)[1:5,]
resid(anfis3)[1:5,]
summary(anfis3)

##Surface comparison between the original training set and the predicted
##ANFIS network
y <- predict(anfis3,X)
z <- matrix(y[,1],ncol=length(x),nrow=length(x))
par(mfrow=c(1,2))
persp(x,x,Z,theta = 45, phi = 15, expand = 0.8, col = "lightblue",
 ticktype="detailed",main="Goal")
persp(x,x,z,theta = 45, phi = 15, expand = 0.8, col = "lightblue",
 ticktype="detailed",main="Fitted training Patterns", zlim=c(min(Z),max(Z)))

anfis documentation built on May 2, 2019, 2:38 a.m.

Related to ANFIS-class in anfis...