truncate

truncate, function

def pure truncate(d: ranvar, low: number, high: number) 🡒 ranvar, pure function

Returns the conditional ranvar between the inclusive boundaries $[\text{low}`, \text{high}]$.

d = ranvar.uniform(1, 6)
d_trunc = truncate(d, 2, 4)
show scalar "d" with d
show scalar "truncate(d, 2, 4)" with d_trunc

Remarks

truncate versus min/max

In general, the output of truncate(d, low, high) is not the same as min(max(d, low), high).

In fact, truncate(d, low, high) will return the conditional distribution of $d|d\in[\text{low}, \text{high}]$, so any “truncated” weight will be redistributed over the remaining support, in proportion to the weight of each bucket.

On the other hand, with min(max(d, low), high), any weight truncated by the lower (resp. higher) bound will be entirely transferred to the lower (resp. higher) bound itself, leaving the weights unchanged in the inside of the remaining support.

The following code snippet provides an example of this difference :

d = ranvar.uniform(1, 6)
d_trunc = truncate(d, 2, 4)
d_minmax = min(4, max(2, d))
show scalar "d" with d
show scalar "truncate(d, 2, 4)" with d_trunc
show scalar "min(max(d, 2), 4)" with d_minmax

Bounds outside of the support

If low is greater than the upper bound of the support of d, truncate(d, low, high) will return dirac(low).

If high is lower than the lower bound of the support of d, truncate(d, low, high) will return dirac(high).

Decimal bounds

Calling truncate with non-integer values for low and high is supported, truncate(d, low, high) being equivalent to truncate(d, floor(low), ceiling(high)).

Errors

Calling truncate with parameters low and high such that low > high will result in the following error:

truncate(_,9, 7): expected 9 smaller or equal to 7.

Recipes and best practices

In a supply chain context, truncate is often used together with quantile in order to eliminate very unlikely scenarios:

rawLeadtime = poisson(35)
rawLeadtime = poisson(12)
truncatedLeadtime = truncate(rawLeadtime, 0, quantile(rawLeadtime, 0.999))
show scalar "Raw leadtime" with rawLeadtime
show scalar "Truncated leadtime" with truncatedLeadtime

Conditional distributions can also be used to estimate, as a ranvar, the leadtime of a pending PO a few days after it was placed :

daysSinceOrderDate = 25
rawLeadtime = poisson(12)
conditionalLeadtime = truncate(rawLeadtime, daysSinceOrderDate, quantile(rawLeadtime, 1))
show scalar "Raw leadtime" with rawLeadtime
show scalar "Conditional leadtime for a pending PO placed 25 days ago" with conditionalLeadtime
User Contributed Notes
0 notes + add a note