def getAnglePlatform(x_pos, y_pos):
    with open('fuzzycontrol_normal_3.pkl', 'rb') as f:
        anf = pickle.load(f)

    input_val = np.array([[x_pos, y_pos]])

    anfis_matrix = anfis.predict(anf, input_val)
    return np.array([anfis_matrix[0,0], anfis_matrix[0, 1], anfis_matrix[0, 2]])
예제 #2
0
def fuzzy_error_test(anf, test_table_csv):
    # grab the input positions from the test table
    test_xyz = numpy.loadtxt(test_table_csv, delimiter=',', usecols=[0, 1, 2])

    # grab the expected angles
    test_angles = numpy.loadtxt(test_table_csv,
                                delimiter=',',
                                usecols=[3, 4, 5])

    # with open('fuzzy_test_gauss.pkl', 'rb') as f:
    #     anf = pickle.load(f)

    # initialize the total error count
    total_error = 0
    average_error = []

    # loop through each row in the demo table
    for row_num in range(len(test_xyz)):
        # grab the input value for ANFIS
        input_val = test_xyz[row_num]

        # put into a numpy array
        input_val = numpy.array([input_val])

        # evaluate ANFIS and get the predicted output
        predicted_output = anfis.predict(anf, input_val)

        # calculate the percent error between the predicted and expected
        percent_error = numpy.mean(
            abs(test_angles[row_num] - predicted_output) /
            test_angles[row_num])

        # add onto the total error
        total_error = total_error + percent_error

        average_error.append(percent_error)

        # print for each row evaluated
        print row_num, len(test_xyz)

    return total_error, numpy.mean(average_error)
    pickle_filename = []
    pickle_filename.append(log_filename[:-4])
    pickle_filename.append('.pkl')
    pickle_filename = ''.join(pickle_filename)

    with open(pickle_filename, 'wb') as f:
        pickle.dump(anf, f, pickle.HIGHEST_PROTOCOL)

    logging.info("Wrote the PICKLE FILE: %s", pickle_filename)

    print time.time() - t

    total_error, average_error = fuzzy_error_test(anf, "test_table_176_184.csv")

    logging.info("The total error is: %f", total_error)
    logging.info("The average error is: %f", average_error)
    print "The total error is: ", total_error
    print "The average error is: ", average_error

    # var = numpy.array([[3, 4], [3, 4]])
    var = np.array([[0,0,-207]])

    print "input", var

    # print the predicted value based on the trained set
    print "The answer is", anfis.predict(anf, var)

except:
    logging.exception('An exception has occured!!')
    raise
예제 #4
0
# set the input value
input_val = numpy.array([[0, 0, -207.70890486488082]])

# set what the expected output should be
output_val = numpy.array([175, 175, 175])

print "input", input_val

# print "the length is", len(var[:,0])
#
# var = numpy.asanyarray(var)
# print "the shape", var.shape
# print "the shape index", var.shape[0]
# print "the shape index", var.shape[1]

# start the timer
start = timeit.timeit()

# print the predicted value based on the trained set
anfis_ans = anfis.predict(anf, input_val)
print "The answer is", anfis_ans

# stop the timer
end = timeit.timeit()
print "Time: ", end - start

# calculate the error
mse = ((output_val - anfis_ans)**2).mean(axis=None)
print "Error: ", mse * 100