IBM/causallib

View on GitHub

Showing 111 of 111 total issues

Similar blocks of code found in 3 locations. Consider refactoring.
Open

std[i] = std[i] + spread * (torch.rand_like(std[i]) - 0.5)
Severity: Major
Found in causallib/contrib/hemm/hemm.py and 2 other locations - About 1 hr to fix
causallib/contrib/hemm/hemm.py on lines 80..80
causallib/contrib/hemm/hemm.py on lines 82..82

Function computeCorrPvals has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

def computeCorrPvals(X, y, is_X_binary, is_y_binary, isLinear=True):
"""
 
Args:
X (pd.DataFrame): The covariate matrix
Severity: Minor
Found in causallib/utils/stat_utils.py - About 1 hr to fix

Function plot_mean_features_imbalance_love_folds has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

def plot_mean_features_imbalance_love_folds(
table1_folds,
cv=None,
aggregate_folds=True,
thresh=None,
Severity: Minor
Found in causallib/evaluation/plots/plots.py - About 1 hr to fix

Function gen_outcomes has 39 lines of code (exceeds 25 allowed). Consider refactoring.
Open

def gen_outcomes(X, T, seed=0):
"""Synthetically generate outcome data from provided covariates and treatment assignment.
 
Args:
X: input covariates
Severity: Minor
Found in causallib/contrib/hemm/gen_synthetic_data.py - About 1 hr to fix

    Function wass has 37 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    def wass(X,t,p,lam=10.0,its=20,sq=False,backpropT=False):
    """
    Computes the Wasserstein metric.
     
    Algorithm 3 from "Fast Computation of Wasserstein Barycenters", Cuturi and Doucet (2014) (https://arxiv.org/pdf/1310.4375.pdf).
    Severity: Minor
    Found in causallib/contrib/hemm/hemm_metrics.py - About 1 hr to fix

      Function generate_random_topology has 36 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      def generate_random_topology(n_covariates, p, n_treatments=1, n_outcomes=1, n_censoring=0, given_vars=(),
      p_hidden=0.0):
      """
      Creates a random graph topology, suitable for describing a causal graph model.
      Generation is based on a G(n,p) random graph model (each edge independently generated or not by a coin toss).
      Severity: Minor
      Found in causallib/simulation/CausalSimulator3.py - About 1 hr to fix

        Function KFoldStratifiedMultiClass has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

        def KFoldStratifiedMultiClass(labels, n, seed=0):
        """Returns a stratified n-fold in a dictionary, trying to distribute classes across folds as well as possible."""
        np.random.seed(seed)
        freqs = np.sum(labels, axis=0) # class frequencies
        tups = zip(freqs, range(19))
        Severity: Minor
        Found in causallib/contrib/hemm/hemm_utilities.py - About 1 hr to fix

        Function _plot_single_performance_curve has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

        def _plot_single_performance_curve(
        xs,
        ys,
        areas,
        areas_type,
        Severity: Minor
        Found in causallib/evaluation/plots/plots.py - About 1 hr to fix

        Function loadIHDPData has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

        def loadIHDPData(cache_dir=None, verbose=0, delete_extracted=True):
        """Downloads and loads IHDP-1000 dataset.
        Taken From Fredrik Johansson's website: http://www.fredjo.com/
         
        Args:
        Severity: Minor
        Found in causallib/contrib/hemm/load_ihdp_data.py - About 1 hr to fix

        Function _convert_scalars_to_vectors has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

        def _convert_scalars_to_vectors(self, x, default_value, x_type):
        """
        Converts scalars (e.g. float, int, str, etc.) into vectors. Mapping between variable names to the desired value.
        In context: If arguments given to the class init are scalar (i.e. float, int, str, etc.), converts them into
        vector shape - mapping every variable to the given value
        Severity: Minor
        Found in causallib/simulation/CausalSimulator3.py - About 1 hr to fix

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

        self.treatment_support_ = {
        c: self.fit_column(X[a == 1][c]) for c in X.columns}
        Severity: Major
        Found in causallib/positivity/univariate_bbox.py and 1 other location - About 1 hr to fix
        causallib/positivity/univariate_bbox.py on lines 182..183

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

        self.control_support_ = {c: self.fit_column(
        X[a == 0][c]) for c in X.columns}
        Severity: Major
        Found in causallib/positivity/univariate_bbox.py and 1 other location - About 1 hr to fix
        causallib/positivity/univariate_bbox.py on lines 180..181

        Function __init__ has 35 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        def __init__(self, topology, var_types, prob_categories, link_types, snr, treatment_importances,
        treatment_methods="gaussian", outcome_types=CATEGORICAL, effect_sizes=None,
        survival_distribution="expon", survival_baseline=1, params=None):
        """
        Constructor
        Severity: Minor
        Found in causallib/simulation/CausalSimulator3.py - About 1 hr to fix

          Identical blocks of code found in 2 locations. Consider refactoring.
          Open

          if list(Xc.shape)[0] == 0.0 or list(Xt.shape)[0] == 0.0:
          Severity: Major
          Found in causallib/contrib/hemm/hemm_metrics.py and 1 other location - About 1 hr to fix
          causallib/contrib/hemm/hemm_metrics.py on lines 98..98

          Identical blocks of code found in 2 locations. Consider refactoring.
          Open

          if list(Xc.shape)[0] == 0.0 or list(Xt.shape)[0] == 0.0:
          Severity: Major
          Found in causallib/contrib/hemm/hemm_metrics.py and 1 other location - About 1 hr to fix
          causallib/contrib/hemm/hemm_metrics.py on lines 66..66

          Similar blocks of code found in 3 locations. Consider refactoring.
          Open

          topology.loc[censoring, treatments] = np.random.binomial(n=1, p=p, size=(n_censoring, n_treatments)).astype(bool)
          Severity: Major
          Found in causallib/simulation/CausalSimulator3.py and 2 other locations - About 1 hr to fix
          causallib/simulation/CausalSimulator3.py on lines 1562..1563
          causallib/simulation/CausalSimulator3.py on lines 1565..1566

          Function estimate_individual_outcome has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
          Open

          def estimate_individual_outcome(self, X, a, y=None, same_dim_as_input=True):
          """estimate individual-level counterfactual predictions.
           
          if `self.individual is True` and `self.outcome_model` has `estimate_individual_outcome()`
          then each observation will get a unique counterfactual value.
          Severity: Minor
          Found in causallib/contrib/bicause_tree/bicause_tree.py - About 1 hr to fix

          Similar blocks of code found in 3 locations. Consider refactoring.
          Open

          topology.loc[generated_vars, covariates] = np.random.binomial(n=1, p=p,
          size=(n_generated_vars, n_covariates)).astype(bool)
          Severity: Major
          Found in causallib/simulation/CausalSimulator3.py and 2 other locations - About 1 hr to fix
          causallib/simulation/CausalSimulator3.py on lines 1562..1563
          causallib/simulation/CausalSimulator3.py on lines 1569..1569

          Function plot_mean_features_imbalance_scatter_plot has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
          Open

          def plot_mean_features_imbalance_scatter_plot(
          table1_folds,
          aggregate_folds=True,
          thresh=None,
          label_imbalanced=True,
          Severity: Minor
          Found in causallib/evaluation/plots/plots.py - About 1 hr to fix

          Function format_for_training has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
          Open

          def format_for_training(self, X, propensities, cf, headers_chars=None, exclude_hidden_vars=True):
          """
          prepare to output. merge the data into two DataFrames - an observed one and one gathering the counterfactuals.
           
          Args:
          Severity: Minor
          Found in causallib/simulation/CausalSimulator3.py - About 1 hr to fix
          Severity
          Category
          Status
          Source
          Language