Skip to content

transitlos.flex.scoring

Recomputable scoring: ONE parameter object (ScoreParams) that fully defines how stops and walking are scored, in numpy.

The same definition is evaluated by the C core (flexcore.c) and by the browser (frontend/score.js); to_json / from_json move it between them.

What can change after the data is processed * parameters anchors, ceilings, elasticity, walking speed, plateau, t0 per mode, coupling k, the MRC value of each mode, an axis weight (0 switches an axis OFF: mode, speed, headway) * SHAPES each of the three curves can be replaced by another family or by any table of points (see shapes.py): headway curve H(headway min) default = transitlos' log-linear-elasticity curve speed curve V(speed km/h) default = Hill curve anchored at 30 km/h walk curve D0(u), u = (t - plateau)/t0(stop score, mode) default = (1+u)^-p * aggregation "nested" min(1, ( MRC^wm * V^ws )^(1/(wm+ws)) * H^wh ) (default; = sqrt(MRCV)H with weights 1) "product" mode^w_mode * speed^w_speed * headway^w_headway "power_mean" generalised weighted mean of (MRC, V, H) with exponent agg_p (1 arithmetic, 0 geometric, -1 harmonic, large negative ~ min)

stop_score = aggregation(MRC(mode), V(speed), H(headway)); PTLOS(stop, d) = stop_score * D(walk time to the stop; stop_score, mode) Modes are integers: 0 bus, 1 tram, 2 rail (the tier of the profile, as in transitlos.scoring.direction_subset).

Default parameters and shapes are read from transitlos.scoring.parameters, so with ScoreParams() this reproduces transitlos.scoring exactly.

Curve(kind='default', lo=0.0, hi=1.0, scale='lin', y=()) dataclass

Shape of one 1-D scoring function.

kind "default": the analytic shape of transitlos (its parameters live in ScoreParams). kind "table": y sampled on a uniform grid of n points over [lo, hi] (scale "lin" or "log" in x), linear interpolation, clamped outside. Any shape can be expressed this way (see shapes.py); numpy, C and JavaScript interpolate identically.

n property

Number of table points.

Returns:

Type Description
int

len(y).

from_function(f, lo, hi, n=512, scale='lin') staticmethod

Sample f on n points over [lo, hi] (linear or log spacing) into a table curve; negative values become 0.

Parameters:

Name Type Description Default
f Callable[[ndarray], ndarray]

Function of an array.

required
lo float

Lowest x.

required
hi float

Highest x.

required
n int

Number of points.

512
scale str

"lin" or "log" spacing in x.

'lin'

Returns:

Type Description
'Curve'

A table :class:Curve.

eval(x)

Table lookup (kind "table" only).

Parameters:

Name Type Description Default
x

Values (any shape).

required

Returns:

Type Description

Interpolated scores (clamped outside [lo, hi]).

ScoreParams(mrc=_D['mrc'], v_anchor=_D['v_anchor'], v_bonus=_D['v_bonus'], v_n=_D['v_n'], h_sat=_D['h_sat'], h_p=_D['h_p'], h_q=_D['h_q'], walk_speed=_D['walk_speed'], plateau_m=_D['plateau_m'], t0_base=_D['t0_base'], k=_D['k'], p_shape=_D['p_shape'], w_mode=1.0, w_speed=1.0, w_headway=1.0, agg='nested', agg_p=0.0, headway_curve=DEFAULT_CURVE, speed_curve=DEFAULT_CURVE, walk_curve=DEFAULT_CURVE) dataclass

Every parameter of the transit level-of-service score: mode values (MRC), the speed, headway and walking curves, and how the three stop scores combine.

Immutable: change a copy with :meth:with_. to_json / from_json save and load it (the browser editor uses the same JSON).

with_(**kw)

A copy with some fields changed.

Parameters:

Name Type Description Default
**kw

Fields to change.

{}

Returns:

Type Description
'ScoreParams'

The new parameters.

to_json()

The parameters as JSON text.

Returns:

Type Description
str

JSON text.

from_json(s) staticmethod

Parameters from JSON text written by :meth:to_json.

Parameters:

Name Type Description Default
s str

JSON text.

required

Returns:

Type Description
'ScoreParams'

The parameters.

mrc(mode, p=DEFAULT)

Mode value (MRC) of each mode.

Parameters:

Name Type Description Default
mode

Mode (0 bus, 1 tram, 2 rail).

required
p ScoreParams

Scoring parameters.

DEFAULT

Returns:

Type Description

float64 array.

speed_score(v, p=DEFAULT)

Speed score (0 to 1 + v_bonus): the speed curve, or the default saturating shape anchored at v_anchor.

Parameters:

Name Type Description Default
v

Speed (km/h).

required
p ScoreParams

Scoring parameters.

DEFAULT

Returns:

Type Description

float64 array (0 for speed 0).

headway_score(h, p=DEFAULT)

Headway score (1 at or below h_sat, falling with the headway): the headway curve, or the default log-quadratic shape.

Parameters:

Name Type Description Default
h

Headway (min).

required
p ScoreParams

Scoring parameters.

DEFAULT

Returns:

Type Description

float64 array.

stop_score(mode, h, v, p=DEFAULT)

Score of a stop pattern from its mode, headway and speed, combined as set by p.agg (nested, power mean or product).

Parameters:

Name Type Description Default
mode

Mode (0 bus, 1 tram, 2 rail).

required
h

Headway (min).

required
v

Speed (km/h).

required
p ScoreParams

Scoring parameters.

DEFAULT

Returns:

Type Description

float64 array, 0 to 1.

walk_decay(dist_m, ss, mode, p=DEFAULT)

Share of a stop's score kept after walking dist_m: 1 up to the plateau, then the walk curve of the walking time over t0 (t0 grows with the stop score when k > 0).

Parameters:

Name Type Description Default
dist_m

Walking distance (m).

required
ss

Stop score.

required
mode

Mode (0 bus, 1 tram, 2 rail).

required
p ScoreParams

Scoring parameters.

DEFAULT

Returns:

Type Description

float64 array, 0 to 1.

ptlos(dist_m, mode, h, v, p=DEFAULT)

Level of service a place gets from one stop pattern: stop score x walk decay.

Parameters:

Name Type Description Default
dist_m

Walking distance (m).

required
mode

Mode (0 bus, 1 tram, 2 rail).

required
h

Headway (min).

required
v

Speed (km/h).

required
p ScoreParams

Scoring parameters.

DEFAULT

Returns:

Type Description

float64 array, 0 to 1.