MSc AI · Fuzzy Logic (CT102) · Jul 2023

Fuzzy Highway

How fast should a car go on this stretch of road? My fuzzy-logic coursework answered with rules instead of a trained model. This is the original Python notebook, ported to run in your browser and checked against the library it was written for. Drag the sliders.

Live · your car is on the slip road
cracks & puddles = poor road cars = traffic density green window = gap you, at the fuzzy speed
See it on your deskTwo models of the highway in AR, with no app to install: still on iPhone and iPad, with your car merging on Android. Tap one, then place it on a table and walk around it.Two models of the highway in AR. Open this page on a phone (iPhone, iPad or Android) to place one on your desk. Want the sliders in AR too? On an Android phone in Chrome, tap Live AR on the scene above. Live AR on iPhone: in development.
View in AR: the 2023 rules with dense traffic, where the OR rule's red shell forces a limit of 17 View in AR: the 27-rule rewrite with light traffic, several rules firing to a limit of 56
Rule base

The seven rules, firing live

AND takes the smaller membership, OR the larger. Each rule cuts its output set at that strength.

Recommended speed limit

centroid of the shaded area—km/h, on a 0–100 scale

The whole decision, at a glance

← poor roadgood road →

Every combination of road (left to right) and gap (bottom to top) at the current traffic density. Red is a low limit, green a high one. Drag the traffic slider and watch the map change.

The browser engine reproduces scikit-fuzzy 0.5 exactly: across 510 test inputs (500 of them random) it gave identical results to 6 decimal places, and it fails on the same input the library does.

What it gets wrong

I kept these behaviours in the demo instead of fixing them, because they're the most useful part.

Where it came from

A group assignment, and the version that survived.

The group report

With two classmates I wrote Intelligent Joining Speed Determination on Highways using Fuzzy Logic: four inputs (speed of incoming traffic, a two-wheeler present, visibility, a gap in traffic), 36 rules, and a centroid answer for how fast to merge.

That program's code didn't survive; only its screenshots did. Its own output shows the same kind of problem: at 120 km/h with clear visibility it advised merging at 21 km/h.

Console: speed 120, no two-wheeler, visibility 10, no gap, joining speed 21.45, level slow
From the July 2023 report, typos and all.

The notebook that survived

My own notebook is a smaller version: three inputs on 0–10 and seven rules, built with scikit-fuzzy. That's what runs above. It's on GitHub along with a 2025 rewrite.

Fuzzy_logic_speed_limit_v2.ipynb
rule1 = ctrl.Rule(road_conditions['poor'] | traffic_density['good'] | gap_in_traffic['poor'], speed_limit['low'])
The two ORs behind the 16.7.

The 2025 rewrite (speed_limit_pure.py) promises 36 rules in its docstring, but the mapping it actually uses ignores traffic density entirely. That's next on my list to fix.

Membership function plots from the report
The report's membership functions, plotted by the original program.