2

I've been trying to use the R Statistical software to build a Takagi Sugeno fuzzy system. Using the R package 'frbs' I've managed to set up the most of components of the FIS following the example in the demo files. Unfortunately I've hit a problem: Error in validate.params(object, newdata) : Please check your num.labels parameters I've been trying to predict some value, and I don't know what is wrong in this script. When i comment the last line everything seems to be ok, but only one plot is drawing.

#  rm(list=ls())  # not generally appreciated
library(frbs)
varinp.mf <- matrix(c( 5, -1, 0.8493, NA, NA, 5, 1, 0.8493, NA, NA,
                       5, -1, 0.8493, NA, NA, 5, 1, 0.8493, NA, NA),
                    nrow = 5, byrow = FALSE)
num.fvalinput <- matrix(c(2,2), nrow=1)
x1 <- c("a1","a2")
x2 <- c("b1","b2")
names.varinput <- c(x1, x2)
range.data <- matrix(c(-1.5,1.5, -1.5, 1.5), nrow=2)
type.defuz <- "5"
type.tnorm <- "MIN"
type.snorm <- "MAX"
type.implication.func <- "MIN"
name <- "Przykład"
newdata <- matrix(c(-0.6, 0.3), ncol = 2, byrow = TRUE)
colnames.var <- c("x1", "x2")
type.model <- "TSK"
func.tsk <- matrix(c(1,   1,  1,
                     2,   1,  0,
                     1,  -2, -1,
                    -1, 0.5, -2),
                   nrow = 4, byrow = TRUE)

rule <- matrix(c("A1","and","B1","->",  
                 "A1","and","B2","->", 
                 "A2","and","B1","->",  
                 "A2","and","B2","->"),
                 nrow = 4, byrow = TRUE)
object <- frbs.gen( range.data, num.fvalinput, names.varinput,
                  num.fvaloutput, varout.mf=NULL, names.varoutput, rule,
                 varinp.mf, type.model, type.defuz, type.tnorm, type.snorm,
                  func.tsk, colnames.var, type.implication.func)



plotMF(object)
res <- predict(object, newdata)$predicted.val
IRTFM
  • 258,963
  • 21
  • 364
  • 487
Garbaczyk
  • 31
  • 4
  • Why's this tagged MATLAB? – Adriaan Jan 05 '16 at 17:46
  • I hope someone in MATLAB tag, know what is wrong – Garbaczyk Jan 05 '16 at 17:50
  • 1
    As it's not written in MATLAB, that is not going to work. I have removed the tag. – Adriaan Jan 05 '16 at 17:51
  • @Garbaczyk You can't assume that anyone in the MATLAB tag is also a `R` programmer. That's like tagging for example a question with both Python and Microsoft VBA... yeah, pairing the two is a bit nonsensical right? The same goes for here. You can't tag questions in conflicting languages unless your question specifically deals with both. Your question only deals with `R` only. – rayryeng Jan 05 '16 at 17:56
  • ok it was my mistake, so I will not do things like that in the future – Garbaczyk Jan 05 '16 at 18:01
  • 1
    Using R functions debugging is often assisted when one supplies arguments to function using pairlists with their named parameters. So you might start by not using positional matching of the `object <- frbs.gen( range.data, num.fvalinput, names.varinput, ...` call. You should also post the entire error message and indicate what function throws the error. I edited you question to comment the destructive code at the top. That tends to annoy people when left in. – IRTFM Jan 05 '16 at 18:07
  • This is the error: Error in validate.params(object, newdata) : Please check your num.labels parameters. But num.labels isn't using in this script. – Garbaczyk Jan 05 '16 at 18:10
  • `num.labels` is an item name in the retruned object from `frbs.gen` – IRTFM Jan 05 '16 at 18:32
  • It seems to be ok. I need to draw 2 MF grade functions, in 2 plots, so values in num.labels need to be 2,2 – Garbaczyk Jan 05 '16 at 18:37

1 Answers1

0

The test that is failing is seen in the validate.params code:

frbs:::validate.params
....
else if (object$type.model == c("TSK")) {
    if (ncol(object$num.labels) != (ncol(object$range.data.ori) - 
        1)) {
        stop("Please check your num.labels parameters")

When I run the code in the example on the frbs.gen help page I then see:

> res <- predict(object, newdata)$predicted.val
> object$range.data.ori
     [,1] [,2] [,3] [,4] [,5]
[1,]    0    0    0    0    0
[2,]  100  100  100  100  100
> object$num.labels
     [,1] [,2] [,3] [,4]
[1,]    3    2    3    3

Whereas with you example I see:

> object$num.labels
     [,1] [,2]
[1,]    2    2
> object$range.data.ori
     [,1] [,2]
[1,] -1.5 -1.5
[2,]  1.5  1.5

So your 'object'-object was not created according to the package author's expectations. Seems that the error should have been caught earlier in the process, rather than letting it get signaled by predict.frbs.

IRTFM
  • 258,963
  • 21
  • 364
  • 487
  • Ok, i add range data to output and now it seems to be ok. But now i have another problem with prediction. Something is wrong with rule Error in rule[, (4 * i), drop = FALSE] : subscript out of bounds – Garbaczyk Jan 05 '16 at 19:24