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

per-metric model selection in MBM #3032

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
37 changes: 6 additions & 31 deletions ax/modelbridge/cross_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,10 @@
from ax.modelbridge.base import ModelBridge, unwrap_observation_data
from ax.utils.common.logger import get_logger
from ax.utils.stats.model_fit_stats import (
_correlation_coefficient,
_fisher_exact_test_p,
_log_likelihood,
_mape,
_mean_prediction_ci,
_mse,
_rank_correlation,
_total_raw_effect,
_wmape,
coefficient_of_determination,
compute_model_fit_metrics,
DIAGNOSTIC_FNS,
FISHER_EXACT_TEST_P,
mean_of_the_standardized_error,
ModelFitMetricProtocol,
std_of_the_standardized_error,
Expand All @@ -44,16 +37,6 @@

CVDiagnostics = dict[str, dict[str, float]]

MEAN_PREDICTION_CI = "Mean prediction CI"
MAPE = "MAPE"
wMAPE = "wMAPE"
TOTAL_RAW_EFFECT = "Total raw effect"
CORRELATION_COEFFICIENT = "Correlation coefficient"
RANK_CORRELATION = "Rank correlation"
FISHER_EXACT_TEST_P = "Fisher exact test p"
LOG_LIKELIHOOD = "Log likelihood"
MSE = "MSE"


class CVResult(NamedTuple):
"""Container for cross validation results."""
Expand Down Expand Up @@ -312,19 +295,11 @@ def compute_diagnostics(result: list[CVResult]) -> CVDiagnostics:
y_pred = _arrayify_dict_values(y_pred)
se_pred = _arrayify_dict_values(se_pred)

diagnostic_fns = {
MEAN_PREDICTION_CI: _mean_prediction_ci,
MAPE: _mape,
wMAPE: _wmape,
TOTAL_RAW_EFFECT: _total_raw_effect,
CORRELATION_COEFFICIENT: _correlation_coefficient,
RANK_CORRELATION: _rank_correlation,
FISHER_EXACT_TEST_P: _fisher_exact_test_p,
LOG_LIKELIHOOD: _log_likelihood,
MSE: _mse,
}
diagnostics = compute_model_fit_metrics(
y_obs=y_obs, y_pred=y_pred, se_pred=se_pred, fit_metrics_dict=diagnostic_fns
y_obs=y_obs,
y_pred=y_pred,
se_pred=se_pred,
fit_metrics_dict=DIAGNOSTIC_FNS,
)
return diagnostics

Expand Down
6 changes: 4 additions & 2 deletions ax/models/torch/botorch_modular/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,11 @@ def fit(
# If a surrogate has not been constructed, construct it.
if self._surrogate is None:
if self.surrogate_spec is not None:
self._surrogate = Surrogate(surrogate_spec=self.surrogate_spec)
self._surrogate = Surrogate(
surrogate_spec=self.surrogate_spec, refit_on_cv=self.refit_on_cv
)
else:
self._surrogate = Surrogate()
self._surrogate = Surrogate(refit_on_cv=self.refit_on_cv)

# Fit the surrogate.
for config in self.surrogate.surrogate_spec.model_configs:
Expand Down
Loading
Loading