-
Notifications
You must be signed in to change notification settings - Fork 38
/
test_searchlight.py
58 lines (45 loc) · 1.76 KB
/
test_searchlight.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
"""
searchlight tests
@author: Daniel Lindh
"""
# pylint: disable=import-outside-toplevel, no-self-use
import unittest
import numpy as np
class TestSearchlight(unittest.TestCase):
def test__get_searchlight_neighbors(self):
from rsatoolbox.util.searchlight import _get_searchlight_neighbors
mask = np.zeros((5, 5, 5))
center = [2, 2, 2]
mask[2, 2, 2] = 10
radius = 2
# a radius of 2 will give us
neighbors = _get_searchlight_neighbors(mask, center, radius=radius)
assert np.array(neighbors).shape == (3, 27)
assert np.mean(mask[tuple(neighbors)]) == 10 / 27
def test_get_volume_searchlight(self):
from rsatoolbox.util.searchlight import get_volume_searchlight
mask = np.array(
[[[False, False, False],
[False, True, False],
[False, False, False]],
[[False, True, False],
[True, True, True],
[False, True, False]],
[[False, False, False],
[False, True, False],
[False, False, False]]], dtype=int)
centers, neighbors = get_volume_searchlight(
mask, radius=1, threshold=1.0)
assert len(centers) == 7
assert len(neighbors) == 7
def test_get_searchlight_RDMs(self):
from rsatoolbox.util.searchlight import get_searchlight_RDMs
n_observations = 5
n_voxels = 5
rng = np.random.default_rng(0)
data_2d = rng.random((n_observations, n_voxels))
centers = np.array([1, 3])
neighbors = [[0, 1, 2], [2, 3, 4]]
events = np.arange(n_observations)
sl_RDMs = get_searchlight_RDMs(data_2d, centers, neighbors, events)
assert sl_RDMs.dissimilarities.shape == (2, 10)