econml/ortho_forest.py
def parameter_estimator_func(Y, T, X,
                                     nuisance_estimates,
                                     sample_weight=None):
            """Calculate the parameter of interest for points given by (Y, T) and corresponding nuisance estimates."""
            # Compute residuals
            Y_hat, T_hat = nuisance_estimates
            Y_res, T_res = reshape_Y_T(Y - Y_hat, T - T_hat)
            X_aug = PolynomialFeatures(degree=1, include_bias=True).fit_transform(X)
            XT_res = cross_product(T_res, X_aug)
            # Compute coefficient by OLS on residuals
            if sample_weight is not None:
                weighted_XT_res = sample_weight.reshape(-1, 1) * XT_res
            else:
                weighted_XT_res = XT_res / XT_res.shape[0]
            # ell_2 regularization
            diagonal = np.ones(XT_res.shape[1])
            diagonal[:T_res.shape[1]] = 0
            reg = lambda_reg * np.diag(diagonal)
            # Ridge regression estimate
            param_estimate = np.linalg.lstsq(np.matmul(weighted_XT_res.T, XT_res) + reg,
                                             np.matmul(weighted_XT_res.T, Y_res.reshape(-1, 1)),
                                             rcond=None)[0].flatten()
            # Parameter returned by LinearRegression is (d_T, )
            return param_estimate
Calculate the parameter of interest for points given by (Y, T) and corresponding nuisance estimates.
Calculate the parameter of interest for points given by (Y, T) and corresponding nuisance estimates.
Calculate the parameter of interest for points given by ( Y T ) and corresponding nuisance estimates .
def parameter_estimator_func(Y, T, X,
                                     nuisance_estimates,
                                     sample_weight=None):
            Y_hat, T_hat = nuisance_estimates
            Y_res, T_res = reshape_Y_T(Y - Y_hat, T - T_hat)
            X_aug = PolynomialFeatures(degree=1, include_bias=True).fit_transform(X)
            XT_res = cross_product(T_res, X_aug)
            if sample_weight is not None:
                weighted_XT_res = sample_weight.reshape(-1, 1) * XT_res
            else:
                weighted_XT_res = XT_res / XT_res.shape[0]
            diagonal = np.ones(XT_res.shape[1])
            diagonal[:T_res.shape[1]] = 0
            reg = lambda_reg * np.diag(diagonal)
            param_estimate = np.linalg.lstsq(np.matmul(weighted_XT_res.T, XT_res) + reg,
                                             np.matmul(weighted_XT_res.T, Y_res.reshape(-1, 1)),
                                             rcond=None)[0].flatten()
            return param_estimate
def parameter_estimator_func ( Y , T , X , nuisance_estimates , sample_weight = None ) : Y_hat , T_hat = nuisance_estimates Y_res , T_res = reshape_Y_T ( Y - Y_hat , T - T_hat ) X_aug = PolynomialFeatures ( degree = 1 , include_bias = True ) . fit_transform ( X ) XT_res = cross_product ( T_res , X_aug ) if sample_weight is not None : weighted_XT_res = sample_weight . reshape ( - 1 , 1 ) * XT_res else : weighted_XT_res = XT_res / XT_res . shape [ 0 ] diagonal = np . ones ( XT_res . shape [ 1 ] ) diagonal [ : T_res . shape [ 1 ] ] = 0 reg = lambda_reg * np . diag ( diagonal ) param_estimate = np . linalg . lstsq ( np . matmul ( weighted_XT_res . T , XT_res ) + reg , np . matmul ( weighted_XT_res . T , Y_res . reshape ( - 1 , 1 ) ) , rcond = None ) [ 0 ] . flatten ( ) return param_estimate
Calculate the parameter of interest for points given by (Y, T) and corresponding nuisance estimates.
Calculate the parameter of interest for points given by ( Y T ) and corresponding nuisance estimates .
"""Calculate the parameter of interest for points given by (Y, T) and corresponding nuisance estimates.""" # Compute residuals # Compute coefficient by OLS on residuals # ell_2 regularization # Ridge regression estimate # Parameter returned by LinearRegression is (d_T, )
Y
T
X
nuisance_estimates
sample_weight