class_docstr: a class to represent a single clause/rule of the form:
  "IF <literal1> AND <literal2> AND ... <literal_k> THEN predict class = 0 or 1"
class_docstr_tok: ["a","class","to","represent","a","single","clause\/rule","of","the","form",":","''","IF","<","literal1",">","AND","<","literal2",">","AND","...","<","literal_k",">","THEN","predict","class","=","0","or","1","''"]
docstr: returns the dict-like representation of the rule, having ranges for all features, if arguments are passed.
  useful for computing intersection, and generating data in the region.
  Args:
      feature_names: list of all feature names in the training data
      total_region: range observed for each feature in the training data
                      if not passed, it is taken as [-inf, inf]
      only_preds: do you want a dictionary representation with only the features/predicates present
                  in this rule?
                  if only_preds is True, the returned dictionary contains features that appear in self.predicates,
                  only useful if you also pass all `feature_names` and `total_region`.
  Returns:
      region: a dictionary whose keys are feature names, and values are a 2 element list (min-val, max-val
              permissible for the feature in that rule)
docstr_tok: ["returns","the","dict-like","representation","of","the","rule",",","having","ranges","for","all","features",",","if","arguments","are","passed",".","useful","for","computing","intersection",",","and","generating","data","in","the","region",".","Args",":","feature_names",":","list","of","all","feature","names","in","the","training","data","total_region",":","range","observed","for","each","feature","in","the","training","data","if","not","passed",",","it","is","taken","as","[","-inf",",","inf","]","only_preds",":","do","you","want","a","dictionary","representation","with","only","the","features\/predicates","present","in","this","rule","?","if","only_preds","is","True",",","the","returned","dictionary","contains","features","that","appear","in","self.predicates",",","only","useful","if","you","also","pass","all","`","feature_names","`","and","`","total_region","`",".","Returns",":","region",":","a","dictionary","whose","keys","are","feature","names",",","and","values","are","a","2","element","list","(","min-val",",","max-val","permissible","for","the","feature","in","that","rule",")"]
code: def as_dict(
      self,
      feature_names: list = None,
      total_region: dict = None,
      only_preds=False,
  ):
      """
      returns the dict-like representation of the rule, having ranges for all features, if arguments are passed.
      useful for computing intersection, and generating data in the region.
      Args:
          feature_names: list of all feature names in the training data
          total_region: range observed for each feature in the training data
                          if not passed, it is taken as [-inf, inf]
          only_preds: do you want a dictionary representation with only the features/predicates present
                      in this rule?
                      if only_preds is True, the returned dictionary contains features that appear in self.predicates,
                      only useful if you also pass all `feature_names` and `total_region`.
      Returns:
          region: a dictionary whose keys are feature names, and values are a 2 element list (min-val, max-val
                  permissible for the feature in that rule)
      """
  
      if (
          feature_names is None
      ):  # then build dict with only appearing features
          feature_names = []
          for pred in self.predicates:
              f, op, th = pred
              feature_names.append(f)
      feature_names = list(set(feature_names))
  
      region = {}
  
      for feature in feature_names:
          if total_region is not None:
              minvalue = total_region[feature][0]
              maxvalue = total_region[feature][1]
          else:  # if ranges not passed, use [-inf, inf] range.
              minvalue = np.NINF
              maxvalue = np.Inf
  
          predicates_having_feature = []
  
          for pred in self.predicates:
              f, op, th = pred
              if f == feature:
                  predicates_having_feature.append(pred)
  
          for idx, pred in enumerate(predicates_having_feature):
              f, op, th = pred
              if op == "<=" or op == "<":
                  if th < maxvalue:
                      maxvalue = th
                  pass
              elif op == ">" or op == ">=":
                  if th > minvalue:
                      minvalue = th
  
          if not only_preds:
              region[feature] = [minvalue, maxvalue]
          elif len(predicates_having_feature) != 0:
              region[feature] = [minvalue, maxvalue]
  
      return region
  
file_path: AIX360/aix360/algorithms/imd/rule.py
imports: from dataclasses import dataclass
  import numpy
  import pandas
label_desc: Use image node_id 3 for calling the Rule obj's underlying member method code with example usage: obj.as_dict(feature_names, total_region, only_preds) and returns: region