Source code for dowhy.causal_refuters.overrule.BCS.beam_search

"""Beam search utilities for optimization.

This module implements the boolean ruleset estimator from OverRule [1]. Code is adapted (with some simplifications)
from https://github.com/clinicalml/overlap-code, under the MIT License.

[1] Oberst, M., Johansson, F., Wei, D., Gao, T., Brat, G., Sontag, D., & Varshney, K. (2020). Characterization of
Overlap in Observational Studies. In S. Chiappa & R. Calandra (Eds.), Proceedings of the Twenty Third International
Conference on Artificial Intelligence and Statistics (Vol. 108, pp. 788–798). PMLR. https://arxiv.org/abs/1907.04138
"""

import numpy as np
import pandas as pd


[docs]class PricingInstance: """ Instance of the pricing problem. For more details, see: Dash, S., Gunluk, O., and Wei, D. (2018). Boolean decision rules via column generation. In Bengio, S., Wallach, H., Larochelle, H., Grauman, K., Cesa- Bianchi, N., and Garnett, R., editors, Advances in Neural Information Processing Systems 31, pages 4660–4670. Curran Associates, Inc. """ def __init__(self, rp, rn, Xp, Xn, v0, z0): self.rp = rp self.rn = rn self.Xp = Xp self.Xn = Xn self.v0 = v0 self.z0 = z0
[docs] def eval_singletons(self, lambda1): """Evaluate all singleton solutions (adding one literal)""" self.Rp = np.dot(self.rp, self.Xp) self.Rn = np.dot(self.rn, self.Xn) self.v1 = self.v0 - self.Rp - self.Rn + lambda1 self.v1 = pd.Series(self.v1, index=self.Xp.columns)
[docs] def compute_LB(self, lambda1): """Compute lower bound on higher-order solutions""" Rp0 = self.rp.sum() self.LB = np.minimum(np.cumsum(np.sort(self.Rp)[::-1])[1:], Rp0) self.LB += np.sort(self.Rn)[-2::-1] self.LB -= lambda1 * np.arange(2, len(self.Rp) + 1) self.LB = self.v0 - self.LB # Lower bound specific to each singleton solution self.LB1 = self.v1 + self.Rp - Rp0 + lambda1 if len(self.LB): self.LB1[self.LB1 < self.LB.min()] = self.LB.min()