コード例 #1
0
def get_variation_operator(name: str, **kwargs) -> VariationOperator:
    """Get the variaton operator class with the given name."""
    name_to_cls = {
        "deletion":
        DeletionMutation,
        "addition":
        AdditionMutation,
        "alternation":
        Alternation,
        "genesis":
        Genesis,
        "cloning":
        Cloning,
        # UMAD citation: https://dl.acm.org/citation.cfm?id=3205455.3205603
        "umad":
        VariationPipeline([AdditionMutation(0.09),
                           DeletionMutation(0.0826)]),
        "umad-shrink":
        VariationPipeline([AdditionMutation(0.09),
                           DeletionMutation(0.1)]),
        "umad-grow":
        VariationPipeline([AdditionMutation(0.09),
                           DeletionMutation(0.0652)])
    }
    op = name_to_cls.get(name, None)
    if op is None:
        raise ValueError(
            "No varition operator '{nm}'. Supported names: {lst}.".format(
                nm=name, lst=list(name_to_cls.keys())))
    if isinstance(op, type):
        op = instantiate_using(op, kwargs)
    return op
コード例 #2
0
ファイル: test_utils.py プロジェクト: erp12/Pysh
def test_instantiate_using_optional():
    args = {
        "this": True
    }
    tmt = instantiate_using(ThisMaybeThat, args)
    assert tmt.this
    assert tmt.that == "default"
コード例 #3
0
ファイル: test_utils.py プロジェクト: erp12/Pysh
def test_instantiate_using_exact():
    args = {
        "a": 1,
        "b": 2
    }
    p = instantiate_using(Pair, args)
    assert p.a == 1
    assert p.b == 2
コード例 #4
0
ファイル: test_utils.py プロジェクト: erp12/Pysh
def test_instantiate_using_extra():
    args = {
        "a": 1,
        "b": 2,
        "c": 3
    }
    p = instantiate_using(Pair, args)
    assert p.a == 1
    assert p.b == 2
コード例 #5
0
ファイル: search.py プロジェクト: fagan2888/pyshgp
def get_search_algo(name: str, **kwargs) -> SearchAlgorithm:
    """Return the search algorithm class with the given name."""
    name_to_cls = {
        "GA": GeneticAlgorithm,
        "SA": SimulatedAnnealing,
        # "ES": EvolutionaryStrategy,
    }
    _cls = name_to_cls.get(name, None)
    if _cls is None:
        raise ValueError(
            "No search algo '{nm}'. Supported names: {lst}.".format(
                nm=name, lst=list(name_to_cls.keys())))
    return instantiate_using(_cls, kwargs)
コード例 #6
0
def get_selector(name: str, **kwargs) -> Selector:
    """Get the selector class with the given name."""
    name_to_cls = {
        "roulette": FitnessProportionate,
        "tournament": Tournament,
        "lexicase": Lexicase,
        "elite": Elite,
    }
    _cls = name_to_cls.get(name, None)
    if _cls is None:
        raise ValueError("No selector '{nm}'. Supported names: {lst}.".format(
            nm=name, lst=list(name_to_cls.keys())))
    return instantiate_using(_cls, kwargs)
コード例 #7
0
ファイル: search.py プロジェクト: erp12/Pysh
def get_search_algo(name: str, **kwargs) -> SearchAlgorithm:
    """Return the search algorithm class with the given name."""
    name_to_cls = {
        "GA": GeneticAlgorithm,
        "SA": SimulatedAnnealing,
        # "ES": EvolutionaryStrategy,
    }
    _cls = name_to_cls.get(name, None)
    if _cls is None:
        raise ValueError("No search algo '{nm}'. Supported names: {lst}.".format(
            nm=name,
            lst=list(name_to_cls.keys())
        ))
    return instantiate_using(_cls, kwargs)
コード例 #8
0
ファイル: selection.py プロジェクト: vishalbelsare/pyshgp
def get_selector(name: str, **kwargs) -> Selector:
    """Get the selector class with the given name."""
    name_to_cls = {
        "roulette": FitnessProportionate,
        "tournament": Tournament,
        "lexicase": Lexicase,
        "epsilon-lexicase": Lexicase(epsilon=True),
        "elite": Elite,
    }
    selector = name_to_cls.get(name, None)
    if selector is None:
        raise ValueError("No selector '{nm}'. Supported names: {lst}.".format(
            nm=name,
            lst=list(name_to_cls.keys())
        ))
    if isinstance(selector, type):
        selector = instantiate_using(selector, kwargs)
    return selector
コード例 #9
0
def test_instantiate_using_optional():
    args = {"this": True}
    tmt = instantiate_using(ThisMaybeThat, args)
    assert tmt.this
    assert tmt.that == "default"
コード例 #10
0
def test_instantiate_using_insufficient():
    args = {"b": 2}
    with pytest.raises(TypeError):
        p = instantiate_using(Pair, args)
コード例 #11
0
def test_instantiate_using_extra():
    args = {"a": 1, "b": 2, "c": 3}
    p = instantiate_using(Pair, args)
    assert p.a == 1
    assert p.b == 2
コード例 #12
0
def test_instantiate_using_exact():
    args = {"a": 1, "b": 2}
    p = instantiate_using(Pair, args)
    assert p.a == 1
    assert p.b == 2
コード例 #13
0
ファイル: test_utils.py プロジェクト: erp12/Pysh
def test_instantiate_using_insufficient():
    args = {
        "b": 2
    }
    with pytest.raises(TypeError):
        p = instantiate_using(Pair, args)