Пример #1
0
    def test_populate_block_multi(self, alm_surr2):
        blk = SurrogateBlock(concrete=True)

        blk.build_model(alm_surr2)

        assert isinstance(blk.inputs, Var)
        assert blk.inputs["x1"].bounds == (None, None)
        assert blk.inputs["x2"].bounds == (None, None)
        assert isinstance(blk.outputs, Var)
        assert blk.outputs["z1"].bounds == (None, None)
        assert blk.outputs["z2"].bounds == (None, None)
        assert isinstance(blk.alamo_constraint, Constraint)
        assert len(blk.alamo_constraint) == 2
        assert str(blk.alamo_constraint["z1"].body) == (
            "outputs[z1] - ("
            "3.9999999999925446*inputs[x1]**2 - "
            "4.000000000002077*inputs[x2]**2 - "
            "2.099999999985938*inputs[x1]**4 + "
            "4.000000000004311*inputs[x2]**4 + "
            "0.33333333332782633*inputs[x1]**6 + "
            "0.9999999999997299*inputs[x1]*inputs[x2])")
        assert str(blk.alamo_constraint["z2"].body) == (
            "outputs[z2] - ("
            "0.07226779984920294*inputs[x1] + "
            "0.06845168475391271*inputs[x2] + "
            "1.0677896915911471*inputs[x1]**2 - "
            "0.7057646480622435*inputs[x2]**2 - "
            "0.04028628356655499*inputs[x1]**3 + "
            "0.006778566802168481*inputs[x2]**5 - "
            "0.14017881460354553*inputs[x1]**6 + "
            "0.7720704944157665*inputs[x2]**6 + "
            "0.4214330995151807*inputs[x1]*inputs[x2] - "
            "0.041818729807213094)")
Пример #2
0
    def test_alamo_object(self, alamo_trainer):
        alamo_object = alamo_trainer.alamo_object
        assert isinstance(alamo_object, AlamoSurrogate)
        assert alamo_object._surrogate_expressions == {
            'z1': ' z1 == 3.9999999999925432980774 * x1**2 - '
            '4.0000000000020792256805 * x2**2 - '
            '2.0999999999859380039879 * x1**4 + '
            '4.0000000000043085535140 * x2**4 + '
            '0.33333333332782683067208 * x1**6 + '
            '0.99999999999973088193883 * x1*x2'}
        assert alamo_object._input_labels == ["x1", "x2"]
        assert alamo_object._output_labels == ["z1"]
        assert alamo_object._input_bounds == {
            "x1": (-1.5, 1.5), "x2": (-1.5, 1.5)}

        # Check populating a block to finish workflow
        blk = SurrogateBlock(concrete=True)

        blk.build_model(alamo_object)

        assert isinstance(blk.inputs, Var)
        assert blk.inputs["x1"].bounds == (-1.5, 1.5)
        assert blk.inputs["x2"].bounds == (-1.5, 1.5)
        assert isinstance(blk.outputs, Var)
        assert blk.outputs["z1"].bounds == (None, None)
        assert isinstance(blk.alamo_constraint, Constraint)
        assert len(blk.alamo_constraint) == 1
Пример #3
0
    def test_populate_block_funcs(self, alm_surr3):
        blk = SurrogateBlock(concrete=True)

        blk.build_model(alm_surr3)

        assert isinstance(blk.inputs, Var)
        assert isinstance(blk.outputs, Var)
        assert isinstance(blk.alamo_constraint, Constraint)
        assert len(blk.alamo_constraint) == 1
        assert str(blk.alamo_constraint["z1"].body) == (
            "outputs[z1] - (2*sin(inputs[x1]**2) - 3*cos(inputs[x2]**3) - "
            "4*log(inputs[x1]**4) + 5*exp(inputs[x2]**5))")
Пример #4
0
    def test_populate_block(self, alm_surr1):
        blk = SurrogateBlock(concrete=True)

        blk.build_model(alm_surr1)
        blk.display()

        assert isinstance(blk.inputs, Var)
        assert blk.inputs["x1"].bounds == (0, 5)
        assert blk.inputs["x2"].bounds == (0, 10)
        assert isinstance(blk.outputs, Var)
        assert blk.outputs["z1"].bounds == (None, None)
        assert isinstance(blk.alamo_constraint, Constraint)
        assert len(blk.alamo_constraint) == 1
        assert str(blk.alamo_constraint["z1"].body) == (
            "outputs[z1] - ("
            "3.9999999999925446*inputs[x1]**2 - "
            "4.000000000002077*inputs[x2]**2 - "
            "2.099999999985938*inputs[x1]**4 + "
            "4.000000000004311*inputs[x2]**4 + "
            "0.33333333332782633*inputs[x1]**6 + "
            "0.9999999999997299*inputs[x1]*inputs[x2])")