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 pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ r2 = [
"boto3>=1.34",
]
policyengine = [
"microimpute==1.15.1 ; python_full_version >= '3.12' and python_full_version < '3.15'",
"microimpute @ git+https://github.com/PolicyEngine/microimpute.git@27d23090dcf04c2c30ae369b0a209e27eb3659f0 ; python_full_version >= '3.12' and python_full_version < '3.15'",
"policyengine-us==1.715.2; python_version >= '3.11' and python_version < '3.15'",
"spm-calculator>=0.3.1",
# Standalone tax-unit construction engine (the extraction of eCPS's
Expand Down
16 changes: 2 additions & 14 deletions src/microplex_us/pipelines/donor_imputers.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,19 +168,13 @@ def __init__(
condition_vars: list[str],
target_vars: list[str],
n_estimators: int = 100,
nonnegative_vars: set[str] | None = None,
classifier_type: str = "hist_gb",
min_class_count: int = 10,
min_class_fraction: float = 0.01,
seed: int = 42,
) -> None:
self.condition_vars = list(condition_vars)
self.target_vars = list(target_vars)
self.n_estimators = int(n_estimators)
self.nonnegative_vars = set(nonnegative_vars or ())
self.classifier_type = str(classifier_type)
self.min_class_count = int(min_class_count)
self.min_class_fraction = float(min_class_fraction)
self.seed = int(seed)
self._fitted: dict[str, Any] = {}
self._regimes: dict[str, str] = {}
Expand All @@ -204,8 +198,7 @@ def fit(
)
if importlib.util.find_spec("quantile_forest") is None:
raise ImportError(
"quantile-forest is required for the RegimeAwareDonorImputer "
"base QRF."
"quantile-forest is required for the RegimeAwareDonorImputer base QRF."
)

from microimpute.models.qrf import QRF
Expand All @@ -224,8 +217,6 @@ def fit(
wrapper = ZeroInflatedImputer(
base_imputer_class=QRF,
base_imputer_kwargs={},
min_class_count=self.min_class_count,
min_class_fraction=self.min_class_fraction,
classifier_type=self.classifier_type,
seed=self.seed,
)
Expand Down Expand Up @@ -256,10 +247,7 @@ def generate(
)
self._reset_prediction_rngs(fitted, seed=column_seed)
preds = fitted.predict(synthetic[self.condition_vars])
values = preds[column].to_numpy(dtype=float)
if column in self.nonnegative_vars:
values = np.maximum(values, 0.0)
synthetic[column] = values
synthetic[column] = preds[column].to_numpy(dtype=float)
return synthetic

def _reset_prediction_rngs(
Expand Down
12 changes: 3 additions & 9 deletions src/microplex_us/pipelines/us.py
Original file line number Diff line number Diff line change
Expand Up @@ -5291,18 +5291,13 @@ def _build_donor_imputer(
nonnegative_vars = {
variable
for variable, support_family in support_families.items()
if support_family
in {
VariableSupportFamily.ZERO_INFLATED_POSITIVE,
VariableSupportFamily.BOUNDED_SHARE,
}
if support_family is VariableSupportFamily.BOUNDED_SHARE
}
if backend == "regime_aware":
return RegimeAwareDonorImputer(
condition_vars=condition_vars,
target_vars=list(target_vars),
n_estimators=self.config.donor_imputer_qrf_n_estimators,
nonnegative_vars=nonnegative_vars,
seed=self.config.random_seed,
)
zero_inflated_vars = (
Expand All @@ -5311,8 +5306,7 @@ def _build_donor_imputer(
for variable, support_family in support_families.items()
if support_family
in {
VariableSupportFamily.ZERO_INFLATED_POSITIVE,
VariableSupportFamily.ZERO_INFLATED_SIGNED,
VariableSupportFamily.SUPPORT_SENSITIVE,
}
}
if backend == "zi_qrf"
Expand Down Expand Up @@ -7147,7 +7141,7 @@ def _rank_match_donor_values(
donor_weight_array = donor_weights.to_numpy(dtype=float)
donor_weight_array = np.clip(donor_weight_array, a_min=0.0, a_max=None)

if strategy is DonorMatchStrategy.ZERO_INFLATED_POSITIVE or (
if (
strategy is DonorMatchStrategy.RANK
and self._is_zero_inflated_positive_distribution(donor_array)
):
Expand Down
Loading
Loading