mlrl.common.config module

Author: Michael Rapp (michael.rapp.ml@gmail.com)

Provides utilities that ease the configuration of rule learning algorithms.

class mlrl.common.config.FeatureBinningParameter

Bases: NominalParameter

A parameter that allows to configure the strategy to be used for feature binning.

class mlrl.common.config.FeatureSamplingParameter

Bases: NominalParameter

A parameter that allows to configure the strategy to be used for feature sampling.

OPTION_NUM_RETAINED = 'num_retained'
class mlrl.common.config.FloatParameter(name: str, description: str, mixin: type)

Bases: NumericalParameter, ABC

An abstract base class for all parameters of a rule learning algorithm that allow to set a floating point value.

class mlrl.common.config.GlobalPruningParameter

Bases: NominalParameter

A parameter that allows to configure the strategy to be used for pruning entire rules.

AGGREGATION_FUNCTION_ARITHMETIC_MEAN = 'avg'
AGGREGATION_FUNCTION_MAX = 'max'
AGGREGATION_FUNCTION_MIN = 'min'
GLOBAL_PRUNING_POST = 'post-pruning'
GLOBAL_PRUNING_PRE = 'pre-pruning'
OPTION_AGGREGATION_FUNCTION = 'aggregation'
OPTION_INTERVAL = 'interval'
OPTION_MIN_IMPROVEMENT = 'min_improvement'
OPTION_MIN_RULES = 'min_rules'
OPTION_NUM_PAST = 'num_past'
OPTION_NUM_RECENT = 'num_recent'
OPTION_REMOVE_UNUSED_RULES = 'remove_unused_rules'
OPTION_STOP_INTERVAL = 'stop_interval'
OPTION_UPDATE_INTERVAL = 'update_interval'
class mlrl.common.config.InstanceSamplingParameter

Bases: NominalParameter

A parameter that allows to configure the strategy to be used for instance sampling.

class mlrl.common.config.IntParameter(name: str, description: str, mixin: type)

Bases: NumericalParameter, ABC

An abstract base class for all parameters of a rule learning algorithm that allow to set an integer value.

class mlrl.common.config.LabelSamplingParameter

Bases: NominalParameter

A parameter that allows to configure the strategy to be used for label sampling.

LABEL_SAMPLING_ROUND_ROBIN = 'round-robin'
class mlrl.common.config.NominalParameter(name: str, description: str)

Bases: Parameter, ABC

An abstract base class for all nominal parameters of a rule learning algorithm that allow to set one out of a set of predefined values.

class Value(name: str, mixin: type, options: Set[str] | None, description: str | None)

Bases: object

A value that can be set for a nominal parameter.

add_to_argument_parser(parser: ArgumentParser, config_type: type)

Adds a command line argument that corresponds to this parameter to an ArgumentParser if it is supported by a configuration of a specific type.

add_value(name: str, mixin: type, options: Set[str] | None = None, description: str | None = None)

Adds a new value to the parameter.

Parameters:
  • name – The name of the value to be added

  • mixin – The type of the mixin that must be implemented by a rule learner to support the value

  • options – A set that contains the names of additional options that may be specified or None, if no additional options are available

  • description – A textual description of the value

Returns:

The parameter itself

configure(config, value)

Configures a rule learner depending on this parameter.

Parameters:
  • config – The configuration to be modified

  • value – The value to be set

class mlrl.common.config.NumericalParameter(name: str, description: str, mixin: type, numeric_type: type)

Bases: Parameter, ABC

An abstract base class for all parameters of a rule learning algorithm that allow to set a numerical value.

add_to_argument_parser(parser: ArgumentParser, config_type: type)

Adds a command line argument that corresponds to this parameter to an ArgumentParser if it is supported by a configuration of a specific type.

configure(config, value)

Configures a rule learner depending on this parameter.

Parameters:
  • config – The configuration to be modified

  • value – The value to be set

class mlrl.common.config.ParallelPredictionParameter

Bases: NominalParameter

A parameter that allows to configure whether predictions for different examples should be obtained in parallel or not.

class mlrl.common.config.ParallelRuleRefinementParameter

Bases: NominalParameter

A parameter that allows to configure whether potential refinements of rules should be searched for in parallel or not.

class mlrl.common.config.ParallelStatisticUpdateParameter

Bases: NominalParameter

A parameter that allows to configure whether the statistics for different examples should be updated in parallel or not.

class mlrl.common.config.Parameter(name: str, description: str)

Bases: ABC

An abstract base class for all parameters of a rule learning algorithm.

abstract add_to_argument_parser(parser: ArgumentParser, config_type: type)

Adds a command line argument that corresponds to this parameter to an ArgumentParser if it is supported by a configuration of a specific type.

property argument_name: str

The name of a command line argument that corresponds to the parameter.

abstract configure(config, value)

Configures a rule learner depending on this parameter.

Parameters:
  • config – The configuration to be modified

  • value – The value to be set

class mlrl.common.config.PartitionSamplingParameter

Bases: NominalParameter

A parameter that allows to configure the strategy to be used for creating a holdout set.

OPTION_HOLDOUT_SET_SIZE = 'holdout_set_size'
PARTITION_SAMPLING_RANDOM = 'random'
class mlrl.common.config.RuleInductionParameter

Bases: NominalParameter

A parameter that allows to configure the algorithm to be used for the induction of individual rules.

OPTION_BEAM_WIDTH = 'beam_width'
OPTION_MAX_CONDITIONS = 'max_conditions'
OPTION_MAX_HEAD_REFINEMENTS = 'max_head_refinements'
OPTION_MIN_COVERAGE = 'min_coverage'
OPTION_MIN_SUPPORT = 'min_support'
OPTION_RECALCULATE_PREDICTIONS = 'recalculate_predictions'
RULE_INDUCTION_TOP_DOWN_GREEDY = 'top-down-greedy'
class mlrl.common.config.RulePruningParameter

Bases: NominalParameter

A parameter that allows to configure the strategy to be used for pruning individual rules.

RULE_PRUNING_IREP = 'irep'
class mlrl.common.config.SequentialPostOptimizationParameter

Bases: NominalParameter

A parameter that allows to configure whether each rule in a previously learned model should be optimized by being relearned in the context of the other rules or not.

OPTION_NUM_ITERATIONS = 'num_iterations'
OPTION_REFINE_HEADS = 'refine_heads'
class mlrl.common.config.SizeStoppingCriterionParameter

Bases: IntParameter

A parameter that allows to configure the maximum number of rules to be induced.

class mlrl.common.config.TimeStoppingCriterionParameter

Bases: IntParameter

A parameter that allows to configure the duration in seconds after which the induction of rules should be canceled.

mlrl.common.config.configure_argument_parser(parser: ArgumentParser, config_type: type, parameters: Set[Parameter])

Configure an ArgumentParser by taking into account a given set of parameters.

Parameters:
  • parser – The ArgumentParser to be configured

  • config_type – The type of the configuration that should support the parameters

  • parameters – A set that contains the parameters to be taken into account

mlrl.common.config.configure_rule_learner(learner, config, parameters: Set[Parameter])

Configures a rule learner by taking into account a given set of parameters.

Parameters:
  • learner – The rule learner to be configured

  • config – The configuration to be modified

  • parameters – A set that contains the parameters to be taken into account

mlrl.common.config.create_kwargs_from_parameters(args, parameters: Set[Parameter])

Creates and returns a dictionary that contains all parameter names and corresponding values that have been specified via an ArgumentParser.

Parameters:

args – The arguments that have been specified via an ArgumentParser

Returns:

A dictionary that contains the parameter names and corresponding values