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_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_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_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_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_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_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_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_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_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_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_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_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.])])
# -*- coding: utf-8 -*- from quail.analysis import analyze from quail.load import load_example_data from quail.egg import Egg import numpy as np import pytest import pandas as pd presented = [[['cat', 'bat', 'hat', 'goat'], ['zoo', 'animal', 'zebra', 'horse']]] recalled = [[['bat', 'cat', 'goat', 'hat'], ['animal', 'horse', 'zoo']]] egg = Egg(pres=presented, rec=recalled) def test_analysis_acc(): print(analyze(egg, analysis='accuracy')) print([np.array([1.]), np.array([.75])]) assert np.array_equal( analyze(egg, analysis='accuracy').data.values, [np.array([1.]), np.array([.75])]) def test_analysis_spc(): assert np.array_equal( analyze(egg, analysis='spc').data.values, [np.array([1., 1., 1., 1.]), np.array([1., 1., 0., 1.])]) def test_analysis_spc_listgroup():
'category' : 'animal', 'size' : 'bigger', 'starting letter' : 'D', 'length' : 3 }, 'SHOE' : { 'category' : 'object', 'size' : 'smaller', 'starting letter' : 'S', 'length' : 4 }, 'HORSE' : { 'category' : 'animal', 'size' : 'bigger', 'starting letter' : 'H', 'length' : 5 }} presented = list(map(lambda x: {'item' : x}, presented)) for p in presented: p.update(**features[p['item']]) recalled = list(map(lambda x: {'item' : x}, recalled)) for r in recalled: r.update(**features[r['item']]) egg = Egg(pres=[[presented]],rec=[[recalled]]) def test_temporal(): egg.analyze('temporal')
def test_egg(): list1 = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]] list2 = [[[10, 20], [30, 40]], [[50, 60], [70, 80]]] egg = Egg(pres=list1, rec=list2) assert type(egg.pres) == pd.core.frame.DataFrame assert type(egg.rec) == pd.core.frame.DataFrame
'size': 'bigger', 'starting letter': 'D', 'length': 3 }, { 'category': 'object', 'size': 'smaller', 'starting letter': 'S', 'length': 4 }, { 'category': 'animal', 'size': 'bigger', 'starting letter': 'H', 'length': 5 }] egg = Egg(pres=[presented], rec=[recalled], features=[features]) def test_egg_works(): assert isinstance(egg, Egg) def test_pres_is_df(): assert isinstance(egg.pres, pd.DataFrame) def test_rec_is_df(): assert isinstance(egg.rec, pd.DataFrame) def test_pres_cells_are_dicts():
def test_egg_recmat(): recmat = [[[3, 4, 2, 1, 0], [4, 2, 5, 3, 2]]] egg = Egg(recmat=recmat, list_length=10) assert isinstance(egg, Egg)
# -*- coding: utf-8 -*- from quail.egg import Egg, FriedEgg import pytest import pandas as pd import six import matplotlib.pyplot as plt presented = [[['cat', 'bat', 'hat', 'goat'], ['zoo', 'animal', 'zebra', 'horse']]] recalled = [[['bat', 'cat', 'goat', 'hat'], ['animal', 'horse', 'zoo']]] fried_egg = Egg(pres=presented, rec=recalled).analyze('accuracy') def test_fried_egg_data_is_df(): assert isinstance(fried_egg.data, pd.DataFrame) def test_fried_egg_analysis(): assert isinstance(fried_egg.analysis, six.string_types) assert fried_egg.analysis == 'accuracy' def test_fried_egg_listlength(): assert fried_egg.list_length == 4 def test_fried_egg_n_lists(): assert fried_egg.n_lists == 2