Skip to content

transitlos.flex.shapes

Library of alternative shapes for the three scoring curves (ScoreParams.headway_curve / speed_curve / walk_curve).

Every function returns a Curve (a sampled table), so the numpy, C and JavaScript evaluators share it exactly. Use piecewise(...) or Curve.from_function(f, lo, hi) for any shape that is not listed. Domains: headway minutes (log grid 1-720), speed km/h (linear 0-150), walk u = (walking time - plateau) / t0 (linear 0-40).

from transitlos.flex import shapes, ScoreParams
p = ScoreParams(headway_curve=shapes.headway_exponential(sat=5, scale=40), speed_curve=shapes.speed_linear(0, 40),
                walk_curve=shapes.walk_gaussian(), agg="power_mean", agg_p=-1)

piecewise(points, lo, hi, scale, n)

Curve through (x, score) points (linear in x between points, flat beyond the first and last).

Parameters:

Name Type Description Default
points Sequence[Tuple[float, float]]

(x, score) points.

required
lo float

Lowest x of the table.

required
hi float

Highest x of the table.

required
scale str

"lin" or "log".

required
n int

Table points.

required

Returns:

Type Description
Curve

A table :class:Curve.

headway_default()

The default analytic headway curve.

Returns:

Type Description
Curve

A default :class:Curve.

headway_as_table(p=DEFAULT)

The default analytic shape sampled as a table (for testing and as a starting point to edit).

Parameters:

Name Type Description Default
p ScoreParams

Scoring parameters whose default shape is sampled.

DEFAULT

Returns:

Type Description
Curve

A table :class:Curve.

headway_exponential(sat=5.0, scale=40.0)

Headway curve 1 up to sat minutes, then exp(-(h - sat) / scale).

Parameters:

Name Type Description Default
sat float

Headway (min) with full score.

5.0
scale float

Decay scale (min).

40.0

Returns:

Type Description
Curve

A table :class:Curve.

headway_power(sat=5.0, exponent=0.6)

Headway curve 1 up to sat minutes, then (sat / h) ** exponent.

Parameters:

Name Type Description Default
sat float

Headway (min) with full score.

5.0
exponent float

Decay exponent.

0.6

Returns:

Type Description
Curve

A table :class:Curve.

headway_logistic(mid=30.0, steepness=0.12)

Logistic headway curve, half score at mid minutes.

Parameters:

Name Type Description Default
mid float

Headway (min) at half score.

30.0
steepness float

Steepness per minute.

0.12

Returns:

Type Description
Curve

A table :class:Curve.

headway_step(levels=((5, 1.0), (10, 0.9), (20, 0.7), (30, 0.5), (60, 0.25), (120, 0.1)))

Staircase: score s while headway <= h (the last level applies beyond with 0).

Parameters:

Name Type Description Default
levels Sequence[Tuple[float, float]]

(headway, score) steps.

((5, 1.0), (10, 0.9), (20, 0.7), (30, 0.5), (60, 0.25), (120, 0.1))

Returns:

Type Description
Curve

A table :class:Curve.

headway_piecewise(points)

Headway curve through (headway, score) points.

Parameters:

Name Type Description Default
points Sequence[Tuple[float, float]]

(headway minutes, score) points.

required

Returns:

Type Description
Curve

A table :class:Curve.

speed_default()

The default analytic speed curve.

Returns:

Type Description
Curve

A default :class:Curve.

speed_as_table(p=DEFAULT)

The default speed shape sampled as a table (to test or edit).

Parameters:

Name Type Description Default
p ScoreParams

Scoring parameters whose default shape is sampled.

DEFAULT

Returns:

Type Description
Curve

A table :class:Curve.

speed_linear(v0=5.0, v1=40.0, ceiling=1.0)

Speed curve rising linearly from 0 at v0 to ceiling at v1 km/h.

Parameters:

Name Type Description Default
v0 float

Speed with score 0.

5.0
v1 float

Speed with full score.

40.0
ceiling float

Highest score.

1.0

Returns:

Type Description
Curve

A table :class:Curve.

speed_logistic(mid=20.0, steepness=0.2, ceiling=1.0)

Logistic speed curve, half of ceiling at mid km/h.

Parameters:

Name Type Description Default
mid float

Speed at half score.

20.0
steepness float

Steepness per km/h.

0.2
ceiling float

Highest score.

1.0

Returns:

Type Description
Curve

A table :class:Curve.

speed_step(levels=((10, 0.2), (20, 0.5), (30, 0.8), (45, 1.0)))

Score s once speed >= v (levels sorted by v).

Parameters:

Name Type Description Default
levels Sequence[Tuple[float, float]]

(speed, score) steps.

((10, 0.2), (20, 0.5), (30, 0.8), (45, 1.0))

Returns:

Type Description
Curve

A table :class:Curve.

speed_piecewise(points)

Speed curve through (speed, score) points.

Parameters:

Name Type Description Default
points Sequence[Tuple[float, float]]

(speed km/h, score) points.

required

Returns:

Type Description
Curve

A table :class:Curve.

walk_default()

The default walking curve (1 + u) ** -p_shape.

Returns:

Type Description
Curve

A default :class:Curve.

walk_offset_power(p=1.0)

Walking curve (1 + u) ** -p (u = walking time beyond the plateau over t0).

Parameters:

Name Type Description Default
p float

Exponent.

1.0

Returns:

Type Description
Curve

A table :class:Curve.

walk_exponential(scale=1.0)

Walking curve exp(-u / scale).

Parameters:

Name Type Description Default
scale float

Decay scale in units of t0.

1.0

Returns:

Type Description
Curve

A table :class:Curve.

walk_gaussian(scale=1.0)

Walking curve exp(-(u / scale) ** 2).

Parameters:

Name Type Description Default
scale float

Decay scale in units of t0.

1.0

Returns:

Type Description
Curve

A table :class:Curve.

walk_linear(u_max=3.0)

Walking curve falling linearly to 0 at u_max.

Parameters:

Name Type Description Default
u_max float

Value of u with score 0.

3.0

Returns:

Type Description
Curve

A table :class:Curve.

walk_logistic(mid=2.0, steepness=2.0)

Logistic walking curve, scaled to 1 at u = 0.

Parameters:

Name Type Description Default
mid float

u at half score.

2.0
steepness float

Steepness.

2.0

Returns:

Type Description
Curve

A table :class:Curve.

walk_hard_buffer()

Everything inside the plateau distance scores fully, nothing beyond it (use plateau_m as the buffer radius).

walk_piecewise(points)

Walking curve through (u, score) points.

Parameters:

Name Type Description Default
points Sequence[Tuple[float, float]]

(u, score) points.

required

Returns:

Type Description
Curve

A table :class:Curve.