Skip to content

Commit

Permalink
Merge pull request #122 from ContextLab/to_numpy
Browse files Browse the repository at this point in the history
switch get_values and as_matrix to to_numpy
  • Loading branch information
paxtonfitzpatrick committed Jun 3, 2021
2 parents c44d06f + 76b25c4 commit 94fa39c
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion docs/_build/html/_downloads/crack_egg.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
"outputs": [],
"source": [
"# Code source: Andrew Heusser\n# License: MIT\n\n#import\nimport quail\n\n#load data\negg = quail.load('example')\n\n#crack egg\ncracked_egg = quail.crack_egg(egg, subjects=[0], lists=[0])\n\ncracked_egg.info()\n\npres = cracked_egg.get_pres_items().as_matrix()[0]\nrec = cracked_egg.get_rec_items().as_matrix()[0]\n\ndef distmat(egg, feature, distdict):\n f = [xi[feature] for xi in egg.get_pres_features()]\n return cdist(f, f, distdict[feature])\n\n\nfor idx in range(len(rec)-1):\n ind1 = np.where(pres==rec[idx])[0][0]\n ind2 = np.where(pres==rec[idx+1])[0][0]\n dists = dist[ind1, :]\n cdist = dist[ind1, ind2]\n rank = np.mean(np.where(np.sort(dists)[::-1] == cdist))"
"# Code source: Andrew Heusser\n# License: MIT\n\n#import\nimport quail\n\n#load data\negg = quail.load('example')\n\n#crack egg\ncracked_egg = quail.crack_egg(egg, subjects=[0], lists=[0])\n\ncracked_egg.info()\n\npres = cracked_egg.get_pres_items().to_numpy()[0]\nrec = cracked_egg.get_rec_items().to_numpy()[0]\n\ndef distmat(egg, feature, distdict):\n f = [xi[feature] for xi in egg.get_pres_features()]\n return cdist(f, f, distdict[feature])\n\n\nfor idx in range(len(rec)-1):\n ind1 = np.where(pres==rec[idx])[0][0]\n ind2 = np.where(pres==rec[idx+1])[0][0]\n dists = dist[ind1, :]\n cdist = dist[ind1, ind2]\n rank = np.mean(np.where(np.sort(dists)[::-1] == cdist))"
]
}
],
Expand Down
4 changes: 2 additions & 2 deletions docs/_build/html/_downloads/crack_egg.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

cracked_egg.info()

pres = cracked_egg.get_pres_items().as_matrix()[0]
rec = cracked_egg.get_rec_items().as_matrix()[0]
pres = cracked_egg.get_pres_items().to_numpy()[0]
rec = cracked_egg.get_rec_items().to_numpy()[0]

def distmat(egg, feature, distdict):
f = [xi[feature] for xi in egg.get_pres_features()]
Expand Down
4 changes: 2 additions & 2 deletions docs/_build/html/_sources/auto_examples/crack_egg.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ This an example of how to crack an egg (take a slice of subjects/lists from it)
cracked_egg.info()
pres = cracked_egg.get_pres_items().as_matrix()[0]
rec = cracked_egg.get_rec_items().as_matrix()[0]
pres = cracked_egg.get_pres_items().to_numpy()[0]
rec = cracked_egg.get_rec_items().to_numpy()[0]
def distmat(egg, feature, distdict):
f = [xi[feature] for xi in egg.get_pres_features()]
Expand Down
2 changes: 1 addition & 1 deletion docs/auto_examples/crack_egg.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
"outputs": [],
"source": [
"# Code source: Andrew Heusser\n# License: MIT\n\n#import\nimport quail\n\n#load data\negg = quail.load('example')\n\n#crack egg\ncracked_egg = quail.crack_egg(egg, subjects=[0], lists=[0])\n\ncracked_egg.info()\n\npres = cracked_egg.get_pres_items().as_matrix()[0]\nrec = cracked_egg.get_rec_items().as_matrix()[0]\n\ndef distmat(egg, feature, distdict):\n f = [xi[feature] for xi in egg.get_pres_features()]\n return cdist(f, f, distdict[feature])\n\n\nfor idx in range(len(rec)-1):\n ind1 = np.where(pres==rec[idx])[0][0]\n ind2 = np.where(pres==rec[idx+1])[0][0]\n dists = dist[ind1, :]\n cdist = dist[ind1, ind2]\n rank = np.mean(np.where(np.sort(dists)[::-1] == cdist))"
"# Code source: Andrew Heusser\n# License: MIT\n\n#import\nimport quail\n\n#load data\negg = quail.load('example')\n\n#crack egg\ncracked_egg = quail.crack_egg(egg, subjects=[0], lists=[0])\n\ncracked_egg.info()\n\npres = cracked_egg.get_pres_items().to_numpy()[0]\nrec = cracked_egg.get_rec_items().to_numpy()[0]\n\ndef distmat(egg, feature, distdict):\n f = [xi[feature] for xi in egg.get_pres_features()]\n return cdist(f, f, distdict[feature])\n\n\nfor idx in range(len(rec)-1):\n ind1 = np.where(pres==rec[idx])[0][0]\n ind2 = np.where(pres==rec[idx+1])[0][0]\n dists = dist[ind1, :]\n cdist = dist[ind1, ind2]\n rank = np.mean(np.where(np.sort(dists)[::-1] == cdist))"
]
}
],
Expand Down
4 changes: 2 additions & 2 deletions docs/auto_examples/crack_egg.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

cracked_egg.info()

pres = cracked_egg.get_pres_items().as_matrix()[0]
rec = cracked_egg.get_rec_items().as_matrix()[0]
pres = cracked_egg.get_pres_items().to_numpy()[0]
rec = cracked_egg.get_rec_items().to_numpy()[0]

def distmat(egg, feature, distdict):
f = [xi[feature] for xi in egg.get_pres_features()]
Expand Down
4 changes: 2 additions & 2 deletions docs/auto_examples/crack_egg.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ This an example of how to crack an egg (take a slice of subjects/lists from it)
cracked_egg.info()
pres = cracked_egg.get_pres_items().as_matrix()[0]
rec = cracked_egg.get_rec_items().as_matrix()[0]
pres = cracked_egg.get_pres_items().to_numpy()[0]
rec = cracked_egg.get_rec_items().to_numpy()[0]
def distmat(egg, feature, distdict):
f = [xi[feature] for xi in egg.get_pres_features()]
Expand Down
12 changes: 6 additions & 6 deletions quail/analysis/recmat.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,16 @@ def recall_matrix(egg, match='exact', distance='euclidean', features=None):
return _recmat_smooth(egg.pres, egg.rec, features, distance, match)

def _recmat_exact(presented, recalled, features):
lists = presented.index.get_values()
lists = presented.index.to_numpy()()
cols = max(presented.shape[1], recalled.shape[1])
result = np.empty((presented.shape[0], cols))*np.nan
for li, l in enumerate(lists):
p_list = presented.loc[l]
r_list = recalled.loc[l]
for i, feature in enumerate(features):
get_feature = lambda x: np.array(x[feature]) if not np.array(pd.isnull(x['item'])).any() else np.nan
p = np.vstack(p_list.apply(get_feature).get_values())
r = r_list.dropna().apply(get_feature).get_values()
p = np.vstack(p_list.apply(get_feature).to_numpy()())
r = r_list.dropna().apply(get_feature).to_numpy()()
r = np.vstack(list(filter(lambda x: x is not np.nan, r)))
try:
m = [np.where((p==x).all(axis=1))[0] for x in r]
Expand Down Expand Up @@ -90,15 +90,15 @@ def _recmat_smooth(presented, recalled, features, distance, match):
return recmat

def _similarity_smooth(presented, recalled, features, distance):
lists = presented.index.get_values()
lists = presented.index.to_numpy()()
res = np.empty((len(lists), len(features), recalled.iloc[0].shape[0], presented.iloc[0].shape[0]))*np.nan
for li, l in enumerate(lists):
p_list = presented.loc[l]
r_list = recalled.loc[l]
for i, feature in enumerate(features):
get_feature = lambda x: np.array(x[feature]) if np.array(pd.notna(x['item'])).any() else np.nan
p = np.vstack(p_list.apply(get_feature).get_values())
r = r_list.dropna().apply(get_feature).get_values()
p = np.vstack(p_list.apply(get_feature).to_numpy()())
r = r_list.dropna().apply(get_feature).to_numpy()()
r = np.vstack(list(filter(lambda x: x is not np.nan, r)))
tmp = 1 - cdist(r, p, distance)
res[li, i, :tmp.shape[0], :] = tmp
Expand Down

0 comments on commit 94fa39c

Please sign in to comment.