You are on page 1of 42

Introduction Design Operation Library Conclusions and Future Work

fuzzylite
A Fuzzy Logic Control Library in C++

Juan Rada-Vilela

www.fuzzylite.com

Juan Rada-Vilela fuzzylite: A Fuzzy Logic Control Library in C++ 1/42


Introduction Design Operation Library Conclusions and Future Work

Introduction

Juan Rada-Vilela fuzzylite: A Fuzzy Logic Control Library in C++ 2/42


Introduction Design Operation Library Conclusions and Future Work

Introduction

Are you familiar with. . . ?

Juan Rada-Vilela fuzzylite: A Fuzzy Logic Control Library in C++ 3/42


Introduction Design Operation Library Conclusions and Future Work

Introduction

Are you familiar with. . . ?

Juan Rada-Vilela fuzzylite: A Fuzzy Logic Control Library in C++ 4/42


Introduction Design Operation Library Conclusions and Future Work

Introduction

Are you familiar with. . . ?

(Lord of the Rings)

Juan Rada-Vilela fuzzylite: A Fuzzy Logic Control Library in C++ 5/42


Introduction Design Operation Library Conclusions and Future Work

Introduction

You should know that. . .


Many of them use Fuzzy Logic Control
Over 50 000 patents involve Fuzzy Logic Control
Over $10 000M in product sales using Fuzzy Logic Control
. . . a single product: a blood pressure monitor
Profits estimated in billions ($$$) using Fuzzy Logic Control

Can you believe that. . . ?


State-of-the-art FLC libraries have strong limitations

http://goo.gl/oYWGkM
http://goo.gl/VDgOk9

Juan Rada-Vilela fuzzylite: A Fuzzy Logic Control Library in C++ 6/42


Introduction Design Operation Library Conclusions and Future Work

State of the Art

Limitations
Matlab and Fuzzy Logic Toolbox: Costly license
Octave and Fuzzy Logic Toolkit: Restrictive license
jFuzzyLogic: Unfortunate design choices
Others: do not even bother. . .

fuzzylite: A Fuzzy Logic Control Library in C++


Free and open source
Commercial friendly license
Mostly fortunate design choices
More features
Very easy to use
Linux, Mac OSX, Windows, and others. . .
Juan Rada-Vilela fuzzylite: A Fuzzy Logic Control Library in C++ 7/42
Introduction Design Operation Library Conclusions and Future Work

Objectives

Overall Goal
Introduction to Fuzzy Logic Controllers

Specific Objectives
Design of Fuzzy Logic Controllers
Operation of Fuzzy Logic Controllers
Examples of Fuzzy Logic Controllers
Description of fuzzylite

Juan Rada-Vilela fuzzylite: A Fuzzy Logic Control Library in C++ 8/42


Introduction Design Operation Library Conclusions and Future Work

Design

Juan Rada-Vilela fuzzylite: A Fuzzy Logic Control Library in C++ 9/42


Introduction Design Operation Library Conclusions and Future Work

Fuzzy Logic Controller

Definition
Controller

if condition then action


..
Inputs . Outputs
if condition then action

Juan Rada-Vilela fuzzylite: A Fuzzy Logic Control Library in C++ 10/42


Introduction Design Operation Library Conclusions and Future Work

Fuzzy Logic Controller

Example

Problem
How much to tip at a restaurant?

Solution
Controller
Service if Service is poor then Tip is cheap Tip
if Service is good then Tip is average
if Service is great then Tip is generous

Juan Rada-Vilela fuzzylite: A Fuzzy Logic Control Library in C++ 11/42


Introduction Design Operation Library Conclusions and Future Work

Linguistic Variables

Quality of Service Tip

great generous

good average

poor cheap

0 2.5 5.0 7.5 10 0 10 15 20 25


x y

S(2.5) = poor T(17.5) = average + generous

Linguistic variables with crisp sets as certainty {0, 1}

Juan Rada-Vilela fuzzylite: A Fuzzy Logic Control Library in C++ 12/42


Introduction Design Operation Library Conclusions and Future Work

Linguistic Variables

Tip
Service

1.0
1.0

( y)
0.5
(x)
0.5

0.0
0.0

0 cheap average generous 25


0 poor good great 10 y
x
T(17.5) =
S(2.5) = 1.0/poor
0.2/average + 0.8/generous

Linguistic variables with fuzzy sets as certainty [0.0, 1.0]

Juan Rada-Vilela fuzzylite: A Fuzzy Logic Control Library in C++ 13/42


Introduction Design Operation Library Conclusions and Future Work

Design of a Fuzzy Logic Controller

Input: Service Output: Tip


1.0

1.0
(x)

(y)
0.5

0.5
0.0

0.0
0 poor good great 10 0 cheap average generous 25
x y

Rules
if Service is poor then Tip is cheap
if Service is good then Tip is average
if Service is great then Tip is generous

Juan Rada-Vilela fuzzylite: A Fuzzy Logic Control Library in C++ 14/42


Introduction Design Operation Library Conclusions and Future Work

Operation of a Fuzzy Logic Controller

25
cheap average generous
Tip
0

0 poor good great 10


Service
Juan Rada-Vilela fuzzylite: A Fuzzy Logic Control Library in C++ 15/42
Introduction Design Operation Library Conclusions and Future Work

Operation

Juan Rada-Vilela fuzzylite: A Fuzzy Logic Control Library in C++ 16/42


Introduction Design Operation Library Conclusions and Future Work

Stages of a Fuzzy Logic Controller

Inputs Fuzzification

Inference

Defuzzification Outputs

Juan Rada-Vilela fuzzylite: A Fuzzy Logic Control Library in C++ 17/42


Introduction Design Operation Library Conclusions and Future Work

Stages of a Fuzzy Logic Controller

Inputs Fuzzification

Inference

Defuzzification Outputs

Juan Rada-Vilela fuzzylite: A Fuzzy Logic Control Library in C++ 18/42


Introduction Design Operation Library Conclusions and Future Work

Fuzzification

Definition
Fuzzification: Converts crisp input values into a fuzzy set

Example

Service Fuzzification
1.0

S(1.0) = 0.4/poor + 0.0/good + 0.0/great


S(2.5) = 1.0/poor + 0.0/good + 0.0/great
(x)

S(7.0) = 0.0/poor + 0.2/good + 0.8/great


0.5

S(x) = i (x)/i
iS
0.0

0 poor good great 10


x i : membership function of term i

Juan Rada-Vilela fuzzylite: A Fuzzy Logic Control Library in C++ 19/42


Introduction Design Operation Library Conclusions and Future Work

Stages of a Fuzzy Logic Controller

Inputs Fuzzification

Inference

Defuzzification Outputs

Juan Rada-Vilela fuzzylite: A Fuzzy Logic Control Library in C++ 20/42


Introduction Design Operation Library Conclusions and Future Work

Inference

Definition
Inference: activates the rules to generate fuzzy outputs

Fuzzy Activation of e.g. if Service is great


Inputs Antecedents

Modification of e.g. then Tip is generous


Consequents

Accumulation of Fuzzy
Outputs Outputs

Juan Rada-Vilela fuzzylite: A Fuzzy Logic Control Library in C++ 21/42


Introduction Design Operation Library Conclusions and Future Work

Inference
Activation of the Antecedents

Example

if Service is poor then Tip is cheap


if Service is good then Tip is average
if Service is great then Tip is generous

S(2.5) = 1.0/poor + 0.0/good + 0.0/great

Activation

if (Service is poor) = 1.0


if (Service is good) = 0.0
if (Service is great) = 0.0

Activation degree

Juan Rada-Vilela fuzzylite: A Fuzzy Logic Control Library in C++ 22/42


Introduction Design Operation Library Conclusions and Future Work

Inference
Activation of the Antecedents

Example

if Service is poor then Tip is cheap


if Service is good then Tip is average
if Service is great then Tip is generous

S(7.0) = 0.0/poor + 0.2/good + 0.8/great

Activation

if (Service is poor) = 0.0


if (Service is good) = 0.2
if (Service is great) = 0.8

Juan Rada-Vilela fuzzylite: A Fuzzy Logic Control Library in C++ 23/42


Introduction Design Operation Library Conclusions and Future Work

Inference
Modification of Consequents

Example

if Service is poor then Tip is cheap


if Service is good then Tip is average
if Service is great then Tip is generous

S(2.5) = 1.0/poor + 0.0/good + 0.0/great

Modification

then Tip is (1.0cheap)


then Tip is (0.0average)
then Tip is (0.0generous)

: Activation Operator

Juan Rada-Vilela fuzzylite: A Fuzzy Logic Control Library in C++ 24/42


Introduction Design Operation Library Conclusions and Future Work

Inference
Modification of Consequents

Example
{(1.0 cheap), (0.0 average), (0.0 generous)}

1.0
(y)
0.5
0.0

0 cheap average generous 25


y

Juan Rada-Vilela fuzzylite: A Fuzzy Logic Control Library in C++ 25/42


Introduction Design Operation Library Conclusions and Future Work

Inference
Modification of Consequents

Example
{(0.0 cheap), (0.2 average), (0.8 generous)}
1.0

1.0
(y)

(y)
0.5

0.5
0.0

0.0

0 cheap average generous 25 0 cheap average generous 25


y y

: min(i , j (x)) : (i , j (x))

Juan Rada-Vilela fuzzylite: A Fuzzy Logic Control Library in C++ 26/42


Introduction Design Operation Library Conclusions and Future Work

Inference
Accumulation of Consequents

Example
S(7.0) = 0.0/poor + 0.2/good + 0.8/great

Activation Modification

if (Service is poor) = 0.0 then Tip is (0.0cheap)


if (Service is good) = 0.2 then Tip is (0.2average)
if (Service is great) = 0.8 then Tip is (0.8generous)

Accumulation
T7.0 = (0.0 cheap) (0.2 average) (0.8 generous)
: Accumulation Operator

Juan Rada-Vilela fuzzylite: A Fuzzy Logic Control Library in C++ 27/42


Introduction Design Operation Library Conclusions and Future Work

Inference
Modification of Consequents

Example
{(0.0 cheap), (0.2 average), (0.8 generous)}
1.0

1.0
(y)

(y)
0.5

0.5
0.0

0.0

0 cheap average generous 25 0 cheap average generous 25


y y

: min(i , j (x)) : (i , j (x))

Juan Rada-Vilela fuzzylite: A Fuzzy Logic Control Library in C++ 28/42


Introduction Design Operation Library Conclusions and Future Work

Inference
Accumulation of Consequents

Example
T7.0 = (0.0 cheap) (0.2 average) (0.8 generous)
1.0

1.0
(y)

(y)
0.5

0.5
0.0

0.0
0 cheap average generous 25 0 cheap average generous 25
y y

: min(i , j (x)) : (i , j (x))


: max(i , j (x)) : (i , j (x))

Juan Rada-Vilela fuzzylite: A Fuzzy Logic Control Library in C++ 29/42


Introduction Design Operation Library Conclusions and Future Work

Stages of a Fuzzy Logic Controller

Inputs Fuzzification

Inference

Defuzzification Outputs

Juan Rada-Vilela fuzzylite: A Fuzzy Logic Control Library in C++ 30/42


Introduction Design Operation Library Conclusions and Future Work

Defuzzification

Definition
Defuzzification: converts the fuzzy outputs into crisp values

Example
Centroid Maxima

1.0
1.0

( y)
(y)

0.5
0.5


0.0
0.0

0 cheap average generous 25 0 cheap average generous 25


y y

Juan Rada-Vilela fuzzylite: A Fuzzy Logic Control Library in C++ 31/42


Introduction Design Operation Library Conclusions and Future Work

Stages of a Fuzzy Logic Controller

Inputs Fuzzification

Inference

Defuzzification Outputs

Juan Rada-Vilela fuzzylite: A Fuzzy Logic Control Library in C++ 32/42


Introduction Design Operation Library Conclusions and Future Work

fuzzylite

Juan Rada-Vilela fuzzylite: A Fuzzy Logic Control Library in C++ 33/42


Introduction Design Operation Library Conclusions and Future Work

Features

fuzzylite is a library (.so, .dylib, .dll)


qtfuzzylite links to fuzzylite

Main Features
Mamdani, Takagi-Sugeno and Tsukamoto FLCs
17+ linguistic terms
13 fuzzy logic operators
Seven defuzzifiers
Six types of hedges (e.g. very, somewhat, not)
Import and export using FCL, FIS, C++
Extend and incorporate new components

Juan Rada-Vilela fuzzylite: A Fuzzy Logic Control Library in C++ 34/42


Introduction Design Operation Library Conclusions and Future Work

Linguistic Terms

Basic Extended Edges

Triangle Gaussian Gaussian P. Ramp

Trapezoid Bell Pi-Shape Sigmoid

Rectangle Sigmoid D. Sigmoid P. S-Shape


f (x) = c
f (x, y) = ax + by + c
Discrete Constant, Linear, Custom Z-Shape

Juan Rada-Vilela fuzzylite: A Fuzzy Logic Control Library in C++ 35/42


Introduction Design Operation Library Conclusions and Future Work

Abstract Model

InputVariable
input : scalar
terms : vector<Term >

Engine RuleBlock
inputs : vector<InputVariable > rules : vector<Rule >
outputs : vector<OutputVariable > tnorm : TNorm
ruleBlocks : vector<RuleBlock > snorm : SNorm
hedges : vector<Hedge > activation : TNorm
process() : void fireRules() : void

OutputVariable
terms : vector<Term >
output : Accumulated
defuzzifier : Defuzzifier
defuzzify() : scalar

Juan Rada-Vilela fuzzylite: A Fuzzy Logic Control Library in C++ 36/42


Introduction Design Operation Library Conclusions and Future Work

Conclusions and Future Work

Juan Rada-Vilela fuzzylite: A Fuzzy Logic Control Library in C++ 37/42


Introduction Design Operation Library Conclusions and Future Work

Conclusions

FLCs are a powerful alternative to traditional control algorithms


Easy to design

Easy to operate

Easy to maintain over time

Many algorithms to tune FLCs

Juan Rada-Vilela fuzzylite: A Fuzzy Logic Control Library in C++ 38/42


Introduction Design Operation Library Conclusions and Future Work

Conclusions

Important to recognize when to utilize FLCs


25
cheap average generous
Tip

vs.

Ramp term
0

0 poor good great 10


Service

Juan Rada-Vilela fuzzylite: A Fuzzy Logic Control Library in C++ 39/42


Introduction Design Operation Library Conclusions and Future Work

Future Work

Type-2 Fuzzy Logic Controllers

Adaptive Neuro-Fuzzy Inference System (ANFIS)

Fuzzy C-Means clustering algorithm

. . . and there are still many more things to do!

Juan Rada-Vilela fuzzylite: A Fuzzy Logic Control Library in C++ 40/42


Introduction Design Operation Library Conclusions and Future Work

Donations

support fuzzylite with a donation

Juan Rada-Vilela fuzzylite: A Fuzzy Logic Control Library in C++ 41/42


Introduction Design Operation Library Conclusions and Future Work

fuzzylite
A Fuzzy Logic Control Library in C++

Juan Rada-Vilela

www.fuzzylite.com

Juan Rada-Vilela fuzzylite: A Fuzzy Logic Control Library in C++ 42/42

You might also like