def test_softmax_bin_targets_channels(seed=0):
    np.random.seed(seed)
    num_classes = 2
    batch_size = 5
    mlp_bin = MLP(
        layers=[Softmax(num_classes, 's1', irange=0.1,
                        binary_target_dim=1)],
        nvis=100
    )
    mlp_vec = MLP(
        layers=[Softmax(num_classes, 's1', irange=0.1)],
        nvis=100
    )

    X = mlp_bin.get_input_space().make_theano_batch()
    y_bin = mlp_bin.get_target_space().make_theano_batch()
    y_vec = mlp_vec.get_target_space().make_theano_batch()

    X_data = np.random.random(size=(batch_size, 100))
    X_data = X_data.astype(theano.config.floatX)
    y_bin_data = np.random.randint(low=0, high=num_classes,
                                   size=(batch_size, 1))
    y_vec_data = np.zeros((batch_size, num_classes),
                          dtype=theano.config.floatX)
    y_vec_data[np.arange(batch_size), y_bin_data.flatten()] = 1

    def channel_value(channel_name, model, y, y_data):
        chans = model.get_monitoring_channels((X, y))
        f_channel = theano.function([X, y], chans['s1_' + channel_name])
        return f_channel(X_data, y_data)

    for channel_name in ['misclass', 'nll']:
        vec_val = channel_value(channel_name, mlp_vec, y_vec, y_vec_data)
        bin_val = channel_value(channel_name, mlp_bin, y_bin, y_bin_data)
        print(channel_name, vec_val, bin_val)
        np.testing.assert_allclose(vec_val, bin_val)
Re-using a global name as the loop variable for a generator
dataset/ETHPy150Open lisa-lab/pylearn2/pylearn2/models/tests/test_mlp.py/test_softmax_bin_targets_channels--crossover with--dataset/ETHPy150Open kevinw/pyflakes/pyflakes/test/test_imports.py/TestSpecialAll.test_redefinedByGenExp