Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/did_sim.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
version: "0.6.11"
version: "0.7.8"

- name: Set up Python
uses: actions/setup-python@v5
Expand Down
38 changes: 23 additions & 15 deletions .github/workflows/rdd_sim.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ jobs:
strategy:
matrix:
script: [
'scripts/rdd/rdd_sharp_coverage.py',
'scripts/rdd/rdd_fuzzy_coverage.py',
'scripts/rdd/rdd_sharp.py',
'scripts/rdd/rdd_fuzzy.py',
]

steps:
Expand Down Expand Up @@ -48,34 +48,42 @@ jobs:
with:
ref: ${{ env.TARGET_BRANCH }}

- name: Install uv
uses: astral-sh/setup-uv@v5
with:
version: "0.7.8"

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
python-version-file: "monte-cover/pyproject.toml"

- name: Install dependencies
- name: Install Monte-Cover
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
cd monte-cover
uv venv
uv sync

- name: Install DoubleML from correct branch
run: |
pip uninstall -y doubleml
pip install "doubleml[rdd] @ git+https://github.com/DoubleML/doubleml-for-py@${{ env.DML_BRANCH }}"
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Install RDFlex from main branch
- name: Install DoubleML from correct branch
run: |
pip uninstall -y doubleml
pip install git+https://github.com/DoubleML/doubleml-rdflex.git@main
pip install rdrobust
source monte-cover/.venv/bin/activate
uv pip uninstall doubleml
uv pip install "doubleml[rdd] @ git+https://github.com/DoubleML/doubleml-for-py@${{ env.DML_BRANCH }}"

- name: Set up Git configuration
run: |
git config --global user.name 'github-actions'
git config --global user.email '[email protected]'

- name: Run scripts
run: python ${{ matrix.script }}
run: |
source monte-cover/.venv/bin/activate
uv run ${{ matrix.script }}

- name: Commit any existing changes
run: |
Expand Down
4 changes: 2 additions & 2 deletions doc/rdd/rdd.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ df_sharp = pd.read_csv("../../results/rdd/rdd_sharp_coverage.csv", index_col=Non
assert df_sharp["repetition"].nunique() == 1
n_rep_sharp = df_sharp["repetition"].unique()[0]

display_columns_sharp = ["Method", "Learner g", "fs specification", "Bias", "CI Length", "Coverage"]
display_columns_sharp = ["Method", "Learner g", "fs_specification", "Bias", "CI Length", "Coverage"]
```

```{python}
Expand Down Expand Up @@ -99,7 +99,7 @@ df_fuzzy = pd.read_csv("../../results/rdd/rdd_fuzzy_coverage.csv", index_col=Non
assert df_fuzzy["repetition"].nunique() == 1
n_rep_fuzzy = df_fuzzy["repetition"].unique()[0]

display_columns_fuzzy = ["Method", "Learner g", "Learner m", "fs specification", "Bias", "CI Length", "Coverage"]
display_columns_fuzzy = ["Method", "Learner g", "Learner m", "fs_specification", "Bias", "CI Length", "Coverage"]
```

```{python}
Expand Down
44 changes: 9 additions & 35 deletions monte-cover/src/montecover/did/did_pa_multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
import numpy as np
import pandas as pd
from doubleml.did.datasets import make_did_CS2021
from lightgbm import LGBMClassifier, LGBMRegressor
from sklearn.linear_model import LinearRegression, LogisticRegression

from montecover.base import BaseSimulation
from montecover.utils import create_learner_from_config


class DIDMultiCoverageSimulation(BaseSimulation):
Expand Down Expand Up @@ -36,39 +35,13 @@ def __init__(
def _process_config_parameters(self):
"""Process simulation-specific parameters from config"""
# Process ML models in parameter grid
# Process ML models in parameter grid
assert "learners" in self.dml_parameters, "No learners specified in the config file"

assert (
"learners" in self.dml_parameters
), "No learners specified in the config file"
required_learners = ["ml_g", "ml_m"]
for learner in self.dml_parameters["learners"]:
assert "ml_g" in learner, "No ml_g specified in the config file"
assert "ml_m" in learner, "No ml_m specified in the config file"

# Convert ml_g strings to actual objects
if learner["ml_g"][0] == "Linear":
learner["ml_g"] = ("Linear", LinearRegression())
elif learner["ml_g"][0] == "LGBM":
learner["ml_g"] = (
"LGBM",
LGBMRegressor(
n_estimators=500, learning_rate=0.02, verbose=-1, n_jobs=1
),
)
else:
raise ValueError(f"Unknown learner type: {learner['ml_g']}")

# Convert ml_m strings to actual objects
if learner["ml_m"][0] == "Linear":
learner["ml_m"] = ("Linear", LogisticRegression())
elif learner["ml_m"][0] == "LGBM":
learner["ml_m"] = (
"LGBM",
LGBMClassifier(
n_estimators=500, learning_rate=0.02, verbose=-1, n_jobs=1
),
)
else:
raise ValueError(f"Unknown learner type: {learner['ml_m']}")
for ml in required_learners:
assert ml in learner, f"No {ml} specified in the config file"

def _calculate_oracle_values(self):
"""Calculate oracle values for the simulation."""
Expand Down Expand Up @@ -102,8 +75,9 @@ def _calculate_oracle_values(self):
def run_single_rep(self, dml_data, dml_params) -> Dict[str, Any]:
"""Run a single repetition with the given parameters."""
# Extract parameters
learner_g_name, ml_g = dml_params["learners"]["ml_g"]
learner_m_name, ml_m = dml_params["learners"]["ml_m"]
learner_config = dml_params["learners"]
learner_g_name, ml_g = create_learner_from_config(learner_config["ml_g"])
learner_m_name, ml_m = create_learner_from_config(learner_config["ml_m"])
score = dml_params["score"]
in_sample_normalization = dml_params["in_sample_normalization"]

Expand Down
7 changes: 7 additions & 0 deletions monte-cover/src/montecover/rdd/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""Monte Carlo coverage simulations for RDD."""

from montecover.rdd.rdd import RDDCoverageSimulation

__all__ = [
"RDDCoverageSimulation",
]
Loading