From 76b25c48801ad1d80c9d3fb89513f0b435437616 Mon Sep 17 00:00:00 2001 From: Kirsten Ziman <> Date: Thu, 3 Jun 2021 10:59:40 -0400 Subject: [PATCH] switch get_values and as_matrix to to_numpy --- docs/_build/html/_downloads/crack_egg.ipynb | 2 +- docs/_build/html/_downloads/crack_egg.py | 4 ++-- .../html/_sources/auto_examples/crack_egg.rst.txt | 4 ++-- docs/auto_examples/crack_egg.ipynb | 2 +- docs/auto_examples/crack_egg.py | 4 ++-- docs/auto_examples/crack_egg.rst | 4 ++-- quail/analysis/recmat.py | 12 ++++++------ 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/docs/_build/html/_downloads/crack_egg.ipynb b/docs/_build/html/_downloads/crack_egg.ipynb index 70958af..7f097d9 100644 --- a/docs/_build/html/_downloads/crack_egg.ipynb +++ b/docs/_build/html/_downloads/crack_egg.ipynb @@ -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))" ] } ], diff --git a/docs/_build/html/_downloads/crack_egg.py b/docs/_build/html/_downloads/crack_egg.py index c916c17..3966b6e 100644 --- a/docs/_build/html/_downloads/crack_egg.py +++ b/docs/_build/html/_downloads/crack_egg.py @@ -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()] diff --git a/docs/_build/html/_sources/auto_examples/crack_egg.rst.txt b/docs/_build/html/_sources/auto_examples/crack_egg.rst.txt index 8a63cce..89eccaa 100644 --- a/docs/_build/html/_sources/auto_examples/crack_egg.rst.txt +++ b/docs/_build/html/_sources/auto_examples/crack_egg.rst.txt @@ -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()] diff --git a/docs/auto_examples/crack_egg.ipynb b/docs/auto_examples/crack_egg.ipynb index 70958af..7f097d9 100644 --- a/docs/auto_examples/crack_egg.ipynb +++ b/docs/auto_examples/crack_egg.ipynb @@ -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))" ] } ], diff --git a/docs/auto_examples/crack_egg.py b/docs/auto_examples/crack_egg.py index c916c17..3966b6e 100644 --- a/docs/auto_examples/crack_egg.py +++ b/docs/auto_examples/crack_egg.py @@ -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()] diff --git a/docs/auto_examples/crack_egg.rst b/docs/auto_examples/crack_egg.rst index 8a63cce..89eccaa 100644 --- a/docs/auto_examples/crack_egg.rst +++ b/docs/auto_examples/crack_egg.rst @@ -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()] diff --git a/quail/analysis/recmat.py b/quail/analysis/recmat.py index e14eb99..d5a0fe8 100644 --- a/quail/analysis/recmat.py +++ b/quail/analysis/recmat.py @@ -51,7 +51,7 @@ 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): @@ -59,8 +59,8 @@ def _recmat_exact(presented, recalled, features): 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] @@ -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