This is a project on my last year at school, everything is free to use, no need to ask for permission. Although everything is free, you can donate me some dollars Donate .

To understand this project, some knowledge about fuzzy logic and Python programming skill is required. Also, your pc or laptop must have Python 2.7, a Python editor (Sublime Text, PyCharm ….), and MatLab installed on it.
To install scikit-fuzzy, go here.
To install Python 2.7, go here.
Download .fis file Obesity.fis
I’ve downloaded MatLab using BitTorrent, but I think that updating the link here might violate copy right. So you can check out Google the link and download it yourself.

First open MatLab, and type ‘fuzzy’: I’ve been using Matlab R2016a, with full packages installed.

A window pop up, looks like this
Click file -> Import -> From File

We got

As you can see, the control system is mamdani, with three input variables : BMI, BF, WC and one output variable : Obesity Level. The system use max for aggregation , centroid for defuzzification. Those are all default values, we rarely change them.
Here are member functions of each input and output variables:
Note *: Usually we use trimf or trapmf as type of member functions. In this case, I use trimf for all member functions.

RULE 24: IF BMI = HIGH AND BF = NORMAL AND WC = LARGE THEN TIP = OBESE

RULE 25: IF BMI = HIGH AND BF = HIGH AND WC = SMALL THEN TIP = OVERWEIGHT

RULE 26: IF BMI = HIGH AND BF = HIGH AND WC = MEDIUM THEN TIP = OBESE

RULE 27: IF BMI = HIGH AND BF = HIGH AND WC = LARGE THEN TIP = OBESE

Edit -> Rules :
View->Rules

With input [BMI; BF; WC] = [17.5; 17.5; 60] , ObesityLevel = 31.9

Implement on Python (using scikit-fuzzy)
As I explained above, there are three steps to build a fuzzy control system. But before we get started, let’s import skfuzzy module and skfuzzy.control and numpy as well.

Three input variables self.__bmi, self.__bf, self.__wc, and one output variable self.__obesity. BMI (kg/m^2) and BF (%) are in range 0-35, WC is from 0 to 120 (cm), Obesity is in range 0-100. We have ‘self’ because I use object-oriented programming to build this fuzzy control system, at the last part of this post, you will get all the code as well as some other instructions to build and run it.

BMI has three membership functions: low, moderate, high
BF has three membership functions: low, normal, high
WC has three membership functions: small, medium, large
OL has three membership functions: healthy, overweight, obese
They’re all trimf type, so they need three values [start,mid,stop].

Just imagine that the comma is equal with ‘then’ and & is equal with ‘and’
Now we got variables, membership functions, rules. What we need to do next is to create a fuzzy control system. The code in step 4 means: create an array of rules, store all 27 rules. And build the control system on top of those rules.

This method take three arguments, bmi, bf and wc. Create a control system simulation base on our control system, then pass into it three input values, and compute(). I have to change directly the code in controlsystem.py of skfuzzy.control to be able to get the step by step instructions of how the control system work. So bare with me and I’ll show you all.

The training dataset is MNIST dataset, with 60k training images and 10k testing images. But with a little ‘twisted’, it becomes 180k training images. You can Google ‘MNIST dataset’ to know more.

With 10k testing images, accuracy is more than 95%. But I don’t want to stop at that, I want to create a program that you can draw a digit, and then it will say which number that you’ve just drawn.

Here’s the demo

The program works quite well with numbers: 0,1,2,3,4,5,6,7,8 , but it can hardly recognize the number 9, because of several reasons. First reason is inside the MNIST dataset, the number 9 is the most … ugly number, it’s so small, and the second reason is the thickness of the number that we draw. I’ve used an algorithm that I came up with, to track a number in side an image. And maybe the algorithm itself is also the reason why the program didn’t work well as I expected.

The source code as well as other related information and materials will be uploaded to Github at the end of this semester (around at the end of December) .

I wrote this snake AI in more than two days.
If you’re interested , send me an email, I’ll give you source code as well as the algorithm.
It will be a great help if you donate me some dollars, because I’m a poor coder 😦