Nexus Learn

Practical 9B: Sugeno Inference and Comparison with Mamdani

Lab Practical CS-511 Artificial Intelligence 9 min read Updated 8 Nov 2026
On this page
  1. 1. Objectives
  2. 2. Word Bank
  3. 3. Background
  4. 4. Time Plan (50 minutes)
  5. Part A - Guided Warm-up (type, run, observe)
  6. Part B - Predict the Output
  7. Part C - Bug Hunt
  8. Part D - Graded Tasks (10 marks)
  9. Part E - Post-Lab Questions (finish as homework if time runs out)
  10. Marking Rubric (applied to Part D)
  11. Submission

1. Objectives

  1. Build a zero-order Sugeno system: constant rule outputs combined by a weighted average.
  2. Compare Sugeno and Mamdani outputs with response curves and control surfaces.
  3. Build a first-order Sugeno system whose rule outputs depend on the inputs.
  4. Explain when to choose Mamdani and when to choose Sugeno.

2. Word Bank

Word

Simple meaning

Real-world example

Sugeno system

A fuzzy system whose rule outputs are numbers or formulas, not fuzzy sets

IF hot AND NOT dry THEN fan = 83

Zero-order Sugeno

Each rule's output is a constant

slow = 17, medium = 50, fast = 83

First-order Sugeno

Each rule's output is a linear formula of the inputs

fan = 40 + 1.2 x temperature

Weighted average

Σ (strength x output) / Σ strength

(0.33 x 17 + 0.2 x 83) / 0.53

Control surface

Output plotted over every input pair

3-D 'landscape' of fan speed

Interpretable

A person can read and understand it

Mamdani rules with fuzzy outputs

3. Background

Sugeno in one line

Michio Sugeno and Tomohiro Takagi (1985) replaced the fuzzy THEN-sets with crisp outputs. Each rule gives a number z (a constant in a ZERO-ORDER system, a formula like a + b·t + c·h in a FIRST-ORDER system). The final output is the weighted average Σ w·z / Σ w, where w is the rule's firing strength. No clipping, no aggregation, no centroid - so it is much faster and works well inside optimisation and learning (ANFIS, P11).

Same rules, same fire()

The IF parts and firing strengths are exactly those of P09a. Only the THEN part changes. We choose the constants 17, 50 and 83 close to the centroids of the slow, medium and fast sets, so the two systems should behave alike.

Which to choose?

Mamdani: rule outputs are fuzzy words, easy for experts to read - good for advice systems. Sugeno: fast, smooth, easy to tune from data - good for control on small devices and for learning.

Data files for this lab

No data file is needed - the programs make their own data.

4. Time Plan (50 minutes)

Minutes

Activity

Part

0-5

Background: weighted average; zero- and first-order Sugeno

1-3

5-10

Guided warm-up: one Sugeno inference; Sugeno vs Mamdani curve

Part A

10-13

Predict the output

Part B

13-17

Bug hunt

Part C

17-47

Graded tasks 1-3

Part D

47-50

Wrap-up; post-lab questions set as homework

Part E

Part A - Guided Warm-up (type, run, observe)

A1. One zero-order Sugeno inference (30 °C, 40 %)

The same five strengths as P09a; each rule now gives a constant. The answer is their weighted average.

import numpy as np

import skfuzzy as fuzz

t_x = np.arange(0, 51, 1); h_x = np.arange(0, 101, 1); f_x = np.arange(0, 101, 1)

T = {"cold": fuzz.trapmf(t_x, [0, 0, 10, 20]), "comfortable": fuzz.trimf(t_x, [15, 24, 33]),

"hot": fuzz.trapmf(t_x, [28, 38, 50, 50])}

H = {"dry": fuzz.trapmf(h_x, [0, 0, 20, 50]), "normal": fuzz.trimf(h_x, [30, 50, 70]),

"humid": fuzz.trapmf(h_x, [50, 80, 100, 100])}

F = {"slow": fuzz.trimf(f_x, [0, 0, 50]), "medium": fuzz.trimf(f_x, [25, 50, 75]),

"fast": fuzz.trimf(f_x, [50, 100, 100])}

mu = lambda x_axis, mf, value: float(fuzz.interp_membership(x_axis, mf, value))

def fire(t, h):

cold, comf, hot = (mu(t_x, T[k], t) for k in ("cold", "comfortable", "hot"))

dry = mu(h_x, H["dry"], h)

return [("slow", cold), ("slow", min(comf, dry)), ("medium", min(comf, 1 - dry)),

("medium", min(hot, dry)), ("fast", min(hot, 1 - dry))]

def mamdani(t, h):

agg = np.zeros_like(f_x, dtype=float)

for term, w in fire(t, h):

agg = np.fmax(agg, np.fmin(F[term], w))

return fuzz.defuzz(f_x, agg, "centroid")

Z = {"slow": 17, "medium": 50, "fast": 83} # zero-order: one constant per output

def sugeno(t, h):

rules = fire(t, h)

w = np.array([s for _, s in rules])

z = np.array([Z[term] for term, _ in rules])

return (w * z).sum() / w.sum() # weighted average

t, h = 30, 40

for i, (term, w) in enumerate(fire(t, h), 1):

print(f"R{i} {term:<6} w = {w:.2f} z = {Z[term]} w x z = {w * Z[term]:.2f}")

print(f"Sugeno: {sugeno(t, h):.2f} % Mamdani (P09a): {mamdani(t, h):.2f} %")

Output

R1 slow w = 0.00 z = 17 w x z = 0.00

R2 slow w = 0.33 z = 17 w x z = 5.67

R3 medium w = 0.33 z = 50 w x z = 16.67

R4 medium w = 0.20 z = 50 w x z = 10.00

R5 fast w = 0.20 z = 83 w x z = 16.60

Sugeno: 45.88 % Mamdani (P09a): 45.04 %

A2. Sugeno and Mamdani side by side

Fan speed against temperature at 70 % humidity for both systems.

# ... set-up: imports, the P08 sets, fire() and mamdani() from P09a (copy from Part A1) ...

Z = {"slow": 17, "medium": 50, "fast": 83} # zero-order: one constant per output

def sugeno(t, h):

rules = fire(t, h)

w = np.array([s for _, s in rules])

z = np.array([Z[term] for term, _ in rules])

return (w * z).sum() / w.sum() # weighted average

import matplotlib.pyplot as plt

temps = np.arange(0, 51, 1)

sug = np.array([sugeno(t, 70) for t in temps]); mam = np.array([mamdani(t, 70) for t in temps])

plt.figure(figsize=(7, 2.6)); plt.plot(temps, mam, label="Mamdani"); plt.plot(temps, sug, "--", label="Sugeno (zero-order)")

plt.xlabel("Temperature (°C)"); plt.ylabel("Fan speed (%)"); plt.title("Humidity 70 %"); plt.legend(); plt.grid(alpha=0.3)

plt.tight_layout(); plt.savefig("compare.png", dpi=90)

d = np.abs(sug - mam)

print(f"largest difference {d.max():.2f} % at {temps[d.argmax()]} C; mean difference {d.mean():.2f} %")

print("Saved compare.png")

Output

largest difference 2.44 % at 15 C; mean difference 0.68 %

Saved compare.png

Part B - Predict the Output

Write your prediction BEFORE running the code. Then run it and correct yourself in a different colour.

B1.

w = [0.2, 0.6]

z = [20, 50]

print(sum(a * b for a, b in zip(w, z)) / sum(w))

My prediction

B2.

w = [0.0, 0.3, 0.0]

z = [17, 83, 50]

print(sum(a * b for a, b in zip(w, z)) / sum(w))

My prediction

B3.

t, h = 36, 70

z_fast = 40 + 1.2 * t # first-order output of the 'fast' rule

print(round(z_fast, 1))

My prediction

Part C - Bug Hunt

Each program has ONE bug. Some crash with an error message; others run but give a wrong answer (silent logic error - the dangerous kind). Find the bug, explain it and write the fix.

C1.

# ... set-up: imports, the P08 sets, fire() and mamdani() from P09a (copy from Part A1) ...

Z = {"slow": 17, "medium": 50, "fast": 83}

rules = fire(5, 50)[1:] # rules 2-5 only

w = [s for _, s in rules]; z = [Z[term] for term, _ in rules]

print(sum(a * b for a, b in zip(w, z)) / sum(w))

Bug, why it happens, and the fixed line(s)

C2.

# ... set-up: imports, the P08 sets, fire() and mamdani() from P09a (copy from Part A1) ...

Z = {"slow": 17, "medium": 50, "fast": 83}

rules = fire(30, 40)

w = np.array([s for _, s in rules]); z = np.array([Z[term] for term, _ in rules])

print(round((w * z).sum() / len(rules), 2))

It runs and prints

9.79

Bug, why it happens, and the fixed line(s)

C3.

# ... set-up: imports, the P08 sets, fire() and mamdani() from P09a (copy from Part A1) ...

t, h = 30, 40

comf, hot = mu(t_x, T["comfortable"], t), mu(t_x, T["hot"], t)

dry = mu(h_x, H["dry"], h)

w = [max(comf, dry), max(comf, 1 - dry), max(hot, dry), max(hot, 1 - dry)] # R2-R5 (AND)

z = [17, 50, 50, 83]

print(round(sum(a * b for a, b in zip(w, z)) / sum(w), 2))

It runs and prints

55.5

Bug, why it happens, and the fixed line(s)

Part D - Graded Tasks (10 marks)

Task

Level

Title

Marks

T1

Easy

Zero-order Sugeno for the five days

3

T2

Medium

Two control surfaces

3

T3

Challenge

A first-order Sugeno system

4

Total

10

Task 1 (Easy, 3 marks): Zero-order Sugeno for the five days

Write sugeno(t, h) with Z = {slow: 17, medium: 50, fast: 83} and the weighted average. Print Sugeno and Mamdani speeds for the five P07b days (30, 40), (34, 65), (38, 75), (41, 55), (36, 90) and the difference. Why do they differ most on day 2?

Sample run (your output must match):

Output

day input Sugeno Mamdani diff

1 30 C, 40 % 45.88 45.04 +0.83

2 34 C, 65 % 83.00 81.43 +1.57

3 38 C, 75 % 83.00 83.33 -0.33

4 41 C, 55 % 83.00 83.33 -0.33

5 36 C, 90 % 83.00 82.78 +0.22

Your code (or attach the file)

Task 2 (Medium, 3 marks): Two control surfaces

Compute both systems on a grid (temperature 0-50 step 2, humidity 0-100 step 5) and draw the two surfaces side by side (two 3-D subplots, save task2.png). Print the largest difference and the input where it happens, and the mean difference.

Sample run (your output must match):

Output

largest difference 7.01 % at 18 C, 45 %

mean difference 0.78 %

Saved task2.png

Your code (or attach the file)

Task 3 (Challenge, 4 marks): A first-order Sugeno system

Make the rule outputs depend on the inputs: slow z = 15; medium z = 30 + t; fast z = 50 + 0.8·t + 0.1·h (more humid -> faster). Write sugeno1(t, h). Print the five days, and plot fan speed against temperature at humidity 40 % and 90 % for the first-order system (save task3.png). What can a first-order system do that the zero-order one cannot?

Sample run (your output must match):

Output

day 1: 30 C, 40 % -> 49.31 %

day 2: 34 C, 65 % -> 83.70 %

day 3: 38 C, 75 % -> 87.90 %

day 4: 41 C, 55 % -> 88.30 %

day 5: 36 C, 90 % -> 87.80 %

at 45 C: humidity 40 % -> 85.0 %, humidity 90 % -> 95.0 %

Saved task3.png

Your code (or attach the file)

Part E - Post-Lab Questions (finish as homework if time runs out)

E1. Write the Sugeno output formula and explain each symbol.

Your answer

E2. Give two differences between Mamdani and Sugeno systems.

Your answer

E3. Why did dividing by the number of rules give 9.79 % instead of 45.88 %?

Your answer

Marking Rubric (applied to Part D)

Criterion

Full

Partial

None

Code runs without errors

Runs fully

Small fixable error

Does not run

Correct weighted average and first-order formulas

All correct

One slip

Several wrong

Tables, surfaces and curves

All present

Some missing

None

Explanations (day 2, surfaces, first-order)

Clear and correct

Partly correct

Missing

Submission

  • Make a folder RollNo_P09b with task1.py, task2.py, task3.py (or P09b.ipynb), task2.png and task3.png.
  • Upload the zipped folder to the LMS / Google Classroom by the end of the day.
  • Copy Task 1 and Task 3 code and output into your Lab Book (Practical 09b page).
  • Keep sugeno1() - ANFIS (P11) learns first-order Sugeno formulas from data.

← All CS-511 material