Exemple #1
0
    def test_call_twice(self, teardown):
        x0 = Input()
        x1 = Input()
        step = DummySISO()
        y0 = step(x0)
        y1 = step(x1)

        assert isinstance(y0, DataPlaceholder)
        assert isinstance(y1, DataPlaceholder)
        assert y0.name == "DummySISO_0:0/0"
        assert y1.name == "DummySISO_0:1/0"
Exemple #2
0
def test_fit_and_predict_model_with_no_fittable_steps(teardown):
    X_data = np.array([[1, 2], [3, 4]])
    y_expected = np.array([[2, 4], [6, 8]])

    x = Input()
    y = DummySISO()(x)

    model = Model(x, y)
    model.fit(X_data)  # nothing to fit
    y_pred = model.predict(X_data)

    assert_array_equal(y_pred, y_expected)
Exemple #3
0
def test_fit_and_predict_model_with_no_fittable_steps(teardown):
    X1_data = np.array([[1, 2], [3, 4]])
    X2_data = np.array([[5, 6], [7, 8]])
    y_expected = np.array([[12, 16], [20, 24]])

    x1 = Input()
    x2 = Input()
    z = DummyMISO()([x1, x2])
    y = DummySISO()(z)

    model = Model([x1, x2], y)
    model.fit([X1_data, X2_data])  # nothing to fit
    y_pred = model.predict([X1_data, X2_data])

    assert_array_equal(y_pred, y_expected)
Exemple #4
0
def test_plot_model(teardown, tmp_path):
    x1 = Input(name="x1")
    x2 = Input(name="x2")
    y1, y2 = DummyMIMO()([x1, x2])
    submodel = Model([x1, x2], [y1, y2], name="submodel")

    x = Input(name="x")
    h1, h2 = DummySIMO()(x)
    z1, z2 = submodel([h1, h2])

    u = Input(name="u")
    v = DummySISO()(u)

    w = DummyMISO()([z1, z2])
    model = Model([x, u], [w, v], name="main_model")

    filename = str(tmp_path / "test_plot_model.png")
    plot_model(model, filename, show=False, expand_nested=True)
Exemple #5
0
def test_plot_big_model(teardown, tmp_path, expand_nested):
    # Below is a very contrived big dummy model

    # ------- Sub-model 1
    x1_sub1 = Input(name="x1_sub1")
    x2_sub1 = Input(name="x2_sub1")
    y_t_sub1 = Input(name="y_t_sub1")
    y_p1_sub1, y_p2_sub1 = DummyMIMO()([x1_sub1, x2_sub1], y_t_sub1)
    submodel1 = Model([x1_sub1, x2_sub1], [y_p1_sub1, y_p2_sub1],
                      y_t_sub1,
                      name="submodel1")

    # ------- Sub-model 2
    y_t_sub2 = Input(name="y_t_sub2")
    y_p_sub2 = DummySISO()(y_t_sub2)
    submodel2 = Model(y_t_sub2, y_p_sub2, name="submodel2")

    # ------- Sub-model 3
    x1_sub3 = Input(name="x1_sub3")
    x2_sub3 = Input(name="x2_sub3")
    y_p1_sub3, y_p2_sub3 = DummyMIMO()([x1_sub3, x2_sub3])
    submodel3 = Model([x1_sub3, x2_sub3], [y_p1_sub3, y_p2_sub3],
                      name="submodel3")

    # ------- Main model
    x = Input(name="x")
    y_t = Input(name="y_t")
    y_t_trans = submodel2(y_t)
    h1, h2 = DummySIMO()(x)
    g1, g2 = submodel3([h1, h2])
    z1, z2 = submodel1([g1, g2], y_t_trans)
    w = DummyMISO()([z1, z2])

    model = Model(x, w, y_t, name="main_model")

    filename = str(tmp_path / "test_plot_model.png")
    plot_model(model, filename, show=False, expand_nested=expand_nested)
Exemple #6
0
 def test_call_with_targets_without_fit_method(self, teardown):
     x = Input()
     y_t = Input()
     with pytest.raises(RuntimeError):
         DummySISO()(x, y_t)
Exemple #7
0
 def test_call_without_targets_without_fit_method(self, teardown):
     x = Input()
     DummySISO()(x)