Esempio n. 1
0
def accuracy_test(t_size, add_noise=False, sigma_sqr=None, ret_acc=True):

    acc = 0

    for i in range(NUM_RANDOM):

        train_data, test_data = load_train_test_data(t_size, True)

        if add_noise:
            train_data = add_gaussian_noises(train_data, sigma_sqr)

        train_data_mat = get_data_matrix(train_data)

        x_mean, x_cov = train_params(train_data_mat)

        acc += test_stat(x_mean, x_cov, test_data)

    acc /= NUM_RANDOM

    print('all accuracy: ', acc)

    if ret_acc:
        return acc
    else:
        return 1 - acc
Esempio n. 2
0
def accuracy_test(t_size, add_noise=False, sigma_sqr=None, ret_acc=True):

    acc = 0

    for i in range(NUM_RANDOM):

        train_data, test_data = load_train_test_data(t_size, True)

        if add_noise:
            train_data = add_gaussian_noises(train_data, sigma_sqr)

        df_param, c_centroids = fisher_discriminant_features(train_data[1], train_data[0])

        acc += test_stat(euclidean_dist, test_data, df_param, c_centroids)

    acc /= NUM_RANDOM

    if ret_acc:
        return acc
    else:
        return 1 - acc
Esempio n. 3
0
def accuracy_test(t_size, hp, add_noise=False, sigma_sqr=None, ret_acc=True):

    acc = 0

    for i in range(NUM_RANDOM):
        train_data, test_data = load_train_test_data(t_size, True)

        if add_noise:
            train_data = add_gaussian_noises(train_data, sigma_sqr)

        train_data_mat = get_data_matrix(train_data)

        w = train_w(train_data_mat, hp)

        acc += test_stat(w, test_data)

    acc /= NUM_RANDOM

    if ret_acc:
        return acc
    else:
        return 1 - acc
Esempio n. 4
0
def accuracy_test(t_size, add_noise=False, sigma_sqr=None, ret_acc=True):

    acc = 0

    for i in range(NUM_RANDOM):

        (train_tgt,
         train_feat), (test_tgt,
                       test_feat) = load_train_test_data(t_size, True)

        if add_noise:
            (train_tgt, train_feat) = add_gaussian_noises(
                (train_tgt, train_feat), sigma_sqr)

        acc += test_stat(euclidean_dist, 3, train_feat, train_tgt, test_feat,
                         test_tgt)

    acc /= NUM_RANDOM

    if ret_acc:
        return acc
    else:
        return 1 - acc
Esempio n. 5
0
def accuracy_against_size_stat(train_sizes, ret_acc=True):

    acc = []

    for s in train_sizes:
        acc.append(accuracy_test(s, ret_acc=ret_acc))

    return acc


def accuracy_against_noise_stat(sigma_sqrs, train_size=0.9, ret_acc=True):

    acc = []

    for s in sigma_sqrs:
        print('sigma square: ', s)
        acc.append(
            accuracy_test(train_size,
                          add_noise=True,
                          sigma_sqr=s,
                          ret_acc=ret_acc))

    return acc


if __name__ == '__main__':
    (train_tgt, train_feat), (test_tgt, test_feat) = load_train_test_data()

    test_stat(euclidean_dist, 3, train_feat, train_tgt, test_feat, test_tgt)
Esempio n. 6
0
        acc.append(accuracy_test(s, hp, ret_acc=ret_acc))

    return acc


def accuracy_against_noise_stat(sigma_sqrs, hp, train_size=0.9, ret_acc=True):

    acc = []

    for s in sigma_sqrs:
        print('sigma square: ', s)
        acc.append(
            accuracy_test(train_size,
                          hp,
                          add_noise=True,
                          sigma_sqr=s,
                          ret_acc=ret_acc))

    return acc


if __name__ == '__main__':

    train_data, test_data = load_train_test_data(0.2)

    train_data_mat = get_data_matrix(train_data)

    w = train_w(train_data_mat, 100)

    test_stat(w, test_data)