##################################
## I. Regression Problem
## The data has two input variables and one output variable.
## We separate them into training, fitting, and testing data.
## data.train, data.fit, data.test, and range.data are inputs
## for all methods except the frcs method.
###################################
## The simulation might take a long time dependent on the hardware we use.
## We might get better results if we take other parameters.
data.train <- matrix(c(5.2, -8.1, 4.8, 8.8, -16.1, 4.1, 10.6, -7.8, 5.5, 10.4, -29.0,
5.0, 1.8, -19.2, 3.4, 12.7, -18.9, 3.4, 15.6, -10.6, 4.9, 1.9,
-25.0, 3.7, 2.2, -3.1, 3.9, 4.8, -7.8, 4.5, 7.9, -13.9, 4.8,
5.2, -4.5, 4.9, 0.9, -11.6, 3.0, 11.8, -2.1, 4.6, 7.9, -2.0,
4.8, 11.5, -9.0, 5.5, 10.6, -11.2, 4.5, 11.1, -6.1, 4.7, 12.8,
-1.0, 6.6, 11.3, -3.6, 5.1, 1.0, -8.2, 3.9, 14.5, -0.5, 5.7,
11.9, -2.0, 5.1, 8.1, -1.6, 5.2, 15.5, -0.7, 4.9, 12.4, -0.8,
5.2, 11.1, -16.8, 5.1, 5.1, -5.1, 4.6, 4.8, -9.5, 3.9, 13.2,
-0.7, 6.0, 9.9, -3.3, 4.9, 12.5, -13.6, 4.1, 8.9, -10.0,
4.9, 10.8, -13.5, 5.1), ncol = 3, byrow = TRUE)
data.fit <- matrix(c(10.5, -0.9, 5.2, 5.8, -2.8, 5.6, 8.5, -0.2, 5.3, 13.8, -11.9,
3.7, 9.8, -1.2, 4.8, 11.0, -14.3, 4.4, 4.2, -17.0, 5.1, 6.9,
-3.3, 5.1, 13.2, -1.9, 4.6), ncol = 3, byrow = TRUE)
data.test <- matrix(c(10.5, -0.9, 5.8, -2.8, 8.5, -0.2, 13.8, -11.9, 9.8, -1.2, 11.0,
-14.3, 4.2, -17.0, 6.9, -3.3, 13.2, -1.9), ncol = 2, byrow = TRUE)
range.data<-matrix(c(0.9, 15.6, -29, -0.2, 3, 6.6), ncol=3, byrow = FALSE)
#############################################################
## I.1 The example: Implementation of Wang & Mendel
#############################################################
method.type <- "WM"
## collect control parameters into a list
control.WM <- list(num.labels = 3, type.mf = 3, name = "Sim-0")
## generate the model and save it as object.WM
object.WM <- frbs.learn(data.train, range.data, method.type, control.WM)
#############################################################
## I.2 The example: Implementation of SBC
#############################################################
method.type <- "SBC"
control.SBC <- list(r.a = 0.5, eps.high = 0.5, eps.low = 0.15, name = "Sim-0")
object.SBC <- frbs.learn(data.train, range.data, method.type, control.SBC)
#############################################################
## I.3 The example: Implementation of HyFIS
#############################################################
method.type <- "HyFIS"
control.HyFIS <- list(num.labels = 5, max.iter = 50, step.size = 0.01,
name = "Sim-0")
object.HyFIS <- frbs.learn(data.train, range.data, method.type, control.HyFIS)
#############################################################
## I.4 The example: Implementation of ANFIS
#############################################################
method.type <- "ANFIS"
control.ANFIS <- list(num.labels = 5, max.iter = 100, step.size = 0.01,
name = "Sim-0")
object.ANFIS <- frbs.learn(data.train, range.data, method.type, control.ANFIS)
#############################################################
## I.5 The example: Implementation of DENFIS
#############################################################
control.DENFIS <- list(Dthr = 0.1, max.iter = 100, step.size = 0.001, d = 2,
name = "Sim-0")
method.type <- "DENFIS"
object.DENFIS <- frbs.learn(data.train, range.data, method.type, control.DENFIS)
#############################################################
## I.6 The example: Implementation of DM
#############################################################
method.type <- "DM"
control.DM <- list(num.labels = 5, max.iter = 100, step.size = 0.01, name = "Sim-0")
object.DM <- frbs.learn(data.train, range.data, method.type, control.DM)
#############################################################
## I.7 The example: Implementation of HGD
#############################################################
method.type <- "HGD"
control.HGD <- list(num.labels = 5, max.iter = 100, step.size = 0.01,
alpha.heuristic = 1, name = "Sim-0")
object.HGD <- frbs.learn(data.train, range.data, method.type, control.HGD)
#############################################################
## I.8 The example: Implementation of GFS
#############################################################
method.type <- "GFS"
control.GFS <- list(num.labels = 5, popu.size = 5, persen_cross = 0.9,
max.iter = 5, persen_mutant = 0.1,
classification = FALSE, name="sim-0")
object.GFS <- frbs.learn(data.train, range.data, method.type, control.GFS)
#############################################################
## I.9 The example: Implementation of MSGFS
#############################################################
method.type <- "MSGFS"
control.MSGFS <- list(popu.size = 15, persen_cross = 0.6,
max.iter = 20, persen_mutant = 0.3,
epsilon = 0.05, name="sim-0")
object.MSGFS <- frbs.learn(data.train, range.data, method.type, control.MSGFS)
#############################################################
## II. Classification Problem
#############################################################
## II.1 The example: Implementation of fuzzy rule-based classification systems (frcs)
## The iris dataset is shuffled and divided into training and
## testing data. Bad results in the predicted values may
## result from casual imbalanced classes in the training data.
data(iris)
irisShuffled <- iris[sample(nrow(iris)),]
irisShuffled[,5] <- unclass(irisShuffled[,5])
tra.iris <- irisShuffled[1:105,]
tst.iris <- irisShuffled[106:nrow(irisShuffled),1:4]
real.iris <- matrix(irisShuffled[106:nrow(irisShuffled),5], ncol = 1)
range.data.input <- matrix(c(4.3, 7.9, 2.0, 4.4, 1.0, 6.9, 0.1, 2.5), nrow=2)
## generate the model
method.type <- "FRCS"
control <- list(num.labels = 7, type.mf = 1)
object <- frbs.learn(tra.iris, range.data.input, method.type, control)
## conduct the prediction process
res.test <- predict(object, tst.iris)
Run the code above in your browser using DataLab