Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
28 views24 pages

Fuzzy Logic

Fuzzy Logic is a reasoning approach that accommodates imprecision and uncertainty, allowing for degrees of truth between 0 and 1, unlike classical logic which is binary. It is particularly useful in real-world scenarios where answers are not strictly yes or no, such as temperature control systems, where fan speed can be adjusted gradually based on fuzzy sets and membership functions. The document also covers fuzzy rules, inference systems, and implementation in Python using libraries like skfuzzy.

Uploaded by

emilyroswell4947
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views24 pages

Fuzzy Logic

Fuzzy Logic is a reasoning approach that accommodates imprecision and uncertainty, allowing for degrees of truth between 0 and 1, unlike classical logic which is binary. It is particularly useful in real-world scenarios where answers are not strictly yes or no, such as temperature control systems, where fan speed can be adjusted gradually based on fuzzy sets and membership functions. The document also covers fuzzy rules, inference systems, and implementation in Python using libraries like skfuzzy.

Uploaded by

emilyroswell4947
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 24

Fuzzy

Logic
Knowledge Representation and Reasoning
Fuzzy Logic

Introduction

Key Components of Fuzzy Logic

Example: Temperature Control System

Applications of Fuzzy Logic


Introduction
• Fuzzy Logic is a way of reasoning that deals with
imprecision and uncertainty.
• Unlike classical (Boolean) logic [FOL], which strictly
classifies values as true (1) or false (0), Fuzzy Logic
allows for degrees of truth between 0 and 1.
Need of Fuzzy Logic
• Many real-world situations don’t have a clear "yes" or
"no" answer.
For example, consider the statement

👉 "The weather is hot."


• If it's 10°C, it’s clearly not hot (0).
• If it's 40°C, it’s clearly hot (1).
• But what about 25°C? It's somewhat hot—not fully 1
orFuzzy
0. Logic handles this by assigning degrees of truth (e.g.,
0.5 for 25°C).
Fuzzy Logic vs Classical If temperature > 30°C, turn
the fan ON (1). Otherwise,
Logic turn the fan OFF (0).

Temperature (°C) Fan (Crisp Logic)

25°C OFF (0)

30°C OFF (0)

31°C ON (1)

40°C ON (1)

If the temperature is just slightly above 30°C, the fan suddenly turns on. This doesn’t feel
natural—what if we want a gradual adjustment?
Fuzzy Logic
Approach Fan
Speed
Temperatur
Instead of just ON/OFF, we (%)
define a smooth transition: e (°C)
(Fuzzy
• 25°C → Fan slow (30% speed) Logic)
• 30°C → Fan medium (60%
speed) 25°C 30%
• 40°C → Fan fast (100% speed) 30°C 60%
• This makes the system more
realistic. 40°C 100%
Fuzzy Sets & Membership
Functions
What is a Fuzzy
Set?
Temperature Membership
• A Fuzzy Set is a collection (°C) in "Hot" Set
of elements where each 10°C 0.0 (Not Hot)
element has a degree of 0.3 (Slightly
membership between 0 25°C
Hot)
and 1. 0.6
30°C (Moderately
Hot)
40 C 1.0 (Hot)
So, at 30°C, we say it's 60% hot
instead of a hard yes/no.
Membership
Functions (MFs)
A Membership Function
(MF) defines how input
values map to fuzzy values.
There are different types of
MFs:
1.Triangular MF (Most
common)
2.Trapezoidal MF
3.Gaussian MF
Triangular Membership function
A triangular MF is defined by three points:
• (a, b, c) → where a is the start, b is the peak, and c is the end.
• It forms a triangle shape.

📌 Example:

For "Hot" temperature MF:


• a = 25°C (start)
• b = 35°C (peak, fully hot)
• c = 50°C (end)
Trapezoidal Membership Function
• A trapezoidal MF is similar to a triangular MF, but it has a
flat top instead of a single peak.
• Useful when a value remains fully in a category for a range.

📌 Example:
For "Warm" temperature MF:
• a = 20°C (start)
• b = 25°C (fully warm starts)
• c = 35°C (fully warm ends)
• d = 40°C (end)
Gaussian Membership Function
Gaussian MF is smooth and bell-shaped.
• Used when gradual change is needed.

📌 Example:
For "Cold" temperature
c = peak (center of the bell curve) MF:
•c = 15°C (most cold)
σ = spread (controls the width of the curve)
•σ = 5 (smooth
transition range)
σ Gaussian Function
🔹 Small Sigma (σ = 3) (Narrow Curve)
• Only values close to 15°C (e.g., 12-18°C) are
considered "cold".
• Values further from 15°C quickly drop to near 0.
🔹 Large Sigma (σ = 8) (Wide Curve)
• Wider range of values (e.g., 5-25°C) are
considered "cold" to some degree.
• Even at 25°C, there is still some small "coldness".
Fuzzy Rules & Inference System
• Fuzzy rules define how input values are mapped to
outputs using human-like reasoning.
• They follow the IF-THEN format
👉 Example: Fan Speed Control
• IF temperature is Cold, THEN fan speed is Slow.
• IF temperature is Warm, THEN fan speed is Medium.
• IF temperature is Hot, THEN fan speed is Fast.

Fuzzy rules work together in a Fuzzy Inference System (FIS) to make decisions.
Step 1: Define Fuzzy Variables
Let’s define temperature as an input and fan speed as
an output.
• Temperature (Input)
• Cold
• Warm
• Hot
• Fan Speed (Output)
• Slow
• Medium
• Fast
Step 2: Define Rules

IF Temperature THEN Fan Speed


Rule
is... is...

• Using fuzzy logic, we can


define rules like 1 Cold Slow

2 Warm Medium

3 Hot Fast
Two Libraries
• skfuzzy (from SciKit-Fuzzy) is used to define
membership functions, perform fuzzification, and
defuzzification.
• skfuzzy.control (Fuzzy Control System) is a higher-
level module built on skfuzzy to create fuzzy rule-based
systems (FIS).
Step 3: Implement Fuzzy Rules
in Python
import numpy as np
import skfuzzy as fuzz
import skfuzzy.control as ctrl

temperature = ctrl.Antecedent(np.arange(0, 51, 1), 'temperature')


fan_speed = ctrl.Consequent(np.arange(0, 101, 1), 'fan_speed’)

temperature['cold'] = fuzz.trimf(temperature.universe, [0, 0, 25])


temperature['warm'] = fuzz.trimf(temperature.universe, [10, 25, 40])
temperature['hot'] = fuzz.trimf(temperature.universe, [25, 50, 50])
Step 3: Implement Fuzzy Rules
in Python
fan_speed['slow'] = fuzz.trimf(fan_speed.universe, [0, 0, 50])
fan_speed['medium'] = fuzz.trimf(fan_speed.universe, [25, 50, 75])
fan_speed['fast'] = fuzz.trimf(fan_speed.universe, [50, 100, 100])

rule1 = ctrl.Rule(temperature['cold'], fan_speed['slow'])


rule2 = ctrl.Rule(temperature['warm'], fan_speed['medium'])
rule3 = ctrl.Rule(temperature['hot'], fan_speed['fast'])

# 4. Create Control System


fan_ctrl = ctrl.ControlSystem([rule1, rule2, rule3])
fan_simulation = ctrl.ControlSystemSimulation(fan_ctrl)
Step 3: Implement Fuzzy Rules
in Python
fan_simulation.input['temperature'] = 30
fan_simulation.compute()
print(f"Fan Speed: {fan_simulation.output['fan_speed']}
%")
Defuzzification
• Once we get fuzzy outputs, we need to convert them
into a crisp number (e.g., exact fan speed in %).
• This process is called Defuzzification.
Common Defuzzification Methods

Method How it Works When to Use


Finds the center of Most common,
Centroid (COG) gravity of the gives smooth
fuzzy output transitions
Max Chooses the value
If you need the
Membership with the highest
most likely value
(MOM) membership
Averages the
When multiple
Mean of values with the
outputs have the
Maxima (MeOM) highest
same max
Centroid (COG)- Weighted Balance
Point
• Centroid finds the "center of gravity" of the fuzzy output area.

• x = Output values (e.g., fan speeds: 25, 50, 75, 100)


• μ(x) = Membership degree at each x
• ∑(μ(x)⋅x) = Weighted sum (higher membership → stronger
influence).
• ∑μ(x) = Total membership sum (normalizing factor).
Fan Speed Calculation
Let our fuzzy output is:
• "Medium" (50% to 75%) → Membership = 0.7
• "Fast" (50% to 100%) → Membership = 0.3

You might also like