Calibrating parameters#
Every number openmobisim assumes is a named parameter with a default. You can list them all, change any by name, and the run records what you changed. The defaults are not calibrated: each comes from a published source or is stated as an assumption (Parameters gives the source of each). For a study, calibrate the ones your results depend on against your own data.
Every parameter in one table#
import pandas as pd
import openmobisim as ms
table = pd.DataFrame(ms.parameters()) # group, argument, name, value, unit, note
table[table.name.str.contains("walk_max")]
group argument name value unit
107 modes mode_options walk_max_s 1800.0 s
112 transit transit_options access_walk_max_s 1800.0 s
114 transit transit_options transfer_walk_max_s 300.0 s
121 parking parking_options walk_max_s 300.0 s
The argument column tells you where to change a parameter:
Group |
Parameters |
Change it through |
|---|---|---|
|
95: speeds, lanes, saturation flows and jam densities by road class; signals; the bike and walk layers |
|
|
6: priority at merges, rerouting, turn pockets |
|
|
6: the longest walk and ride offered, the car fallback, the car’s access and egress times and where car trips join the roads |
|
|
11: walks to and between stops, boarding, journey limits, buses on the roads |
|
|
13: walks, reach, candidates, bins |
|
|
7: running costs, fares, parking fees |
|
|
7: the flow level and step, the window, the seed, the choice-set limits |
the |
|
10 |
|
|
12 |
|
|
4 |
|
|
79: the coefficients of |
|
Changing them by name#
network = ms.network_read_osm(
"city.osm.pbf",
network_options={"residential.free_flow_km_h": 25, "signal_cycle_s": 80},
)
scenario = ms.Scenario.from_parts(
network, trips,
mode_options={"bike_max_s": 2700}, # offer rides of up to 45 minutes
choice_options={"beta_time_min": -0.12}, # the weight of a minute in the utility
)
Or with the typed classes, one per group, whose keywords an editor completes with their defaults:
network = ms.network_read_osm(
"city.osm.pbf",
network_options=ms.NetworkOptions(signal_cycle_s=80, residential=ms.LinkClassOptions(free_flow_km_h=25)),
)
scenario = ms.Scenario.from_parts(
network, trips,
mode_options=ms.ModeOptions(bike_max_s=2700),
choice_options=ms.NestedLogitOptions(beta_time_min=-0.12),
)
Each class (NetworkOptions, LoadingOptions, ModeOptions, TransitOptions, ParkingOptions, PriceOptions,
MsaOptions, FreeFlowOptions, PenaltyOptions, MonteCarloOptions, BestResponseOptions, LogitOptions,
NestedLogitOptions) is a read-only dict of the options given, so it goes wherever the dict goes and the two make the
same run. A misspelt keyword fails where it is written. The two options whose default is a rule of the flow level
(reroute, increments) read None until you set them.
A misspelt name is refused, with the list of valid ones. Network options are checked when the network is read; the others when the scenario runs:
ValueError: mode_options has no "walk_max"; the options are: walk_max_s, bike_max_s, fallback_car, car_access_s, car_egress_s, car_snap_motorway_m
ValueError: no network option called "motorway.free_flow_kmh"; the options are: bike_dedicated_km_h, …
A coefficient no alternative carries is refused in the same way, with the attributes the alternatives carry.
To read a network’s values back, call ms.network_options(network). Without a network, it lists the shipped values.
Coefficients by class#
A traveller class may set its own coefficients: any beta_* column of the class table, or key of a classes dict. A
class’s value replaces the run-wide one for its travellers. When you set a run-wide coefficient that some classes
set too, the scenario warns you, so a study that varies it is not misled:
UserWarning: choice_options' beta_mode_bike is replaced by the class's own for bike_only, car_and_bike: a class's
coefficients win by name, so the run-wide value applies to the other classes only.
What is recorded#
Every run writes the values it used to manifest.json: each method with all its options in canonical form (for
example choice_descriptor: logit;beta_bike_mixed_km=-0.16;…;beta_time_min=-0.12;…;class:bike_only.beta_mode_bike=3.1),
the limits, and defaults_version, the version of the shipped defaults. The values also enter the run’s fingerprint,
so two runs with different parameters never share one. See Reproducibility.
A calibration loop#
The parameters are plain arguments, so a calibration is a loop in Python. Each run is repeatable, and runs with the same seed share their random draws (common random numbers), so the difference between two runs is the parameter’s effect, not noise:
for beta in (-0.08, -0.10, -0.12):
run = ms.Scenario.from_parts(network, trips, choice_options={"beta_time_min": beta}).run(f"beta{beta}")
# compare run.trip_modes(), run.link_bins_table(), … with your counts or survey
Notebook 06 · Parameters and experiments works through this on a starter case.
For bikes#
The cycling parameters are in four groups:
Group |
Parameters |
|---|---|
|
The bike layer’s speeds by facility ( |
|
The longest ride offered ( |
|
The bike’s reach to a parking ( |
|
The bike’s weights: |
Calibrating them against counts on cycle paths, or a survey’s cycling share, follows the same loop.