# Fuzzy Logic CPSC 386 Artificial Intelligence Ellen Walker

• Slides: 18

Fuzzy Logic CPSC 386 Artificial Intelligence Ellen Walker Hiram College

Why fuzzy? • Imprecision better approximates human reasoning – It is warm today. • 65 degrees F in April is warm • 65 degrees F in August is cool • Imprecise calculation can be much faster (and “good enough”) – This is the idea behind heuristics • TSP (0. 75%) 1, 000 cities, 7 months • TSP (3. 5%) 1, 000 cities, 3. 5 hours

Fuzzy vs. Crisp Sets • Crisp set A – Each item x is an element of A (100%) or is not (0%) • Fuzzy set A – Each item x has degree of membership in the set A – An item can have non-zero membership in both A and ~A

Membership function • Horizontal axis: all potential members of the set (sorted, if possible) • Vertical axis: membership value from 0 (not at all) to 1 (totally) cold warm 0. 8 0. 2 65 F Temperature hot

Linguistic Values • Cold, Warm and Hot are linguistic values, represented by overlapping membership functions • We can also define linguistic modifiers – – Very A = membership in A squared Somewhat hot = sqrt (membership in A) Not A = 1 -A So, “not very A” = 1 -A 2

Fuzzy Logic Operations • AND – X cannot have more membership in the set (A and B) than it does in A – Therefore, membership in (A and B) = min (membership in A, membership in B) • OR – X must have at least as much membership in (A or B) as in A – Therefore, membership in (A or B) = max (membership in A, membership in B)

Fuzzy Rules • The basic fuzzy rule form – If x is A then y is B • First, determine membership of x in A • Then use that value to limit the degree to which y is B

Example: Adjusting a Bath/Shower • Rules – If temperature is cold, then add-hot-water = high – If temperature is warm, then add-hot-water = med – If temperature is cold, then add-cold-water = low – If temperature is warm, then add-cold-water = low

Example: Membership functions cold warm hot 0. 8 0. 2 65 F Temperature low med Water flow high

Resulting Membership Functions low med high Center of mass Cold water flow (. 8 low, . 2 low) low med high Center of mass Hot water flow (. 8 med, . 2 high)

More complex left sides • If X is A and Y is B, then Z is C – Take AND (min) of A and B membership values to limit C • If X is A and Y is not B … – Take min (A, 1 -B) membership values to limit C

Designing a Fuzzy Rule-based System • Develop linguistic variables for each input and output variable • Express a set of rules in terms of variables – One rule for each input, output combination • Test and adjust – Change rules – Change linguistic variables • Often done using neural net, genetic algorithm, etc.

Operating a Fuzzy Rule Based System • Fuzzify inputs – Numerical input -> set of linguistic memberships • Apply rules – Find the degree to which the left side applies – Limit the m. f. of the right side at that value – OR (union) m. f. s of all applicable rules • Defuzzify output – Find the center of mass of the resulting fuzzy set, translate that to a numerical output (if needed)

Rules as Fuzzy Graphs – If temperature is cold, then add-hot-water = high – If temperature is warm, then add-hot-water = med – If temperature is hot, then add-hot-water = low hot warm cold low med high

Advantages of Fuzzy Rules • Rules are expressed in (close to) natural language • Fewer rules are needed because of interpolation • No precise thresholds – Precise thresholds tend to make systems brittle

Fuzzy Clustering • If you have data that you want to classify, you are essentially specifying subsets of your data. • Crisp clustering = crisp sets. Each item in (at most) one cluster. • Fuzzy clustering = fuzzy sets. Items can belong to multiple clusters (with membership values between 0 and 1) – Typically, membership values add up to 1

K Means Clustering (Crisp) Choose K random cluster centers Repeat For each data point (feature vector) Find the closest cluster Assign point to cluster For each cluster Recompute the center (avg. data pt) Until clusters don’t change

Fuzzy C-Means Clustering • Same as fuzzy K-means except: – Point has (0 -1) membership in cluster – Membership computed based on distance from center – Center computed based on weighted average of cluster members (weight by membership) • “Borderline points” belong to multiple clusters, but don’t pull the centers much • Overlapping clusters make sense