Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _pointwise_effect(self, X_single):
"""
We need to post-process the parameters returned by the _pointwise_effect
of the BaseOrthoForest class due to the local linear correction. The
base class function will return the intercept and the coefficient of the
local linear fit. We multiply it with the input co-variate to get the
predicted effect.
"""
parameter = super(ContinuousTreatmentOrthoForest, self)._pointwise_effect(X_single)
X_aug = np.append([1], X_single)
parameter = parameter.reshape((X_aug.shape[0], -1)).T
return np.dot(parameter, X_aug)
self.model_Y = model_Y
self.model_T_final = model_T_final
self.model_Y_final = model_Y_final
if self.model_T_final is None:
self.model_T_final = clone(self.model_T, safe=False)
if self.model_Y_final is None:
self.model_Y_final = clone(self.model_Y, safe=False)
# Define nuisance estimators
nuisance_estimator = ContinuousTreatmentOrthoForest.nuisance_estimator_generator(
self.model_T, self.model_Y, random_state, second_stage=False)
second_stage_nuisance_estimator = ContinuousTreatmentOrthoForest.nuisance_estimator_generator(
self.model_T_final, self.model_Y_final, random_state, second_stage=True)
# Define parameter estimators
parameter_estimator = ContinuousTreatmentOrthoForest.parameter_estimator_func
second_stage_parameter_estimator =\
ContinuousTreatmentOrthoForest.second_stage_parameter_estimator_gen(self.lambda_reg)
# Define
moment_and_mean_gradient_estimator = ContinuousTreatmentOrthoForest.moment_and_mean_gradient_estimator_func
super(ContinuousTreatmentOrthoForest, self).__init__(
nuisance_estimator,
second_stage_nuisance_estimator,
parameter_estimator,
second_stage_parameter_estimator,
moment_and_mean_gradient_estimator,
n_trees=n_trees,
min_leaf_size=min_leaf_size,
max_depth=max_depth,
subsample_ratio=subsample_ratio,
bootstrap=bootstrap,
n_jobs=n_jobs,
random_state=random_state)
self.model_Y_final = model_Y_final
if self.model_T_final is None:
self.model_T_final = clone(self.model_T, safe=False)
if self.model_Y_final is None:
self.model_Y_final = clone(self.model_Y, safe=False)
# Define nuisance estimators
nuisance_estimator = ContinuousTreatmentOrthoForest.nuisance_estimator_generator(
self.model_T, self.model_Y, random_state, second_stage=False)
second_stage_nuisance_estimator = ContinuousTreatmentOrthoForest.nuisance_estimator_generator(
self.model_T_final, self.model_Y_final, random_state, second_stage=True)
# Define parameter estimators
parameter_estimator = ContinuousTreatmentOrthoForest.parameter_estimator_func
second_stage_parameter_estimator =\
ContinuousTreatmentOrthoForest.second_stage_parameter_estimator_gen(self.lambda_reg)
# Define
moment_and_mean_gradient_estimator = ContinuousTreatmentOrthoForest.moment_and_mean_gradient_estimator_func
super(ContinuousTreatmentOrthoForest, self).__init__(
nuisance_estimator,
second_stage_nuisance_estimator,
parameter_estimator,
second_stage_parameter_estimator,
moment_and_mean_gradient_estimator,
n_trees=n_trees,
min_leaf_size=min_leaf_size,
max_depth=max_depth,
subsample_ratio=subsample_ratio,
bootstrap=bootstrap,
n_jobs=n_jobs,
random_state=random_state)
n_jobs=-1,
random_state=None):
# Copy and/or define models
self.lambda_reg = lambda_reg
self.model_T = model_T
self.model_Y = model_Y
self.model_T_final = model_T_final
self.model_Y_final = model_Y_final
if self.model_T_final is None:
self.model_T_final = clone(self.model_T, safe=False)
if self.model_Y_final is None:
self.model_Y_final = clone(self.model_Y, safe=False)
# Define nuisance estimators
nuisance_estimator = ContinuousTreatmentOrthoForest.nuisance_estimator_generator(
self.model_T, self.model_Y, random_state, second_stage=False)
second_stage_nuisance_estimator = ContinuousTreatmentOrthoForest.nuisance_estimator_generator(
self.model_T_final, self.model_Y_final, random_state, second_stage=True)
# Define parameter estimators
parameter_estimator = ContinuousTreatmentOrthoForest.parameter_estimator_func
second_stage_parameter_estimator =\
ContinuousTreatmentOrthoForest.second_stage_parameter_estimator_gen(self.lambda_reg)
# Define
moment_and_mean_gradient_estimator = ContinuousTreatmentOrthoForest.moment_and_mean_gradient_estimator_func
super(ContinuousTreatmentOrthoForest, self).__init__(
nuisance_estimator,
second_stage_nuisance_estimator,
parameter_estimator,
second_stage_parameter_estimator,
moment_and_mean_gradient_estimator,
n_trees=n_trees,
min_leaf_size=min_leaf_size,
max_depth=max_depth,
self.lambda_reg = lambda_reg
self.model_T = model_T
self.model_Y = model_Y
self.model_T_final = model_T_final
self.model_Y_final = model_Y_final
if self.model_T_final is None:
self.model_T_final = clone(self.model_T, safe=False)
if self.model_Y_final is None:
self.model_Y_final = clone(self.model_Y, safe=False)
# Define nuisance estimators
nuisance_estimator = ContinuousTreatmentOrthoForest.nuisance_estimator_generator(
self.model_T, self.model_Y, random_state, second_stage=False)
second_stage_nuisance_estimator = ContinuousTreatmentOrthoForest.nuisance_estimator_generator(
self.model_T_final, self.model_Y_final, random_state, second_stage=True)
# Define parameter estimators
parameter_estimator = ContinuousTreatmentOrthoForest.parameter_estimator_func
second_stage_parameter_estimator =\
ContinuousTreatmentOrthoForest.second_stage_parameter_estimator_gen(self.lambda_reg)
# Define
moment_and_mean_gradient_estimator = ContinuousTreatmentOrthoForest.moment_and_mean_gradient_estimator_func
super(ContinuousTreatmentOrthoForest, self).__init__(
nuisance_estimator,
second_stage_nuisance_estimator,
parameter_estimator,
second_stage_parameter_estimator,
moment_and_mean_gradient_estimator,
n_trees=n_trees,
min_leaf_size=min_leaf_size,
max_depth=max_depth,
subsample_ratio=subsample_ratio,
bootstrap=bootstrap,
n_jobs=n_jobs,