def compare_flattener_composite_mlp_with_separate_mlps(first_composite_layer,
                                                       second_composite_layer,
                                                       first_indep_layer,
                                                       second_indep_layer,
                                                       features_in_first_mlp,
                                                       features_in_second_mlp,
                                                       targets_in_first_mlp,
                                                       targets_in_second_mlp):

    # Create network with composite layers.

    mlp_composite = MLP(
        layers=[
            FlattenerLayer(
                CompositeLayer(
                    'composite',
                    [first_composite_layer,
                     second_composite_layer],
                    {
                        0: [0],
                        1: [1]
                    }
                )
            )
        ],
        input_space=CompositeSpace([VectorSpace(features_in_first_mlp),
                                   VectorSpace(features_in_second_mlp)]),
        input_source=('features0', 'features1')
    )

    # Create network with single softmax layer, corresponding to first
    # layer in the composite network.
    mlp_first_part = MLP(
        layers=[
            first_indep_layer
        ],
        input_space=VectorSpace(features_in_first_mlp),
        input_source=('features0')
    )

    # Create network with single softmax layer, corresponding to second
    # layer in the composite network.
    mlp_second_part = MLP(
        layers=[
            second_indep_layer
        ],
        input_space=VectorSpace(features_in_second_mlp),
        input_source=('features1')
    )

    # Create dataset which we will test our networks against.
    shared_dataset = np.random.rand(20, 19).astype(theano.config.floatX)

    # Make dataset for composite network.
    dataset_composite = VectorSpacesDataset(
        (shared_dataset[:, 0:features_in_first_mlp],
         shared_dataset[:,
                        features_in_first_mlp:(features_in_first_mlp
                                               + features_in_second_mlp)],
         shared_dataset[:,
                        (features_in_first_mlp + features_in_second_mlp):
                        (features_in_first_mlp + features_in_second_mlp
                         + targets_in_first_mlp + targets_in_second_mlp)]),
        (CompositeSpace([
            VectorSpace(features_in_first_mlp),
            VectorSpace(features_in_second_mlp),
            VectorSpace(targets_in_first_mlp + targets_in_second_mlp)]),
         ('features0', 'features1', 'targets'))
    )

    # Make dataset for first single softmax layer network.
    dataset_first_part = VectorSpacesDataset(
        (shared_dataset[:, 0:features_in_first_mlp],
         shared_dataset[:, (features_in_first_mlp + features_in_second_mlp):
                           (features_in_first_mlp + features_in_second_mlp
                            + targets_in_first_mlp)]),
        (CompositeSpace([
            VectorSpace(features_in_first_mlp),
            VectorSpace(targets_in_first_mlp)]),
         ('features0', 'targets'))
    )

    # Make dataset for second single softmax layer network.
    dataset_second_part = VectorSpacesDataset(
        (shared_dataset[:,
                        features_in_first_mlp:
                        (features_in_first_mlp + features_in_second_mlp)],
            shared_dataset[:, (features_in_first_mlp
                               + features_in_second_mlp
                               + targets_in_first_mlp):
                              (features_in_first_mlp
                               + features_in_second_mlp
                               + targets_in_first_mlp
                               + targets_in_second_mlp)]),
        (CompositeSpace([
            VectorSpace(features_in_second_mlp),
            VectorSpace(targets_in_second_mlp)]),
         ('features1', 'targets'))
    )

    # Initialize all MLPs to start from zero weights.
    mlp_composite.layers[0].raw_layer.layers[0].set_weights(
        mlp_composite.layers[0].raw_layer.layers[0].get_weights() * 0.0)
    mlp_composite.layers[0].raw_layer.layers[1].set_weights(
        mlp_composite.layers[0].raw_layer.layers[1].get_weights() * 0.0)
    mlp_first_part.layers[0].set_weights(
        mlp_first_part.layers[0].get_weights() * 0.0)
    mlp_second_part.layers[0].set_weights(
        mlp_second_part.layers[0].get_weights() * 0.0)

    # Train all models with their respective datasets.
    train_composite = Train(dataset_composite, mlp_composite,
                            SGD(0.0001, batch_size=20))
    train_composite.algorithm.termination_criterion = EpochCounter(1)
    train_composite.main_loop()

    train_first_part = Train(dataset_first_part, mlp_first_part,
                             SGD(0.0001, batch_size=20))
    train_first_part.algorithm.termination_criterion = EpochCounter(1)
    train_first_part.main_loop()

    train_second_part = Train(dataset_second_part, mlp_second_part,
                              SGD(0.0001, batch_size=20))
    train_second_part.algorithm.termination_criterion = EpochCounter(1)
    train_second_part.main_loop()

    # Check that the composite feed-forward neural network has learned
    # same parameters as each individual feed-forward neural network.
    np.testing.assert_allclose(
        mlp_composite.layers[0].raw_layer.layers[0].get_weights(),
        mlp_first_part.layers[0].get_weights())
    np.testing.assert_allclose(
        mlp_composite.layers[0].raw_layer.layers[1].get_weights(),
        mlp_second_part.layers[0].get_weights())

    # Check that we get same output given the same input on a randomly
    # generated dataset.
    X_composite = mlp_composite.get_input_space().make_theano_batch()
    X_first_part = mlp_first_part.get_input_space().make_theano_batch()
    X_second_part = mlp_second_part.get_input_space().make_theano_batch()

    fprop_composite = theano.function(X_composite,
                                      mlp_composite.fprop(X_composite))
    fprop_first_part = theano.function([X_first_part],
                                       mlp_first_part.fprop(X_first_part))
    fprop_second_part = theano.function([X_second_part],
                                        mlp_second_part.fprop(X_second_part))

    X_data = np.random.random(size=(10,
                              (features_in_first_mlp
                               + features_in_second_mlp))).astype(
                                   theano.config.floatX)
    y_data = np.random.randint(low=0, high=10, size=(10,
                               (targets_in_first_mlp
                                + targets_in_second_mlp)))

    np.testing.assert_allclose(fprop_composite(X_data[:,
                               0:features_in_first_mlp],
                               X_data[:,
                               features_in_first_mlp:
                               (features_in_first_mlp
                                + features_in_second_mlp)])
                               [:, 0:targets_in_first_mlp],
                               fprop_first_part(X_data[:,
                                                0:features_in_first_mlp]))
    np.testing.assert_allclose(fprop_composite(X_data[:,
                               0:features_in_first_mlp],
                               X_data[:, features_in_first_mlp:
                               (features_in_first_mlp
                                + features_in_second_mlp)])
                               [:, targets_in_first_mlp:
                                (targets_in_first_mlp
                                 + targets_in_second_mlp)],
                               fprop_second_part(X_data[:,
                                                 features_in_first_mlp:
                                                 (features_in_first_mlp
                                                  + features_in_second_mlp)]))

    # Finally check that calling the internal FlattenerLayer behaves
    # as we would expect. First, retrieve the FlattenerLayer.
    fl = mlp_composite.layers[0]

    # Check that it agrees on the input space.
    assert mlp_composite.get_input_space() == fl.get_input_space()

    # Check that it agrees on the parameters.
    for i in range(0, 4):
        np.testing.assert_allclose(fl.get_params()[i].eval(),
                                   mlp_composite.get_params()[i].eval())
Adds the specified import to the import manager.
dataset/ETHPy150Open lisa-lab/pylearn2/pylearn2/models/tests/test_mlp.py/compare_flattener_composite_mlp_with_separate_mlps--crossover with--dataset/ETHPy150Open google/apis-client-generator/src/googleapis/codegen/cpp_import_manager.py/CppImportManager.AddImport