How to write a python code for Adaptive Neuro Fuzzy Inference System (ANFIS)

Ask Questions Forum: ask Machine Learning Questions to our readersCategory: Machine LearningHow to write a python code for Adaptive Neuro Fuzzy Inference System (ANFIS)
Chamud Pathirana asked 5 days ago

I wish to include ANFIS in the project I’m doing. Basically the system is to insert the daily symptoms of coronavirus and system will tell which day it is after getting affected by corona. There are 13 symptoms and 10 outputs(the days). Each symptom has 2-4 number of membership functions. img: mapping of symptoms with days
As a start, I plotted a diagram similar to a fuzzy-neural network: Visualization of fuzzy Neural network Here I have taken each input (each input is a value between 1-10), separate them under each membership function, then assign a value between 0-1 by converting the input scale to 0-1 scale, pass those values to the relevant days and finally get the average value which is again between 0-1.
The following example is for higher clarity: imgSymptom ‘1’ membership functions The first symptom to consider is ‘cold’. If the fuzzy value of the input cold is 2.5, it will go through mild section which is between 1 & 6 and then 2.5(let it be x value) will be converted to 0.5(let it be y value) after scaling 1-6 to 0-1. [y=(x-1)/5]. And this value will be sent to all the dates that are connected to cold-mild function. (day 1 to day 6). The same process will happen to each input and finally the summation of y values in each day will be divided by 13, to get the average value which is again between 0-1. By taking the day with the highest value the system can say which day the input symptoms are most likely to be.
Now the issue is, even though this approach seems similar to neuro fuzzy I simply wrote the whole code with if-else statements.

#Input variables with sample data
cold = 4
jointPain = 0
feelingWeek = 0
lossOfAppt = 0
abdominalPain = 0 
soreThroat = 5
headache = 0
temperature = 3 
dryCough = 0
Dyspnea = 0
nausea = 0
vomiting = 0
diarrhea = 0

#output variables
day0 = 0
day1or2 = 0
day3 = 0
day4 = 0
day5 = 0
day6 = 0
day7 = 0
day8or9 = 0
day10 = 0
day11 = 0

#conversions and adding weights
if(cold<=1):#null
    weight = 1
    day0 += weight
elif(cold<=6):#mild
    weight = (cold-1)/5
    day1or2 += weight
    day3 += weight
    day4 += weight
    day5 += weight
    day6 += weight
else:#severe
    weight = (cold-6)/4
    day7 += weight
    day8or9 += weight
    day10 += weight
    day11 += weight
    
if(jointPain<=1):#null
    weight = 1
    day0 += weight
    day1or2 += weight
    day3 += weight
elif(jointPain<=4):#mild
    weight = (jointPain-1)/3
    day4 += weight
    day5 += weight
    day6 += weight
elif(jointPain<=7):#painful
    weight = (jointPain-4)/3
    day7 += weight
    day8or9 += weight
    day10 += weight
    day11 += weight
else:#severe
    weight = (jointPain-7)/3
    day11 += weight

if(feelingWeek<=1):#null
    weight = 1
    day0 += weight
    day1or2 += weight
    day3 += weight
elif(feelingWeek<=6):#occasional
    weight = (feelingWeek-1)/5
    day4 += weight
else:#often
    weight = (feelingWeek-6)/4
    day5 += weight
    day6 += weight
    day7 += weight
    day8or9 += weight
    day10 += weight
    day11 += weight

if(lossOfAppt<=1):#no
    weight = 1
    day0 += weight
    day1or2 += weight
    day3 += weight
    day4 += weight
    day5 += weight
    day6 += weight
    day7 += weight
    day8or9 += weight
else:#yes
    weight = (lossOfAppt-1)/9
    day10 += weight
    day11 += weight

if(abdominalPain<=1):#null
    weight = 1
    day0 += weight
    day1or2 += weight
    day3 += weight
    day4 += weight
    day5 += weight
    day6 += weight
    day7 += weight
    day8or9 += weight
elif(abdominalPain<=4):#mild
    weight = (abdominalPain-1)/3
    day10 += weight
elif(abdominalPain<=7):#painful
    weight = (abdominalPain-4)/3
    day10 += weight
    day11 += weight
else:#severe
    weight = (abdominalPain-7)/3
    day11 += weight

if(soreThroat<=1):
    weight = 1
    day0 += weight
elif(soreThroat<=4):
    weight = (soreThroat-1)/3
    day1or2 += weight
    day3 += weight
elif(soreThroat<=7):
    weight = (soreThroat-4)/3
    day3 += weight
    day4 += weight
    day5 += weight
    day6 += weight
else:
    weight = (soreThroat-7)/3
    day7 += weight
    day8or9 += weight
    day10 += weight
    day11 += weight    

if(headache<=1):
    weight = 1
    day0 += weight
    day1or2 += weight
    day3 += weight
    day4 += weight
elif(headache<=4):
    weight = (headache-1)/3
    day5 += weight
    day6 += weight
elif(headache<=7):
    weight = (headache-4)/3
    day6 += weight
    day7 += weight
    day8or9 += weight
    day10 += weight
    day11 += weight
else:
    weight = (headache-7)/3
    day7 += weight
    day8or9 += weight
    day10 += weight
    day11 += weight

if(temperature<=4):
    weight = 1
    day0 += weight
    day1or2 += weight
    day3 += weight
    day4 += weight
elif(temperature<=6):
    weight = (temperature-4)/2
    day5 += weight
    day6 += weight
    day7 += weight
    day8or9 += weight
    day10 += weight
    day11 += weight
else:
    weight = (temperature-6)/4
    day8or9 += weight
    day10 += weight
    day11 += weight
    
if(dryCough<=1):
    weight = 1
    day0 += weight
    day1or2 += weight
    day3 += weight
    day4 += weight
elif(dryCough<=4):
    weight = (dryCough-1)/3
    day5 += weight
    day6 += weight
elif(dryCough<=7):
    weight = (dryCough-4)/3
    day7 += weight
else:
    weight = (dryCough-7)/3
    day7 += weight
    day8or9 += weight
    day10 += weight
    day11 += weight

if(Dyspnea<=1):
    weight = 1
    weight = 1
    day0 += weight
    day1or2 += weight
    day3 += weight
    day4 += weight
elif(Dyspnea<=4):
    weight = (Dyspnea-1)/3
    day5 += weight
    day6 += weight
elif(Dyspnea<=7):
    weight = (Dyspnea-4)/3
    day7 += weight
    day8or9 += weight
    day10 += weight
else:
    weight = (Dyspnea-7)/3
    day8or9 += weight
    day10 += weight
    day11 += weight

if(nausea<=1):
    weight = 1
    day0 += weight
    day1or2 += weight
    day3 += weight
    day4 += weight
elif(nausea<=6):
    weight = (nausea-1)/5
    day3 += weight
    day4 += weight
    day5 += weight
    day6 += weight
else:
    weight = (nausea-6)/4
    day7 += weight
    day8or9 += weight
    day10 += weight
    day11 += weight
    
    
if(vomiting<=1):
    weight = 1
    day0 += weight
    day1or2 += weight
    day3 += weight
    day4 += weight
elif(vomiting<=6):
    weight = (vomiting-1)/5
    day3 += weight
    day4 += weight
    day5 += weight
else:
    weight = (vomiting-6)/4
    day6 += weight
    day7 += weight
    day8or9 += weight
    day10 += weight
    day11 += weight
    

if(diarrhea<=1):
    weight = 1
    day0 += weight
    day1or2 += weight
    day3 += weight
    day4 += weight
elif(diarrhea<=6):
    weight = (diarrhea-1)/5
    day3 += weight
    day4 += weight
    day5 += weight
    day6 += weight
else:
    weight = (diarrhea-6)/4
    day7 += weight
    day8or9 += weight
    day10 += weight
    day11 += weight

#final conversion 
day0 /= 13
day1or2 /= 13
day3 /= 13
day4 /= 13
day5 /= 13
day6 /= 13
day7 /= 13
day8or9 /= 13
day10 /= 13
day11 /= 13

#Displaying results
print("not afected : ", day0)
print("day 1 or 2 : ",day1or2)
print("day 3 : ",day3)
print("day 4 : ",day4)
print("day 5 : ",day5)
print("day 6 : ",day6)
print("day 7 : ",day7)
print("day 8 or 9 : ",day8or9)
print("day 10 : ",day10)
print("day 11 or more : ",day11)

The code is bit lengthy but the process is very simple.

Now I would like to implement this whole process using an actual ANFIS.

If someone can explain me which tools to use and how to write the code or at least put a link to a tutorial or a sample code of a neuro-fuzzy system with multiple inputs and outputs, that would be highly appreciated.

Your Answer

20 + 1 =