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
1,129 changes: 492 additions & 637 deletions doc/oop.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 14 additions & 14 deletions doubleml/double_ml.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ def fit(self, n_jobs_cv=None, keep_scores=True, store_predictions=False):

# ml estimation of nuisance models and computation of score elements
self._psi_a[:, self._i_rep, self._i_treat], self._psi_b[:, self._i_rep, self._i_treat], preds =\
self._ml_nuisance_and_score_elements(self.__smpls, n_jobs_cv)
self._nuisance_est(self.__smpls, n_jobs_cv)

if store_predictions:
self._store_predictions(preds)
Expand Down Expand Up @@ -799,11 +799,11 @@ def tune(self,
self._i_rep = i_rep

# tune hyperparameters
res = self._ml_nuisance_tuning(self.__smpls,
param_grids, scoring_methods,
n_folds_tune,
n_jobs_cv,
search_mode, n_iter_randomized_search)
res = self._nuisance_tuning(self.__smpls,
param_grids, scoring_methods,
n_folds_tune,
n_jobs_cv,
search_mode, n_iter_randomized_search)

tuning_res[i_rep][i_d] = res
nuisance_params.append(res['params'])
Expand All @@ -816,11 +816,11 @@ def tune(self,
else:
smpls = [(np.arange(self._dml_data.n_obs), np.arange(self._dml_data.n_obs))]
# tune hyperparameters
res = self._ml_nuisance_tuning(smpls,
param_grids, scoring_methods,
n_folds_tune,
n_jobs_cv,
search_mode, n_iter_randomized_search)
res = self._nuisance_tuning(smpls,
param_grids, scoring_methods,
n_folds_tune,
n_jobs_cv,
search_mode, n_iter_randomized_search)
tuning_res[i_d] = res

if set_as_params:
Expand Down Expand Up @@ -887,12 +887,12 @@ def _initialize_ml_nuisance_params(self):
pass

@abstractmethod
def _ml_nuisance_and_score_elements(self, smpls, n_jobs_cv):
def _nuisance_est(self, smpls, n_jobs_cv):
pass

@abstractmethod
def _ml_nuisance_tuning(self, smpls, param_grids, scoring_methods, n_folds_tune, n_jobs_cv,
search_mode, n_iter_randomized_search):
def _nuisance_tuning(self, smpls, param_grids, scoring_methods, n_folds_tune, n_jobs_cv,
search_mode, n_iter_randomized_search):
pass

@staticmethod
Expand Down
6 changes: 3 additions & 3 deletions doubleml/double_ml_iivm.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def _check_data(self, obj_dml_data):
raise ValueError(err_msg)
return

def _ml_nuisance_and_score_elements(self, smpls, n_jobs_cv):
def _nuisance_est(self, smpls, n_jobs_cv):
x, y = check_X_y(self._dml_data.x, self._dml_data.y,
force_all_finite=False)
x, z = check_X_y(x, np.ravel(self._dml_data.z),
Expand Down Expand Up @@ -283,8 +283,8 @@ def _score_elements(self, y, z, d, g_hat0, g_hat1, m_hat, r_hat0, r_hat1, smpls)

return psi_a, psi_b

def _ml_nuisance_tuning(self, smpls, param_grids, scoring_methods, n_folds_tune, n_jobs_cv,
search_mode, n_iter_randomized_search):
def _nuisance_tuning(self, smpls, param_grids, scoring_methods, n_folds_tune, n_jobs_cv,
search_mode, n_iter_randomized_search):
x, y = check_X_y(self._dml_data.x, self._dml_data.y,
force_all_finite=False)
x, z = check_X_y(x, np.ravel(self._dml_data.z),
Expand Down
6 changes: 3 additions & 3 deletions doubleml/double_ml_irm.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def _check_data(self, obj_dml_data):
'needs to be specified as treatment variable.')
return

def _ml_nuisance_and_score_elements(self, smpls, n_jobs_cv):
def _nuisance_est(self, smpls, n_jobs_cv):
x, y = check_X_y(self._dml_data.x, self._dml_data.y,
force_all_finite=False)
x, d = check_X_y(x, self._dml_data.d,
Expand Down Expand Up @@ -230,8 +230,8 @@ def _score_elements(self, y, d, g_hat0, g_hat1, m_hat, smpls):

return psi_a, psi_b

def _ml_nuisance_tuning(self, smpls, param_grids, scoring_methods, n_folds_tune, n_jobs_cv,
search_mode, n_iter_randomized_search):
def _nuisance_tuning(self, smpls, param_grids, scoring_methods, n_folds_tune, n_jobs_cv,
search_mode, n_iter_randomized_search):
x, y = check_X_y(self._dml_data.x, self._dml_data.y,
force_all_finite=False)
x, d = check_X_y(x, self._dml_data.d,
Expand Down
30 changes: 15 additions & 15 deletions doubleml/double_ml_pliv.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,33 +255,33 @@ def _check_data(self, obj_dml_data):
'use DoubleMLPLR instead of DoubleMLPLIV.')
return

def _ml_nuisance_and_score_elements(self, smpls, n_jobs_cv):
def _nuisance_est(self, smpls, n_jobs_cv):
if self.partialX & (not self.partialZ):
psi_a, psi_b, preds = self._ml_nuisance_and_score_elements_partial_x(smpls, n_jobs_cv)
psi_a, psi_b, preds = self._nuisance_est_partial_x(smpls, n_jobs_cv)
elif (not self.partialX) & self.partialZ:
psi_a, psi_b, preds = self._ml_nuisance_and_score_elements_partial_z(smpls, n_jobs_cv)
psi_a, psi_b, preds = self._nuisance_est_partial_z(smpls, n_jobs_cv)
else:
assert (self.partialX & self.partialZ)
psi_a, psi_b, preds = self._ml_nuisance_and_score_elements_partial_xz(smpls, n_jobs_cv)
psi_a, psi_b, preds = self._nuisance_est_partial_xz(smpls, n_jobs_cv)

return psi_a, psi_b, preds

def _ml_nuisance_tuning(self, smpls, param_grids, scoring_methods, n_folds_tune, n_jobs_cv,
search_mode, n_iter_randomized_search):
def _nuisance_tuning(self, smpls, param_grids, scoring_methods, n_folds_tune, n_jobs_cv,
search_mode, n_iter_randomized_search):
if self.partialX & (not self.partialZ):
res = self._ml_nuisance_tuning_partial_x(smpls, param_grids, scoring_methods, n_folds_tune, n_jobs_cv,
res = self._nuisance_tuning_partial_x(smpls, param_grids, scoring_methods, n_folds_tune, n_jobs_cv,
search_mode, n_iter_randomized_search)
elif (not self.partialX) & self.partialZ:
res = self._ml_nuisance_tuning_partial_z(smpls, param_grids, scoring_methods, n_folds_tune, n_jobs_cv,
res = self._nuisance_tuning_partial_z(smpls, param_grids, scoring_methods, n_folds_tune, n_jobs_cv,
search_mode, n_iter_randomized_search)
else:
assert (self.partialX & self.partialZ)
res = self._ml_nuisance_tuning_partial_xz(smpls, param_grids, scoring_methods, n_folds_tune, n_jobs_cv,
res = self._nuisance_tuning_partial_xz(smpls, param_grids, scoring_methods, n_folds_tune, n_jobs_cv,
search_mode, n_iter_randomized_search)

return res

def _ml_nuisance_and_score_elements_partial_x(self, smpls, n_jobs_cv):
def _nuisance_est_partial_x(self, smpls, n_jobs_cv):
x, y = check_X_y(self._dml_data.x, self._dml_data.y,
force_all_finite=False)
x, d = check_X_y(x, self._dml_data.d,
Expand Down Expand Up @@ -357,7 +357,7 @@ def _score_elements(self, y, z, d, g_hat, m_hat, r_hat, smpls):

return psi_a, psi_b

def _ml_nuisance_and_score_elements_partial_z(self, smpls, n_jobs_cv):
def _nuisance_est_partial_z(self, smpls, n_jobs_cv):
y = self._dml_data.y
xz, d = check_X_y(np.hstack((self._dml_data.x, self._dml_data.z)),
self._dml_data.d,
Expand All @@ -380,7 +380,7 @@ def _ml_nuisance_and_score_elements_partial_z(self, smpls, n_jobs_cv):

return psi_a, psi_b, preds

def _ml_nuisance_and_score_elements_partial_xz(self, smpls, n_jobs_cv):
def _nuisance_est_partial_xz(self, smpls, n_jobs_cv):
x, y = check_X_y(self._dml_data.x, self._dml_data.y,
force_all_finite=False)
xz, d = check_X_y(np.hstack((self._dml_data.x, self._dml_data.z)),
Expand Down Expand Up @@ -423,7 +423,7 @@ def _ml_nuisance_and_score_elements_partial_xz(self, smpls, n_jobs_cv):

return psi_a, psi_b, preds

def _ml_nuisance_tuning_partial_x(self, smpls, param_grids, scoring_methods, n_folds_tune, n_jobs_cv,
def _nuisance_tuning_partial_x(self, smpls, param_grids, scoring_methods, n_folds_tune, n_jobs_cv,
search_mode, n_iter_randomized_search):
x, y = check_X_y(self._dml_data.x, self._dml_data.y,
force_all_finite=False)
Expand Down Expand Up @@ -486,7 +486,7 @@ def _ml_nuisance_tuning_partial_x(self, smpls, param_grids, scoring_methods, n_f

return res

def _ml_nuisance_tuning_partial_z(self, smpls, param_grids, scoring_methods, n_folds_tune, n_jobs_cv,
def _nuisance_tuning_partial_z(self, smpls, param_grids, scoring_methods, n_folds_tune, n_jobs_cv,
search_mode, n_iter_randomized_search):
xz, d = check_X_y(np.hstack((self._dml_data.x, self._dml_data.z)),
self._dml_data.d,
Expand All @@ -511,7 +511,7 @@ def _ml_nuisance_tuning_partial_z(self, smpls, param_grids, scoring_methods, n_f

return res

def _ml_nuisance_tuning_partial_xz(self, smpls, param_grids, scoring_methods, n_folds_tune, n_jobs_cv,
def _nuisance_tuning_partial_xz(self, smpls, param_grids, scoring_methods, n_folds_tune, n_jobs_cv,
search_mode, n_iter_randomized_search):
x, y = check_X_y(self._dml_data.x, self._dml_data.y,
force_all_finite=False)
Expand Down
6 changes: 3 additions & 3 deletions doubleml/double_ml_plr.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def _check_data(self, obj_dml_data):
'To fit a partially linear IV regression model use DoubleMLPLIV instead of DoubleMLPLR.')
return

def _ml_nuisance_and_score_elements(self, smpls, n_jobs_cv):
def _nuisance_est(self, smpls, n_jobs_cv):
x, y = check_X_y(self._dml_data.x, self._dml_data.y,
force_all_finite=False)
x, d = check_X_y(x, self._dml_data.d,
Expand Down Expand Up @@ -188,8 +188,8 @@ def _score_elements(self, y, d, g_hat, m_hat, smpls):

return psi_a, psi_b

def _ml_nuisance_tuning(self, smpls, param_grids, scoring_methods, n_folds_tune, n_jobs_cv,
search_mode, n_iter_randomized_search):
def _nuisance_tuning(self, smpls, param_grids, scoring_methods, n_folds_tune, n_jobs_cv,
search_mode, n_iter_randomized_search):
x, y = check_X_y(self._dml_data.x, self._dml_data.y,
force_all_finite=False)
x, d = check_X_y(x, self._dml_data.d,
Expand Down