|
4 | 4 | model_x_knockoff_bootstrap_e_value, |
5 | 5 | model_x_knockoff_bootstrap_quantile, |
6 | 6 | ) |
7 | | -from hidimstat.gaussian_knockoff import gaussian_knockoff_generation, _s_equi |
8 | 7 | from hidimstat._utils.scenario import multivariate_simulation |
9 | 8 | from hidimstat.statistical_tools.multiple_testing import fdp_power |
10 | 9 | import numpy as np |
@@ -235,72 +234,3 @@ def test_estimate_distribution(): |
235 | 234 | ) |
236 | 235 | for i in selected: |
237 | 236 | assert np.any(i == non_zero) |
238 | | - |
239 | | - |
240 | | -def test_gaussian_knockoff_equi(): |
241 | | - """test function of gaussian knockoff""" |
242 | | - seed = 42 |
243 | | - n = 100 |
244 | | - p = 50 |
245 | | - X, y, beta, noise = multivariate_simulation(n, p, seed=seed) |
246 | | - non_zero = np.where(beta)[0] |
247 | | - mu = X.mean(axis=0) |
248 | | - sigma = LedoitWolf(assume_centered=True).fit(X).covariance_ |
249 | | - |
250 | | - X_tilde, mu_tilde, sigma_tilde_decompose = gaussian_knockoff_generation( |
251 | | - X, mu, sigma, seed=seed * 2 |
252 | | - ) |
253 | | - |
254 | | - assert X_tilde.shape == (n, p) |
255 | | - |
256 | | - |
257 | | -def test_gaussian_knockoff_equi_warning(): |
258 | | - "test warning in guassian knockoff" |
259 | | - seed = 42 |
260 | | - n = 100 |
261 | | - p = 50 |
262 | | - tol = 1e-14 |
263 | | - rgn = np.random.RandomState(seed) |
264 | | - X = rgn.randn(n, p) |
265 | | - mu = X.mean(axis=0) |
266 | | - # create a positive definite matrix |
267 | | - u, s, vh = np.linalg.svd(rgn.randn(p, p)) |
268 | | - d = np.eye(p) * tol / 10 |
269 | | - sigma = u * d * u.T |
270 | | - with pytest.warns( |
271 | | - UserWarning, |
272 | | - match="The conditional covariance matrix for knockoffs is not positive", |
273 | | - ): |
274 | | - X_tilde, mu_tilde, sigma_tilde_decompose = gaussian_knockoff_generation( |
275 | | - X, mu, sigma, seed=seed * 2, tol=tol |
276 | | - ) |
277 | | - |
278 | | - assert X_tilde.shape == (n, p) |
279 | | - |
280 | | - |
281 | | -def test_s_equi_not_define_positive(): |
282 | | - """test the warning and error of s_equi function""" |
283 | | - n = 10 |
284 | | - tol = 1e-7 |
285 | | - seed = 42 |
286 | | - |
287 | | - # random positive matrix |
288 | | - rgn = np.random.RandomState(seed) |
289 | | - a = rgn.randn(n, n) |
290 | | - a -= np.min(a) |
291 | | - with pytest.raises( |
292 | | - Exception, match="The covariance matrix is not positive-definite." |
293 | | - ): |
294 | | - _s_equi(a) |
295 | | - |
296 | | - # matrix with positive eigenvalues, positive diagonal |
297 | | - while not np.all(np.linalg.eigvalsh(a) > tol): |
298 | | - a += 0.1 * np.eye(n) |
299 | | - with pytest.warns(UserWarning, match="The equi-correlated matrix"): |
300 | | - _s_equi(a) |
301 | | - |
302 | | - # positive definite matrix |
303 | | - u, s, vh = np.linalg.svd(a) |
304 | | - d = np.eye(n) |
305 | | - sigma = u * d * u.T |
306 | | - _s_equi(sigma) |
0 commit comments