Fuzzy system in R

I am trying to create a fuzzy system in R using the "sets" packages. In my model, I have three types of fuzzy sets with three states each and with different โ€œuniversesโ€. When I draw the system, I have no problem, but when I try to draw a conclusion, I get this error: "Error in gset_charfun (x): The argument" x "must be a generic set." Does anyone have a solution to this problem ?. Here is the code.

library(sets)
U1 <- seq(from = 0, to = 1, by = 0.0001)
U2  <- seq(from = -0.5, to = 0.5, by = 0.001)

##  se definen los conjuntos difusos

variables <- set(produccion = fuzzy_variable(
                             bajo = fuzzy_trapezoid_gset(corners = c(-2, 0, 0.3, 0.6),universe=U1),
                             normal = fuzzy_trapezoid_gset(corners = c(0.4, 0.55, 0.55, 0.7), universe=U1), 
                             alto = fuzzy_trapezoid_gset(corners = c(0.5, 0.7, 1, -2), universe=U1)), 

tendencia = fuzzy_variable(bajo = fuzzy_trapezoid_gset(corners = c(-10, -0.4, -0.05, 0.1),universe=U2),
                           normal = fuzzy_triangular_gset(corners = c(-0.067, 0.067, 0.2), universe=U2), 
                           alto = fuzzy_trapezoid_gset(corners = c(0.1, 0.15, 0.15, -10), universe=U2) ) ,

zona = fuzzy_variable(roja = fuzzy_triangular_gset(corners = c(-2, 0, 0.33), universe=U1),
                      amarilla = fuzzy_triangular_gset(corners = c(0.33, 0.5, 0.66),universe=U1), 
                      verde = fuzzy_triangular_gset(corners = c(0.66, 1, 2), universe=U1))
)


## definir las reglas
reglas <-
        set(
                fuzzy_rule(produccion %is% alta || tendencia %is% alta, zona %is% verde),
                fuzzy_rule(produccion %is% alta || tendencia %is% baja, zona %is% amarilla), 
                fuzzy_rule(produccion %is% media|| tendencia %is% baja, zona %is% roja), 
                fuzzy_rule(produccion %is% baja || tendencia %is% alta, zona %is% verde), 
                fuzzy_rule(produccion %is% baja || tendencia %is% baj, zona %is% roja)

        )

## combina el sistema 


system <- fuzzy_system(variables, reglas)
print(system)
plot(system) ## plots variables

## se realiza la inferencia 
inferencia <- fuzzy_inference(system, list(produccion = 0.6, tendencia = 0.2))

## Error in gset_charfun(x) : Argument 'x' must be a generalized set.
+4
source share
1 answer

You just have a bunch of typos. Rule matching values โ€‹โ€‹must match your variable definitions. For example, you have three levels defined for "produccion"

  • bajo = fuzzy_trapezoid_gset(...)
  • normal = fuzzy_trapezoid_gset(...)
  • alto = fuzzy_trapezoid_gset(...)

however in your rules you refer to

  • produccion %is% alta
  • produccion %is% media
  • produccion %is% baja

. "tendencia".

+1

All Articles