# Defining two different types of membership functions
trap_mf <- function(a, b, c, d) {
function(x) {
pmax(pmin((x - a)/(b - a), 1, (d - x)/(d - c), na.rm = TRUE), 0)
}
}
trim_mf <- function(a, b, c) {
function(x) {
pmax(pmin((x - a)/(b - a), (c - x)/(c - b), na.rm = TRUE), 0)
}
}
# Creating the FSI model
fsi <- fsi_create("To visit or not to visit, that is the question",
default_conseq = trim_mf(10, 30, 60))
# Creating the vector with the linguistic values of the linguistic variable "visiting experience"
lvals_visiting_exp <- c("awful", "average", "great")
# Defining the membership function for each linguistic value
awful_mf <- trim_mf(0, 0, 20)
average_mf <- trim_mf(10, 30, 60)
great_mf <- trap_mf(40, 80, 100, 100)
# Adding the consequent to the FSI model
fsi <- fsi_add_cs(fsi, "visiting experience", lvals_visiting_exp,
c(awful_mf, average_mf, great_mf), c(0, 100))
Run the code above in your browser using DataLab