Fis {FisPro} | R Documentation |
Class "Fis"
Description
Class to manage a Fis "Fuzzy Inference System"
Fields
name
character vector, The name of the Fis
conjunction
character vector, The conjunction operator of rules in the Fis
Allowed values are: "min" (the default), "prod" or "luka"
Constructors
Fis()
-
The default constructor to build an empty Fis
The Fis is initialized with "min" conjunction and empty name
The design must be completed using the available functions to add inputs, outputs and rules before it can be used for inference- return:
Fis object
Fis(fis_file)
-
The constructor to build a Fis from a configuration file
The configuration file can be designed using the FisPro open source software
Methods
input_size()
-
- return:
integer value, The number of inputs in the Fis
add_input(input)
-
- argument:
input
FisIn object, The input to add in the Fis
- argument:
get_input(input_index)
get_inputs()
-
Get all inputs in the Fis
output_size()
-
- return:
integer value, The number of outputs in the Fis
add_output(output)
-
- argument:
output
FisOut object, The output to add in the Fis
- argument:
get_output(output_index)
get_outputs()
-
Get all outputs in the Fis
rule_size()
-
- return:
integer value, The number of rules in the Fis
add_rule(rule)
-
- argument:
rule
Rule object, The rule to add in the Fis
- argument:
get_rule(rule_index)
get_rules()
-
Get all rules in the Fis
infer(data)
-
Infers all outputs
- argument:
data
numeric vector, matrix or data.frame, The input data or dataset to infer (the vector length or the number of columns must be equal to the number of inputs)
- return:
- argument:
infer_output(data, output_index)
-
Infers a single output
- argument:
data
numeric vector, matrix or data.frame, The input data or dataset to infer (the vector length or the number of columns must be equal to the number of inputs)
- argument:
output_index
integer value, The index (1-based index) of the output to infer
- return:
numeric value or vector (in case of 2D input data)
- argument:
See Also
Fuzzy Logic Elementary Glossary
Examples
# build a Fis from a configuration file
fis_file <- system.file("extdata", "test.fis", package = "FisPro")
fis <- NewFis(fis_file)
# 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 test_data dataset
test_file <- system.file("extdata", "test_data.csv", package = "FisPro")
dataset <- read.csv(test_file)
inferred_dataset <- fis$infer(dataset)
########################################################################
# or build a Fis from scratch
fis <- NewFis()
fis$name <- "foo"
# build the first input
fisin1 <- NewFisIn(0, 1)
fisin1$name <- "input1"
fisin1$add_mf(NewMfTrapezoidalInf(0, 1))
fisin1$add_mf(NewMfTrapezoidalSup(0, 1))
fis$add_input(fisin1)
# build the second input
fisin2 <- NewFisIn(0, 1)
fisin2$name <- "input2"
fisin2$add_mf(NewMfTrapezoidalInf(0, 0.5))
fisin2$add_mf(NewMfTriangular(0, 0.5, 1))
fisin2$add_mf(NewMfTrapezoidalSup(0.5, 1))
fis$add_input(fisin2)
# build an output
fisout <- NewFisOutCrisp(0, 1)
fisout$name <- "output"
fis$add_output(fisout)
# add rules to the Fis
fis$add_rule(NewRule(c(1, 2), 0))
fis$add_rule(NewRule(c(2, 0), 1))