Anfis Manual
Anfis Manual
Anfis Manual
R topics documented:
ANFIS-class . tted . . . . . getRules . . . initialize . . . LSE . . . . . plot . . . . . plotMF . . . predict . . . . print . . . . . trainSet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 . 4 . 5 . 6 . 6 . 8 . 9 . 9 . 10 . 11
2 Index
ANFIS-class 12
ANFIS-class
Description Features: 1.- Independent number of membership functions(MF) for each input, and also different MF 2.- Type 3 Takagi and Sugenos fuzzy if-then rule. 3.- Full Rule combinations, e.g. 2 inputs 2 membership funtions -> 4 fuzzy rules. 4.- Hibrid learning, i.e. Descent Gradient for precedents and Least Squares Estimation for consequents. 5.- Multiple outputs. Details premises list with the MembershipFunctions for each input consequents numeric matrix with nrow= #rules, ncol= #outputs rules matrix with the conectivity 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) tted.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 Note Additional functions implemented: (initialize) constructur of ANFIS Architecture to regerate 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 trainnig error acording with training Type; (LSE) auxiliary function for Least Square Estimation to avoid singular matrix system in ofine training; (trainHybridJangOffLine) Jang Hybrid offline training; (trainHybridOffLine) Hybrid off-line training with momentum and adaptative learning rate; (trainHybridJangOnLine) Jang Hybrid on-line training; (summary, tted, tted.values, coef, coefcients, resid, residuals) wrappers for traditional model functions See Also BellMF-class, GaussianMF-class and NormalizedGaussianMF-class
ANFIS-class Examples
##Set 4 cores using global options for multicore options(cores=4) # ##Example domain for bidimentional sinc(x,y) function x <- seq(-1 , 1 , length= 11) trainingSet <- trainSet(x,x) Z <- matrix(trainingSet[,"z"],ncol=length(x),nrow=length(x)) ## Not run: persp(x,x,Z,theta = 45, phi = 15, expand = .8, col = "lightblue",ticktype="detailed",main="sinc(x)*sin # ##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=-1 ,sigma=2)), new(Class="NormalizedGaussianMF",parameters=c(mu=-5,sigma=2)), new(Class="NormalizedGaussianMF",parameters=c(mu= ,sigma=2)), new(Class="NormalizedGaussianMF",parameters=c(mu=5,sigma=2)), new(Class="NormalizedGaussianMF",parameters=c(mu=1 ,sigma=2))), y=c(new(Class="NormalizedGaussianMF",parameters=c(mu=-1 ,sigma=2)), new(Class="NormalizedGaussianMF",parameters=c(mu=-5,sigma=2)), new(Class="NormalizedGaussianMF",parameters=c(mu= ,sigma=2)), new(Class="NormalizedGaussianMF",parameters=c(mu=5,sigma=2)), new(Class="NormalizedGaussianMF",parameters=c(mu=1 ,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 ## Not run: plotMFs(anfis3) # ##Training the ANFIS network trainOutput <- trainHybridJangOffLine(anfis3, epochs=1 ) # ##How the training went ## Not run: plot(anfis3) # ##Test the fit ##MembershipFunctions ## Not run: plotMFs(anfis3) # ##Just to see if premises, consequents and errors were updated getPremises(anfis3)[[1]][[1]] getConsequents(anfis3)[1:2,] getErrors(anfis3) #Training errors getTrainingType(anfis3) names(coef(anfis3)) coef(anfis3)$premises[[input=1]][[mf=1]] coef(anfis3)$consequents[1:2,] #
tted
##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)) ## Not run: par(mfrow=c(1,2)) persp(x,x,Z,theta = 45, phi = 15, expand = .8, col = "lightblue",ticktype="detailed",main="Goal",xlim=c(-1 ,1 ),y persp(x,x,z,theta = 45, phi = 15, expand = .8, col = "lightblue",ticktype="detailed",main="Fitted training Pattern ## End(Not run)
fitted
Description Obtain ANFIS slot information, acording to training output Usage ## S4 method for signature ANFIS fitted.values(object, ...) ## S4 method for signature ANFIS coef(object, ...) ## S4 method for signature ANFIS coefficients(object, ...) ## S4 method for signature ANFIS resid(object, ...) ## S4 method for signature ANFIS residuals(object, ...) ## S4 method for signature ANFIS summary(object, ...) Arguments object ... ANFIS class object required by resid, residuals, coef and coefcients
getRules Value according to the call one of the following objects can be returned list numeric printed Note see full example in ANFIS-class list with premises and consequents numeric vector with trainnig errors, tted training values and residuals statistics of the training process
getRules
Description Obtain ANFIS slot information, acording to the given function call. Usage ## S4 method for signature ANFIS getRules(object) ## S4 method for signature ANFIS getPremises(object) ## S4 method for signature ANFIS getConsequents(object) ## S4 method for signature ANFIS getErrors(object) ## S4 method for signature ANFIS getTrainingType(object) Arguments object Value according to the call one of the following objects can be returned matrix list character numeric numeric matrix with rules or consequents list with MembershipFunctions or premises and consequents name of the trainingType numeric vector with trainnig errors, tted training values and residuals ANFIS class object
LSE
initialize
Description Create the ANFIS object arquitecture for the trainingSet (X,Y) with full rules Arguments .Object X Y ANFIS class input matrix with ncol=#inputs and nrow=#individuals output matrix with ncol=#output and nrow=#individuals
membershipFunction list with the MembershipFunction for each input Value ANFIS object Note see full example in ANFIS-class See Also ANFIS-class
LSE
Description ANFIS on-line or off-line hybrid Jang dinamic learning training process. In addition for off-line learning there is also adaptative learning coecient and momentum term.
LSE Usage ## S4 method for signature ANFIS LSE(object, A, B, initialGamma = 1 ) ## S4 method for signature ANFIS trainHybridJangOffLine(object, epochs = 5, tolerance = 1e- 5, initialGamma = 1 k = . 1)
## S4 method for signature ANFIS trainHybridOffLine(object, epochs = 5, tolerance = 1e- 5, initialGamma = 1 , eta = . 5, phi = .2, a = . 1, b = .1, delta_alpha_t_1 = list()) ## S4 method for signature ANFIS trainHybridJangOnLine(object, epochs = 5, tolerance = 1e-15, initialGamma = 1 , k = . 1, lamda = .9, S = matrix(nrow = , ncol = )) Arguments object ANFIS class object A internal matrix for Iterative Least Squares Estimation of the system AX=B B internal matrix for Iterative Least Squares Estimation of the system AX=B initialGamma numeric large number 0. Default 1000 epochs the max number of training epochs. Default 5 tolerance convergence error to stop training. Default 1e-5 k numeric with the initial step size for the learning rule. Default 0.01 eta numeric learning rule coefcient. Default 0.05 phi numeric momentum rule coefcient. Default 0.2 a numeric step to increase eta if delta_e is < 0, i.e. descending. Default 0.01 b numeric fraction to decrease eta if delta_e is > 0, i.e. ascending. Default 0.1 delta_alpha_t_1 list with numeric matrix with last time step. Default list() lamda 0 < numeric < 1 forgetting factor. Default 0.9 S covariance matrix for on-line LSE. Default matrix(nrow=0,ncol=0) Value matrix error convergence updated with the system solution for LSE output numeric vector with training asociated errors (pattern or epoch) according to trainingType TRUE/FALSE if it reached convergence or not trainingType, premises, consequents, error, residuals, tted.values and coefcient
plot
plot
Description Plot the trainning error of the network. If trainingType is "on-line" then full pattern errors along the patterns of the whole training process; for a specic epoch or the epoch summary error
Arguments x y epoch ... ANFIS class object not used but necesary for redening the generic function for on-line only: epoch == Inf the whole training error; epoch == integer > 0 the give epoch trainings errors, epoch == 0 the abs epoch trainnig sum of errors. plot aditional parameters
plotMF
plotMF
Description Plot the corresponding MembershipFunctions for each/all input/s domain Usage ## S4 method for signature ANFIS plotMF(object, x, input, ...) ## S4 method for signature ANFIS plotMFs(object, ...) Arguments object x input ... Value output graphics Note see full example in ANFIS-class See Also ANFIS-class ANFIS class object numeric sequence to evaluate each MembershipFunction integer with the input MembershipFunctions to plot plot aditional parameters
predict
Description Foward Pass to predict the ANFIS output Arguments object x ANFIS class object numeric matrix [patterns x inputs] of input patterns
Description Generic Print/Show Method for ANFIS class output visualization. Usage: print(x, ...), show(object,...)
Arguments x object ... ANFIS class object ANFIS class object not used but included for generic print comparitibility
trainSet
11
trainSet
Description Generates the training set of sinc(x)*sinc(y) for the (x,y) regular grid Usage trainSet(x, y) Arguments x y Value matrix Examples
##Domain definition for a regular (x,y) grid with 11 points for each coordenates x <- seq(-1 , 1 , length= 11) trainingSet <- trainSet(x,x) Z <- matrix(trainingSet[,"z"],ncol=length(x),nrow=length(x)) ##Ploting the domain persp(x,x,Z,theta = 45, phi = 15, expand = .8, col = "lightblue",ticktype="detailed",main="sinc(x)*sinc(y)")
numeric vector with the x-th grid coordenates numeric vector with the x-th grid coordenates
Index
ANFIS-class, 5, 6, 810 ANFIS-class, 2 BellMF-class, 2 coef (fitted), 4 coef,ANFIS-method (fitted), 4 coefficients (fitted), 4 coefficients,ANFIS-method (fitted), 4 fitted, 4 fitted,ANFIS-method (fitted), 4 fitted.values (fitted), 4 fitted.values,ANFIS-method (fitted), 4 GaussianMF-class, 2 getConsequents (getRules), 5 getConsequents,ANFIS-method (getRules), 5 getErrors (getRules), 5 getErrors,ANFIS-method (getRules), 5 getPremises (getRules), 5 getPremises,ANFIS-method (getRules), 5 getPremises-methods (getRules), 5 getRules, 5 getRules,ANFIS-method (getRules), 5 getRules-methods (getRules), 5 getTrainingType (getRules), 5 getTrainingType,ANFIS-method (getRules), 5 initialize, 6 initialize,ANFIS-method (initialize), 6 LSE, 6 LSE,ANFIS-method (LSE), 6 LSE-methods (LSE), 6 NormalizedGaussianMF-class, 2 plot, 8 12 plot,ANFIS-method (plot), 8 plotMF, 9 plotMF,ANFIS-method (plotMF), 9 plotMF-methods (plotMF), 9 plotMFs (plotMF), 9 plotMFs,ANFIS-method (plotMF), 9 plotMFs-methods (plotMF), 9 predict, 9 predict,ANFIS-method (predict), 9 print, 10 print,ANFIS-method (print), 10 resid (fitted), 4 resid,ANFIS-method (fitted), 4 residuals (fitted), 4 residuals,ANFIS-method (fitted), 4 show (print), 10 show,ANFIS-method (print), 10 summary (fitted), 4 summary,ANFIS-method (fitted), 4 trainHybridJangOffLine (LSE), 6 trainHybridJangOffLine,ANFIS-method (LSE), 6 trainHybridJangOffLine-methods (LSE), 6 trainHybridJangOnLine (LSE), 6 trainHybridJangOnLine,ANFIS-method (LSE), 6 trainHybridJangOnLine-methods (LSE), 6 trainHybridOffLine (LSE), 6 trainHybridOffLine,ANFIS-method (LSE), 6 trainHybridOffLine-methods (LSE), 6 trainSet, 11