Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Learnable backdoor with SymPyTorch #217

Open
cthoyt opened this issue Mar 22, 2024 · 0 comments
Open

Learnable backdoor with SymPyTorch #217

cthoyt opened this issue Mar 22, 2024 · 0 comments

Comments

@cthoyt
Copy link
Member

cthoyt commented Mar 22, 2024

This takes some code out of #210 for later:

def get_single_door_learnable(
    graph: NxMixedGraph, data: pd.DataFrame
) -> dict[tuple[Variable, Variable], float]:
    """Estimate parameter values for a linear SCM using backdoor adjustment."""
    inference = graph.to_pgmpy_causal_inference()
    rv = {}
    for source, target in graph.directed.edges():
        try:
            adjustment_sets = inference.get_all_backdoor_adjustment_sets(source.name, target.name)
        except ValueError:
            continue
        if not adjustment_sets:
            continue

        # 2 ways - learnable, or specify a prior. Interpret lower and upper
        # bound as range for learnable paramter OR as a prior

        adjustment_set = list(adjustment_sets)[0]
        variables = sorted(adjustment_set | {source.name})
        idx = variables.index(source.name)
        model = LinearRegression()
        model.fit(data[variables], data[target.name])
        rv[source, target] = model.coef_[idx]
    return rv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant