2016-03-10 2 views
0

Я пытаюсь реализовать систему нечетких выводов в R, используя пакет frbs. Вот мой код -Ошибка в функции вывода в пакете 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) 

Я получаю эту ошибку -

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

Error in MF[k, temp[j + 2]] : subscript out of bounds

Я взял справку из примера дать по этой ссылке - http://www.inside-r.org/packages/cran/frbs/docs/frbs.gen

Но пример работает нормально. Я не могу найти, что такое ошибка в моем коде.

ответ

0

Я нашел способ блокировать ошибку: уменьшить список правил, вплоть до 3-х элементов, как в примере :-(
Но до сих пор не знаю, почему
BTW создает некоторые дополнительные правила (до 5.!) в этом примере не вызывает ошибки.
Редактировать 16.07.199: я не повторяю все данные, но это, безусловно, связано с форматом данных/структуры.
Посмотрите формат данных/структуры примера и тщательно придерживайтесь этого формата для каждой создаваемой и отправляемой вами информации/структуры. Это должно решить вашу текущую ошибку.

Смежные вопросы