Ejemplo n.º 1
0
def case_1(c1_test, c2_test, c3_test, p_c1, p_c2, p_c3, cov_matrix1,
           cov_matrix2, cov_matrix3, mean1, mean2, mean3, x1, x2, x3, y1, y2,
           y3, which_plot, c_min_max):

    cov_matrix = np.zeros((2, 2))
    covv_matrix = np.zeros((2, 2))

    inv_cov_matrix = np.zeros((2, 2))
    inv_cov_matrix1 = np.zeros((2, 2))
    inv_cov_matrix2 = np.zeros((2, 2))
    inv_cov_matrix3 = np.zeros((2, 2))
    confusion_matrix = np.zeros((3, 3))
    for i in range(2):
        for j in range(2):
            if (i + j) % 2 == 0:
                covv_matrix[i][j] = (cov_matrix1[i][j] + cov_matrix2[i][j] +
                                     cov_matrix3[i][j]) / 3

            else:
                cov_matrix[i][j] = 0
    cov_matrix[0][0] = (covv_matrix[0][0] + covv_matrix[1][1]) / 2.0000
    cov_matrix[1][1] = (covv_matrix[0][0] + covv_matrix[1][1]) / 2.0000
    inv_cov_matrix = np.linalg.inv(cov_matrix)
    inv_cov_matrix1 = inv_cov_matrix2 = inv_cov_matrix3 = inv_cov_matrix
    #confusion_matrix=test.test_1(c1_test,c2_test,c3_test,inv_cov_matrix1,inv_cov_matrix2,inv_cov_matrix3,mean1,mean2,mean3)
    if which_plot == 0:
        confusion_matrix = test.test_1(c1_test, c2_test, c3_test, p_c1, p_c2,
                                       p_c3, inv_cov_matrix1, inv_cov_matrix2,
                                       inv_cov_matrix3, mean1, mean2, mean3)
        plot.plot_1(p_c1, p_c2, p_c3, inv_cov_matrix1, inv_cov_matrix2,
                    inv_cov_matrix3, mean1, mean2, mean3, x1, x2, x3, y1, y2,
                    y3, 0, c_min_max)
        return (confusion_matrix)
    elif which_plot == 10:
        plot.plot_1(p_c1, p_c2, p_c3, inv_cov_matrix1, inv_cov_matrix2,
                    inv_cov_matrix3, mean1, mean2, mean3, x1, x2, x3, y1, y2,
                    y3, 10, c_min_max)
    elif which_plot == -1:
        plot.plot_1_1(p_c1, p_c2, inv_cov_matrix1, inv_cov_matrix2, mean1,
                      mean2, x1, x2, y1, y2, -1, c_min_max)
    elif which_plot == 1:
        plot.plot_1_1(p_c1, p_c2, inv_cov_matrix1, inv_cov_matrix2, mean1,
                      mean2, x1, x2, y1, y2, 1, c_min_max)
    elif which_plot == -2:
        plot.plot_1_1(p_c2, p_c3, inv_cov_matrix2, inv_cov_matrix3, mean2,
                      mean3, x2, x3, y2, y3, -2, c_min_max)
    elif which_plot == 2:
        plot.plot_1_1(p_c2, p_c3, inv_cov_matrix2, inv_cov_matrix3, mean2,
                      mean3, x2, x3, y2, y3, 2, c_min_max)
    elif which_plot == -3:
        plot.plot_1_1(p_c1, p_c3, inv_cov_matrix1, inv_cov_matrix3, mean1,
                      mean3, x1, x3, y1, y3, -3, c_min_max)
    elif which_plot == 3:
        plot.plot_1_1(p_c1, p_c3, inv_cov_matrix1, inv_cov_matrix3, mean1,
                      mean3, x1, x3, y1, y3, 3, c_min_max)
Ejemplo n.º 2
0
def case_4(c1_test, c2_test, c3_test, p_c1, p_c2, p_c3, cov_matrix1,
           cov_matrix2, cov_matrix3, mean1, mean2, mean3, x1, x2, x3, y1, y2,
           y3, which_plot, c_min_max):

    cov_matrix = np.zeros((2, 2))
    inv_cov_matrix1 = np.zeros((2, 2))
    inv_cov_matrix2 = np.zeros((2, 2))
    inv_cov_matrix3 = np.zeros((2, 2))
    confusion_matrix = np.zeros((3, 3))

    inv_cov_matrix1 = np.linalg.inv(cov_matrix1)
    inv_cov_matrix2 = np.linalg.inv(cov_matrix2)
    inv_cov_matrix3 = np.linalg.inv(cov_matrix3)
    #confusion_matrix=test.test_1(c1_test,c2_test,c3_test,inv_cov_matrix1,inv_cov_matrix2,inv_cov_matrix3,mean1,mean2,mean3)
    if which_plot == 0:
        confusion_matrix = test.test_1(c1_test, c2_test, c3_test, p_c1, p_c2,
                                       p_c3, inv_cov_matrix1, inv_cov_matrix2,
                                       inv_cov_matrix3, mean1, mean2, mean3)
        plot.plot_1(p_c1, p_c2, p_c3, inv_cov_matrix1, inv_cov_matrix2,
                    inv_cov_matrix3, mean1, mean2, mean3, x1, x2, x3, y1, y2,
                    y3, 0, c_min_max)
        return (confusion_matrix)
    elif which_plot == 10:
        plot.plot_1(p_c1, p_c2, p_c3, inv_cov_matrix1, inv_cov_matrix2,
                    inv_cov_matrix3, mean1, mean2, mean3, x1, x2, x3, y1, y2,
                    y3, 10, c_min_max)
    elif which_plot == -1:
        plot.plot_1_1(p_c1, p_c2, inv_cov_matrix1, inv_cov_matrix2, mean1,
                      mean2, x1, x2, y1, y2, -1, c_min_max)
    elif which_plot == 1:
        plot.plot_1_1(p_c1, p_c2, inv_cov_matrix1, inv_cov_matrix2, mean1,
                      mean2, x1, x2, y1, y2, 1, c_min_max)
    elif which_plot == -2:
        plot.plot_1_1(p_c2, p_c3, inv_cov_matrix2, inv_cov_matrix3, mean2,
                      mean3, x2, x3, y2, y3, -2, c_min_max)
    elif which_plot == 2:
        plot.plot_1_1(p_c2, p_c3, inv_cov_matrix2, inv_cov_matrix3, mean2,
                      mean3, x2, x3, y2, y3, 2, c_min_max)
    elif which_plot == -3:
        plot.plot_1_1(p_c1, p_c3, inv_cov_matrix1, inv_cov_matrix3, mean1,
                      mean3, x1, x3, y1, y3, -3, c_min_max)
    elif which_plot == 3:
        plot.plot_1_1(p_c1, p_c3, inv_cov_matrix1, inv_cov_matrix3, mean1,
                      mean3, x1, x3, y1, y3, 3, c_min_max)
def case_1(c1, c2, c3, cov_matrix1, cov_matrix2, cov_matrix3, mean1, mean2,
           mean3, x1, x2, x3, y1, y2, y3):

    cov_matrix = np.zeros((2, 2))
    inv_cov_matrix = np.zeros((2, 2))
    confusion_matrix = np.zeros((3, 3))
    for i in range(2):
        for j in range(2):
            if (i + j) % 2 == 0:
                cov_matrix[i][j] = (cov_matrix1[i][j] + cov_matrix2[i][j] +
                                    cov_matrix3[i][j]) / 3

            else:
                cov_matrix[i][j] = 0

    inv_cov_matrix = np.linalg.inv(cov_matrix)
    confusion_matrix = test.test_1(c1, c2, c3, inv_cov_matrix, mean1, mean2,
                                   mean3)

    plot.plot_1(inv_cov_matrix, mean1, mean2, mean3, x1, x2, x3, y1, y2, y3)
    return (confusion_matrix)
Ejemplo n.º 4
0
def case_3(c1_test, c2_test, c3_test, p_c1, p_c2, p_c3, cov_matrix1,
           cov_matrix2, cov_matrix3, mean1, mean2, mean3, x1, x2, x3, y1, y2,
           y3, which_plot, c_min_max):

    cov_matrix = np.zeros((2, 2))
    cov_matrix1_1 = np.zeros((2, 2))
    cov_matrix2_2 = np.zeros((2, 2))
    cov_matrix3_3 = np.zeros((2, 2))
    cov_matrix1_1[0][0] = cov_matrix1[0][0]
    cov_matrix2_2[0][0] = cov_matrix2[0][0]
    cov_matrix3_3[0][0] = cov_matrix3[0][0]
    cov_matrix1_1[1][1] = cov_matrix1[1][1]
    cov_matrix2_2[1][1] = cov_matrix2[1][1]
    cov_matrix3_3[1][1] = cov_matrix3[1][1]

    inv_cov_matrix1 = np.zeros((2, 2))
    inv_cov_matrix2 = np.zeros((2, 2))
    inv_cov_matrix3 = np.zeros((2, 2))
    confusion_matrix = np.zeros((3, 3))
    '''
	for i in range(2):
		for j in range(2):
			if(i+j)%2!=0:
				cov_matrix1_1[i][j]=0;
				cov_matrix2_2[i][j]=0;
				cov_matrix3_3[i][j]=0;
    '''

    inv_cov_matrix1 = np.linalg.inv(cov_matrix1_1)
    inv_cov_matrix2 = np.linalg.inv(cov_matrix2_2)
    inv_cov_matrix3 = np.linalg.inv(cov_matrix3_3)
    #confusion_matrix=test.test_1(c1_test,c2_test,c3_test,inv_cov_matrix1,inv_cov_matrix2,inv_cov_matrix3,mean1,mean2,mean3)
    if which_plot == 0:
        confusion_matrix = test.test_1(c1_test, c2_test, c3_test, p_c1, p_c2,
                                       p_c3, inv_cov_matrix1, inv_cov_matrix2,
                                       inv_cov_matrix3, mean1, mean2, mean3)
        plot.plot_1(p_c1, p_c2, p_c3, inv_cov_matrix1, inv_cov_matrix2,
                    inv_cov_matrix3, mean1, mean2, mean3, x1, x2, x3, y1, y2,
                    y3, 0, c_min_max)
        return (confusion_matrix)
    elif which_plot == 10:
        plot.plot_1(p_c1, p_c2, p_c3, inv_cov_matrix1, inv_cov_matrix2,
                    inv_cov_matrix3, mean1, mean2, mean3, x1, x2, x3, y1, y2,
                    y3, 10, c_min_max)
    elif which_plot == -1:
        plot.plot_1_1(p_c1, p_c2, inv_cov_matrix1, inv_cov_matrix2, mean1,
                      mean2, x1, x2, y1, y2, -1, c_min_max)
    elif which_plot == 1:
        plot.plot_1_1(p_c1, p_c2, inv_cov_matrix1, inv_cov_matrix2, mean1,
                      mean2, x1, x2, y1, y2, 1, c_min_max)
    elif which_plot == -2:
        plot.plot_1_1(p_c2, p_c3, inv_cov_matrix2, inv_cov_matrix3, mean2,
                      mean3, x2, x3, y2, y3, -2, c_min_max)
    elif which_plot == 2:
        plot.plot_1_1(p_c2, p_c3, inv_cov_matrix2, inv_cov_matrix3, mean2,
                      mean3, x2, x3, y2, y3, 2, c_min_max)
    elif which_plot == -3:
        plot.plot_1_1(p_c1, p_c3, inv_cov_matrix1, inv_cov_matrix3, mean1,
                      mean3, x1, x3, y1, y3, -3, c_min_max)
    elif which_plot == 3:
        plot.plot_1_1(p_c1, p_c3, inv_cov_matrix1, inv_cov_matrix3, mean1,
                      mean3, x1, x3, y1, y3, 3, c_min_max)
Ejemplo n.º 5
0
	one_to_one=OnetoOne(0, 0)
	full_search=FullSearch(0, 0)
	piles =[]

	read_data(piles)
	one_to_one.setAB(piles[0], piles[1])
	full_search.setAB(piles[0], piles[1])

	start_one = timer()
	cost_o = one_to_one.simulation()
	t_one = timer() - start_one

	start_one = timer()
	cost_f = full_search.simulation()
	t_full = timer() - start_one

	if cost_f == cost_o :
		one_result=one_to_one.get_result()
		full_result=full_search.get_result()
		print("\nCosts for both solutions are the same and equal: {}".format(cost_f) )
		print('\nSolution one_to_one A:{0} B:{1} \nExecution time: {2:0.3g} seconds'.format(one_result[0],one_result[1], t_one))
		print('\nSolution full_search A:{0} B:{1} \nExecution time: {2:0.3g} seconds'.format(full_result[0],full_result[1], t_full))
	else: print('The cost are not the same.')

	test_1(OnetoOne(0, 0), FullSearch(0, 0))
	test_2(OnetoOne(0, 0), FullSearch(0, 0))




	
Ejemplo n.º 6
0
"""
Create a Test object and run tests from it.

@author: Fang
"""

import test

if __name__ == "__main__":
    test = test.Test()
    test.test_1()
    test.test_2()
Ejemplo n.º 7
0
epochs = 25
batch_size = 70
validation_split = 0.1

X, y, X_final = dataread()

X_train, X_test, y_train, y_test, prop_HF = datatreat_A1(
    X,
    y,
    train_size=0.8,
    Shuffle=True,
    preprocess="None",
    ratio="50/50",
    balancing_method="SMOTEENN")

model = cnn_1()

history = model.fit(X_train,
                    y_train,
                    epochs=epochs,
                    batch_size=batch_size,
                    validation_split=validation_split)

save_model(model, id)

accuracy, roc, f1_macro, f1_wei = test_1(model, X_test, y_test, id)

save_results(id, 'datatreat_A1', 'cnn_1', epochs, batch_size, accuracy, roc,
             f1_macro, f1_wei, validation_split)

plot_loss_acc_history(history, id, validation_split)