Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
frbs包-R中的推理函数出错_R_Fuzzy Logic - Fatal编程技术网

frbs包-R中的推理函数出错

frbs包-R中的推理函数出错,r,fuzzy-logic,R,Fuzzy Logic,我正在尝试使用frbs包在R中实现一个模糊推理系统。 这是我的密码- varinp.mf <- matrix(c(1,1,1,1,3,1,1,4,3,1,1,1,1,3,1,4,4,3, 0,20,40,70,85,0,5,30,65,0,25,40,70,85,0,20,45,70, 15,35,65,85,95,5,25,45,90,20,30,50,75,95,15,30,50,90,

我正在尝试使用frbs包在R中实现一个模糊推理系统。 这是我的密码-

varinp.mf <- matrix(c(1,1,1,1,3,1,1,4,3,1,1,1,1,3,1,4,4,3,
                  0,20,40,70,85,0,5,30,65,0,25,40,70,85,0,20,45,70,
                  15,35,65,85,95,5,25,45,90,20,30,50,75,95,15,30,50,90,
                  30,45,75,90,0,10,35,65,90,30,45,75,90,100,25,40,65,100,
                  0,0,0,0,0,0,0,75,100,0,0,0,0,0,0,50,75,0
 ), nrow=5, byrow=TRUE)

 ## Define number of linguistic terms of input variables.
num.fvalinput <- matrix(c(5, 4, 5, 4), nrow=1)

varinput.1 <- c("veryPoor", "Poor", "Average","Good","veryGood")
varinput.2 <- c("Less", "Average", "Many", "aLot")
varinput.3 <- c("veryPoor", "Poor", "Average","Good","veryGood")
varinput.4 <- c("Less", "Average", "More","High")
names.varinput <- c(varinput.1, varinput.2, varinput.3, varinput.4)

## Set interval of data.
range.data <- matrix(c(0, 100, 0, 100, 0, 100, 0, 100, 0, 100), nrow = 2)

 ## Define inference parameters.
 ## Detailed information about values can be seen in the inference function.
type.defuz <- "WAM"
type.tnorm <- "MIN"
type.snorm <- "MAX"
type.implication.func <- "ZADEH"

## Give the name of simulation.
name <- "Sim-0"

## the names of variables
colnames.var <- c("Hotel_Facility_Score", "Visited_Count", "Room_facility_score", "Average_price", "Relative_Class")

## Define number of linguistic terms of output variable.
## In this case, we set the number of linguistic terms to 3.
num.fvaloutput <- matrix(c(5), nrow = 1)

## Give the names of the linguistic terms of the output variable.
varoutput.1 <- c("veryGood", "Good", "Average","Poor","veryPoor")
names.varoutput <- c(varoutput.1)


## Define the shapes and parameters of the membership functions of the output variables.
varout.mf <- matrix(c(5,5,5,5,5,
                  95,75,55,35,20,
                  4,8,5,7,5,
                  0,0,0,0,0,
                  0,0,0,0,0),
                nrow = 5, byrow = TRUE)

## Define the fuzzy IF-THEN rules;

rule <- matrix(
 c("veryGood", "and", "aLot", "and", "veryGood", "and", "less", "->", "veryGood",
"veryGood", "and", "Many", "and", "veryGood", "and", "Average", "->", "veryGood",
"veryGood", "and", "aLot", "and", "veryGood", "and", "Average", "->", "Good",
"veryGood", "and", "aLot", "and", "veryGood", "and", "Less", "->", "Good",
"Good", "and", "Many", "and", "Good", "and", "Less", "->", "Good",
"Good", "and", "aLot", "and", "Good", "and", "Average", "->", "Good",
"Average", "and", "aLot", "and", "Good", "and", "Less", "->", "Average",
"veryGood", "and", "Average", "and", "veryGood", "and", "More", "->", "Average",
"Good", "and", "Many", "and", "Good", "and", "Average", "->", "Average",
"Average", "and", "Average", "and", "Average", "and", "More", "->", "Poor",
"Good", "and", "Many", "and", "vGood", "and", "High", "->", "Poor",
"Average", "and", "Average", "and", "Average", "and", "High", "->", "Poor",
"Poor", "and", "Less", "and", "Poor","and", "High", "->", "veryPoor",
"veryPoor", "and", "Less", "and", "veryPoor", "and", "High", "->", "veryPoor"),
  nrow = 14, byrow = TRUE)

## Set type of model which is "MAMDANI".
type.model <- "MAMDANI"



## Generate a fuzzy model with frbs.gen.
object <- frbs.gen(range.data, num.fvalinput, names.varinput,
               num.fvaloutput, varout.mf, names.varoutput, rule,
               varinp.mf, type.model, type.defuz, type.tnorm,
               type.snorm, func.tsk = NULL, colnames.var, type.implication.func, name)

## Plot the membership function.
plotMF(object)


newdata <- matrix(c(15, 80, 85, 85, 45, 75, 78, 70), nrow = 2, byrow = TRUE)

## Fuzzification Module:

num.varinput <- ncol(num.fvalinput)
MF <- fuzzifier(newdata, num.varinput, num.fvalinput, varinp.mf)


## Check input data given by user.
ruleb <- rulebase(type.model, rule, func.tsk = NULL)


## Inference Module:
miu.rule <- inference(MF, ruleb, names.varinput, type.tnorm, type.snorm)

varinp.mf我找到了一种阻止错误的方法:将规则列表减少到3个元素,如示例所示:-(.
但还是不知道为什么!
顺便说一句,在示例中创建一些附加规则(最多5条)不会触发错误。
编辑19年7月16日:我没有重新测试全部内容,但这肯定与数据/结构格式有关。
查看示例中的数据/结构格式,对于您创建并发送到包中的每个数据/结构,都要完全遵循此格式。这将解决您当前的错误