def logreg_image(train: np.ndarray,
                 test: np.ndarray,
                 regularization_coefficients: List[float],
                 is_cifar: bool = False) -> None:
    '''
    without reg : 0
    with reg: regularization_coefficients = 1 / 2sigma^2
    :param train: data and labels for classifier training
    :param test: data and labels for classifier test
    :param is_cifar: True if CIFAR dataset is used, False if MNIST
    '''
    train_label = np.transpose(train[0, :].astype(np.double))
    train_label[train_label < 0] = 0.0
    train_x = train.astype(np.double)
    train_x[0, :] = 1.0

    print("Dataset ballance in training {:.2f}%".format(
        100 * np.sum(train_label) / len(train_label)))

    test_label = np.transpose(test[0, :].astype(np.double))
    test_label[test_label < 0] = 0.0
    test_x = test.astype(np.double)
    test_x[0, :] = 1.0

    print("Dataset ballance in test {:.2f}%".format(100 * np.sum(test_label) /
                                                    len(test_label)))

    for r in regularization_coefficients:
        logreg = LOGREG(r)

        print(
            'Training a LOGREG classifier with regularization coefficient: {}'.
            format(r))

        # training
        logreg.train(train_x, train_label, 50)
        print('Training')
        logreg.printClassification(train_x, train_label)
        print('Test')
        logreg.printClassification(test_x, test_label)

        visualizeClassification(train_x[1:, :], train_label,
                                logreg.classify(train_x), 3 * 3, is_cifar,
                                'training with reg: {}'.format(r))
        visualizeClassification(test_x[1:, :], test_label,
                                logreg.classify(test_x), 3 * 3, is_cifar,
                                'test with reg: {}'.format(r))
def logregMNIST(train, test):
    '''
    without reg : 0
    with reg: regcoeff = 1 / 2sigma^2
    :param train:
    :param test:
    :return:
    '''
    regcoeff = [0, 0.1, 0.5]

    train_label = np.transpose(train[0, :].astype(np.double))
    train_label[train_label < 0] = 0.0
    train_x = train[0:, :].astype(np.double)
    train_x[0, :] = 1.0

    test_label = np.transpose(test[0, :].astype(np.double))
    test_label[test_label < 0] = 0.0
    test_x = test[0:, :].astype(np.double)
    test_x[0, :] = 1.0

    for r in regcoeff:
        logreg = LOGREG(r)

        print(
            'Training a LOGREG classifier with regularization coefficient: {}'.
            format(r))

        # training
        logreg.train(train_x, train_label, 50)
        print('Training')
        logreg.printClassification(train_x, train_label)
        print('Test')
        logreg.printClassification(test_x, test_label)

        visualizeClassification(train_x[1:, :], train_label,
                                logreg.classify(train_x), 3 * 3,
                                'training with reg: {}'.format(r))
        visualizeClassification(test_x[1:, :], test_label,
                                logreg.classify(test_x), 3 * 3,
                                'test with reg: {}'.format(r))