###########################################################
## Example 1: Dataset containing nominal values for
## all attributes.
###########################################################
## Decision table is represented as data frame
dt.ex1 <- data.frame(c(1,0,2,1,1,2,2,0), c(0, 1,0, 1,0,2,1,1),
c(2,1,0,0,2,0,1,1), c(2,1,1,2,0,1,1,0), c(0,2,1,2,1,1,2,1))
colnames(dt.ex1) <- c("aa", "bb", "cc", "dd", "ee")
decision.table <- SF.asDecisionTable(dataset = dt.ex1, decision.attr = 5)
## In this case, we only consider the second and third attributes.
attributes <- c(2, 3)
#### calculate fuzzy indiscernibility relation ####
## in this case, we are using "crisp" as a type of relation and type of aggregation
control.ind <- list(type.relation = c("crisp"), type.aggregation = c("crisp"))
IND <- BC.IND.relation.FRST(decision.table, attribute = attributes, control = control.ind)
###########################################################
## Example 2: Dataset containing real-valued attributes
###########################################################
dt.ex2 <- data.frame(c(-0.4, -0.4, -0.3, 0.3, 0.2, 0.2),
c(-0.3, 0.2, -0.4, -0.3, -0.3, 0),
c(-0.5, -0.1, -0.3, 0, 0, 0),
c("no", "yes", "no", "yes", "yes", "no"))
colnames(dt.ex2) <- c("a", "b", "c", "d")
desc.attributes <- list(a = c(-0.4, 0.3), b = c(-0.4, 0.2),
c = c(-0.5, 0), d = c("no", "yes"))
decision.table <- SF.asDecisionTable(dataset = dt.ex2, decision.attr = 4)
## in this case, we only consider the first and second attributes
attributes <- c(1, 2)
#### Calculate fuzzy indiscernibility relation ####
## in this case, we choose "tolerance" relation and "eq.1" as similarity equation
## and "lukasiewicz" as t-norm of type of aggregation
control.ind <- list(type.aggregation = c("t.tnorm", "lukasiewicz"),
type.relation = c("tolerance", "eq.1"))
IND.1 <- BC.IND.relation.FRST(decision.table, attributes = attributes,
control = control.ind)
#### Calculate fuzzy indiscernibility relation: gaussian kernel ####
control.ind <- list(type.aggregation = c("t.tnorm", "t.cos"),
type.relation = c("transitive.kernel", "gaussian", 0.2))
IND.2 <- BC.IND.relation.FRST(decision.table, attributes = attributes,
control = control.ind)
#### calculate fuzzy transitive closure ####
control.ind <- list(type.aggregation = c("t.tnorm", "lukasiewicz"),
type.relation = c("transitive.closure", "eq.1"))
IND.3 <- BC.IND.relation.FRST(decision.table, attributes = attributes,
control = control.ind)
#### Calculate fuzzy indiscernibility relation: using user-defined relation #####
## The customized function should have three arguments which are : decision.table
## and object x, and y.
## This following example shows that we have an equation for similarity equation:
## 1 - abs(x - y) where x and y are two objects that will be compared.
## In this case, we do not consider decision.table in calculation.
FUN.relation <- function(decision.table, x, y) {
return(1 - (abs(x - y)))
}
control.ind <- list(type.aggregation = c("t.tnorm", "lukasiewicz"),
type.relation = c("custom", FUN.relation))
IND.4 <- BC.IND.relation.FRST(decision.table, attributes = attributes,
control = control.ind)
#### The other example using "custom"
## In this case, we calculate aggregation as average of all objects
FUN.average <- function(data){
return(Reduce("+", data)/length(data))
}
control.ind <- list(type.aggregation = c("custom", FUN.average),
type.relation = c("tolerance", "eq.1"))
IND.5 <- BC.IND.relation.FRST(decision.table, attributes = attributes,
control = control.ind)
#### Calculate fuzzy indiscernibility relation: using user-defined tnorms ####
FUN.tnorm <- function(left.side, right.side) {
if ((left.side + right.side) > 1)
return(min(left.side, right.side))
else return(0)}
control.ind <- list(type.aggregation = c("t.tnorm", FUN.tnorm),
type.relation = c("tolerance", "eq.1"))
IND.6 <- BC.IND.relation.FRST(decision.table, attributes = attributes,
control = control.ind)
##################################################################
## Example 3: Dataset containing continuous and nominal attributes
## Note. we only consider type.relation = c("tolerance", "eq.1")
## but other approaches have the same way.
##################################################################
data(RoughSetData)
decision.table <- RoughSetData$housing7.dt
## in this case, we only consider the attribute: 1, 2, 3, 4
attributes <- c(1,2,3,4)
#### Calculate fuzzy indiscernibility relation ####
control.ind <- list(type.aggregation = c("t.tnorm", "lukasiewicz"),
type.relation = c("tolerance", "eq.1"))
IND.6 <- BC.IND.relation.FRST(decision.table, attributes = attributes, control = control.ind)
Run the code above in your browser using DataLab