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

"other than modeled person" fomulation #22

Closed
fscottfoti opened this issue Feb 25, 2015 · 8 comments · Fixed by #41
Closed

"other than modeled person" fomulation #22

fscottfoti opened this issue Feb 25, 2015 · 8 comments · Fixed by #41

Comments

@fscottfoti
Copy link
Contributor

@jiffyclub I think this one is for you. I'm working my way through hundreds of variable specifications, many of which are straightforward. I now see about 20 that all have the same formulation that has me a bit stumped. Something along the lines of a [retiree] in the household that is NOT the current person. What do you think is the best way (pandas and/or simulation framework) to formulate a variable like this from the perspective of the chooser?

@jiffyclub
Copy link
Contributor

That is a tough one. If you had a list of the person types for the household that didn't include the current person you could a "retired_type in household". Or if you had a Series mapping from person ID to person type for the whole household you could do "retired_type in household.drop(current_id)".

@fscottfoti
Copy link
Contributor Author

Right - so this is what I'm doing without worrying about the perspective of the person

def presence_of(ptype, persons, households):
    return (persons.household_id[persons.ptype_cat == ptype].\
        value_counts() > 0).reindex(households.index).fillna(False)

And I could also pass in a choosers Series giving the index of the persons I care about. And I could drop the people in that series from the persons table and do the above. But that would still be the wrong answer because I would want copies of the household for the people where more than one person is from the same household and the variable might be different from the perspective of each person.

I think it might be an involved answer unfortunately and we'll just have to take the performance hit to do the copies, reindexes, and appropriate drops. Might want to put on the back burner for now and come back to it unless you see a quicker answer.

@jiffyclub
Copy link
Contributor

It's something you have to do household-by-household and person-by-person unless you've pre-loaded the persons table with information about the rest of the household.

@fscottfoti
Copy link
Contributor Author

Per our discussion yesterday, I realized I already have a single function which definitely only uses person type as the relevant variable.

https://github.com/synthicity/activitysim/blob/254da40fe1acd175819533ffcb528a6e5d72053b/activitysim/defaults/tables/households.py#L166

The current version checks for the presence of that type including the chooser. The intended version is meant to check for presence of that type excluding the chooser. So like you said, one way to do this would be to create a list of person types excluding the chooser for each person. Alternatively, it's a bit sneaky, but I wonder if an even easier way is to look for 2 or greater of that person type in the household if the person is that type, or one of greater if the person is not the person type.

@jiffyclub
Copy link
Contributor

Okay, I came up with this, but I haven't actually tried it yet:

def presence_of(ptype, persons, households, at_home=False):
    if at_home:
        # if at_home, they need to be of given type AND at home
        s = persons.household_id[(persons.ptype_cat == ptype) &
                                 (persons.cdap_activity == "H")]
    else:
        s = persons.household_id[persons.ptype_cat == ptype]

    counts = s.value_counts()
    sf = s.to_frame(name='right')
    sf['household_id'] = persons['household_id']
    gt0 = (counts > 0).to_frame(name='left').merge(
        sf, how='right', left_index=True, right_on='household_id')
    gt1 = (counts > 1).to_frame(name='left').merge(
        sf, how='right', left_index=True, right_on='household_id')

    return gt1['left'].where(s, other=gt0['left'])

This is different than the current presence_of because it puts things on the person level instead of households. You can only put "other than" info on the person table.

@fscottfoti
Copy link
Contributor Author

That's some real Pandas-fu. Should probably test it first but that looks great.

@jiffyclub
Copy link
Contributor

One question is how general this needs to be? With the at_home parameter and hard-coded column names this is specific to the person-type variables.

@fscottfoti
Copy link
Contributor Author

I don't know. So far it's the only one I've encountered that looks like this, though there could be others. If it's easy to generalize, that would be good. If it's not easy, it might not be worth it yet.

bstabler added a commit that referenced this issue Jul 29, 2020
* estimation through atwork_subtour_mode_choice

* Tnc updates and notebooks (#18)

* move other resources into folder since examples now part of package as well

* add shapefile

* clean up folder setup

* estimation notebooks for larch (#19)

* multiprocessing related logging and error checking

* trip_destination handle all trips fail

* skim caching with numpy memmap to speed skim loading

* better chunking in vectorize_tour_scheduling

* Cli (#22)

* use activitysim_resources

Fixed auto sufficiency conditions in tour_mode_choice.csv. (Issue #324)

* increment to version 0.9.5

* correct write trip matrices sampling expansion and add vehicle occupancy to the expression file

* updates to documentation for phase 5 work except multiple zone systems
bstabler added a commit that referenced this issue Aug 11, 2020
* download example data

* comments, tests

* use activitysim_resources

* add estimation examples

* add commented out examples

Co-authored-by: bstabler <benstabler@yahoo.com>
bstabler added a commit that referenced this issue Sep 4, 2020
* update docs, drop scripts no longer needed, include example files in package

* Pandas 1.0 fixes

* Location and mode choice logsums (#298)

* Tncs (#14)

* write trip matrices (#311)

* small fixes for semcog deployment (#319)

* improved validation diagnostics in trip_purpose and various windows-related int32/int64 conversions

* fix bug in handling of no viable trips case in choose_trip_destination

* major work on phase 5 (#325)

* estimation through atwork_subtour_mode_choice

* Tnc updates and notebooks (#18)

* move other resources into folder since examples now part of package as well

* add example zone shapefile

* estimation notebooks for larch (#19)

* multiprocessing related logging and error checking

* trip_destination handle all trips fail

* skim caching with numpy memmap to speed skim loading

* better chunking in vectorize_tour_scheduling

* Cli (#22)

* use activitysim_resources

Fixed auto sufficiency conditions in tour_mode_choice.csv. (Issue #324)

* correct write trip matrices sampling expansion and add vehicle occupancy to the expression file

* additional updates for estimation integration  (#328)

* improve LICENSE (#30)

* correct univ coeff template lookup (#28)

Co-authored-by: Clint Daniels <clint.daniels@wsp.com>
Co-authored-by: Blake <brosenthalpdx@gmail.com>
Co-authored-by: Blake Rosenthal <blake.rosenthal@rsginc.com>
Co-authored-by: Jeff Doyle <toliwaga@gmail.com>
Co-authored-by: Jeffrey Doyle <jeff.doyle@rsginc.com>
Co-authored-by: Jeffrey Newman <jeff@newman.me>
toliwaga added a commit that referenced this issue Sep 16, 2020
* publish v0.9.5 (#340)

* update docs, drop scripts no longer needed, include example files in package

* Pandas 1.0 fixes

* Location and mode choice logsums (#298)

* Tncs (#14)

* write trip matrices (#311)

* small fixes for semcog deployment (#319)

* improved validation diagnostics in trip_purpose and various windows-related int32/int64 conversions

* fix bug in handling of no viable trips case in choose_trip_destination

* major work on phase 5 (#325)

* estimation through atwork_subtour_mode_choice

* Tnc updates and notebooks (#18)

* move other resources into folder since examples now part of package as well

* add example zone shapefile

* estimation notebooks for larch (#19)

* multiprocessing related logging and error checking

* trip_destination handle all trips fail

* skim caching with numpy memmap to speed skim loading

* better chunking in vectorize_tour_scheduling

* Cli (#22)

* use activitysim_resources

Fixed auto sufficiency conditions in tour_mode_choice.csv. (Issue #324)

* correct write trip matrices sampling expansion and add vehicle occupancy to the expression file

* additional updates for estimation integration  (#328)

* improve LICENSE (#30)

* correct univ coeff template lookup (#28)

Co-authored-by: Clint Daniels <clint.daniels@wsp.com>
Co-authored-by: Blake <brosenthalpdx@gmail.com>
Co-authored-by: Blake Rosenthal <blake.rosenthal@rsginc.com>
Co-authored-by: Jeff Doyle <toliwaga@gmail.com>
Co-authored-by: Jeffrey Doyle <jeff.doyle@rsginc.com>
Co-authored-by: Jeffrey Newman <jeff@newman.me>

* Remove duplicate coefficient.

* move coefficient processing up

* Update joint_tour_destination.py

* Fix reference to joint tour destination.yaml

* Error check for COEFFICIENT files

* Add person_id to joint choosers.

* move notebooks to examples folder so they are installed and update docs as a result (#343)

* publish (#344)

* move notebooks to examples folder so they are installed and update docs as a result (#343)

* correct doc links

* Remove duplicate coefficient.

* move coefficient processing up

* Update joint_tour_destination.py

* Fix reference to joint tour destination.yaml

* Error check for COEFFICIENT files

* Add person_id to joint choosers.

* Remove duplicate coefficient.

* move coefficient processing up

* Update joint_tour_destination.py

* Fix reference to joint tour destination.yaml

* Error check for COEFFICIENT files

* Add person_id to joint choosers.

Co-authored-by: Ben Stabler <bstabler@users.noreply.github.com>
Co-authored-by: Blake <brosenthalpdx@gmail.com>
Co-authored-by: Blake Rosenthal <blake.rosenthal@rsginc.com>
Co-authored-by: Jeff Doyle <toliwaga@gmail.com>
Co-authored-by: Jeffrey Doyle <jeff.doyle@rsginc.com>
Co-authored-by: Jeffrey Newman <jeff@newman.me>
Co-authored-by: bstabler <benstabler@yahoo.com>
danielsclint pushed a commit to danielsclint/activitysim that referenced this issue Dec 15, 2020
…tivitySim#342)

* publish v0.9.5 (ActivitySim#340)

* update docs, drop scripts no longer needed, include example files in package

* Pandas 1.0 fixes

* Location and mode choice logsums (ActivitySim#298)

* Tncs (ActivitySim#14)

* write trip matrices (ActivitySim#311)

* small fixes for semcog deployment (ActivitySim#319)

* improved validation diagnostics in trip_purpose and various windows-related int32/int64 conversions

* fix bug in handling of no viable trips case in choose_trip_destination

* major work on phase 5 (ActivitySim#325)

* estimation through atwork_subtour_mode_choice

* Tnc updates and notebooks (ActivitySim#18)

* move other resources into folder since examples now part of package as well

* add example zone shapefile

* estimation notebooks for larch (ActivitySim#19)

* multiprocessing related logging and error checking

* trip_destination handle all trips fail

* skim caching with numpy memmap to speed skim loading

* better chunking in vectorize_tour_scheduling

* Cli (ActivitySim#22)

* use activitysim_resources

Fixed auto sufficiency conditions in tour_mode_choice.csv. (Issue ActivitySim#324)

* correct write trip matrices sampling expansion and add vehicle occupancy to the expression file

* additional updates for estimation integration  (ActivitySim#328)

* improve LICENSE (ActivitySim#30)

* correct univ coeff template lookup (ActivitySim#28)

Co-authored-by: Clint Daniels <clint.daniels@wsp.com>
Co-authored-by: Blake <brosenthalpdx@gmail.com>
Co-authored-by: Blake Rosenthal <blake.rosenthal@rsginc.com>
Co-authored-by: Jeff Doyle <toliwaga@gmail.com>
Co-authored-by: Jeffrey Doyle <jeff.doyle@rsginc.com>
Co-authored-by: Jeffrey Newman <jeff@newman.me>

* Remove duplicate coefficient.

* move coefficient processing up

* Update joint_tour_destination.py

* Fix reference to joint tour destination.yaml

* Error check for COEFFICIENT files

* Add person_id to joint choosers.

* move notebooks to examples folder so they are installed and update docs as a result (ActivitySim#343)

* publish (ActivitySim#344)

* move notebooks to examples folder so they are installed and update docs as a result (ActivitySim#343)

* correct doc links

* Remove duplicate coefficient.

* move coefficient processing up

* Update joint_tour_destination.py

* Fix reference to joint tour destination.yaml

* Error check for COEFFICIENT files

* Add person_id to joint choosers.

* Remove duplicate coefficient.

* move coefficient processing up

* Update joint_tour_destination.py

* Fix reference to joint tour destination.yaml

* Error check for COEFFICIENT files

* Add person_id to joint choosers.

Co-authored-by: Ben Stabler <bstabler@users.noreply.github.com>
Co-authored-by: Blake <brosenthalpdx@gmail.com>
Co-authored-by: Blake Rosenthal <blake.rosenthal@rsginc.com>
Co-authored-by: Jeff Doyle <toliwaga@gmail.com>
Co-authored-by: Jeffrey Doyle <jeff.doyle@rsginc.com>
Co-authored-by: Jeffrey Newman <jeff@newman.me>
Co-authored-by: bstabler <benstabler@yahoo.com>
bstabler added a commit that referenced this issue Jan 12, 2021
* Provide more flexibility for defining mandatory schedule specifications.

* provide more flexibility for time periods.

* Improve consistency in slicing and fix code syntax issues.

* Consistency and code syntax.

* code syntax.

* code syntax fixes.

* syntax fix.

* Add necessary change to test script settings.

* Modify relevant section of the settings.yml for tests and examples.

* restore 'hours' as deprecated for backwards compatibility.

* Add default value for period_minutes for backwards compatibilitiy.

* create develop branch so we can merge features here before merging (releasing) to master

* provide more flexibility for time periods.

* Improve consistency in slicing and fix code syntax issues.

* Consistency and code syntax.

* code syntax fixes.

* Modify relevant section of the settings.yml for tests and examples.

* restore 'hours' as deprecated for backwards compatibility.

* Add default value for period_minutes for backwards compatibilitiy.

* Fix overflows

* Complete testing of the flexible time periods.

* pep8

* test some floats too.

* pep8

* start with csvs and write hdf5 outputs if desired  (#290)

* add h5_store option to write_tables

* keep csv files as the default

* read input tables from CSV

* update docs, drop scripts no longer needed, include example files in package

* formatting

Co-authored-by: Blake <brosenthalpdx@gmail.com>

* Update travis.yml

* Pandas 1.0 fixes

* Location and mode choice logsums (#298)

* optional logsums for location_choice and tour destination models

* mode choice logsums for trous and trips

* trip DEST_CHOICE_SAMPLE_TABLE_NAME

* update docs for writing logsums and also a couple small development page updates

* fix small py2 py 3 compatibility issue

* py2 py3 compatibility

Co-authored-by: Blake <brosenthalpdx@gmail.com>
Co-authored-by: Jeff Doyle <toliwaga@gmail.com>

* Deprecate Py2 and add CLI

* Tncs (#14)

* add tncs

* lognormal_for_df broadcasts duplicate indexes

* lognormal_for_df broadcasts duplicate indexes code

* correct lognormal calculations and add functions to calculation lognormal location and scale

* clean-up tnc wait time expressions

* set taxi, tnc wait time standard deviations to zero until we have better data

* add scaled option to random.lognormal_for_df

* add mobility-as-a-service modes to docs

* updated tnc mode constants

* rename maas to ridehail

Co-authored-by: Jeff Doyle <toliwaga@gmail.com>
Co-authored-by: Blake Rosenthal <blake.rosenthal@rsginc.com>

* write trip matrices (#311)

require newer pandas

add ability to save trips table to pipeline and begin to finish example

all time periods

fix trip scheduling bug

add support for odt skims as well

Co-authored-by: Ben Stabler <benstabler@yahoo.com>

Co-authored-by: Blake Rosenthal <blake.rosenthal@rsginc.com>

* small fixes for semcog deployment (#319)

* improved validation diagnostics in trip_purpose and various windows-related int32/int64 conversions

* pycodestyle

* deprecations in test code

* fix bug in handling of no viable trips case in choose_trip_destination

* add trace folder to example_mtc output folder

Co-authored-by: Jeffrey Doyle <jeff.doyle@rsginc.com>
Co-authored-by: Jeff Doyle <toliwaga@gmail.com>

* major work on phase 5 (#325)

* estimation through atwork_subtour_mode_choice

* Tnc updates and notebooks (#18)

* move other resources into folder since examples now part of package as well

* add shapefile

* clean up folder setup

* estimation notebooks for larch (#19)

* multiprocessing related logging and error checking

* trip_destination handle all trips fail

* skim caching with numpy memmap to speed skim loading

* better chunking in vectorize_tour_scheduling

* Cli (#22)

* use activitysim_resources

Fixed auto sufficiency conditions in tour_mode_choice.csv. (Issue #324)

* increment to version 0.9.5

* correct write trip matrices sampling expansion and add vehicle occupancy to the expression file

* updates to documentation for phase 5 work except multiple zone systems

* additional updates for estimation integration  (#328)

* estimation integration updates #327
* drop module no longer needed

* update license, fix univ coeff bug, update estimation example (#339)

* improve example setup for specifying input tables (#27)
* improve LICENSE (#30)
* correct univ coeff template lookup (#28)

* add license to package (#341)

* move notebooks to examples folder so they are installed and update docs as a result (#343)

* correct doc links

* Address Minor Issues Associated with ARC Update to Develop Branch (#342)

* publish v0.9.5 (#340)

* update docs, drop scripts no longer needed, include example files in package

* Pandas 1.0 fixes

* Location and mode choice logsums (#298)

* Tncs (#14)

* write trip matrices (#311)

* small fixes for semcog deployment (#319)

* improved validation diagnostics in trip_purpose and various windows-related int32/int64 conversions

* fix bug in handling of no viable trips case in choose_trip_destination

* major work on phase 5 (#325)

* estimation through atwork_subtour_mode_choice

* Tnc updates and notebooks (#18)

* move other resources into folder since examples now part of package as well

* add example zone shapefile

* estimation notebooks for larch (#19)

* multiprocessing related logging and error checking

* trip_destination handle all trips fail

* skim caching with numpy memmap to speed skim loading

* better chunking in vectorize_tour_scheduling

* Cli (#22)

* use activitysim_resources

Fixed auto sufficiency conditions in tour_mode_choice.csv. (Issue #324)

* correct write trip matrices sampling expansion and add vehicle occupancy to the expression file

* additional updates for estimation integration  (#328)

* improve LICENSE (#30)

* correct univ coeff template lookup (#28)

Co-authored-by: Clint Daniels <clint.daniels@wsp.com>
Co-authored-by: Blake <brosenthalpdx@gmail.com>
Co-authored-by: Blake Rosenthal <blake.rosenthal@rsginc.com>
Co-authored-by: Jeff Doyle <toliwaga@gmail.com>
Co-authored-by: Jeffrey Doyle <jeff.doyle@rsginc.com>
Co-authored-by: Jeffrey Newman <jeff@newman.me>

* Remove duplicate coefficient.

* move coefficient processing up

* Update joint_tour_destination.py

* Fix reference to joint tour destination.yaml

* Error check for COEFFICIENT files

* Add person_id to joint choosers.

* move notebooks to examples folder so they are installed and update docs as a result (#343)

* publish (#344)

* move notebooks to examples folder so they are installed and update docs as a result (#343)

* correct doc links

* Remove duplicate coefficient.

* move coefficient processing up

* Update joint_tour_destination.py

* Fix reference to joint tour destination.yaml

* Error check for COEFFICIENT files

* Add person_id to joint choosers.

* Remove duplicate coefficient.

* move coefficient processing up

* Update joint_tour_destination.py

* Fix reference to joint tour destination.yaml

* Error check for COEFFICIENT files

* Add person_id to joint choosers.

Co-authored-by: Ben Stabler <bstabler@users.noreply.github.com>
Co-authored-by: Blake <brosenthalpdx@gmail.com>
Co-authored-by: Blake Rosenthal <blake.rosenthal@rsginc.com>
Co-authored-by: Jeff Doyle <toliwaga@gmail.com>
Co-authored-by: Jeffrey Doyle <jeff.doyle@rsginc.com>
Co-authored-by: Jeffrey Newman <jeff@newman.me>
Co-authored-by: bstabler <benstabler@yahoo.com>

* fix #288 chunk joint_touyr_participation by chunk_id and update tests to catch such errors

* gitignore trivia

* Support for Multiple Zone Systems and Transit Virtual Path Building (#362)

* TransitVirtualPathBuilder first cut - get_tvpb_logsum computes logsums on demand

* tour_mode_choice logsums for 3-zone working for school and workplace location

* z3 running all models, but with hacked trip_mode_choice (no coefficient templates)

* z3 running all models

* passing tests

* pcodestyle passes

* refactored test teardown

* tvpb tracing

* tvpb tracing roughout

* build multizone test data before running test

* read_settings_file support include_settings

* read_settings_file support include_settings

* move constants to configs yaml and expressions from abm.util to core

* tvpb estimate_chunk_overhead

* adaptive chunking

* fixed bug in trip scheduling when no trips in leg after iteration

* 3 zone tap_tap uniquify

* tvpb TableCache

* tvpb TableCache - all fiiels

* 3 zone with feather cache

* tidy up notes around creating the marin example

* memmap skims

* memmap skims

* correct drive transit cost expression for miles/feet.  Still need to add some additional missing expressions now that everything appears to be working correctly.

* skim docstrings

* disable 3 zone tap_tap caching for traced taps

* initialize_los

* 3 zone mp plumbing untested

* THREE_ZONE tvpb multiprocessing tests and fixes

* THREE_ZONE tvpb multiprocessing tests and fixes

* reanme core tvpb and cache modules

* reanme core tvpb and cache modules

* util.iprod alias for np.prod with dtype int64

* THREE_ZONE cache initialization bug bixes

* multizone bug fixes

* bugs

* multiprocessing mjultizone tweaks

* tvpb cacha\e as array

* complain if apporting with more process than slice rows

* complain if apporting with more process than slice rows

* chunk initialize_tvpb

* shorter trace file names because windows

* refactor pathbuilder sans DYNAMIC

* fix tour_scheduling_calc_row_size

* fix multiprocess resume across mp step bug

* pycodestyle

* minor chunk cleanup

* allow MemMapSkimFactory multiprocessing

* consolidate mtc and multizone configs

* commit updated marin example config files

* some more marin example config updates

* add validation summaries script

* some additional marin example updates

* update example skim time period settings to align with tm1 (#360)

* update example settings to align with tm1

* correct home_is_rural coding since tm1 was incorrect

* corrected skim time periods go in network_los.yaml now

* travis depends on these scripts for testing

* improve logging and increase travis timeout

* #359 (#364)

* updates for CDAP person type mapping

* allow duplicate time labels

* fix a copy small items for #359

* test updates

* pycodestyle

* 3 zone test fix

Co-authored-by: Clint Daniels <clint.daniels@wsp.com>

* longer travis timeout and avoid file permissions between tests related to caching

* test-travis

* ls fix

* add timeout

* fix path

* put in both locations for now

* reduce household sample sizes for tests to avoid travis timeout

* not sure what's taking so long with the second and third tests.  It runs in 40 minutes with py 3.7 on my computer as well

* linux file paths

* cli test depends on py 3.7+

* add coveralls back

* test new architecture

* try build matrix

* setup environments

* correct matrix expansion

* correct duplicate key

* correct key

* correct env usage

* no need to specify architecture

* update inject settings for tests

* updated examples to use activitysim resources repo

* rename folder

* update survey test files so all example_manifest.yaml examples now running

* updated notebooks, default settings for examples, and updated rst files

* fix a couple typos

* add comments to travis script

* ARC Updates (#365)

Add parking_location_choice, trip_departure_choice, and trip_scheduling_choice models.

* add example_mtc_arc_extensions so arc extensions can be run and tested

* small doc update

* fix arc extensions example

Co-authored-by: Clint Daniels <clint.daniels@wsp.com>
Co-authored-by: Blake <brosenthalpdx@gmail.com>
Co-authored-by: Blake Rosenthal <blake.rosenthal@rsginc.com>
Co-authored-by: Jeff Doyle <toliwaga@gmail.com>
Co-authored-by: Jeffrey Doyle <jeff.doyle@rsginc.com>
Co-authored-by: Jeffrey Newman <jeff@newman.me>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants