User Guide

Package FisPro 1.1.4

Jean-Luc Lablée, Serge Guillaume

Introduction

This package is the R implementation of functions to manage a Fuzzy Inference System (FIS) provided by the open source software FisPro.
FisPro allows to create Fuzzy Inference Systems and to use them for reasoning purposes, especially for simulating a physical or biological system.
In this brief User Guide we describe how to build and use a FIS to infer input values.
See Fuzzy Logic Elementary Glossary for more details about Fuzzy Logic.

library(FisPro)

Build a FIS from a configuration file

The FIS configuration file can be designed using the FisPro open source software.

fis_file <- system.file("extdata", "test.fis", package = "FisPro")
fis <- NewFis(fis_file)

Build a FIS from scratch

Create a new empty FIS.
The design must be completed using the available functions to add inputs, outputs and rules before it can be used for inference.

fis <- NewFis()
fis$name <- "foo"

Create inputs

Add 2 inputs to the FIS.

Create the first input with 2 MFs regular standardized fuzzy partition:

fisin1 <- NewFisIn(2, 0, 1)
fisin1$name <- "input1"
fis$add_input(fisin1)

Create the second input with 3 MFs:

fisin2 <- NewFisIn(0, 1)
fisin2$name <- "input2"

mf1 <- NewMfTrapezoidalInf(0, 0.5)
mf1$label <- "Low"
fisin2$add_mf(mf1)

mf2 <- NewMfTriangular(0, 0.5, 1)
mf2$label <- "Average"
fisin2$add_mf(mf2)

mf3 <- NewMfTrapezoidalSup(0.5, 1)
mf3$label <- "High"
fisin2$add_mf(mf3)

fis$add_input(fisin2)

Create outputs

Add 2 outputs to the FIS.

Create a crisp output with range [0, 1]:

fisout1 <- NewFisOutCrisp(0, 1)
fisout1$name <- "output1"
fis$add_output(fisout1)

Create a fuzzy output with 2 MFs regular standardized fuzzy partition in range [0, 1]:

fisout2 <- NewFisOutFuzzy(2, 0, 1)
fisout2$name <- "output2"
fis$add_output(fisout2)

Create the rule base

Add 2 rules to the FIS.
Each rule is initialized with a vector of premises and conclusions.
- a premise is the 1-based index of MF in the input [FisIn], 0 means the rule is incompelete.
- a conclusion is a numeric value for crisp output [FisOutCrisp], or the 1-based index of MF in the fuzzy output [FisOutFuzzy].
In this example the second rule is incomplete, the second input of the FIS has no effect on this rule.

fis$add_rule(NewRule(c(1, 2), c(0, 1)))
fis$add_rule(NewRule(c(2, 0), c(1, 2)))

Save the FIS configuration file

Save the FIS to the file “foo.fis”:

fis$save("foo.fis")

FIS inference

Infers all outputs:

inferred <- fis$infer(c(0.25, 0.75))

Infers first output:

inferred_output1 <- fis$infer_output(c(0.25, 0.75), 1)

Infers second output:

inferred_output2 <- fis$infer_output(c(0.25, 0.75), 2)

Infers dataset:

test_file <- system.file("extdata", "test_data.csv", package = "FisPro")
dataset <- read.csv(test_file)
inferred_dataset <- fis$infer(dataset)