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})
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)
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)
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)
def test_maui_updates_neural_weight_product_when_training(): maui_model = Maui(n_hidden=[10], n_latent=2, epochs=1) z_before = maui_model.fit_transform({"d1": df1, "d2": df2}) nwp_before_fine_tuning = maui_model.get_neural_weight_product() maui_model.fine_tune({"d1": df1, "d2": df2}) z_after = maui_model.transform({"d1": df1, "d2": df2}) nwp_after_fine_tuning = maui_model.get_neural_weight_product() assert not np.allclose(z_before, z_after) assert not np.allclose(nwp_before_fine_tuning, nwp_after_fine_tuning)
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}) )
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})
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)