title: frbs rule base or in R
body: <p>I've been trying to use the R Statistical software to build a fuzzy inference system(FIS). 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:</p>
  
  <p>I want to modify the Rule base from using 'and' to 'or'.  The modification is no problem but the frbs.gen command only seems to able to generate rules using 'and'. Although I saw in the help file rule base were some examples that used the 'or' logical operator. Here's the URL for the help file: <code>http://127.0.0.1:12572/library/frbs/html/rulebase.html</code></p>
  
  <p>when I rerun the <code>frbs.gen</code> command it seems to automatically still use the original rule base. It ignored the changes that I made to the <code>rule</code> variable and continues to use the 'and' logical operator even when I changed the rule base. T_T anybody else having the same issues?</p>
  
  <p>PS. Updated to the latest version of R(3.1.2) and even tried it on an older version R(3.0.2) but frbs.gen still won't use/allow the 'or' logical operator....</p>
  
  <p>Here's the full code.</p>
  
  <pre><code>&gt; demo(FRBS.Mamdani.Manual)
  
  
      demo(FRBS.Mamdani.Manual)
      ---- ~~~~~~~~~~~~~~~~~~~
  
  Type  &lt;Return&gt;   to start : 
  
  &gt;  ## This example shows how to use frbs without 
  &gt;  ## learning process.
  &gt;  ## Note: some variables might be shared for other examples.
  &gt; 
  &gt;  ## Define shape and parameters of membership functions of input variables.
  &gt;  ## Please see fuzzifier function to contruct the matrix.
  
  varinp.mf &lt;- matrix(c(2, 0, 20, 40, NA, 4, 20, 40, 60, 80, 3, 60, 80, 100, NA,
  +                        2, 0, 35, 75, NA, 3, 35, 75, 100, NA,
  +                        2, 0, 20, 40, NA, 1, 20, 50, 80, NA, 3, 60, 80, 100, NA,
  +                        2, 0, 20, 40, NA, 4, 20, 40, 60, 80, 3, 60, 80, 100, NA),
  +                        nrow = 5, byrow = FALSE)
  
  &gt;  ## Define number of fuzzy terms of input variables.
  &gt;  ## Suppose, we have 3, 2, 3, and 3 numbers of fuzzy terms 
  &gt;  ## for first, second, third and fourth variables, respectively.
  &gt;  num.fvalinput &lt;- matrix(c(3, 2, 3, 3), nrow=1)
  
  &gt;  ## Give the names of the fuzzy terms of each input variable.
  &gt;  ## It should be noted that the names of the fuzzy terms must be unique,
  &gt;  ## so we put a number for making it unique.
  &gt;  varinput.1 &lt;- c("a1", "a2", "a3")
  
  &gt;  varinput.2 &lt;- c("b1", "b2")
  
  &gt;  varinput.3 &lt;- c("c1", "c2", "c3")
  
  &gt;  varinput.4 &lt;- c("d1", "d2", "d3")
  
  &gt;  names.varinput &lt;- c(varinput.1, varinput.2, varinput.3, varinput.4)
  
  &gt;  ## Set interval of data.
  &gt;  range.data &lt;- matrix(c(0,100, 0, 100, 0, 100, 0, 100, 0, 100), nrow=2)
  
  &gt;  ## Set weighted average method to be used as defuzzification method.
  &gt;  type.defuz &lt;- "WAM"
  
  &gt;  ## We are using standard t-norm and s-norm.
  &gt;  type.tnorm &lt;- "MIN"
  
  &gt;  type.snorm &lt;- "MAX"
  
  &gt;  type.implication.func &lt;- "ZADEH"
  
  &gt;  ## Give the name of simulation.
  &gt;  name &lt;- "Sim-0"
  
  &gt;  ## Provide new data for testing. 
  &gt;  newdata&lt;- matrix(c(25, 40, 35, 15, 45, 75, 78, 70), nrow= 2, byrow = TRUE)
  
  &gt;  ## the names of variables
  &gt;  colnames.var &lt;- c("input1", "input2", "input3", "input4", "output1")
  
  &gt;  ###################################################################
  &gt;  ## 1. The following codes show how to generate a fuzzy model using the frbs.gen function
  &gt;  ## 1a. Using Mamdani Model 
  &gt;  ####################################################################
  &gt;  ## Define number of fuzzy terms of output variable.
  &gt;  ## In this case, we set the number of fuzzy terms to 3.
  &gt;  num.fvaloutput &lt;- matrix(c(3), nrow=1)
  
  &gt;  ## Give the names of the fuzzy terms of the output variable.
  &gt;  ## Note: the names of the fuzzy terms must be unique.
  &gt;  varoutput.1 &lt;- c("e1", "e2", "e3")
  
  &gt;  names.varoutput &lt;- c(varoutput.1)
  
  &gt;  ## Define the shapes and parameters of the membership functions of the output variables.
  &gt;  varout.mf &lt;- matrix(c(2, 0, 20, 40, NA, 4, 20, 40, 60, 80, 3, 60, 80, 100, NA),
  +                        nrow = 5, byrow = FALSE)
  
  &gt;  ## Set type of model which is 1 or 2 for Mamdani or Takagi Sugeno Kang model, respectively.
  &gt;  ## In this case, we choose Mamdani model.
  &gt;  type.model &lt;- "MAMDANI"
  
  &gt;  ## Define the fuzzy IF-THEN rules; 
  &gt;  ## there are two kinds of model: Mamdani and Takagi Sugeno Kang model
  &gt;  ## if we use the Mamdani model then the consequent part is a linguistic term,
  &gt;  ## but if we use Takagi Sugeno Kang then we build a matrix representing 
  &gt;  ## linear equations in the consequent part.
  &gt;  ## In this example we are using the Mamdani model 
  &gt;  ## (see the type.model parameter). 
  &gt;  ## Note:
  &gt;  ## "a1", "and", "b1, "-&gt;", "e1" means that "IF inputvar.1 is a1 and inputvar.2 is b1 THEN           outputvar.1 is e1" 
  &gt;  ## Make sure that each rule has a "-&gt;" sign. 
  &gt;  rule &lt;- matrix(c("a1","and","b1","and","c1","and","d1","-&gt;","e1",
  +                   "a2","and","b2","and","c2","and","d2", "-&gt;", "e2", 
  +                   "a3","and","b2","and","c2","and","d1", "-&gt;", "e3"), 
  +                   nrow=3, byrow=TRUE) 
  
  &gt;  ## Generate a fuzzy model with frbs.gen.
  &gt;  object &lt;- 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)
  
  &gt;  ## We can plot the membership function
  &gt;  plotMF(object)
  Waiting to confirm page change...
  
  &gt;  ## Predicting using new data.
  &gt;  res &lt;- predict(object, newdata)$predicted.val
  </code></pre>
  
  <p>End of R-demo file. The next part is where I adjust the rule base then rebuild the FIS before finally checking which rule base it used.</p>
  
  <pre><code>&gt; rule
       [,1] [,2]  [,3] [,4]  [,5] [,6]  [,7] [,8] [,9]
  [1,] "a1" "and" "b1" "and" "c1" "and" "d1" "-&gt;" "e1"
  [2,] "a2" "and" "b2" "and" "c2" "and" "d2" "-&gt;" "e2"
  [3,] "a3" "and" "b2" "and" "c2" "and" "d1" "-&gt;" "e3"
  &gt; rule &lt;- matrix(c("a1","or","b1","or","c1","or","d1","-&gt;","e1",         "a2","and","b2","and","c2","and","d2", "-&gt;", "e2", 
  + "a3","and","b2","and","c2","and","d1", "-&gt;", "e3"),
  + nrow=3, byrow=TRUE)
  &gt; rule
       [,1] [,2]  [,3] [,4]  [,5] [,6]  [,7] [,8] [,9]
  [1,] "a1" "or"  "b1" "or"  "c1" "or"  "d1" "-&gt;" "e1"
  [2,] "a2" "and" "b2" "and" "c2" "and" "d2" "-&gt;" "e2"
  [3,] "a3" "and" "b2" "and" "c2" "and" "d1" "-&gt;" "e3"
  &gt; object &lt;- 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)
  &gt; object
  $num.labels
       [,1] [,2] [,3] [,4] [,5]
  [1,]    3    2    3    3    3
  
  $varout.mf
       e1 e2  e3
  [1,]  2  4   3
  [2,]  0 20  60
  [3,] 20 40  80
  [4,] 40 60 100
  [5,] NA 80  NA
  
  
  
   $rule
       [,1] [,2]  [,3] [,4] [,5]  [,6][,7] [,8] [,9]  [,10]    [,11] [,12] [,13] [,14][,15]     [,16] [,17]  [,18][,19] [,20]
  [1,] "IF" "input1" "is" "a1" "and" "input2" "is" "b1" "and" "input3" "is"  "c1"  "and" "input4"              
  "is"  "d1"  "THEN" "output1" "is"  "e1" 
  [2,] "IF" "input1" "is" "a2" "and" "input2" "is" "b2" "and" "input3" "is"  "c2"  "and" "input4"     
  "is"  "d2"  "THEN" "output1" "is"  "e2" 
  [3,] "IF" "input1" "is" "a3" "and" "input2" "is" "b2" "and" "input3" "is"  "c2"  "and" "input4" 
  "is"  "d1"  "THEN" "output1" "is"  "e3" 
  
  $varinp.mf
       a1 a2  a3 b1  b2 c1 c2  c3 d1 d2  d3
  [1,]  2  4   3  2   3  2  1   3  2  4   3
  [2,]  0 20  60  0  35  0 20  60  0 20  60
  [3,] 20 40  80 35  75 20 50  80 20 40  80
  [4,] 40 60 100 75 100 40 80 100 40 60 100
  [5,] NA 80  NA NA  NA NA NA  NA NA 80  NA
  
  $range.data.ori
       [,1] [,2] [,3] [,4] [,5]
  [1,]    0    0    0    0    0
  [2,]  100  100  100  100  100
  
  $type.model
  [1] "MAMDANI"
  
  $type.tnorm
  [1] "MIN"
  
  $type.implication.func
  [1] "ZADEH"
  
  $type.mf
  [1] "MIX"
  
  $type.defuz
  [1] "WAM"
  
  $type.snorm
  [1] "MAX"
  
  $func.tsk
  NULL
  
  $method.type
  [1] "MANUAL"
  
  $name
  [1] "Sim-0"
  
  $colnames.var
  [1] "input1"  "input2"  "input3"  "input4"  "output1"
  
  $class
  function (x)  .Primitive("class")
  
  attr(,"class")
  [1] "frbs"
  </code></pre>