def test_mkda_analytic_empirical_convergence(testdata_cbma_full): est_a = MKDADensity(null_method="analytic") n_iter = 10000 est_e = MKDADensity(null_method="empirical", n_iter=n_iter) res_a = est_a.fit(testdata_cbma_full) res_e = est_e.fit(testdata_cbma_full) # Get smallest p-value above 0 from the empirical estimator; above this, # the two should converge reasonably closely. min_p = 1 / n_iter p_idx = res_e.maps["p"] > min_p p_analytical = res_a.maps["p"][p_idx] p_empirical = res_e.maps["p"][p_idx] # Correlation must be near unity and mean difference should be tiny assert np.corrcoef(p_analytical, p_empirical)[0, 1] > 0.98 assert (p_analytical - p_empirical).mean() < 1e-3
def test_MKDADensity_memory_limit(testdata_cbma): """Smoke test for MKDADensity with memory_limit option.""" meta = MKDADensity(null_method="montecarlo", n_iters=10, memory_limit="1gb") res = meta.fit(testdata_cbma) assert meta.memory_limit assert not meta.kernel_transformer.memory_limit assert isinstance(res, nimare.results.MetaResult)
def test_MKDADensity_approximate_montecarlo_convergence(testdata_cbma_full): """Evaluate convergence between approximate and montecarlo null methods in MKDA.""" est_a = MKDADensity(null_method="approximate") n_iters = 10 est_e = MKDADensity(null_method="montecarlo", n_iters=n_iters) res_a = est_a.fit(testdata_cbma_full) res_e = est_e.fit(testdata_cbma_full) # Get smallest p-value above 0 from the montecarlo estimator; above this, # the two should converge reasonably closely. min_p = 1 / n_iters p_idx = res_e.maps["p"] > min_p p_approximate = res_a.maps["p"][p_idx] p_montecarlo = res_e.maps["p"][p_idx] # Correlation must be near unity and mean difference should be tiny assert np.corrcoef(p_approximate, p_montecarlo)[0, 1] > 0.98 assert (p_approximate - p_montecarlo).mean() < 1e-3
def test_MKDADensity_approximate_null(testdata_cbma_full, caplog): """Smoke test for MKDADensity with the "approximate" null_method.""" meta = MKDADensity(null="approximate") res = meta.fit(testdata_cbma_full) corr = FWECorrector(method="montecarlo", voxel_thresh=0.001, n_iters=5, n_cores=1) cres = corr.transform(res) assert isinstance(res, nimare.results.MetaResult) assert isinstance(cres, nimare.results.MetaResult) # Check that the vfwe_only option does not work corr2 = FWECorrector( method="montecarlo", voxel_thresh=0.001, n_iters=5, n_cores=1, vfwe_only=True, ) with caplog.at_level(logging.WARNING): cres2 = corr2.transform(res) assert "Running permutations from scratch." in caplog.text assert isinstance(cres2, nimare.results.MetaResult) assert "logp_level-voxel_corr-FWE_method-montecarlo" in cres2.maps assert "logp_desc-size_level-cluster_corr-FWE_method-montecarlo" not in cres2.maps
def test_mkda_density_kernel_instance(testdata_cbma): """ Smoke test for MKDADensity with a kernel transformer object. """ kern = MKDAKernel(r=5) meta = MKDADensity(kern, null_method="empirical", n_iters=100) res = meta.fit(testdata_cbma) assert isinstance(res, nimare.results.MetaResult)
def test_MKDADensity_kernel_class(testdata_cbma): """Smoke test for MKDADensity with a kernel transformer class.""" meta = MKDADensity(MKDAKernel, kernel__r=5, null_method="montecarlo", n_iters=10) res = meta.fit(testdata_cbma) assert isinstance(res, nimare.results.MetaResult)
def test_MKDADensity(testdata_cbma): """Smoke test for MKDADensity.""" meta = MKDADensity(null_method="montecarlo", n_iters=10) res = meta.fit(testdata_cbma) corr = FWECorrector(method="montecarlo", voxel_thresh=0.001, n_iters=5, n_cores=1) cres = corr.transform(res) assert isinstance(res, nimare.results.MetaResult) assert isinstance(cres, nimare.results.MetaResult)
def test_Peaks2MapsKernel_MKDADensity(testdata_cbma, tmp_path_factory): """Test that the Peaks2Maps kernel can work with an estimator.""" tmpdir = tmp_path_factory.mktemp("test_Peaks2MapsKernel_MKDADensity") model_dir = extract.download_peaks2maps_model() testdata_cbma.update_path(tmpdir) kern = kernel.Peaks2MapsKernel(model_dir=model_dir) est = MKDADensity(kernel_transformer=kern, null_method="approximate") res = est.fit(testdata_cbma) assert isinstance(res, nimare.results.MetaResult) assert res.get_map("p", return_type="array").dtype == np.float64
def test_mkda_density_analytic_null(testdata_cbma_full): """ Smoke test for MKDADensity """ meta = MKDADensity(null="analytic") res = meta.fit(testdata_cbma_full) corr = FWECorrector(method="montecarlo", voxel_thresh=0.001, n_iters=1, n_cores=1) cres = corr.transform(res) assert isinstance(res, nimare.results.MetaResult) assert isinstance(cres, nimare.results.MetaResult)
def test_MKDADensity_approximate_null(testdata_cbma_full): """Smoke test for MKDADensity with the "approximate" null_method.""" meta = MKDADensity(null="approximate") res = meta.fit(testdata_cbma_full) corr = FWECorrector(method="montecarlo", voxel_thresh=0.001, n_iters=5, n_cores=1) cres = corr.transform(res) assert isinstance(res, nimare.results.MetaResult) assert isinstance(cres, nimare.results.MetaResult) # Check that the vfwe_only option does not work corr2 = FWECorrector( method="montecarlo", voxel_thresh=0.001, n_iters=5, n_cores=1, vfwe_only=True, ) with pytest.raises(ValueError): corr2.transform(res)
def test_MKDADensity_montecarlo_null(testdata_cbma): """Smoke test for MKDADensity with the "montecarlo" null_method.""" meta = MKDADensity(null_method="montecarlo", n_iters=10) res = meta.fit(testdata_cbma) corr = FWECorrector(method="montecarlo", voxel_thresh=0.001, n_iters=5, n_cores=1) cres = corr.transform(res) assert isinstance(res, nimare.results.MetaResult) assert isinstance(cres, nimare.results.MetaResult) # Check that the vfwe_only option works corr2 = FWECorrector( method="montecarlo", voxel_thresh=0.001, n_iters=5, n_cores=1, vfwe_only=True, ) cres2 = corr2.transform(res) assert isinstance(cres2, nimare.results.MetaResult) assert "logp_level-voxel_corr-FWE_method-montecarlo" in cres2.maps assert "logp_desc-size_level-cluster_corr-FWE_method-montecarlo" not in cres2.maps