Skip to content

Add some type checks to algorithm/estimation/estimators.py #294

@callahanr

Description

@callahanr

Here's get_primal_point_estimate:

def get_primal_ipw_point_estimate(
    *,
    data: pd.DataFrame,
    graph: NxMixedGraph,
    treatment: Variable,
    treatment_value: int | float,
    outcome: Variable,
) -> float:
    """Estimate the counterfactual mean E[Y(t)] with the Primal IPW estimator on p-fixable graphs."""
    # TODO: This function currently returns type Any to conform with mypy requirements. 
    #       That's not the best reason to make a return type less restrictive. 
    #       Consider warning the user if the type of the return value cannot be 
    #       coerced to a float. -callahanr
    beta_primal = get_beta_primal(
        data=data,
        graph=graph,
        treatment=treatment,
        treatment_value=treatment_value,
        outcome=outcome,
    )
    return np.mean(beta_primal).item()

This function currently returns an object of type Any because beta_primal is of type np.ndarray[Any, np.dtype[Any]]. Currently to conform to mypy standards we allow the return value to be either a float or Any, but ideally we would want to coerce the return value from Any to a float if possible, and if not then warn the user that something may have gone wrong with the computation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions