Module: control

skfuzzy.control subpackage, providing a high-level API for fuzzy system design.

skfuzzy.control.Antecedent(universe, label) Antecedent (input/sensor) variable for a fuzzy control system.
skfuzzy.control.Consequent(universe, label) Consequent (output/control) variable for a fuzzy control system.
skfuzzy.control.ControlSystem([rules]) Base class to contain a Fuzzy Control System.
skfuzzy.control.ControlSystemSimulation(...) Calculate results from a ControlSystem.
skfuzzy.control.Rule([antecedent, ...]) Rule in a fuzzy control system, connecting antecedent(s) to consequent(s).

Antecedent

class skfuzzy.control.Antecedent(universe, label)[source]

Bases: skfuzzy.control.fuzzyvariable.FuzzyVariable

Antecedent (input/sensor) variable for a fuzzy control system.

Parameters:

universe : array-like

Universe variable. Must be 1-dimensional and convertible to a NumPy array.

label : string

Name of the universe variable.

__init__(universe, label)[source]
graph

NetworkX graph which connects this Antecedent with its Term(s).

input

Consequent

class skfuzzy.control.Consequent(universe, label)[source]

Bases: skfuzzy.control.fuzzyvariable.FuzzyVariable

Consequent (output/control) variable for a fuzzy control system.

Parameters:

universe : array-like

Universe variable. Must be 1-dimensional and convertible to a NumPy array.

label : string

Name of the universe variable.

Notes

The label string chosen must be unique among Antecedents and Consequents in the ControlSystem.

__init__(universe, label)[source]
graph

NetworkX graph which connects this Consequent with its Term(s).

output

ControlSystem

class skfuzzy.control.ControlSystem(rules=None)[source]

Bases: object

Base class to contain a Fuzzy Control System.

Parameters:

rules : Rule or iterable of Rules, optional

If provided, the system is initialized and populated with a set of fuzzy Rules (see skfuzzy.control.Rule). This is optional. If omitted the ControlSystem can be built interactively.

__init__(rules=None)[source]
addrule(rule)[source]

Add a new rule to the system.

antecedents

Generator which yields Antecedents in the system.

consequents

Generator which yields Consequents in the system.

fuzzy_variables

Generator which yields fuzzy variables in the system.

This includes Antecedents, Consequents, and Intermediaries.

rules

Generator which yields Rules in the system in calculation order.

view()[source]

View a representation of the system NetworkX graph.

ControlSystemSimulation

class skfuzzy.control.ControlSystemSimulation(control_system, clip_to_bounds=True, cache=True, flush_after_run=1000)[source]

Bases: object

Calculate results from a ControlSystem.

Parameters:

control_system : ControlSystem

A fuzzy ControlSystem object.

clip_to_bounds : bool, optional

Controls if input values should be clipped to the consequent universe range. Default is True.

cache : bool, optional

Controls if results should be stored for reference in fuzzy variable objects, allowing fast lookup for repeated runs of .compute(). Unless you are heavily memory constrained leave this True (default).

flush_after_run : int, optional

Clears cached results after this many repeated, unique simulations. The default of 1000 is appropriate for most hardware, but for small embedded systems this can be lowered as appropriate. Higher memory systems may see better performance with a higher limit.

__init__(control_system, clip_to_bounds=True, cache=True, flush_after_run=1000)[source]
compute()[source]

Compute the fuzzy system.

compute_rule(rule)[source]

Implement rule according to Mamdani inference.

The three step method consists of::
  • Aggregation
  • Activation
  • Accumulation
inputs(input_dict)[source]

Convenience method to accept multiple inputs to antecedents.

Parameters:

input_dict : dict

Contains key:value pairs where the key is the label for a connected Antecedent and the value is the input.

print_state()[source]

Print info about the inner workings of a ControlSystemSimulation.

Rule

class skfuzzy.control.Rule(antecedent=None, consequent=None, label=None)[source]

Bases: object

Rule in a fuzzy control system, connecting antecedent(s) to consequent(s).

Parameters:

antecedent : Antecedent term(s) or logical combination thereof, optional

Antecedent terms serving as inputs to this rule. Multiple terms may be combined using operators | (OR), & (AND), ~ (NOT), and parentheticals to group terms.

consequent : Consequent term(s) or logical combination thereof, optional

Consequent terms serving as outputs from this rule. Multiple terms may be combined using operators | (OR), & (AND), ~ (NOT), and parentheticals to group terms.

label : string, optional

Label to reference the meaning of this rule. Optional, but recommended. If provided, the label must be unique among rules in any particular ControlSystem.

Notes

Fuzzy Rules can be completely built on instantatiation or one can begin with an empty Rule and construct interactively by setting .antecedent, .consequent, and .label variables.

__init__(antecedent=None, consequent=None, label=None)[source]

Rule in a fuzzy system, connecting antecedent(s) to consequent(s).

Parameters:

antecedent : Antecedent term(s) or combination thereof, optional

Antecedent terms serving as inputs to this rule. Multiple terms may be combined using operators | (OR), & (AND), ~ (NOT), and parentheticals to group terms.

consequent : Consequent term(s) or combination thereof, optional

Consequent terms serving as outputs from this rule. Multiple terms may be combined using operators | (OR), & (AND), ~ (NOT), and parentheticals to group terms.

label : string, optional

Label to reference the meaning of this rule. Optional, but recommended.

aggregate_firing
antecedent

Antecedent clause, consisting of multiple term(s) in this fuzzy Rule.

antecedent_terms

Utility function to list all Antecedent terms present in this clause.

consequent

Consequent clause, consisting of multiple term(s) in this fuzzy Rule.

graph

NetworkX directed graph representing this Rule’s connectivity.

view()[source]

Show a visual representation of this Rule.