xlemoo.ruleset_interpreter
- XLEMOO.ruleset_interpreter.extract_slipper_rules(classifier: SlipperClassifier) Tuple[List[Dict[Tuple[str, str], str]], List[float]][source]
Given a trained SlipperClassifier, extracts the trained rules alongside the weight for each rule. The rules are returned in a list of dictionaries. Each rule is represented by one dictionary. Each dictionary is of the format:
{(“feature_name”, “comparison_op”): “value”} where comparison_op can be “<”, “<=”, “>”, or “>=”.
The weight represents the importance of each rule. The feature names are expected to be of the format “x_i” where ‘i’ is zero-indexed (first feature is ‘x_0’ etc.).
- XLEMOO.ruleset_interpreter.instantiate_rules(rules: Dict[Tuple[str, str], str], n_features: int, feature_limits: List[Tuple[float, float]], n_samples: int) ndarray[source]
Takes Rules and instantiates them producing n_samples of new decision variable vectors corresponding to the rules. If there are no rules for a variable, a random value is generated for that variable between its limits. Notice that when rules define a range for a variable, then that variable’s value will be generated between those ranges randomly.
- Parameters:
rules (Rules) – Should be a dict with the following structure: {(“feature_name”, “comparison_op”): “value”} where comparison_op can be “<”, “<=”, “>”, or “>=”. The feature names are expected to be formatted as “x_i” where ‘i’ is zero indexed (i.e., x_0, x_1, x_2, etc.).
n_features (int) – Number of features to instantiate based on the rules provided.
feature_limits (List[Tuple[float, float]]) – 2D array, each row corresponds to a decision variable. The first column has the lower limits for each variable and the second the upper limit.
n_samples (int) – How many samples to generate based on the rules provided.
- Returns:
The new samples generated based on the provided rules in a 2D array.
- Return type:
np.ndarray
- XLEMOO.ruleset_interpreter.instantiate_ruleset_rules(rules: List[Dict[Tuple[str, str], str]], weights: List[float], n_features: int, feature_limits: List[Tuple[float, float]], n_samples: int) ndarray[source]
Instantiate samples according to a rule set. Instantiates in total approximately n_samples of new samples according to the rules and features limits. If for some feature there are no rules, then only the feature limits are used. The feature limits will override rules if there is a conflict. The given weights will dictate how large of a fraction of n_samples will be generated for each rule. It is assumed that the rules supplied (in a list) have a weight at the same index in the argument weights.
- Parameters:
rules (List[Rules]) – The rules contained in the rule set. See ‘instantiate_rules’.
weights (List[float]) – The weights for each rule in the rule set. It is assumed tht the weight at index i corresponds to the weight of rules at index i in ‘rules’.
n_features (int) – How many new samples to generate according to the rules. This is approximate, but the total of new samples should be relatively close to this number.
feature_limits (List[Tuple[float, float]]) – Pairs representing the lower and upper bounds of each feature.
n_samples (int) – Approximately how many new samples to generate in total.
- Returns:
A 2D array with all the new generated samples. If a list of samples per rule is desired, see ‘_instantiate_ruleset_rules’.
- Return type:
np.ndarray