R模糊集 - 无法绘制模糊多重集的元组

时间:2016-09-02 17:28:32

标签: r fuzzy-logic

我正在尝试使用R的模糊集功能来实现this example。代码:

sets_options("universe", seq(from = -200, to = 200, by = 1))
#------------------------------------------------------------------------------------------
# Fuzzy Variables
variables <-
  set (
    temp = fuzzy_variable(cold   = fuzzy_trapezoid(corners=c(-101, -100, 40, 70)),
                          ok     = fuzzy_triangular(corners=c(40,70,100)),
                          hot    = fuzzy_trapezoid(corners=c(70, 100, 200, 201))),
    ctrl = fuzzy_variable(small  = fuzzy_triangular(corners=c(-50,0,50)),
                          med    = fuzzy_triangular(corners=c(0, 50, 100)),
                          large  = fuzzy_triangular(corners=c(50, 100, 150)))
  )

#------------------------------------------------------------------------------------------
# Fuzzy Rules
rules <-
  set(
    fuzzy_rule(temp %is% cold, ctrl %is% large),
    fuzzy_rule(temp %is% ok,   ctrl %is% med),
    fuzzy_rule(temp %is% hot,  ctrl %is% small)
  )

#------------------------------------------------------------------------------------------
# Set up Fuzzy System
system <- fuzzy_system(variables, rules)
print(system)
plot(system)

#------------------------------------------------------------------------------------------
# Example
# If the measured temperature is 80 degrees, what's the control effort?
fi <- fuzzy_inference(system, list(temp=80))
## plot resulting fuzzy set
plot(fi)
## defuzzify
gset_defuzzify(fi, "centroid")

## reset universe
sets_options("universe", NULL)

然而,当我运行它时,我得到两个错误:

> plot(system)
Error in lines.tuple(as.tuple(x), ...) : 
  Cannot plot tuple of fuzzy multisets.
> fi <- fuzzy_inference(system, list(temp=80))
Error in rep.int(0, len - length(ret)) : invalid 'times' value

我有点难过。找到this看起来像一个类似的问题,但我在上面看不到拼写错误。

任何帮助表示赞赏。谢谢。在重要的情况下在Windows上使用R v3.2.4。

1 个答案:

答案 0 :(得分:2)

这是一个环境问题。重置RStudio环境&amp;有效。在这里留下Q&amp; A以防万一有人看到同样的事情。