def _check_debiased_coefs(self, X, y, sample_weight, expected_coefs, expected_intercept=0, params={}): debiased_lasso = MultiOutputDebiasedLasso( ) if np.ndim(y) > 1 else DebiasedLasso() debiased_lasso.set_params(**params) debiased_lasso.fit(X, y, sample_weight) all_params = debiased_lasso.get_params() # Check coeffcients and intercept are the same within tolerance if np.ndim(y) > 1: for i in range(y.shape[1]): np.testing.assert_allclose(debiased_lasso.coef_[i], expected_coefs[i], atol=5e-2) if all_params["fit_intercept"]: self.assertAlmostEqual(debiased_lasso.intercept_[i], expected_intercept[i], delta=1e-2) else: np.testing.assert_allclose(debiased_lasso.coef_, expected_coefs, atol=5e-2) if all_params["fit_intercept"]: self.assertAlmostEqual(debiased_lasso.intercept_, expected_intercept, delta=1e-2) return debiased_lasso.coef_
def _check_debiased_CI_2D(self, X, y, sample_weight, expected_coefs, expected_intercept=0, n_experiments=200, params={}): # Unit vectors X_test = np.eye(TestLassoExtensions.n_dim) y_test_mean = expected_intercept + expected_coefs.T is_in_interval = np.zeros( (y.shape[1], n_experiments, TestLassoExtensions.n_dim)) for i in range(n_experiments): np.random.seed(i) X_exp = np.random.normal(size=X.shape) err = np.random.normal(scale=TestLassoExtensions.error_sd, size=(X.shape[0], y.shape[1])) y_exp = expected_intercept + np.dot(X_exp, expected_coefs.T) + err debiased_lasso = MultiOutputDebiasedLasso() debiased_lasso.set_params(**params) debiased_lasso.fit(X_exp, y_exp, sample_weight) y_lower, y_upper = debiased_lasso.predict_interval(X_test, alpha=0.1) for j in range(y.shape[1]): is_in_interval[j, i, :] = ((y_test_mean[:, j] >= y_lower[:, j]) & (y_test_mean[:, j] <= y_upper[:, j])) for i in range(y.shape[1]): CI_coverage = np.mean(is_in_interval[i], axis=0) self.assertTrue(all(CI_coverage >= 0.85))