I was going over some code from a few years back. I have tons if AI/ datamining, etc code from over the years. I was working on some WPF related UI stuff – and decided to dig out and dust off some of my fuzzy logic code. So – here is the 1st bit of code for NFuzz – a simple fuzzy logic library for .net.

***Quick* Primer on fuzzy logic**

The basic idea of fuzzy logic is a simple extension of plain old logical proofs. Take for example:

- true and false = false
- true and true = true
- etc.

These are examples of classical logic – or crisp logic. Now – fuzzy logic is basically that – but with numbers and ‘degrees of trueness/ falseness’.

Here is a coarse example:

- 1-3 = low
- 3-5Â = med
- 5-7 = hi

This might look something like this:

That is basically ‘crisp’ logic – you can say “is it low?” or “is it high”.

**Fuzzy Sets**

Here are a few more possibilities – fuzzy sets:

Â or Â or Â or even

Here we have triangle, trapezoid, gaussian and mixed “fuzzy sets”.

**Fuzzy Membership Functions**

A Fuzzy set is a group of labeled ‘fuzzy membership functions’. Each of the “low, med,etc” items we see above is a fuzzy membership function. These membership functions job is to return a # from 0-1 – the degree of membership to that label in the term set. So if – for example – your “low” triangle membership function is from 0, peaks at 5 and ends at 10, any # that is sent into it will have a ‘degree of membership’. If I send a 11 in, or a 1000, – I will get a zero membership (it is not found in that membership function’s space. If i send a number between 0 and 10 in – I will get a # > 0 <=1. This works the same way for all fuzzy membership functions.

**Fuzzy Logic**

It starts to get interesting when you add in LOGIC. You can say things like “low or med” or “low and medium” or even things (when you include ‘hedge terms’) like “very high” or “somewhat low”.

The idea with ALL of this is that you can have rules – stated in logical terms – and abstract away from the #s of it all. You can then ‘tune the membership functions’ to fit your domain best. This has proven very useful for trading systems in the past. You can push streams of data into your fuzzy sets and have rules for trading this way. It is applicable to MANY domains…

More to come on all this… For now – here is a quick code snap.

NFuzz.zip

-Chris-