Learn R Programming

sets (version 1.0-18)

fuzzyinference: Fuzzy inference

Description

Basic infrastructure for building and using fuzzy inference systems.

Usage

fuzzy_inference(system, values, implication = c("minimum", "product"))
fuzzy_rule(antecedent, consequent)
fuzzy_system(variables, rules)
fuzzy_partition(varnames, FUN = fuzzy_normal, universe = NULL, …)
fuzzy_variable(…)
x %is% y

Arguments

For fuzzy_variable: named list of fuzzy sets (or membership functions from which the fuzzy sets will be created using the default universe). For fuzy_partition: further arguments passed to FUN.

antecedent, consequent

parts of an inference rule (see details).

variables

Set or tuple of fuzzy variables (note that tuples must be used if two variables have the same definition).

rules

Set of rules.

system

A fuzzy system.

values

Named list of input values to the system. The names must match the labels of the variable set.

implication

A vectorized function taking two arguments, or a character string indicating the parallel minimum or the product function.

varnames

Either a character vector of fuzzy category labels, to be used with the default locations, or a named numeric vector of locations.

FUN

Function generator for membership functions to be used for the fuzzy partition.

universe

Universal set used for computing the memberships grades.

x

The name of a fuzzy variable.

y

The name of a category, belonging to a fuzzy variable.

Value

For fuzzy_inference: a generalized set. For fuzzy_rule and fuzzy_system: an object of class fuzzy_rule and fuzzy_system, respectively. For fuzzy_variable and fuzzy_partition: an object of class fuzzy_variable, inheriting from tuple.

Details

These functions can be used to create simple fuzzy inference machines based on fuzzy (“linguistic”) variables and fuzzy rules. This involves five steps:

  1. Fuzzification of the input variables.

  2. Application of fuzzy operators (AND, OR, NOT) in the antecedents of some given rules.

  3. Implication from the antecedent to the consequent.

  4. Aggregation of the consequents across the rules.

  5. Defuzzification of the resulting fuzzy set.

Implication is based on either the minimum or the product. The evaluation of the logical expressions in the antecedents, as well as the aggregation of the evaluation result for each single rule, depends on the fuzzy logic currently set.

See Also

set and gset for the set types, fuzzy_tuple for available fuzzy functions, and fuzzy_logic on the behavior of the implemented fuzzy operators.

Examples

Run this code
# NOT RUN {
## set universe
sets_options("universe", seq(from = 0, to = 25, by = 0.1))

## set up fuzzy variables
variables <-
set(service =
    fuzzy_partition(varnames =
                    c(poor = 0, good = 5, excellent = 10),
                    sd = 1.5),
    food =
    fuzzy_variable(rancid =
                   fuzzy_trapezoid(corners = c(-2, 0, 2, 4)),
                   delicious =
                   fuzzy_trapezoid(corners = c(7, 9, 11, 13))),
    tip =
    fuzzy_partition(varnames =
                    c(cheap = 5, average = 12.5, generous = 20),
                    FUN = fuzzy_cone, radius = 5)
    )

## set up rules
rules <-
set(
    fuzzy_rule(service %is% poor || food %is% rancid,
               tip %is% cheap),
    fuzzy_rule(service %is% good,
               tip %is% average),
    fuzzy_rule(service %is% excellent || food %is% delicious,
               tip %is% generous)
    )

## combine to a system
system <- fuzzy_system(variables, rules)
print(system)
plot(system) ## plots variables

## do inference
fi <- fuzzy_inference(system, list(service = 3, food = 8))

## plot resulting fuzzy set
plot(fi)

## defuzzify
gset_defuzzify(fi, "centroid")

## reset universe
sets_options("universe", NULL)
# }

Run the code above in your browser using DataLab