def test_pfr_smooth_correlation_3d(): presented = [[[[10, 0, 10], [20, 0, 0], [30, 0, -10], [40, 0, -20]], [[10, 0, 10], [20, 0, 0], [30, 0, -10], [40, 0, -20]]]] recalled = [[[[20, 0, 0], [10, 0, 10], [40, 0, -20], [30, 0, -10]], [[20, 0, 0], [40, 0, -20], [10, 0, 10]]]] egg = Egg(pres=presented, rec=recalled) egg.analyze('pfr', match='smooth', distance='correlation', features='item').data.values
def test_acc(): presented = [[['cat', 'bat', 'hat', 'goat'], ['zoo', 'animal', 'zebra', 'horse']]] recalled = [[['bat', 'cat', 'goat', 'hat'], ['animal', 'horse', 'zoo']]] egg = Egg(pres=presented, rec=recalled) assert np.allclose( egg.analyze('accuracy').data.values, [np.array([1.]), np.array([.75])])
def test_analysis_pfr(): presented = [[['cat', 'bat', 'hat', 'goat'], ['zoo', 'animal', 'zebra', 'horse']]] recalled = [[['bat', 'cat', 'goat', 'hat'], ['animal', 'horse', 'zoo']]] egg = Egg(pres=presented, rec=recalled) assert np.array_equal( egg.analyze('pfr').data.values, [np.array([0., 1., 0., 0.]), np.array([0., 1., 0., 0.])])
def test_spc_best_euclidean(): presented = [[[10, 20, 30, 40], [10, 20, 30, 40]]] recalled = [[[20, 10, 40, 30], [20, 40, 10]]] egg = Egg(pres=presented, rec=recalled) assert np.allclose( egg.analyze('spc', match='best', distance='euclidean', features='item').data.values, [np.array([1., 1., 1., 1.]), np.array([1., 1., 0., 1.])])
def test_pfr_best_euclidean_3d_exception_item_specified(): presented = [[[[10, 0, 0], [20, 0, 0], [30, 0, 0], [40, 0, 0]], [[10, 0, 0], [20, 0, 0], [30, 0, 0], [40, 0, 0]]]] recalled = [[[[20, 0, 0], [10, 0, 0], [40, 0, 0], [30, 0, 0]], [[20, 0, 0], [40, 0, 0], [10, 0, 0]]]] egg = Egg(pres=presented, rec=recalled) assert np.array_equal( egg.analyze('pfr', match='best', distance='euclidean', features='item').data.values, [np.array([0., 1., 0., 0.]), np.array([0., 1., 0., 0.])])
def test_pfr_best_euclidean_3d_exception_no_features(): presented = [[[[10, 0, 0], [20, 0, 0], [30, 0, 0], [40, 0, 0]], [[10, 0, 0], [20, 0, 0], [30, 0, 0], [40, 0, 0]]]] recalled = [[[[20, 0, 0], [10, 0, 0], [40, 0, 0], [30, 0, 0]], [[20, 0, 0], [40, 0, 0], [10, 0, 0]]]] egg = Egg(pres=presented, rec=recalled) with pytest.raises(Exception): assert np.array_equal( egg.analyze('pfr', match='best', distance='euclidean').data.values, [np.array([0., 1., 0., 0.]), np.array([0., 1., 0., 0.])])
def test_analysis_acc_multisubj(): presented = [[['cat', 'bat', 'hat', 'goat'], ['zoo', 'animal', 'zebra', 'horse']], [['cat', 'bat', 'hat', 'goat'], ['zoo', 'animal', 'zebra', 'horse']]] recalled = [[['bat', 'cat', 'goat', 'hat'], ['animal', 'horse', 'zoo']], [['bat', 'cat', 'goat', 'hat'], ['animal', 'horse', 'zoo']]] multisubj_egg = Egg(pres=presented, rec=recalled) assert np.array_equal( multisubj_egg.analyze('accuracy').data.values, np.array([[1.], [.75], [1.], [.75]]))
def test_lagcrp_exact(): # example from kahana lab lag-crp tutorial presented = [[['1', '2', '3', '4', '5', '6', '7', '8']]] recalled = [[['8', '7', '1', '2', '3', '5', '6', '4']]] egg = Egg(pres=presented, rec=recalled) assert np.allclose(egg.analyze('lagcrp').data.values, np.array([[ 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.333333, 0.333333, np.nan, 0.75, 0.333333, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]]), equal_nan=True)
def test_acc_best_correlation_3d(): presented = [[[[10, 0, 10], [20, 0, 0], [30, 0, -10], [40, 0, -20]], [[10, 0, 10], [20, 0, 0], [30, 0, -10], [40, 0, -20]]]] recalled = [[[[20, 0, 0], [10, 0, 10], [40, 0, -20], [30, 0, -10]], [[20, 0, 0], [40, 0, -20], [10, 0, 10]]]] egg = Egg(pres=presented, rec=recalled) assert np.array_equal( egg.analyze('accuracy', match='best', distance='correlation', features='item').data.values, [np.array([1.]), np.array([.75])])
def test_analysis_spc_multisubj(): presented = [[['cat', 'bat', 'hat', 'goat'], ['zoo', 'animal', 'zebra', 'horse']], [['cat', 'bat', 'hat', 'goat'], ['zoo', 'animal', 'zebra', 'horse']]] recalled = [[['bat', 'cat', 'goat', 'hat'], ['animal', 'horse', 'zoo']], [['bat', 'cat', 'goat', 'hat'], ['animal', 'horse', 'zoo']]] multisubj_egg = Egg(pres=presented, rec=recalled) assert np.allclose( multisubj_egg.analyze('spc').data.values, np.array([[1., 1., 1., 1.], [1., 1., 0., 1.], [1., 1., 1., 1.], [1., 1., 0., 1.]]))
def test_lagcrp_best_euclidean(): presented = [[[10, 20, 30, 40, 50, 60, 70, 80]]] recalled = [[[81, 71, 11, 21, 31, 51, 61, 41]]] egg = Egg(pres=presented, rec=recalled) assert np.allclose(egg.analyze('lagcrp', match='best', distance='euclidean', features='item').data.values, np.array([[ 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.333333, 0.333333, np.nan, 0.75, 0.333333, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]]), equal_nan=True)
def test_lagcrp_exact_3d(): presented = [[[[10, 0, 0], [20, 0, 0], [30, 0, 0], [40, 0, 0], [50, 0, 0], [60, 0, 0], [70, 0, 0], [80, 0, 0]]]] recalled = [[[[80, 0, 0], [70, 0, 0], [10, 0, 0], [20, 0, 0], [30, 0, 0], [50, 0, 0], [60, 0, 0], [40, 0, 0]]]] egg = Egg(pres=presented, rec=recalled) assert np.allclose(egg.analyze('lagcrp', match='best', features='item').data.values, np.array([[ 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.333333, 0.333333, np.nan, 0.75, 0.333333, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]]), equal_nan=True)
def test_acc_best_euclidean_3d_features_not_set(): presented = [[[{ 'item': i, 'feature1': [i * 10, 0, 0] } for i in range(1, 5)] for i in range(2)]] recalled = [[[{ 'item': i, 'feature1': [i * 10, 0, 0] } for i in [2, 1, 4, 3]], [{ 'item': i, 'feature1': [i * 10, 0, 0] } for i in [2, 4, 1]]]] egg = Egg(pres=presented, rec=recalled) assert np.array_equal( egg.analyze('pfr', match='best', distance='euclidean').data.values, [np.array([0., 1., 0., 0.]), np.array([0., 1., 0., 0.])])
def test_acc_best_euclidean(): presented = [[[{ 'item': i, 'feature1': i * 10 } for i in range(1, 5)] for i in range(2)]] recalled = [[[{ 'item': i, 'feature1': i * 10 } for i in [2, 1, 4, 3]], [{ 'item': i, 'feature1': i * 10 } for i in [2, 4, 1]]]] egg = Egg(pres=presented, rec=recalled) assert np.array_equal( egg.analyze('accuracy', match='best', distance='euclidean', features=['feature1']).data.values, [np.array([1.]), np.array([.75])])
def test_spc_best_euclidean(): presented = [[[{ 'item': i, 'feature1': i * 10 } for i in range(1, 5)] for i in range(2)]] recalled = [[[{ 'item': i, 'feature1': i * 10 } for i in [2, 1, 4, 3]], [{ 'item': i, 'feature1': i * 10 } for i in [2, 4, 1]]]] egg = Egg(pres=presented, rec=recalled) assert np.allclose( egg.analyze('spc', match='best', distance='euclidean', features='feature1').data.values, [np.array([1., 1., 1., 1.]), np.array([1., 1., 0., 1.])])
def test_spc_best_euclidean_3d_2features(): presented = [[[{ 'item': i, 'feature1': [i * 10, 0, 0], 'feature2': [i * 10, 0, 0] } for i in range(1, 5)] for i in range(2)]] recalled = [[[{ 'item': i, 'feature1': [i * 10, 0, 0], 'feature2': [i * 10, 0, 0] } for i in [2, 1, 4, 3]], [{ 'item': i, 'feature1': [i * 10, 0, 0], 'feature2': [i * 10, 0, 0] } for i in [2, 4, 1]]]] egg = Egg(pres=presented, rec=recalled) assert np.array_equal( egg.analyze('spc', match='best', distance='euclidean', features=['feature1', 'feature2']).data.values, [np.array([1., 1., 1., 1.]), np.array([1., 1., 0., 1.])])