Fis: Class "Fis"

FisR 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

argument: fis_file

character vector, The filename of the Fis configuration file

return:

Fis object

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

get_input(input_index)
argument: input_index

integer value, The index (1-based index) of the input in the Fis

return:

FisIn object

get_inputs()

Get all inputs in the Fis

return:

list of FisIn objects

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

get_output(output_index)
argument: output_index

integer value, The index (1-based index) of the output in the Fis

return:

FisOut object

get_outputs()

Get all outputs in the Fis

return:

list of FisOut objects

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

get_rule(rule_index)
argument: rule_index

integer value, The index (1-based index) of the rule in the Fis

return:

Rule object

get_rules()

Get all rules in the Fis

return:

list of Rule objects

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:

numeric vector or matrix (in case of 2D input data)

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)

See Also

NewFis

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))

FisPro documentation built on March 31, 2023, 7:22 p.m.