def test__result_derived_properties(self):
        lower_limit_lists = [[0.0, 0.0], [0.0, 0.5], [0.5, 0.0], [0.5, 0.5]]

        # noinspection PyTypeChecker
        grid_search_result = af.GridSearchResult(
            results=None,
            grid_priors=[
                af.UniformPrior(
                    lower_limit=-2.0,
                    upper_limit=2.0
                ),
                af.UniformPrior(
                    lower_limit=-3.0,
                    upper_limit=3.0
                )
            ],
            lower_limits_lists=lower_limit_lists,
        )

        assert grid_search_result.shape == (2, 2)
        assert grid_search_result.physical_step_sizes == (2.0, 3.0)
        assert grid_search_result.physical_centres_lists == [
            [-1.0, -1.5],
            [-1.0, 1.5],
            [1.0, -1.5],
            [1.0, 1.5],
        ]
        assert grid_search_result.physical_upper_limits_lists == [
            [0.0, 0.0],
            [0.0, 3.0],
            [2.0, 0.0],
            [2.0, 3.0],
        ]
Example #2
0
    def test__result_derived_properties(self):
        lower_limit_lists = [[0.0, 0.0], [0.0, 0.5], [0.5, 0.0], [0.5, 0.5]]
        physical_lower_limits_lists = [
            [-2.0, -3.0],
            [-2.0, 0.0],
            [0.0, -3.0],
            [0.0, 0.0],
        ]

        grid_search_result = af.GridSearchResult(
            results=None,
            physical_lower_limits_lists=physical_lower_limits_lists,
            lower_limit_lists=lower_limit_lists,
        )

        print(grid_search_result)

        assert grid_search_result.shape == (2, 2)
        assert grid_search_result.physical_step_sizes == (2.0, 3.0)
        assert grid_search_result.physical_centres_lists == [
            [-1.0, -1.5],
            [-1.0, 1.5],
            [1.0, -1.5],
            [1.0, 1.5],
        ]
        assert grid_search_result.physical_upper_limits_lists == [
            [0.0, 0.0],
            [0.0, 3.0],
            [2.0, 0.0],
            [2.0, 3.0],
        ]
Example #3
0
def test_unpickle_result():
    result = af.GridSearchResult(
        [af.Result(samples=None, model=None)],
        lower_limit_lists=[[1]],
        physical_lower_limits_lists=[[1]],
    )
    result = pickle.loads(pickle.dumps(result))
    assert result is not None
def test_unpickle_result():
    # noinspection PyTypeChecker
    result = af.GridSearchResult(
        results=[af.Result(samples=None, model=None)],
        lower_limits_lists=[[1]],
        grid_priors=[],
    )
    result = pickle.loads(pickle.dumps(result))
    assert result is not None
def make_grid_search_result():
    one = af.m.MockResultGrid(1)
    two = af.m.MockResultGrid(2)

    # noinspection PyTypeChecker
    return af.GridSearchResult(
        results=[one, two],
        lower_limits_lists=[[1], [2]],
        grid_priors=[[1], [2]]
    )
def test_higher_dimensions(
        n_dimensions,
        n_steps
):
    shape = n_dimensions * (n_steps,)
    total = n_steps ** n_dimensions
    model = af.Model(
        af.Gaussian
    )
    result = af.GridSearchResult(
        results=total * [
            af.Result(
                af.NestSamples(
                    model,
                    [
                        af.Sample(
                            1.0,
                            1.0,
                            1.0,
                            {
                                "centre": 1.0,
                                "sigma": 1.0,
                                "normalization": 1.0
                            }
                        )
                    ]
                ),
                model=model
            )
        ],
        grid_priors=[],
        lower_limits_lists=total * [
            n_dimensions * [0.0]
        ]
    )
    assert result.shape == shape
    assert result.results_native.shape == shape
    assert result.log_likelihoods_native.shape == shape
Example #7
0
    def test__result_derived_properties(self):

        lower_limit_lists = [[0.0, 0.0], [0.0, 0.5], [0.5, 0.0], [0.5, 0.5]]

        grid_search_result = af.GridSearchResult(
            results=None,
            grid_priors=[
                af.UniformPrior(lower_limit=-2.0, upper_limit=2.0),
                af.UniformPrior(lower_limit=-3.0, upper_limit=3.0),
            ],
            lower_limits_lists=lower_limit_lists,
        )

        subhalo_result = SubhaloResult(
            grid_search_result=grid_search_result, result_no_subhalo=1
        )

        subhalo_array = subhalo_result._subhalo_array_from(
            values_native=np.array([[1.0, 2.0], [3.0, 4.0]])
        )

        assert isinstance(subhalo_array, al.Array2D)
        assert (subhalo_array.native == np.array([[3.0, 4.0], [1.0, 2.0]])).all()
Example #8
0
def make_result(model):
    return af.GridSearchResult(results=[],
                               lower_limits_lists=[[0.0], [0.5]],
                               grid_priors=[model.centre])
Example #9
0
def make_grid_search_result():
    one = MockResult(1)
    two = MockResult(2)

    # noinspection PyTypeChecker
    return af.GridSearchResult([one, two], [[1], [2]], [[1], [2]])