Jump to content

Getting Fuzzy: Part 1

- - - - -

  • Please log in to reply
12 replies to this topic

#1
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
This is the first part of a three tutorial series, based on fuzzy logic and fuzzy set theory (yes, they are real). Since many of you may not have heard of these, I'm going to spend part 1 explaining what these mathematical concepts are. My plan is to then implement each in C++ in parts 2 and 3.

What do I mean by "fuzzy"? Have you ever been given a question where you're pretty sure you know the answer, but not quite certain? This is a case where you are dealing with fuzziness. You may be 90% sure you have the right answer, or even 95% sure, but you aren't 100% sure. We deal with this type of uncertainty on a regular basis in life. Xav might tell you about his sexual exploits, and you decide there's a 5% chance he's telling the truth. I might talk about having a masters in math and you decide there's a 50% chance I'm telling the truth.

I can apply this to the concept of sets as well. In normal set theory, you have to precisely define the set so a potential element is either definitely in or definitely not in the set. This is great for math, but not so great when you want to talk about the "set of tall people". At 5'10", should I be included in the set? How about my 4'11" tall wife? What about Shaquille O'Neal? Since I don't know how tall is tall enough, I might have a 40% chance of being considered tall. My wife a 1% chance, and Shaq a 100% chance.

These two concepts are closely related. Rather than deal with TRUE or FALSE, we will deal with % likelihood of being true. Rather than deal with IN or OUT of a set, we will deal with % likelihood of being in. 100% means TRUE or definitely IN. 0% means FALSE or definitely OUT.

Logic has three primary operations: AND, OR, NOT. We need to define these in Fuzzy Logic. However we define them should cause them to be consistent with standard logic. Evaluating the standard and fuzzy interpretations for what we know gives us this:
TRUE AND TRUE = TRUE --> 100% AND 100% = 100%
TRUE AND FALSE = FALSE --> 100% AND 0% = 0%
FALSE AND TRUE = FALSE --> 0% AND 100% = 0%
FALSE AND FALSE = FALSE --> 0% AND 0% = 0%

TRUE OR TRUE = TRUE --> 100% OR 100% = 100%
TRUE OR FALSE = TRUE --> 100% OR 0% = 100%
FALSE OR TRUE = TRUE --> 0% OR 100% = 100%
FALSE OR FALSE = FALSE --> 0% OR 0% = 0%

NOT TRUE = FALSE --> NOT 100% = 0%
NOT FALSE = TRUE --> NOT 0% = 100%

Notice that AND gives the smaller percent, OR gives the higher percent, and NOT gives the "opposite" percent. We'll define AND to be the smaller, OR to be the larger, and NOT to be (100% - given).

Then we'll get:
75% AND 75% = 75%
75% AND 25% = 25%
25% AND 75% = 25%
25% AND 25% = 25%

75% OR 75% = 75%
75% OR 25% = 75%
25% OR 75% = 75%
25% OR 25% = 25%

NOT 75% = 25%
NOT 25% = 75%

For Fuzzy Set Theory, we need to define equivalents to UNION, INTERSECTION, and COMPLEMENT:
If the "universe" (all available elements) is {1,2,3,4,5}:
{1,2,3} INTERSECT {2,3,4} = {2,3}
{1,2,3} UNION {2,3,4} = {1,2,3,4}
COMPLEMENT {1,2,3} = {4,5}

Translating this to Fuzzy Sets gives us:
{1: 100%, 2: 100%, 3: 100%, 4: 0%, 5: 0%} INTERSECT {1: 0%, 2: 100%, 3: 100%, 4: 100%, 5: 0%} = {1: 0%, 2: 100%, 3: 100%, 4: 0%, 5: 0%}

{1: 100%, 2: 100%, 3: 100%, 4: 0%, 5: 0%} UNION {1: 0%, 2: 100%, 3: 100%, 4: 100%, 5: 0%} = {1: 100%, 2: 100%, 3: 100%, 4: 100%, 5: 0%}

COMPLEMENT {1: 100%, 2: 100%, 3: 100%, 4: 0%, 5: 0%} = {1: 0%, 2: 0%, 3: 0%, 4: 100%, 5: 100%}

Notice again that INTERSECT gets the low percentage for each element, UNION gets the high percentage for each element, and COMPLEMENT gets the "opposite" percentage for each element. So some fuzzy sets would give:
{1: 100%, 2: 75%, 3: 60%, 4: 20%, 5: 0%} INTERSECT {1: 0%, 2: 80%, 3: 65%, 4: 60%, 5: 30%} = {1: 0%, 2: 75%,3: 60%, 4: 20%, 5: 0%}

{1: 100%, 2: 75%, 3: 60%, 4: 20%, 5: 0%} UNION {1: 0%, 2: 80%, 3: 65%, 4: 60%, 5: 30%} = {1: 100%, 2: 80%,3: 65%, 4: 60%, 5: 30%}

COMPLEMENT {1: 100%, 2: 75%, 3: 60%, 4: 20%, 5: 0%} = {1: 0%, 2: 25%,3: 40%, 4: 80%, 5: 100%}

The goal, then, is to take these two concepts, and create classes equivalent to the set and boolean template/type. We won't try to perfectly recreate the mathematical objects, but we would like to extend the C++ functionality that already exists.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#2
Guest_Jordan_*

Guest_Jordan_*
  • Guests
Excellent read. I'm 90% sure I understand what you are talking about. :) +rep

#3
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
The key is, if this doesn't make any sense, the tutorials to follow will really not make sense.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#4
Guest_Jordan_*

Guest_Jordan_*
  • Guests
My response was fuzzy. :)

Thanks for the excellent read. I intend on reading part 2 fully in just a few minutes (if I can find it on my mobile).

Posted via CodeCall Mobile

#5
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
I would imagine that reading code on a mobile device is not the most pleasant of experiences.

Implementing a Fuzzy Boolean is part II.

Edited by WingedPanther, 14 November 2008 - 07:33 PM.
add followup link

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#6
marwex89

marwex89

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 10,720 posts
Interesting :) I've used something similar in a smaller scale +rep
Hey! Check out my new Toyota keyboaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

#7
amrosama

amrosama

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 8,674 posts
Wow gr8
i read about fuzzy but ive never seen real implementation
thnx alot
Posted via CodeCall Mobile

#8
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts

Quote

Xav might tell you about his sexual exploits, and you decide there's a 5% chance he's telling the truth.

You missed out on your +rep for that.
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#9
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
LOL. It was worth the lost rep.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#10
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
All 75 points?
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#11
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
Yup. You're the one who cares about +rep, not me. The fact that you would have +rep'd me is all I need :)
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#12
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
In that case, I will say that I wouldn't have +repped you anyway.
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users