Skip to content

Conversation

dhensle
Copy link
Contributor

@dhensle dhensle commented Dec 17, 2024

Estimation work as part of ActivitySim's Phase 9B development effort.

  • Implement multiprocessing for estimation mode
  • Implement destination choice sampling in estimation mode
  • Change the formatting and data written to EDBs
  • Update Larch integration to accept new file formats
  • Functionality to quickly test different specifications
  • Improved larch reporting on estimated models
  • Adding "predict" functionality with estimated models in larch
  • Unit testing for the above features
  • Updated documentation

dhensle and others added 30 commits August 16, 2024 17:33
* pydantic for estimation settings

* allow df as type in config

* fix table_info

* repair for Pydantic

* df is attribute
* pydantic for estimation settings

* allow df as type in config

* fix table_info

* auto ownership

* repair for pydantic

* update for ruff

* updated for simple models

* repair for Pydantic

* simple simulate and location choice

* df is attribute

* scheduling

* stop freq

* test locations

* cdap

* nonmand_and_joint_tour_dest_choice

* nonmand_tour_freq

* fix ci to stop using mamba

* test updates

* use larch6 from pip

* use numba for stop freq

* fix for pandas 1.5

* fix stop freq test for numba

* Sharrow Cache Dir Setting (ActivitySim#893)

* setting necessary filesystem changes from settings file

* set for multiprocessing

* repair github actions

* github action updates (ActivitySim#903)

* script to make data

* unified script for making data

* remove older

* bug

* doc note

* load from parquet if available

* add original alt ids to EDB output when using compact

* fix MP race

* script arg to skip to EDB

* clean up CDAP and blacken

* refactor model_estimation_table_types

change to estimation_table_types, to avoid pydantic namespace clash

* repair drop_dupes

* blacken

* location choice with compact

* choice_def for compact

* spec changes for simple-simulate

* re-estimation demo for auto ownership

* clean up status messages

* change name to stop pydantic warnings

* edit configs

* default estimation sample size is same as regular sample size

* allow location alts not in cv format

* dummy zones for location choice

* update scheduling model estimation

* various cleanup

* stop freq

* tidy build script

* update 02 school location for larger example

* update notebook 04

* editable model re-estimation for location choice

* fix test names

* update notebooks

* cdap print filenames as loading

* notebook 07

* tests thru 07

* notebooks 08 09

* build the data first

* runnable script

* change larch version dependency

* keep pandas<2

* notebooks 10 11

* notebook 12

* remove odd print

* add matplotlib

* notebook 13 14

* test all the notebooks

* add xlsxwriter to tests

* notebook 15

* CDAP revise model spec demo

* notebook 16

* notebook 17

* longer timeout

* notebook 18

* notebook 19

* notebook 20

* smaller notebook 15

* configurable est mode setup

* notebook 21

* notebook 22

* config sample size in GA

* notebook 23

* updates for larch and graphviz

* change default to compact

* compare model 03

* test updates

* rename test targets

* repair_av_zq

* move doctor up

* add another repair

* oops

---------

Co-authored-by: David Hensle <51132108+dhensle@users.noreply.github.com>
@jpn--
Copy link
Member

jpn-- commented Jun 24, 2025

@asiripanich, this is a sharrow-related error. I'll take a look at it and see if I can figure out what's wrong...

Thanks @dhensle for your response.

I ran into an issue today while trying to add a new utility term to the tour mode choice spec of my tour mode choice EDB. This might be a bug or something that needs to be explained a bit more in the documentation. (However, I didn't have any issues modifying or adding new terms to the auto_ownership model. Despite this minor issue, I'm loving this new capability!)

When I tried to add a new line to my tour mode choice spec file, I kept getting this error:

modelname = "tour_mode_choice"

from activitysim.estimation.larch import component_model

model, data = component_model(
    modelname,
    edb_directory=f"output/estimation_data_bundle/{modelname}/",
    return_data=True,
)

> loading from output/estimation_data_bundle/tour_mode_choice/tour_mode_choice_coefficients.csv
> loading from output/estimation_data_bundle/tour_mode_choice/tour_mode_choice_coefficients_template.csv
> loading spec from output/estimation_data_bundle/tour_mode_choice/tour_mode_choice_SPEC.csv
> loading from output/estimation_data_bundle/tour_mode_choice/tour_mode_choice_values_combined.parquet
> unable to rewrite 'util_test' to itself

I tested this using example_estimation and 17_tour_mode_choice.ipynb from this PR.

I added these following lines:

tour_mode_choice_SPEC.csv

util_test,Drive alone not available for escort tours,1,coef_test,,,,,,,,,,,,,,,,,,,,

tour_mode_choice_coefficients_template.csv

coef_test,coef_test_eatout_escort_othdiscr_othmaint_shopping_social_work_atwork,coef_test_eatout_escort_othdiscr_othmaint_shopping_social_work_atwork,coef_test_eatout_escort_othdiscr_othmaint_shopping_social_work_atwork,coef_test_eatout_escort_othdiscr_othmaint_shopping_social_work_atwork,coef_test_school_univ,coef_test_eatout_escort_othdiscr_othmaint_shopping_social_work_atwork,coef_test_eatout_escort_othdiscr_othmaint_shopping_social_work_atwork,coef_test_school_univ,coef_test_eatout_escort_othdiscr_othmaint_shopping_social_work_atwork,coef_test_eatout_escort_othdiscr_othmaint_shopping_social_work_atwork

tour_mode_choice_coefficients.csv

coef_test_eatout_escort_othdiscr_othmaint_shopping_social_work_atwork,0,F
coef_test_school_univ,0,F

Any advice on what I might be doing wrong would be greatly appreciated. 😀

See full error

@jpn--
Copy link
Member

jpn-- commented Jun 26, 2025

@asiripanich, turns out you were doing nothing wrong, you just happened to find a bug -- a couple arguments were missing from the code to re-estimate the mode choice models. I've fixed it, and taken your edits to create an example / unit test of re-estimation on the tour mode choice notebook. If you try again it should work now. 😄

jpn-- added 4 commits June 26, 2025 10:46
# Conflicts:
#	.github/workflows/core_tests.yml
#	conda-environments/activitysim-dev-base.yml
#	conda-environments/activitysim-dev.yml
#	conda-environments/docbuild.yml
#	conda-environments/github-actions-tests.yml
@asiripanich
Copy link
Contributor

@asiripanich, turns out you were doing nothing wrong, you just happened to find a bug -- a couple arguments were missing from the code to re-estimate the mode choice models. I've fixed it, and taken your edits to create an example / unit test of re-estimation on the tour mode choice notebook. If you try again it should work now. 😄

@jpn-- Brilliant! I was away and haven't had a chance to test the new changes in this PR yet, but I'm looking forward to trying it out. I remember seeing this feature was planned for v1.4.0... is there an updated timeline for its release?

@bhargavasana
Copy link
Collaborator

bhargavasana commented Aug 13, 2025

Would it be possible to confirm that this issue still exists #595 ? Also #752 please.

@bhargavasana
Copy link
Collaborator

@dhensle please confirm that this PR fixes #897

@dhensle
Copy link
Contributor Author

dhensle commented Aug 26, 2025

@dhensle please confirm that this PR fixes #897

Yes, closed that issue under the assumption this will be pulled in shortly.

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 this pull request may close these issues.

5 participants