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

Mandatory tour generation model #19

Merged
merged 3 commits into from
Mar 9, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions activitysim/defaults/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ def income_segment(households):
labels=[1, 2, 3, 4])


@sim.column("households")
def non_workers(households, persons):
return persons.household_id.value_counts() - households.workers


@sim.column("households")
def drivers(households, persons):
# we assume that everyone 16 and older is a potential driver
Expand Down
64 changes: 64 additions & 0 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
This is a list of items to double check before using in practice:

* Make sure the units in things like distance_to_work match the walk thresholds
in the mandatory tour frequency spec. The original divided by 100. This is
true also of round trip auto to work and round trip auto to school.

* There might be a few variables left off of some of the models. Look for
`head` in reading of the spec files as this is meant to eliminate some of the
rows. Also can look for `#` to comment out variables in the spec.

* Go back to the 3 school location choices, and run the models for the
appropriate persons.

* Probably needs code review of the variable definitions. How much of the
variable definitions are shared between regions and how much unique? Age
categories are shared? Income categories are unique?




A few overarching principles

* A little discussion of "NOT so object oriented" - this is more like a
database - data is in standard tables, NOT in objects

* The implications of this are that most of the core code is pandas and thus
the quality is controlled by the larger community. We are thankful that its
quality is very high. Specifically, there's not so much code in activitysim
"proper"

* What it takes to add a new model
* define a new model
* define any new data sources necessary
* add any new assumptions in settings.yaml
* co-create the spec and any variables that are too complicated (or
reusable) for the spec
* run in notebook

* Literally everything is really Python functions that compute something.
Case study of `num_under16_not_at_school` to show the inter-dependencies.




A few questions about "best practices"

* What to put into the default data sources and variable specs and what to
put in the example / client-specific stuff?

* Want to split up injectables from variables from tables or all one big file
so it's easier to search?

* How much variable computation to put in excel versus Python

* There were some hard coded limits in the original csv - (area_type < 4 and
distance_to_work < 3) - these are now just left in the csv spec. Why would
this be different than (income_in_thousands > 50)? I've made an effort to
not have such "magic numbers" in Python code. (Elizabeth: MAX_NUM_AUTOS
exists now)

* Want to name or number the person types in the spec files?

* Testing for client-specific code? It's harder because outputs are "data
dependent." It's easier to take a small dataset and make sure it always runs.
30 changes: 30 additions & 0 deletions example/configs/auto_ownership.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Description,Expression,cars0,cars1,cars2,cars3,cars4
2 Adults (age 16+),drivers==2,,0,3.0773,3.1962,2.6616
3 Adults (age 16+),drivers==3,,0,3.5401,5.5131,5.208
4+ Adults (age 16+),drivers>3,,2.0107,6.3662,8.5148,9.5807
Persons age 16-17,num_adolescents,,0,-0.881,-1.7313,-1.7313
Persons age 18-24,num_college_age,,-0.4087,-1.0095,-1.0107,-1.0107
Persons age 35-34,num_young_adults,,0,-0.4849,-0.8596,-0.8596
Presence of children age 0-4,num_young_children>0,,0.3669,0.7627,0.7627,0.7627
Presence of children age 5-17,(num_children+num_adolescents)>0,,0.0158,0.2936,0.4769,0.4769
"Number of workers, capped at 3",@df.workers.clip(upper=3),,0,0.2936,0.6389,0.8797
"Piecewise Linear household income, $0-30k","@df.income_in_thousands.clip(0, 30)",,0.0383,0.054,0.0559,0.0619
"Piecewise Linear household income, $30-75k","@(df.income_in_thousands-30).clip(0, 45)",,0,0.0083,0.011,0.0147
"Piecewise Linear household income, $75k+, capped at $125k","@(df.income_in_thousands-75).clip(0, 50)",,0,0.0083,0.011,0.0147
"Density index up to 10, if 0 workers","@(df.workers==0)*df.density_index.clip(0, 10)",,0,-0.2028,-0.3654,-0.3654
"Density index in excess of 10, if 0 workers",@(df.workers==0)*(df.density_index-10).clip(0),,-0.0152,-0.1106,-0.1766,-0.1766
"Density index up to 10, if 1+ workers","@(df.workers>0)*df.density_index.clip(0, 10)",,0,-0.2028,-0.3654,-0.3654
"Density index in excess of 10, if 1+ workers",@(df.workers>0)*(df.density_index-10).clip(0),,-0.0152,-0.1106,-0.1766,-0.1766
Constants,@1,,1.1865,-1.0846,-3.2502,-5.313
San Francisco county,county_name == 'San Francisco',,0.4259,0.4683,0.1458,0.1458
Solano county,county_name == 'Solano',,-0.566,-0.4429,-0.2372,-0.2372
Napa county,county_name == 'Napa',,-0.566,-0.4429,-0.2372,-0.2372
Sonoma county,county_name == 'Sonoma',,-0.566,-0.4429,-0.2372,-0.2372
Marin county,county_name == 'Marin',,-0.2434,0,0,0
"Retail accessibility (0.66*PK + 0.34*OP) by auto, if 0 workers",(workers==0)*(0.66*AUTOPEAKRETAIL+0.34*AUTOOFFPEAKRETAIL),,0.0626,0.0626,0.0626,0.0626
"Retail accessibility (0.66*PK + 0.34*OP) by auto, if 1+ workers",(workers>0)*(0.66*AUTOPEAKRETAIL+0.34*AUTOOFFPEAKRETAIL),,0.1646,0.1646,0.1646,0.1646
"Retail accessibility (0.66*PK + 0.34*OP) by transit, if 0 workers",(workers==0)*(0.66*TRANSITPEAKRETAIL+0.34*TRANSITOFFPEAKRETAIL),,-0.3053,-0.3053,-0.3053,-0.3053
"Retail accessibility (0.66*PK + 0.34*OP) by transit, if 1+ workers",(workers>0)*(0.66*TRANSITPEAKRETAIL+0.34*TRANSITOFFPEAKRETAIL),,-0.5117,-0.5117,-0.5117,-0.5117
"Retail accessibility by non-motorized, if 0 workers",(workers==0)*NONMOTORIZEDRETAIL,,-0.03,-0.03,-0.03,-0.03
"Retail accessibility by non-motorized, if 1+ workers",(workers>0)*NONMOTORIZEDRETAIL,,-0.03,-0.03,-0.03,-0.03
"Auto time savings per worker (over walk or transit, max 120) to work",workTourAutoTimeSavings/workers,,0.4707,0.6142,0.5705,0.7693
1 change: 0 additions & 1 deletion example/configs/auto_ownership_coeffs.csv

This file was deleted.

100 changes: 100 additions & 0 deletions example/configs/mandatory_tour_frequency.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
Description,Expression,work1,work2,school1,school2,work_and_school
Full-time worker alternative-specific constants,ptype == 1,0,-3.3781,,,
Part-time worker alternative-specific constants,ptype == 2,0,-3.0476,,,
University student alternative-specific constants,ptype == 3,2.166,-1.3965,0,-3.7429,0.1073
Non-working adult alternative-specific constants,ptype == 4,,,,,
Retired alternative-specific constants,ptype == 5,,,,,
Driving-age child alternative-specific constants,ptype == 6,,,0,-3.136,-4.4362
Pre-driving age child who is in school alternative-specific constants,ptype == 7,,,0,-3.9703,
Female - Full-time worker interaction,(ptype == 1) & (sex == 2),0,-0.2255,0.1592,,-0.3442
Female - Part-time worker interaction,(ptype == 2) & (sex == 2),0,-0.2255,0.1592,,-0.3442
Female - University student interaction,(ptype == 3) & (sex == 2),0.1737,-0.2255,0.1592,0.114,-0.3442
Female - Non-working adult interaction,(ptype == 4) & (sex == 2),0,-0.2255,0.1592,,
Female - Retired interaction,(ptype == 5) & (sex == 2),0,-0.2255,0.1592,,
Female - Driving-age child interaction,(ptype == 6) & (sex == 2),0.1737,,0,0.114,-0.3442
Female - Pre-driving age child who is in school interaction,(ptype == 7) & (sex == 2),0.1737,,0,0.114,
Under 35 - Full-time worker interaction,(ptype == 1) & (age <= 35),0,-0.1375,0.7218,,0.9761
Under 35 - Part-time worker interaction,(ptype == 2) & (age <= 35),0,-0.1375,0.7218,,0.9761
Under 35 - University student interaction,(ptype == 3) & (age <= 35),-0.4629,-0.1375,0,1.275,0.9761
Under 35 - Non-working adult interaction,(ptype == 4) & (age <= 35),0,-0.1375,0.7218,,
Can walk to work - Full-time worker interaction,(ptype == 1) & (distance_to_work < 3),,0.5268,,,
Can walk to work - Part-time worker interaction,(ptype == 2) & (distance_to_work < 3),,0.5268,,,
Can walk to work - University student interaction,(ptype == 3) & (distance_to_work < 3),,0.5268,,,
Can walk to work - Non-working adult interaction,(ptype == 4) & (distance_to_work < 3),,0.5268,,,
Can walk to work - Retired interaction,(ptype == 5) & (distance_to_work < 3),,0.5268,,,
Can walk to school - University student interaction,(ptype == 3) & (distance_to_school < 3),,,,0.7114,
Can walk to school - Driving-age child interaction,(ptype == 6) & (distance_to_school < 3),,,,0.7114,
Can walk to school - Pre-driving age child who is in school interaction,(ptype == 7) & (distance_to_school < 3),,,,0.7114,
Can walk to work or school - Full-time worker interaction,(ptype == 1) & (distance_to_work < 3 | distance_to_school < 3),,,,,0.1391
Can walk to work or school - Part-time worker interaction,(ptype == 2) & (distance_to_work < 3 | distance_to_school < 3),,,,,0.1391
Can walk to work or school - University student interaction,(ptype == 3) & (distance_to_work < 3 | distance_to_school < 3),,,,,0.1391
Can walk to work or school - Driving-age child interaction,(ptype == 6) & (distance_to_work < 3 | distance_to_school < 3),,,,,0.1391
Round trip auto time to work - Full-time worker interaction,(ptype == 1) * roundtrip_auto_time_to_work,,-0.0035,,,-0.0031
Round trip auto time to work - Part-time worker interaction,(ptype == 2) * roundtrip_auto_time_to_work,,-0.0035,,,-0.0031
Round trip auto time to work - University student interaction,(ptype == 3) * roundtrip_auto_time_to_work,,-0.0035,,,-0.0031
Round trip auto time to work - Non-working adult interaction,(ptype == 4) * roundtrip_auto_time_to_work,,-0.0035,,,
Round trip auto time to work - Retired,(ptype == 5) * roundtrip_auto_time_to_work,,-0.0035,,,
Round trip auto time to school - University student interaction,(ptype == 3) * roundtrip_auto_time_to_school,,,,-0.0034,-0.0031
Round trip auto time to school - Driving-age child interaction,(ptype == 6) * roundtrip_auto_time_to_school,,,,-0.0034,-0.0031
Round trip auto time to school - Pre-driving age child who is in school interaction,(ptype == 7) * roundtrip_auto_time_to_school,,,,-0.0034,
Student is employed - University student interaction,(ptype == 3) & student_is_employed,3.014,3.014,,,3.014
Student is employed - Driving-age child interaction,(ptype == 6) & student_is_employed,3.014,3.014,,,3.014
Non-student goes to school - Full-time worker interaction,(ptype == 1) & nonstudent_to_school,,,3.883,,3.883
Non-student goes to school - Part-time worker interaction,(ptype == 2) & nonstudent_to_school,,,3.883,,3.883
Non-student goes to school - Non-working adult interaction,(ptype == 4) & nonstudent_to_school,,,3.883,,
Non-student goes to school - Retired interaction,(ptype == 5) & nonstudent_to_school,,,3.883,,
No cars in household - Full-time worker interaction,(ptype == 1) & (auto_ownership == 0),,-1.306,,,-1.302
No cars in household - Part-time worker interaction,(ptype == 2) & (auto_ownership == 0),,-1.306,,,-1.302
No cars in household - University student interaction,(ptype == 3) & (auto_ownership == 0),,-1.306,,-1.413,-1.302
No cars in household - Non-working adult interaction,(ptype == 4) & (auto_ownership == 0),,-1.306,,,
No cars in household - Retired interaction,(ptype == 5) & (auto_ownership == 0),,-1.306,,,
No cars in household - Driving-age student interaction,(ptype == 6) & (auto_ownership == 0),,,,-1.413,-1.302
No cars in household - Pre-driving age child who is in school interaction,(ptype == 7) & (auto_ownership == 0),,,,-1.413,
Fewer cars than drivers in household - University student interaction,(ptype == 3) & (auto_ownership < drivers),,,,-0.5759,
Fewer cars than drivers in household - Driving-age student interaction,(ptype == 6) & (auto_ownership < drivers),,,,-0.5759,
Fewer cars than drivers in household - Pre-driving age child who is in school interaction,(ptype == 7) & (auto_ownership < drivers),,,,-0.5759,
Number of preschool children in household - Full-time worker interaction,(ptype == 1) * (num_young_children),0,-0.1478,-0.1335,,-0.1251
Number of preschool children in household - Part-time worker interaction,(ptype == 2) * (num_young_children),0,-0.1478,-0.1335,,-0.1251
Number of preschool children in household - University student interaction,(ptype == 3) * (num_young_children),0.2191,-0.1478,0,-0.5577,-0.1251
Number of preschool children in household - Non-working adult interaction,(ptype == 4) * (num_young_children),0,-0.1478,-0.1335,,
Number of preschool children in household - Retired interaction,(ptype == 5) * (num_young_children),0,-0.1478,-0.1335,,
Number of preschool children in household - Driving-age student interaction,(ptype == 6) * (num_young_children),0.2191,,0,-0.5577,-0.1251
Number of preschool children in household - Pre-driving age child who is in school interaction,(ptype == 7) * (num_young_children),0.2191,,0,-0.5577,
Number of non-workers in the household - Full-time worker interaction,(ptype == 1) * non_workers,,,0.2574,,
Number of non-workers in the household - Part-time worker interaction,(ptype == 2) * non_workers,,,0.2574,,
Household income higher than $50k - Full-time worker interaction,(ptype == 1) & (income_in_thousands > 50),0,,0.0347,,0.0347
Household income higher than $50k - Part-time worker interaction,(ptype == 2) & (income_in_thousands > 50),0,,0.0347,,0.0347
Household income higher than $50k - University student interaction,(ptype == 3) & (income_in_thousands > 50),-0.0528,-0.0528,0,,-0.0528
Household income higher than $50k - Non-working adult interaction,(ptype == 4) & (income_in_thousands > 50),0,,0.0347,,
Household income higher than $50k - Retired interaction,(ptype == 5) & (income_in_thousands > 50),0,,0.0347,,
Household income higher than $50k - Driving-age student interaction,(ptype == 6) & (income_in_thousands > 50),-0.0528,,0,,-0.0528
Household income higher than $50k - Pre-driving age child who is in school interaction,(ptype == 7) & (income_in_thousands > 50),-0.0528,,0,,
Non-family household - Full-time worker interaction,(ptype == 1) & non_family,0,,-0.25,,-0.25
Non-family household - Part-time worker interaction,(ptype == 2) & non_family,0,,-0.25,,-0.25
Non-family household - University student interaction,(ptype == 3) & non_family,-0.1792,-0.1792,0,,-0.1792
Non-family household - Non-working adult interaction,(ptype == 4) & non_family,0,,-0.25,,
Non-family household - Retired interaction,(ptype == 5) & non_family,0,,-0.25,,
Non-family household - Driving-age student interaction,(ptype == 6) & non_family,-0.1792,,0,,-0.1792
Non-family household - Pre-driving age child who is in school interaction,(ptype == 7) & non_family,-0.1792,,0,,
Number of children under 16 not at school - Full-time worker interaction,(ptype == 1) * num_under16_not_at_school,,0.1804,,,-0.1955
Number of children under 16 not at school - Part-time worker interaction,(ptype == 2) * num_under16_not_at_school,,0.1804,,,-0.1955
Number of children under 16 not at school - University student interaction,(ptype == 3) * num_under16_not_at_school,,0.1804,,0.0866,-0.1955
Number of children under 16 not at school - Non-working adult interaction,(ptype == 4) * num_under16_not_at_school,,0.1804,,,
Number of children under 16 not at school - Retired,(ptype == 5) * num_under16_not_at_school,,0.1804,,,
Number of children under 16 not at school - Driving-age student interaction,(ptype == 6) * num_under16_not_at_school,,,,0.0866,-0.1955
Number of children under 16 not at school - Pre-driving age child who is in school interaction,(ptype == 7) * num_under16_not_at_school,,,,0.0866,
Home is in urban area - Full-time worker interaction,(ptype == 1) & (area_type < 4),0,0.2308,-0.1361,,-0.3509
Home is in urban area - Part-time worker interaction,(ptype == 2) & (area_type < 4),0,0.2308,-0.1361,,-0.3509
Home is in urban area - University student interaction,(ptype == 3) & (area_type < 4),-0.2831,0.2308,0,0.317,-0.3509
Home is in urban area - Non-working adult interaction,(ptype == 4) & (area_type < 4),0,0.238,-0.1361,,
Home is in urban area - Retired interaction,(ptype == 5) & (area_type < 4),0,0.2308,-0.1361,,
Home is in urban area - Driving-age student interaction,(ptype == 6) & (area_type < 4),-0.2831,,0,0.317,-0.3509
Home is in urban area - Pre-driving age child who is in school interaction,(ptype == 7) & (area_type < 4),-0.2831,,0,0.317,
Unavailable: Full-time worker,ptype == 1,,,,-999,
Unavailable: Part-time worker,ptype == 2,,,,-999,
Unavailable: Non-working adult,ptype == 4,,,,-999,-999
Unavailable: Retired,ptype == 5,,,,-999,-999
Unavailable: Driving-age child,ptype == 6,-999,-999,,,
Unavailable: Pre-driving age child who is in school,ptype == 7,,-999,,,-999
Unavailable: Work tours for those with no usual work location,~(workplace_taz > -1),-999,-999,,,-999
Unavailalbe: School tours for those with no usual school location,~(school_taz > -1),,,-999,-999,-999
33 changes: 32 additions & 1 deletion example/configs/settings.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
store: mtc_asim.h5

households_sample_size: 100000
households_sample_size: 10000

county_map:
San Francisco: 1
Expand All @@ -12,3 +12,34 @@ county_map:
Napa: 7
Sonoma: 8
Marin: 9

employment_map:
1: "full"
2: "part"
3: "not"
4: "child"

student_map:
1: "high"
2: "college"
3: "not"

person_type_map:
1: "full"
2: "part"
3: "university"
4: "nonwork"
5: "retired"
6: "driving"
7: "school"
8: "preschool"

household_type_map:
0: "null"
1: "family_married"
2: "family_male"
3: "family_female"
4: "nonfamily_male_alone"
5: "nonfamily_male_notalone"
6: "nonfamily_female_alone"
7: "nonfamily_female_notalone"
Loading