Ask a question

How do i go about seperating my numerical data into fuzzy sections and putting it into code in Python ?

My inputs X1 and X2 are the values from -12 and 12 including 0 (i.e:(-12,-11,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10,11,12) for both X1 and X2 and my output y is the function y=(2*(X1^2))+(X2^2),. In my code I got the values for y as [432 363 300 243 192 147 108 75 48 27 12 3 0 3 12 27 48 75 108 147 192 243 300 363 432]

1 Answer by Expert Tutors

Tutors, sign in to answer this question.
Timothy S. | Will help you LOVE math, science, and computing!Will help you LOVE math, science, and co...
5.0 5.0 (9 lesson ratings) (9)
for loops and dictionaries are your best friends in the world
#declare y as a dictionary to allow for negative indexing
y = {}

#calculate all y
for x1 in range(-12,13):
    #add a new dictionary to the main dictionary at the key of x1's current value to allow multidimensional space
    y[x1] = {}
    for x2 in range(-12,13):
        y[x1][x2] = 2*x1*x1 + x2*x2

#print all y (could be done in line with calculation for efficiency but done separately for understanding
for x1 in range(-12, 13):
    for x2 in range(-12,13):
        print "y[%d][%d] = %d" %(x1, x2, y[x1][x2])


That said, I'm not really sure what you mean by fuzzy sections. This will store all the values for that function in a precomputed dictionary y (however, precomputing all the values is highly inefficient if you are just looking to train your artificial intelligence systems on a parameter.
If you are looking to partition the space for that utility function, you really need to think about the metric by which you are doing that. Arbitrarily setting the limits is not very effective. What you really want is to be able to train on the the signal and response of your data and the decision your algorithm makes.
For example. You may start out with two even partitions for your data. When your algorithm makes a choice for an action based on that partition and fails to accomplish its task, the input parameters should be noted and the partition shifted. Once the partition finds its way to convergence on some value, the system is considered trained. If you find that moving the partition does not improve or diminish overall performance but performance only for each category, another partition should be added, and some variant of the behavior should be attempted for parameters falling within the new partition. 
Without more information about the actual assignment I am not sure that I can assist you. What is it that you are trying to accomplish?
 Hi I'm trying to implement the learning from examples algorithm in fuzzy logic using the function and limits i gave in Python