class_docstr: Overlap Boolean Rule class in the style of scikit-learn
class_docstr_tok: ["Overlap","Boolean","Rule","class","in","the","style","of","scikit-learn"]
docstr: Round the rule coefficients to integer values.
  
  For DNF, this starts with no conjunctions, and adds them greedily based on a cost, which penalizes (any)
  inclusion of negative samples, and rewards (new) inclusion of positive samples, and goes until it covers at
  least alpha fraction of positive samples.
  
  :param X: Pandas DataFrame containing covariates
  :param y: +1 for Overlap/Support (depending on rules being learned), 0 for
      non-overlap, and -1 for background samples.  Should only contain (+1/0) for
      overlap rules, or (+1/-1) for learning support rules.
  :param xi: Reward for including positive samples, relative to cost (1) for including negative samples
  :param use_lp: Restrict to those conjuctions where the LP coefficients are positive.  Note that the LP makes a
      difference regardless, as we only consider the rules generated by column generation here.
docstr_tok: ["Round","the","rule","coefficients","to","integer","values",".","For","DNF",",","this","starts","with","no","conjunctions",",","and","adds","them","greedily","based","on","a","cost",",","which","penalizes","(","any",")","inclusion","of","negative","samples",",","and","rewards","(","new",")","inclusion","of","positive","samples",",","and","goes","until","it","covers","at","least","alpha","fraction","of","positive","samples",".",":","param","X",":","Pandas","DataFrame","containing","covariates",":","param","y",":","+1","for","Overlap\/Support","(","depending","on","rules","being","learned",")",",","0","for","non-overlap",",","and","-1","for","background","samples",".","Should","only","contain","(","+1\/0",")","for","overlap","rules",",","or","(","+1\/-1",")","for","learning","support","rules",".",":","param","xi",":","Reward","for","including","positive","samples",",","relative","to","cost","(","1",")","for","including","negative","samples",":","param","use_lp",":","Restrict","to","those","conjuctions","where","the","LP","coefficients","are","positive",".","Note","that","the","LP","makes","a","difference","regardless",",","as","we","only","consider","the","rules","generated","by","column","generation","here","."]
code: def greedy_round_(
      self,
      X: pd.DataFrame,
      y: Union[np.ndarray, pd.DataFrame],
      xi: float = 0.5,
      use_lp: bool = False,
  ):
      """
      Round the rule coefficients to integer values.
  
      For DNF, this starts with no conjunctions, and adds them greedily based on a cost, which penalizes (any)
      inclusion of negative samples, and rewards (new) inclusion of positive samples, and goes until it covers at
      least alpha fraction of positive samples.
  
      :param X: Pandas DataFrame containing covariates
      :param y: +1 for Overlap/Support (depending on rules being learned), 0 for
          non-overlap, and -1 for background samples.  Should only contain (+1/0) for
          overlap rules, or (+1/-1) for learning support rules.
      :param xi: Reward for including positive samples, relative to cost (1) for including negative samples
      :param use_lp: Restrict to those conjuctions where the LP coefficients are positive.  Note that the LP makes a
          difference regardless, as we only consider the rules generated by column generation here.
      """
  
      A = self.compute_conjunctions(X)
      R = np.arange(0, A.shape[1])  # Remaining conjunctions
      U = []  # Used conjunctions
      C = np.zeros(X.shape[0])  # Coverage indicator
      MAX_ITER = 1000
      i = 0
  
      # Restrict conjunctions to those used by LP
      if use_lp:
          R = [R[i] for i in range(len(R)) if self.w_raw[i] > 0]
  
      # NOTE: This is a greedy approach, so it does not incorporate lambda0 explicitly
      # Similarly, it will prefer a larger number of smaller rules if lambda1 is set
      # to a larger value, because the incremental cost will be lower.
      while (i < MAX_ITER) and (C[y == 1].mean() < self.alpha):
          if (y == 0).sum() > 0:
              neg_cover = (A[(y == 0), :][:, R]).mean(0)
          else:
              neg_cover = 0
  
          if (y == -1).sum() > 0:
              # Fraction of reference samples that each conjunction covers
              ref_cover = (A[(y == -1), :][:, R]).mean(0)
          else:
              ref_cover = 0
  
          # Regularization (for each conjunction)
          reg = self.lambda1 * self.z.values[:, R].sum(0)
  
          # Positive samples newly covered (for each conjunction)
          pos_new_cover = (A[(y == 1) & (C < 1), :][:, R] + 1e-8).mean(
              0
          )
  
          # Costs (for each conjunction)
          costs = neg_cover + ref_cover + reg - xi * pos_new_cover
  
          r = np.argmin(costs)  # Find min-cost conjunction
          C = (C + A[:, R[r]]) > 0.0  # Update coverage
          U.append(R[r])
          R = np.array([R[i] for i in range(len(R)) if not i == r])
  
          i += 1
  
      # Zero out the rules and only take those which are used
      self.w = np.zeros(A.shape[1])
      self.w[U] = 1
  
imports: import logging
  from typing import Union
  import cvxpy
  import numpy
  import pandas
  from sklearn.metrics import roc_auc_score
  from .beam_search import beam_search
label_desc: Use image node_id 5 for calling the OverlapBooleanRule obj's underlying member method code with example usage: obj.greedy_round_(X, y, xi, use_lp) without return types