Skip to content

iaml_super

class IAMLSuperConfig
dataclass
#

Bases: IAMLConfig

Config has conditionals and as such, we use None to indicate not set.

def validate() #

Validate this config.

Source code in src/mfpbench/yahpo/benchmarks/iaml/iaml_super.py
@no_type_check
def validate(self) -> None:  # noqa: C901, PLR0915, PLR0912
    """Validate this config."""
    assert self.learner_id in ["glmnet", "ranger", "rpart", "xgboost"]

    # We do some conditional checking here
    learner = self.learner_id

    # We filter out all attributes except for those that must always be contained
    # or are the selected learner, ...
    attrs = [
        attr
        for attr in dir(self)
        if not attr.startswith("__")
        or not attr.startswith(learner)
        or attr in ["learner_id"]
    ]

    # ... the remaining must always have None set then
    for attr in attrs:
        assert attr is None

    if learner == "glmnet":
        assert self.glmnet__alpha is not None
        assert self.glmnet__s is not None
        assert 0.0 <= self.glmnet__alpha <= 1.0
        assert 0.00010000000000000009 <= self.glmnet__s <= 999.9999999999998

    elif learner == "rpart":
        assert self.rpart__cp is not None
        assert self.rpart__maxdepth is not None
        assert self.rpart__minbucket is not None
        assert self.rpart__minsplit is not None
        assert 0.00010000000000000009 <= self.rpart__cp <= 1.0
        assert 1 <= self.rpart__maxdepth <= 30
        assert 1 <= self.rpart__minbucket <= 100
        assert 1 <= self.rpart__minsplit <= 100

    elif learner == "ranger":
        assert self.ranger__min__node__size is not None
        assert self.ranger__mtry__power is not None
        assert self.ranger__num__trees is not None
        assert self.ranger__respect__unordered__factors is not None
        assert self.ranger__sample__fraction is not None
        assert 1 <= self.ranger__min__node__size <= 100
        assert 0 <= self.ranger__mtry__power <= 1
        assert 1 <= self.ranger__num__trees <= 2000
        assert self.ranger__respect__unordered__factors in [
            "ignore",
            "order",
            "partition",
        ]
        assert 0.1 <= self.ranger__sample__fraction <= 1.0
        assert self.ranger__splitrule in ["gini", "extratrees"]

        if self.ranger__num__random__splits is not None:
            assert self.ranger__splitrule == "extratrees"
            assert 1 <= self.ranger__num__random__splits <= 100

    elif learner == "xgboost":
        assert self.xgboost__alpha is not None
        assert self.xgboost__lambda is not None
        assert self.xgboost__nrounds is not None
        assert self.xgboost__subsample is not None
        assert self.xgboost__booster in ["gblinear", "gbtree", "dart"]
        assert 0.00010000000000000009 <= self.xgboost__alpha <= 999.9999999999998
        assert 0.00010000000000000009 <= self.xgboost__lambda <= 999.9999999999998
        assert 7 <= self.xgboost__nrounds <= 2981
        assert 0.1 <= self.xgboost__subsample <= 1.0

        if self.xgboost__colsample_bylevel is not None:
            assert self.xgboost__booster in ["dart", "gbtree"]
            assert 0.01 <= self.xgboost__colsample_bylevel <= 1.0

        if self.xgboost__colsample_bytree is not None:
            assert self.xgboost__booster in ["dart", "gbtree"]
            assert 0.01 <= self.xgboost__colsample_bytree <= 1.0

        if self.xgboost__eta is not None:
            assert self.xgboost__booster in ["dart", "gbtree"]
            assert 0.00010000000000000009 <= self.xgboost__eta <= 1.0

        if self.xgboost__gamma is not None:
            assert self.xgboost__booster in ["dart", "gbtree"]
            assert (
                0.00010000000000000009 <= self.xgboost__gamma <= 6.999999999999999
            )

        if self.xgboost__max_depth is not None:
            assert self.xgboost__booster in ["dart", "gbtree"]
            assert 1 <= self.xgboost__max_depth <= 15

        if self.xgboost__min_child_weight is not None:
            assert self.xgboost__booster in ["dart", "gbtree"]
            assert (
                2.718281828459045
                <= self.xgboost__min_child_weight
                <= 149.99999999999997
            )

        if self.xgboost__rate_drop is not None:
            assert self.xgboost__booster in ["dart"]
            assert 0.0 <= self.xgboost__rate_drop <= 1.0

        if self.xgboost__skip_drop is not None:
            assert self.xgboost__booster in ["dart"]
            assert 0.0 <= self.xgboost__skip_drop <= 1.0

    else:
        raise NotImplementedError()