Skip to content
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

Gerbil data analysis #96

Open
wants to merge 175 commits into
base: main
Choose a base branch
from
Open

Gerbil data analysis #96

wants to merge 175 commits into from

Conversation

emackev
Copy link
Contributor

@emackev emackev commented Jul 31, 2024

No description provided.

Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@emackev emackev added the status:WIP Work-in-progress not yet ready for review label Jul 31, 2024
@emackev
Copy link
Contributor Author

emackev commented Aug 1, 2024

@rfl-urbaniak , I'm working on getting inference running on the gerbil data, modeling the analysis off of the RHF bird analysis. I got the derived predictors calculated, but I'm getting a value error when I try to run samples_random = get_samples(proximity, trace, visibility, how_far_score) . Have you seen this before? Ideas why it may be happening? It seems to be erroring related to how_far_score, but a quick inspection of how_far_score looks reasonable (numbers bt 0 and 1)

ValueError                                Traceback (most recent call last)
File ~/mambaforge/envs/collab_from_setup/lib/python3.10/site-packages/pyro/poutine/trace_messenger.py:174, in TraceHandler.__call__(self, *args, **kwargs)
    [173](https://file+.vscode-resource.vscode-cdn.net/Users/emily/code/collaborative-intelligence/docs/experimental/~/mambaforge/envs/collab_from_setup/lib/python3.10/site-packages/pyro/poutine/trace_messenger.py:173) try:
--> [174](https://file+.vscode-resource.vscode-cdn.net/Users/emily/code/collaborative-intelligence/docs/experimental/~/mambaforge/envs/collab_from_setup/lib/python3.10/site-packages/pyro/poutine/trace_messenger.py:174)     ret = self.fn(*args, **kwargs)
    [175](https://file+.vscode-resource.vscode-cdn.net/Users/emily/code/collaborative-intelligence/docs/experimental/~/mambaforge/envs/collab_from_setup/lib/python3.10/site-packages/pyro/poutine/trace_messenger.py:175) except (ValueError, RuntimeError) as e:

File ~/mambaforge/envs/collab_from_setup/lib/python3.10/site-packages/pyro/poutine/messenger.py:12, in _context_wrap(context, fn, *args, **kwargs)
     [11](https://file+.vscode-resource.vscode-cdn.net/Users/emily/code/collaborative-intelligence/docs/experimental/~/mambaforge/envs/collab_from_setup/lib/python3.10/site-packages/pyro/poutine/messenger.py:11) with context:
---> [12](https://file+.vscode-resource.vscode-cdn.net/Users/emily/code/collaborative-intelligence/docs/experimental/~/mambaforge/envs/collab_from_setup/lib/python3.10/site-packages/pyro/poutine/messenger.py:12)     return fn(*args, **kwargs)

File ~/mambaforge/envs/collab_from_setup/lib/python3.10/site-packages/pyro/poutine/messenger.py:12, in _context_wrap(context, fn, *args, **kwargs)
     [11](https://file+.vscode-resource.vscode-cdn.net/Users/emily/code/collaborative-intelligence/docs/experimental/~/mambaforge/envs/collab_from_setup/lib/python3.10/site-packages/pyro/poutine/messenger.py:11) with context:
---> [12](https://file+.vscode-resource.vscode-cdn.net/Users/emily/code/collaborative-intelligence/docs/experimental/~/mambaforge/envs/collab_from_setup/lib/python3.10/site-packages/pyro/poutine/messenger.py:12)     return fn(*args, **kwargs)

Cell In[30], [line 27](vscode-notebook-cell:?execution_count=30&line=27)
     [26](vscode-notebook-cell:?execution_count=30&line=26) with pyro.plate("data", len(how_far_score)):
---> [27](vscode-notebook-cell:?execution_count=30&line=27)     pyro.sample("obs", dist.Normal(mean, sigma), obs=how_far_score)

File ~/mambaforge/envs/collab_from_setup/lib/python3.10/site-packages/pyro/distributions/distribution.py:24, in DistributionMeta.__call__(cls, *args, **kwargs)
     [23](https://file+.vscode-resource.vscode-cdn.net/Users/emily/code/collaborative-intelligence/docs/experimental/~/mambaforge/envs/collab_from_setup/lib/python3.10/site-packages/pyro/distributions/distribution.py:23)         return result
---> [24](https://file+.vscode-resource.vscode-cdn.net/Users/emily/code/collaborative-intelligence/docs/experimental/~/mambaforge/envs/collab_from_setup/lib/python3.10/site-packages/pyro/distributions/distribution.py:24) return super().__call__(*args, **kwargs)

File ~/mambaforge/envs/collab_from_setup/lib/python3.10/site-packages/torch/distributions/normal.py:56, in Normal.__init__(self, loc, scale, validate_args)
     [55](https://file+.vscode-resource.vscode-cdn.net/Users/emily/code/collaborative-intelligence/docs/experimental/~/mambaforge/envs/collab_from_setup/lib/python3.10/site-packages/torch/distributions/normal.py:55)     batch_shape = self.loc.size()
...
      bs dist |
        value |
Trace Shapes:
 Param Sites:
Sample Sites:


@emackev
Copy link
Contributor Author

emackev commented Aug 2, 2024

@rfl-urbaniak , I'm working on getting inference running on the gerbil data, modeling the analysis off of the RHF bird analysis. I got the derived predictors calculated, but I'm getting a value error when I try to run samples_random = get_samples(proximity, trace, visibility, how_far_score) . Have you seen this before? Ideas why it may be happening? It seems to be erroring related to how_far_score, but a quick inspection of how_far_score looks reasonable (numbers bt 0 and 1)

ValueError                                Traceback (most recent call last)
File ~/mambaforge/envs/collab_from_setup/lib/python3.10/site-packages/pyro/poutine/trace_messenger.py:174, in TraceHandler.__call__(self, *args, **kwargs)
    [173](https://file+.vscode-resource.vscode-cdn.net/Users/emily/code/collaborative-intelligence/docs/experimental/~/mambaforge/envs/collab_from_setup/lib/python3.10/site-packages/pyro/poutine/trace_messenger.py:173) try:
--> [174](https://file+.vscode-resource.vscode-cdn.net/Users/emily/code/collaborative-intelligence/docs/experimental/~/mambaforge/envs/collab_from_setup/lib/python3.10/site-packages/pyro/poutine/trace_messenger.py:174)     ret = self.fn(*args, **kwargs)
    [175](https://file+.vscode-resource.vscode-cdn.net/Users/emily/code/collaborative-intelligence/docs/experimental/~/mambaforge/envs/collab_from_setup/lib/python3.10/site-packages/pyro/poutine/trace_messenger.py:175) except (ValueError, RuntimeError) as e:

File ~/mambaforge/envs/collab_from_setup/lib/python3.10/site-packages/pyro/poutine/messenger.py:12, in _context_wrap(context, fn, *args, **kwargs)
     [11](https://file+.vscode-resource.vscode-cdn.net/Users/emily/code/collaborative-intelligence/docs/experimental/~/mambaforge/envs/collab_from_setup/lib/python3.10/site-packages/pyro/poutine/messenger.py:11) with context:
---> [12](https://file+.vscode-resource.vscode-cdn.net/Users/emily/code/collaborative-intelligence/docs/experimental/~/mambaforge/envs/collab_from_setup/lib/python3.10/site-packages/pyro/poutine/messenger.py:12)     return fn(*args, **kwargs)

File ~/mambaforge/envs/collab_from_setup/lib/python3.10/site-packages/pyro/poutine/messenger.py:12, in _context_wrap(context, fn, *args, **kwargs)
     [11](https://file+.vscode-resource.vscode-cdn.net/Users/emily/code/collaborative-intelligence/docs/experimental/~/mambaforge/envs/collab_from_setup/lib/python3.10/site-packages/pyro/poutine/messenger.py:11) with context:
---> [12](https://file+.vscode-resource.vscode-cdn.net/Users/emily/code/collaborative-intelligence/docs/experimental/~/mambaforge/envs/collab_from_setup/lib/python3.10/site-packages/pyro/poutine/messenger.py:12)     return fn(*args, **kwargs)

Cell In[30], [line 27](vscode-notebook-cell:?execution_count=30&line=27)
     [26](vscode-notebook-cell:?execution_count=30&line=26) with pyro.plate("data", len(how_far_score)):
---> [27](vscode-notebook-cell:?execution_count=30&line=27)     pyro.sample("obs", dist.Normal(mean, sigma), obs=how_far_score)

File ~/mambaforge/envs/collab_from_setup/lib/python3.10/site-packages/pyro/distributions/distribution.py:24, in DistributionMeta.__call__(cls, *args, **kwargs)
     [23](https://file+.vscode-resource.vscode-cdn.net/Users/emily/code/collaborative-intelligence/docs/experimental/~/mambaforge/envs/collab_from_setup/lib/python3.10/site-packages/pyro/distributions/distribution.py:23)         return result
---> [24](https://file+.vscode-resource.vscode-cdn.net/Users/emily/code/collaborative-intelligence/docs/experimental/~/mambaforge/envs/collab_from_setup/lib/python3.10/site-packages/pyro/distributions/distribution.py:24) return super().__call__(*args, **kwargs)

File ~/mambaforge/envs/collab_from_setup/lib/python3.10/site-packages/torch/distributions/normal.py:56, in Normal.__init__(self, loc, scale, validate_args)
     [55](https://file+.vscode-resource.vscode-cdn.net/Users/emily/code/collaborative-intelligence/docs/experimental/~/mambaforge/envs/collab_from_setup/lib/python3.10/site-packages/torch/distributions/normal.py:55)     batch_shape = self.loc.size()
...
      bs dist |
        value |
Trace Shapes:
 Param Sites:
Sample Sites:

@rfl-urbaniak, how_far_score looks reasonable, proximity is what's causing the issue -- it's all nans. Any ideas what may be causing this?

PalkaPuri and others added 2 commits August 2, 2024 16:57
* add collab2 folder

* edit setup to add collab2

* remove comment in setup

---------

Co-authored-by: rfl-urbaniak <rfl.urbaniak@gmail.com>
@emackev
Copy link
Contributor Author

emackev commented Aug 2, 2024

@rfl-urbaniak , the nans were happening because the default params for calculating derived predictors were way to small for this dataset. I increased the visibility range and preferred proximity, and the nans went away. I believe this type of thing will get caught in a clearer way in collab2, so we don't need to fix it in general yet.

In the gerbil case in particular, can you please check that the derived predictors look reasonable? I'm trying to plot them with animate_foragers, but they are not showing up at all. Current status of the notebook is that it runs without error messages, but I'm still suspicious about the predictor calculations.

Ultimately, I'd like to compare coefficients for proximity vs trace across individual gerbils in this dataset. Currently, I'm running it on all gerbils at once, and just a short time slice so it runs quickly.

Another thing to note, there are tracking errors in the data, which show up as nans. I'm currently excluding times when any gerbils are missing. Ultimately, we may want to find segments with good tracking (there's a ton of data total, this is just one of many files), or at least confirm that the derived predictors take account of the missing datapoints in a reasonable way.

Emily and others added 21 commits August 2, 2024 17:30
* add collab2 folder

* updated rescale-to-grid

* replace object_from_data w/ dataObject class

* add comment to init.py

* add function tests

* lint/format

* check step_size_max

* edit setup to add collab2

* add comment

* adding PP_TODO

* added backticks in warnings

* added reference to forager

* added df display to notebook

* removed redundant comment in setup

* resolved comments

* dataObject DF preprocessing

* updated indices to start at 0

* format/lint

* add pytest and fix bugs

* grid_size type int bug fix

* fixed bug in subsampling

* fixed bug in data object

* format in collab2

* lint

* conditioned file saving in locust validate on not in CI

* added black to isort profile

* format after updating profile

* lint fix

* lint 2

* lint whitespace

* whitespace fixing

* whitespaces fixed

---------

Co-authored-by: rfl-urbaniak <rfl.urbaniak@gmail.com>
* add collab2 folder

* updated rescale-to-grid

* replace object_from_data w/ dataObject class

* add comment to init.py

* add function tests

* lint/format

* check step_size_max

* add local_windows functions

* add function tests

* edit setup to add collab2

* edit setup to add collab2

* add comment

* update function spec

* fix func output spec

* adding PP_TODO

* added backticks in warnings

* added reference to forager

* added df display to notebook

* removed redundant comment in setup

* resolved comments

* dataObject DF preprocessing

* updated indices to start at 0

* format/lint

* add pytest and fix bugs

* grid_size type int bug fix

* shifting indices WIP

* fixed bug in subsampling

* fixed bug in data object

* pytest for local_windows + bug fix

* lint

* format in collab2

* lint

* conditioned file saving in locust validate on not in CI

* format

* format

* format

* added black to isort profile

* format after updating profile

* pull scripts with black in isort profile

* lint fix

* small update to toolkit init

* lint 2

* lint whitespace

* whitespace fixing

* small fixes

* lint fixes

* format

* one more lint

* deepcopy grid

---------

Co-authored-by: rfl-urbaniak <rfl.urbaniak@gmail.com>
* add collab2 folder

* updated rescale-to-grid

* replace object_from_data w/ dataObject class

* add comment to init.py

* add function tests

* lint/format

* check step_size_max

* add local_windows functions

* add function tests

* edit setup to add collab2

* edit setup to add collab2

* filtering WIP

* add comment

* add filtering function and test

* formatting

* update function spec

* update function spec

* fix function output type spec

* fix func output spec

* adding PP_TODO

* added backticks in warnings

* added reference to forager

* added df display to notebook

* removed redundant comment in setup

* resolved comments

* dataObject DF preprocessing

* updated indices to start at 0

* format/lint

* add pytest and fix bugs

* grid_size type int bug fix

* shifting indices WIP

* fixed bug in subsampling

* fixed bug in data object

* pytest for local_windows + bug fix

* lint

* merge pp-collab2-generate-local-windows

* filtering nb update

* format in collab2

* lint

* conditioned file saving in locust validate on not in CI

* format

* format

* format

* added black to isort profile

* format after updating profile

* pull scripts with black in isort profile

* lint fix

* small update to toolkit init

* lint 2

* update scripts

* format, lint

* lint whitespace

* whitespace fixing

* small fixes

* lint fixes

* format

* one more lint

* lint

* one more format

* added comment about using derived quantities in constraints

* small format

* deepcopy grid

* deepcopy in filtering

* noqa in init

* format

---------

Co-authored-by: rfl-urbaniak <rfl.urbaniak@gmail.com>
rfl-urbaniak and others added 30 commits September 17, 2024 14:47
* add_velocity function

* velocity predictor WIP

* wip

* format/lint

* specify forager column as int

* add warning

* format/lint

* rename f,t for clarity

* rerun notebook

* add docstrings

* format/lint

* use inbuilt function for gaussian pdf

* updated visualization

* add handling of nan values in visualization

* add _generate_pairwise_copying predictor

* format/lint

* type hints

* add pairwise predictor and animation function

* change velocity to backward looking

* docstrings and type hints

* generate function and typehints

* fixed naming, nan handling

* refactoring

* vicsek wip

* update normalization of velocity predictors

* distance_to_next_move WIP

* added alternates for distance_to_next_pos

* lint/format

* updated nb example

* update scores wip

* merge rafal's changes

* absolute paths for imports in modules

* update module to allow chnaging n

* renaming

* format

* trace code in place

* rename n

* add derive_predictors

* test inference wip

* derive WIP

* test inference pipeline

* format/lint

* format again

* one more format

* lint

* format

* adding doc to local_windows WIP

* small typos in docstrings

* added predictor time to logging

* added time to score logging

* time to logging, a few typos

* format lint

* refactored proximity

* removed old proximity code

* format lint

* refactored trace

* added generate food to init

* format, lint

* update parameter names in docstring

* explanation of score_kwargs

* update next_step_score notebook

* update warning and add docstring to dataObject

* removing reusing velocity warning

* removed individual drop warning, add to derive_predictors_and_scores

* lint/format

* fix bug in test

* format

* local_windows update constraint implementation, add docstring

* rename variables

* filter_by_distance update constraint implementation

* remove fps argument from subsampling func

* velocity- rename predictorID, update constraint implementation, docstring

* ensure all test notebooks run

* format/lint WIP

* ensure rafals nbs run

* type hints for kwargs in constraint func

* add collab2 notebooks to automatic testing

* small fixes to local_windows.py docstrings

* interpunction in filtering.py

* proximity notebook now works

* wip

* fixed trace and derivation notebooks

* resolved type hinting problems

* fix some bugs

* notebook issue fix

* fix type hint in proximity

* grid_constraint_params updated to dict

* interaction_constraint_params updated to dict

* make sure all notebooks pass + format/lint

* lint

* lint

* lint

* lint

* lint

* lint

* lint

* suspended old velocity test

* rhf old update

* re-ran hungry and random foragers

* following foragers replicated

* format, lint

* change to sublinear

* fixing velocity_predicts WIP

* updated trace_predictor

* suspend animations in velocity predictors

* added access predictor

* updated random with access

* updateg hungry foragers

* updated followers with access

* format, lint

* fixed lint

* fixed imports in random foragers

* fixing init

* format, lint

* restored init fix

* bump pyro to 1.9.1

* revert (chirho), remove deterministic from rendering

* Some polishing of the random/hungry/followers notebooks and fixing stuff (collab2 ). (#126)

* Some work on the random_foragers notebook and fixing stuff.

* Linting + completing the random_foragers notebook.

* Finished random_foragers

* Interactive plots now should be displayed in HTML

* make format

* small fixes to random foragers

* Some more tweaks + zero-index fixes.

* Hungry birds simulation updated.

* Minor.

* Completed the follower NB.

* Saves the samples from each one of the R,H,F to disk, for later plotting in a single figure.

* Comparative fig.

* Minor.

* Make lint and format

* Typos

* Improved explanations of the predictors and the scores.

* Updated the model description in the random notebook.

* Minor

* Added option for initial positions. Updated RHF.

* reviewed random

* added toc to followers

* fixed followers

* Small formulas + model updates

* small modification

* small fixes, re-ran

* fixing save and display in follower

* format lint, dilling in hungry

---------

Co-authored-by: rfl-urbaniak <rfl.urbaniak@gmail.com>

* format lint

---------

Co-authored-by: Palka Puri <ppuri.cash@gmail.com>
Co-authored-by: Dmitry Batenkov <dimkab@users.noreply.github.com>
…ebook (#125)

* add_velocity function

* velocity predictor WIP

* wip

* format/lint

* specify forager column as int

* add warning

* format/lint

* rename f,t for clarity

* rerun notebook

* add docstrings

* format/lint

* use inbuilt function for gaussian pdf

* updated visualization

* add handling of nan values in visualization

* add _generate_pairwise_copying predictor

* format/lint

* type hints

* add pairwise predictor and animation function

* change velocity to backward looking

* docstrings and type hints

* generate function and typehints

* fixed naming, nan handling

* refactoring

* vicsek wip

* update normalization of velocity predictors

* distance_to_next_move WIP

* added alternates for distance_to_next_pos

* lint/format

* updated nb example

* update scores wip

* merge rafal's changes

* absolute paths for imports in modules

* update module to allow chnaging n

* renaming

* format

* trace code in place

* rename n

* add derive_predictors

* test inference wip

* derive WIP

* test inference pipeline

* format/lint

* format again

* one more format

* lint

* format

* adding doc to local_windows WIP

* small typos in docstrings

* added predictor time to logging

* added time to score logging

* time to logging, a few typos

* format lint

* refactored proximity

* removed old proximity code

* format lint

* refactored trace

* added generate food to init

* format, lint

* update parameter names in docstring

* explanation of score_kwargs

* update next_step_score notebook

* update warning and add docstring to dataObject

* removing reusing velocity warning

* removed individual drop warning, add to derive_predictors_and_scores

* lint/format

* fix bug in test

* format

* local_windows update constraint implementation, add docstring

* rename variables

* filter_by_distance update constraint implementation

* remove fps argument from subsampling func

* velocity- rename predictorID, update constraint implementation, docstring

* ensure all test notebooks run

* format/lint WIP

* ensure rafals nbs run

* type hints for kwargs in constraint func

* add collab2 notebooks to automatic testing

* small fixes to local_windows.py docstrings

* interpunction in filtering.py

* proximity notebook now works

* wip

* fixed trace and derivation notebooks

* resolved type hinting problems

* fix some bugs

* notebook issue fix

* fix type hint in proximity

* grid_constraint_params updated to dict

* interaction_constraint_params updated to dict

* make sure all notebooks pass + format/lint

* lint

* lint

* lint

* lint

* lint

* lint

* lint

* suspended old velocity test

* rhf old update

* re-ran hungry and random foragers

* following foragers replicated

* format, lint

* change to sublinear

* fixing velocity_predicts WIP

* updated trace_predictor

* suspend animations in velocity predictors

* added access predictor

* updated random with access

* updateg hungry foragers

* updated followers with access

* format, lint

* communication WIP

* wip

* fixed lint

* WIP

* fixed imports in random foragers

* WIP

* fixing init

* communication predictor notebook functional

* format, lint

* restored init fix

* bump pyro to 1.9.1

* revert (chirho), remove deterministic from rendering

* pkl to gitignore

* Some work on the random_foragers notebook and fixing stuff.

* Linting + completing the random_foragers notebook.

* Finished random_foragers

* Interactive plots now should be displayed in HTML

* make format

* small fixes to random foragers

* Some more tweaks + zero-index fixes.

* Hungry birds simulation updated.

* Minor.

* Completed the follower NB.

* Saves the samples from each one of the R,H,F to disk, for later plotting in a single figure.

* Comparative fig.

* Minor.

* Make lint and format

* Typos

* Improved explanations of the predictors and the scores.

* Updated the model description in the random notebook.

* Minor

* Added option for initial positions. Updated RHF.

* reviewed random

* added toc to followers

* fixed followers

* Small formulas + model updates

* small modification

* small fixes, re-ran

* fixing save and display in follower

* format lint, dilling in hungry

* Some polishing of the random/hungry/followers notebooks and fixing stuff (collab2 ). (#126)

* Some work on the random_foragers notebook and fixing stuff.

* Linting + completing the random_foragers notebook.

* Finished random_foragers

* Interactive plots now should be displayed in HTML

* make format

* small fixes to random foragers

* Some more tweaks + zero-index fixes.

* Hungry birds simulation updated.

* Minor.

* Completed the follower NB.

* Saves the samples from each one of the R,H,F to disk, for later plotting in a single figure.

* Comparative fig.

* Minor.

* Make lint and format

* Typos

* Improved explanations of the predictors and the scores.

* Updated the model description in the random notebook.

* Minor

* Added option for initial positions. Updated RHF.

* reviewed random

* added toc to followers

* fixed followers

* Small formulas + model updates

* small modification

* small fixes, re-ran

* fixing save and display in follower

* format lint, dilling in hungry

---------

Co-authored-by: rfl-urbaniak <rfl.urbaniak@gmail.com>

* format

* pin cleanup package versions

* upgrade and pin nbqa

* suspend outdated velocity test

* format, lint

* suspend outdated test for velocity

* remove outdated velocity test file

* add blank test velocity

* format lint

* missing import for generate_communication_predictor in __init__.py

* decoupled communicator simulations from collab 1

* format lint

* ensure starts at 0 with communicators inference, re-run

* format, lint

* Started working on the communicators simulation

* Comm. simulations - minor.

* Cntd - comm sim.

* Added TOC to hungry

* Comm. inference - doc

* Completed comm. inference notebook

* render directive

* format + lint

* typo

---------

Co-authored-by: Palka Puri <ppuri.cash@gmail.com>
Co-authored-by: Dmitry Batenkov <dima.batenkov@gmail.com>
Co-authored-by: Dmitry Batenkov <dimkab@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:WIP Work-in-progress not yet ready for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants