def test_nested_fold(): splitter_subjects = [(range(5), range(5, 10))] splitter_runs = [([0], [1])] class FoldFxStore(object): def __init__(self): self.train = [] self.test = [] self.calls = 0 def __call__(self, data_train, data_test): self.calls += 1 self.train.append(data_train) self.test.append(data_test) return data_train.samples, data_test.samples mock_foldfx = FoldFxStore() scores = reproducibility(dss, [splitter_subjects, splitter_runs], WardClusterMethod(), spaces=['sa.subjects', 'sa.runs'], fold_fx=mock_foldfx, ks=[2], ground_truth=ground_truth, verbose=0) assert_equal(mock_foldfx.calls, 1) assert_array_equal(np.unique(mock_foldfx.train[0].sa.subjects), splitter_subjects[0][0]) assert_array_equal(np.unique(mock_foldfx.train[0].sa.runs), splitter_runs[0][0]) assert_array_equal(np.unique(mock_foldfx.test[0].sa.subjects), splitter_subjects[0][1]) assert_array_equal(np.unique(mock_foldfx.test[0].sa.runs), splitter_runs[0][1])
def test_run_method(): scores = reproducibility(dss, fake_splitter, WardClusterMethod(), ks=np.arange(2, 21), ground_truth=ground_truth, verbose=0) for key, value in scores.items(): assert_array_equal(value[0], np.arange(2, 21)) if not key.endswith('_gt'): # this works only with ARI and AMI -- default assert_array_equal(value[1], np.ones(value[1].shape)) else: # only the first is 1. assert_equal(value[1, 0], 1.)