Exemplo n.º 1
0
def test_maui_complains_if_fine_tune_with_wrong_features():
    maui_model = Maui(n_hidden=[], n_latent=2, epochs=1)
    maui_model.fit({"d1": df1, "d2": df2})

    df1_wrong_features = df1.reindex(df1.index[:len(df1.index) - 1])
    with pytest.raises(ValueError):
        z = maui_model.fine_tune({"df1": df1_wrong_features, "df2": df2})
Exemplo n.º 2
0
def test_maui_model_validates_feature_names_on_predict_after_fit():
    maui_model = Maui(n_hidden=[10], n_latent=2, epochs=1)
    maui_model.fit({"d1": df1, "d2": df2})

    z = maui_model.transform({"d1": df1, "d2": df2})

    df1_wrong_features = df1.reindex(df1.index[:len(df1.index) - 1])
    with pytest.raises(ValueError):
        z = maui_model.transform({"df1": df1_wrong_features, "df2": df2})
Exemplo n.º 3
0
def test_maui_can_print_verbose_training(capsys):
    maui_model = Maui(n_hidden=[10], n_latent=2, epochs=1)
    maui_model = maui_model.fit({"d1": df1, "d2": df2})

    stdout, stderr = capsys.readouterr()
    assert stdout == ""

    maui_model = Maui(n_hidden=[10], n_latent=2, epochs=1, verbose=1)
    maui_model = maui_model.fit({"d1": df1, "d2": df2})

    stdout, stderr = capsys.readouterr()
    assert "Epoch" in stdout
Exemplo n.º 4
0
def test_maui_can_save_to_folder():
    maui_model = Maui(n_hidden=[10], n_latent=2, epochs=1)
    maui_model = maui_model.fit({"d1": df1, "d2": df2})
    with tempfile.TemporaryDirectory() as tmpdirname:
        maui_model.save(tmpdirname)
        assert os.path.isfile(os.path.join(tmpdirname, 'maui_weights.h5'))
        assert os.path.isfile(os.path.join(tmpdirname, 'maui_args.json'))
Exemplo n.º 5
0
def test_maui_model_saves_feature_names_to_disk():
    maui_model = Maui(n_hidden=[10], n_latent=2, epochs=1)
    maui_model = maui_model.fit({"d1": df1, "d2": df2})
    with tempfile.TemporaryDirectory() as tmpdirname:
        maui_model.save(tmpdirname)
        maui_model_from_disk = Maui.load(tmpdirname)
    assert maui_model.feature_names == maui_model_from_disk.feature_names
Exemplo n.º 6
0
def test_maui_produces_different_prediction_when_run_twice_with_sampling():
    """This is to show the maui encoder model picks the mean of
    the distribution, not a sample."""
    maui_model = Maui(n_hidden=[10], n_latent=2, epochs=1)
    maui_model = maui_model.fit({'d1': df1, 'd2': df2})
    z1 = maui_model.transform({'d1': df1, 'd2': df2}, encoder='sample')
    z2 = maui_model.transform({'d1': df1, 'd2': df2}, encoder='sample')
    assert not np.allclose(z1, z2)
Exemplo n.º 7
0
def test_maui_produces_same_prediction_when_run_twice():
    """This is to show the maui encoder model picks the mean of
    the distribution, not a sample."""
    maui_model = Maui(n_hidden=[10], n_latent=2, epochs=1)
    maui_model = maui_model.fit({"d1": df1, "d2": df2})
    z1 = maui_model.transform({"d1": df1, "d2": df2})
    z2 = maui_model.transform({"d1": df1, "d2": df2})
    assert np.allclose(z1, z2)
Exemplo n.º 8
0
def test_maui_produces_pos_and_neg_zs_if_relu_embedding_false():
    maui_model = Maui(n_hidden=[10],
                      n_latent=2,
                      epochs=1,
                      relu_embedding=False)
    maui_model = maui_model.fit({"d1": df1, "d2": df2})
    z1 = maui_model.transform({"d1": df1, "d2": df2})
    assert not np.all(z1 >= 0)
Exemplo n.º 9
0
def test_maui_model_loads_model_without_feature_names_from_disk_and_warns():
    maui_model = Maui(n_hidden=[10], n_latent=2, epochs=1)
    maui_model = maui_model.fit({"d1": df1, "d2": df2})
    with tempfile.TemporaryDirectory() as tmpdirname:
        maui_model.save(tmpdirname)
        os.remove(os.path.join(tmpdirname, "maui_feature_names.txt"))
        with pytest.warns(MauiWarning):
            maui_model_from_disk = Maui.load(tmpdirname)
        assert maui_model_from_disk.feature_names is None
Exemplo n.º 10
0
def test_maui_can_load_from_folder():
    maui_model = Maui(n_hidden=[10], n_latent=2, epochs=1)
    maui_model = maui_model.fit({"d1": df1, "d2": df2})
    with tempfile.TemporaryDirectory() as tmpdirname:
        maui_model.save(tmpdirname)
        maui_model_from_disk = Maui.load(tmpdirname)

    assert maui_model_from_disk.n_latent == maui_model.n_latent
    assert np.allclose(maui_model.vae.get_weights()[0],
        maui_model_from_disk.vae.get_weights()[0])
    assert np.allclose(
        maui_model.transform({"d1": df1, "d2": df2}),
        maui_model_from_disk.transform({"d1": df1, "d2": df2})
        )
Exemplo n.º 11
0
def test_maui_supports_single_layer_vae():
    maui_model = Maui(n_hidden=None, n_latent=2, epochs=1)
    maui_model = maui_model.fit({'d1': df1, 'd2': df2})
    z1 = maui_model.transform({'d1': df1, 'd2': df2})
Exemplo n.º 12
0
def test_maui_produces_nonnegative_zs_if_relu_embedding_true():
    maui_model = Maui(n_hidden=[10], n_latent=2, epochs=1, relu_embedding=True)
    maui_model = maui_model.fit({'d1': df1, 'd2': df2})
    z1 = maui_model.transform({'d1': df1, 'd2': df2})
    assert np.all(z1>=0)
Exemplo n.º 13
0
def test_maui_can_fine_tune():
    maui_model = Maui(n_hidden=[], n_latent=2, epochs=1)
    maui_model = maui_model.fit({"d1": df1, "d2": df2})
    maui_model.fine_tune({"d1": df1, "d2": df2}, epochs=1)