-
Notifications
You must be signed in to change notification settings - Fork 4
Allowing tracking of non-consecutive forager indices #168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
eb2504d
adding global_forager_id as a property of dataObject. this solves kee…
tommybotch 4263d5a
checking that column doesn't already exist
tommybotch f1ae1db
updating test to consider new global_forager_id column
tommybotch 99863ee
passed all tests
tommybotch c37c478
updating workflows for action/cache@v4
tommybotch e016174
Merge branch 'tlb-workflow' into tlb-dev
tommybotch 235e5dc
Merge branch 'main' into tlb-dev
dimkab 479e4e7
Merge branch 'main' into tlb-dev
dimkab 9c00b39
removing erroneous addition to gitignore
tommybotch f3f5c25
Merge branch 'main' into tlb-dev
dimkab 24776f7
restoring old files for tests -- removing addition of extra column
tommybotch 37bf2c1
updating utils w/ stored mappings and function to apply mappings
tommybotch 2d184c9
updating imports to be inline w lint?
tommybotch fa5c6b2
forgot to run make statements
tommybotch 6ffe1d5
updating with property of local/global forager id mapping
tommybotch 8341e87
accidentally updated too much
tommybotch 6da6c7f
restoring old dill file
tommybotch 4bcdda9
removing redundancy in code
tommybotch 247780d
adding back in setting type of forager
tommybotch 7d7b740
adding make lint format
tommybotch c9b2d35
reorganized utils file -- moved local/global mapping step to before s…
tommybotch 2abc286
forgot a self tag
tommybotch 453477d
forgot a self tag again...
tommybotch 643c6e5
fixing needs_forager_id_mapping, and indexing within apply_forager_id…
tommybotch 429bac8
line too long for lint...
tommybotch ea30c41
updating after linting
tommybotch 8e9facb
type hints and return value consistent
dimkab 56d2a54
updating w/ test and demonstration of index conversion
tommybotch aa66b6b
Merge branch 'tlb-dev' of https://github.com/BasisResearch/collab-cre…
tommybotch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
tommybotch marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
181 changes: 181 additions & 0 deletions
181
docs/experimental/collab_tests/forager_index_conversion.ipynb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,181 @@ | ||
| { | ||
| "cells": [ | ||
| { | ||
| "cell_type": "markdown", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "# Test of forager index conversation\n", | ||
| "\n", | ||
| "When forager indices are non-consecutive (i.e., [0, 2]), the dataObject internally converts these indices to consecutive (i.e., [0,1]) and stores the mapping within two variables:\n", | ||
| "- local_to_global_map: mapping back to original, non-consecutive indices\n", | ||
| "- global_to_local_map: mapping to consecutive indices (applied internally at ```__init__``` when creating dataObject) " | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": 23, | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "import os\n", | ||
| "\n", | ||
| "import pandas as pd\n", | ||
| "\n", | ||
| "import collab.foraging.toolkit as ftk\n", | ||
| "\n", | ||
| "smoke_test = \"CI\" in os.environ\n", | ||
| "\n", | ||
| "num_svi_iters = 400 if not smoke_test else 4\n", | ||
| "num_samples = 1000 if not smoke_test else 10" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "### Load data\n", | ||
| "\n", | ||
| "Setup for dataObject with ground-truth indices" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": 24, | ||
| "metadata": {}, | ||
| "outputs": [ | ||
| { | ||
| "name": "stderr", | ||
| "output_type": "stream", | ||
| "text": [ | ||
| "/Users/tommybotch/Documents/collab-creatures/collab/foraging/toolkit/utils.py:42: UserWarning: \n", | ||
| " NaN values in data. The default behavior of predictor/score generating functions is\n", | ||
| " to ignore foragers with missing positional data. To modify, see documentation of\n", | ||
| " `derive_predictors_and_scores` and `generate_local_windows`\n", | ||
| " \n", | ||
| " warnings.warn(\n" | ||
| ] | ||
| } | ||
| ], | ||
| "source": [ | ||
| "# load data\n", | ||
| "fish_data = pd.read_csv(\"4wpf_test.csv\")\n", | ||
| "gridMin = 0\n", | ||
| "gridMax = 300\n", | ||
| "grid_size = 50\n", | ||
| "\n", | ||
| "# scaling and subsampling\n", | ||
| "fishDF_scaled = ftk.rescale_to_grid(\n", | ||
| " fish_data, size=grid_size, gridMin=gridMin, gridMax=gridMax\n", | ||
| ")\n", | ||
| "# create a test foragers object with 20 frames\n", | ||
| "num_frames = 10\n", | ||
| "foragers_object = ftk.dataObject(\n", | ||
| " fishDF_scaled,\n", | ||
| " grid_size=grid_size,\n", | ||
| ")" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "### Modify the original dataframe\n", | ||
| "\n", | ||
| "We subsample forager indices to test the global (non-consecutive) to local (consecutive) mapping" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": 26, | ||
| "metadata": {}, | ||
| "outputs": [ | ||
| { | ||
| "name": "stderr", | ||
| "output_type": "stream", | ||
| "text": [ | ||
| "/Users/tommybotch/Documents/collab-creatures/collab/foraging/toolkit/utils.py:42: UserWarning: \n", | ||
| " NaN values in data. The default behavior of predictor/score generating functions is\n", | ||
| " to ignore foragers with missing positional data. To modify, see documentation of\n", | ||
| " `derive_predictors_and_scores` and `generate_local_windows`\n", | ||
| " \n", | ||
| " warnings.warn(\n", | ||
| "/Users/tommybotch/Documents/collab-creatures/collab/foraging/toolkit/utils.py:59: UserWarning: \n", | ||
| " Original forager indices were converted to consecutive integers starting from 0.\n", | ||
| " To access the original forager IDs, use the apply_forager_id_mapping() method.\n", | ||
| " Original IDs were: [0 2]\n", | ||
| " \n", | ||
| " warnings.warn(\n" | ||
| ] | ||
| } | ||
| ], | ||
| "source": [ | ||
| "fishDF_nonconsecutive = fishDF_scaled[fishDF_scaled[\"forager\"].isin([0, 2])]\n", | ||
| "\n", | ||
| "# Given non-consecutive indices, forager indices are converted to consecutive integers and a warning is raised\n", | ||
| "foragers_nonconsecutive_obj = ftk.dataObject(fishDF_nonconsecutive, grid_size=grid_size)" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "### Demonstrate application of local-global maps\n", | ||
| "\n", | ||
| "Whether mapping is needed is stored in a read-only property ```needs_forager_id_mapping```" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": 27, | ||
| "metadata": {}, | ||
| "outputs": [ | ||
| { | ||
| "name": "stdout", | ||
| "output_type": "stream", | ||
| "text": [ | ||
| "Original DF needed mapping: False\n", | ||
| "Non-consecutive DF needed mapping: True\n", | ||
| "Local to global map: {0: 0, 1: 2}\n", | ||
| "Global to local map: {0: 0, 2: 1}\n" | ||
| ] | ||
| } | ||
| ], | ||
| "source": [ | ||
| "# Original object\n", | ||
| "print(f\"Original DF needed mapping: {foragers_object.needs_forager_id_mapping}\")\n", | ||
| "\n", | ||
| "# Non-consecutive object\n", | ||
| "print(\n", | ||
| " f\"Non-consecutive DF needed mapping: {foragers_nonconsecutive_obj.needs_forager_id_mapping}\"\n", | ||
| ")\n", | ||
| "\n", | ||
| "# Maps are accessible as properties\n", | ||
| "# Local to global = maps back to original indices\n", | ||
| "# Global to local = maps back to consecutive indices\n", | ||
| "print(f\"Local to global map: {foragers_nonconsecutive_obj.local_to_global_map}\")\n", | ||
| "print(f\"Global to local map: {foragers_nonconsecutive_obj.global_to_local_map}\")" | ||
| ] | ||
| } | ||
| ], | ||
| "metadata": { | ||
| "kernelspec": { | ||
| "display_name": "collab", | ||
| "language": "python", | ||
| "name": "python3" | ||
| }, | ||
| "language_info": { | ||
| "codemirror_mode": { | ||
| "name": "ipython", | ||
| "version": 3 | ||
| }, | ||
| "file_extension": ".py", | ||
| "mimetype": "text/x-python", | ||
| "name": "python", | ||
| "nbconvert_exporter": "python", | ||
| "pygments_lexer": "ipython3", | ||
| "version": "3.11.11" | ||
| } | ||
| }, | ||
| "nbformat": 4, | ||
| "nbformat_minor": 2 | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.