Aggregations#

Catalogue#

Aggregation catalogue#

The aggregations, one row each. A cursor is a series cursor, and T the type of the slot it reads. The builtins page’s columns apply.

Name

Arities

Tier

Signature

Summary

Defined by

contains

2

pure

(cursor, value: T) → Bool

Whether the value is among the series’ samples in its window.

[LSER.16.7.1]

count

1

pure

(cursor) → Int

Number of samples in the series’ window.

[LSER.16.2]

count_distinct

1

pure

(cursor) → Int

Number of distinct sample values in the series’ window.

[LSER.16.5.1]

count_of

2

pure

(cursor, value: T) → Int

Number of samples in the series’ window equal to the value.

[LSER.16.6.1]

direction

1

pure

(cursor) → Int?

Sign of the difference of the two newest samples: −1, 0 or 1.

[LSER.16.9]

mean

1

pure

(cursor) → Float?

Arithmetic mean of the series’ window.

[LSER.16.2]

median

1

pure

(cursor) → Float?

Median of the series’ window, as p50.

[LSER.16.2]

p1

1

pure

(cursor) → Float?

Percentile 1 of the series’ window, interpolated.

[LSER.16.4.1]

p2

1

pure

(cursor) → Float?

Percentile 2 of the series’ window, interpolated.

[LSER.16.4.1]

p3

1

pure

(cursor) → Float?

Percentile 3 of the series’ window, interpolated.

[LSER.16.4.1]

p4

1

pure

(cursor) → Float?

Percentile 4 of the series’ window, interpolated.

[LSER.16.4.1]

p5

1

pure

(cursor) → Float?

Percentile 5 of the series’ window, interpolated.

[LSER.16.4.1]

p6

1

pure

(cursor) → Float?

Percentile 6 of the series’ window, interpolated.

[LSER.16.4.1]

p7

1

pure

(cursor) → Float?

Percentile 7 of the series’ window, interpolated.

[LSER.16.4.1]

p8

1

pure

(cursor) → Float?

Percentile 8 of the series’ window, interpolated.

[LSER.16.4.1]

p9

1

pure

(cursor) → Float?

Percentile 9 of the series’ window, interpolated.

[LSER.16.4.1]

p10

1

pure

(cursor) → Float?

Percentile 10 of the series’ window, interpolated.

[LSER.16.4.1]

p11

1

pure

(cursor) → Float?

Percentile 11 of the series’ window, interpolated.

[LSER.16.4.1]

p12

1

pure

(cursor) → Float?

Percentile 12 of the series’ window, interpolated.

[LSER.16.4.1]

p13

1

pure

(cursor) → Float?

Percentile 13 of the series’ window, interpolated.

[LSER.16.4.1]

p14

1

pure

(cursor) → Float?

Percentile 14 of the series’ window, interpolated.

[LSER.16.4.1]

p15

1

pure

(cursor) → Float?

Percentile 15 of the series’ window, interpolated.

[LSER.16.4.1]

p16

1

pure

(cursor) → Float?

Percentile 16 of the series’ window, interpolated.

[LSER.16.4.1]

p17

1

pure

(cursor) → Float?

Percentile 17 of the series’ window, interpolated.

[LSER.16.4.1]

p18

1

pure

(cursor) → Float?

Percentile 18 of the series’ window, interpolated.

[LSER.16.4.1]

p19

1

pure

(cursor) → Float?

Percentile 19 of the series’ window, interpolated.

[LSER.16.4.1]

p20

1

pure

(cursor) → Float?

Percentile 20 of the series’ window, interpolated.

[LSER.16.4.1]

p21

1

pure

(cursor) → Float?

Percentile 21 of the series’ window, interpolated.

[LSER.16.4.1]

p22

1

pure

(cursor) → Float?

Percentile 22 of the series’ window, interpolated.

[LSER.16.4.1]

p23

1

pure

(cursor) → Float?

Percentile 23 of the series’ window, interpolated.

[LSER.16.4.1]

p24

1

pure

(cursor) → Float?

Percentile 24 of the series’ window, interpolated.

[LSER.16.4.1]

p25

1

pure

(cursor) → Float?

Percentile 25 of the series’ window, interpolated.

[LSER.16.4.1]

p26

1

pure

(cursor) → Float?

Percentile 26 of the series’ window, interpolated.

[LSER.16.4.1]

p27

1

pure

(cursor) → Float?

Percentile 27 of the series’ window, interpolated.

[LSER.16.4.1]

p28

1

pure

(cursor) → Float?

Percentile 28 of the series’ window, interpolated.

[LSER.16.4.1]

p29

1

pure

(cursor) → Float?

Percentile 29 of the series’ window, interpolated.

[LSER.16.4.1]

p30

1

pure

(cursor) → Float?

Percentile 30 of the series’ window, interpolated.

[LSER.16.4.1]

p31

1

pure

(cursor) → Float?

Percentile 31 of the series’ window, interpolated.

[LSER.16.4.1]

p32

1

pure

(cursor) → Float?

Percentile 32 of the series’ window, interpolated.

[LSER.16.4.1]

p33

1

pure

(cursor) → Float?

Percentile 33 of the series’ window, interpolated.

[LSER.16.4.1]

p34

1

pure

(cursor) → Float?

Percentile 34 of the series’ window, interpolated.

[LSER.16.4.1]

p35

1

pure

(cursor) → Float?

Percentile 35 of the series’ window, interpolated.

[LSER.16.4.1]

p36

1

pure

(cursor) → Float?

Percentile 36 of the series’ window, interpolated.

[LSER.16.4.1]

p37

1

pure

(cursor) → Float?

Percentile 37 of the series’ window, interpolated.

[LSER.16.4.1]

p38

1

pure

(cursor) → Float?

Percentile 38 of the series’ window, interpolated.

[LSER.16.4.1]

p39

1

pure

(cursor) → Float?

Percentile 39 of the series’ window, interpolated.

[LSER.16.4.1]

p40

1

pure

(cursor) → Float?

Percentile 40 of the series’ window, interpolated.

[LSER.16.4.1]

p41

1

pure

(cursor) → Float?

Percentile 41 of the series’ window, interpolated.

[LSER.16.4.1]

p42

1

pure

(cursor) → Float?

Percentile 42 of the series’ window, interpolated.

[LSER.16.4.1]

p43

1

pure

(cursor) → Float?

Percentile 43 of the series’ window, interpolated.

[LSER.16.4.1]

p44

1

pure

(cursor) → Float?

Percentile 44 of the series’ window, interpolated.

[LSER.16.4.1]

p45

1

pure

(cursor) → Float?

Percentile 45 of the series’ window, interpolated.

[LSER.16.4.1]

p46

1

pure

(cursor) → Float?

Percentile 46 of the series’ window, interpolated.

[LSER.16.4.1]

p47

1

pure

(cursor) → Float?

Percentile 47 of the series’ window, interpolated.

[LSER.16.4.1]

p48

1

pure

(cursor) → Float?

Percentile 48 of the series’ window, interpolated.

[LSER.16.4.1]

p49

1

pure

(cursor) → Float?

Percentile 49 of the series’ window, interpolated.

[LSER.16.4.1]

p50

1

pure

(cursor) → Float?

Percentile 50 of the series’ window, interpolated; the median.

[LSER.16.4.1]

p51

1

pure

(cursor) → Float?

Percentile 51 of the series’ window, interpolated.

[LSER.16.4.1]

p52

1

pure

(cursor) → Float?

Percentile 52 of the series’ window, interpolated.

[LSER.16.4.1]

p53

1

pure

(cursor) → Float?

Percentile 53 of the series’ window, interpolated.

[LSER.16.4.1]

p54

1

pure

(cursor) → Float?

Percentile 54 of the series’ window, interpolated.

[LSER.16.4.1]

p55

1

pure

(cursor) → Float?

Percentile 55 of the series’ window, interpolated.

[LSER.16.4.1]

p56

1

pure

(cursor) → Float?

Percentile 56 of the series’ window, interpolated.

[LSER.16.4.1]

p57

1

pure

(cursor) → Float?

Percentile 57 of the series’ window, interpolated.

[LSER.16.4.1]

p58

1

pure

(cursor) → Float?

Percentile 58 of the series’ window, interpolated.

[LSER.16.4.1]

p59

1

pure

(cursor) → Float?

Percentile 59 of the series’ window, interpolated.

[LSER.16.4.1]

p60

1

pure

(cursor) → Float?

Percentile 60 of the series’ window, interpolated.

[LSER.16.4.1]

p61

1

pure

(cursor) → Float?

Percentile 61 of the series’ window, interpolated.

[LSER.16.4.1]

p62

1

pure

(cursor) → Float?

Percentile 62 of the series’ window, interpolated.

[LSER.16.4.1]

p63

1

pure

(cursor) → Float?

Percentile 63 of the series’ window, interpolated.

[LSER.16.4.1]

p64

1

pure

(cursor) → Float?

Percentile 64 of the series’ window, interpolated.

[LSER.16.4.1]

p65

1

pure

(cursor) → Float?

Percentile 65 of the series’ window, interpolated.

[LSER.16.4.1]

p66

1

pure

(cursor) → Float?

Percentile 66 of the series’ window, interpolated.

[LSER.16.4.1]

p67

1

pure

(cursor) → Float?

Percentile 67 of the series’ window, interpolated.

[LSER.16.4.1]

p68

1

pure

(cursor) → Float?

Percentile 68 of the series’ window, interpolated.

[LSER.16.4.1]

p69

1

pure

(cursor) → Float?

Percentile 69 of the series’ window, interpolated.

[LSER.16.4.1]

p70

1

pure

(cursor) → Float?

Percentile 70 of the series’ window, interpolated.

[LSER.16.4.1]

p71

1

pure

(cursor) → Float?

Percentile 71 of the series’ window, interpolated.

[LSER.16.4.1]

p72

1

pure

(cursor) → Float?

Percentile 72 of the series’ window, interpolated.

[LSER.16.4.1]

p73

1

pure

(cursor) → Float?

Percentile 73 of the series’ window, interpolated.

[LSER.16.4.1]

p74

1

pure

(cursor) → Float?

Percentile 74 of the series’ window, interpolated.

[LSER.16.4.1]

p75

1

pure

(cursor) → Float?

Percentile 75 of the series’ window, interpolated.

[LSER.16.4.1]

p76

1

pure

(cursor) → Float?

Percentile 76 of the series’ window, interpolated.

[LSER.16.4.1]

p77

1

pure

(cursor) → Float?

Percentile 77 of the series’ window, interpolated.

[LSER.16.4.1]

p78

1

pure

(cursor) → Float?

Percentile 78 of the series’ window, interpolated.

[LSER.16.4.1]

p79

1

pure

(cursor) → Float?

Percentile 79 of the series’ window, interpolated.

[LSER.16.4.1]

p80

1

pure

(cursor) → Float?

Percentile 80 of the series’ window, interpolated.

[LSER.16.4.1]

p81

1

pure

(cursor) → Float?

Percentile 81 of the series’ window, interpolated.

[LSER.16.4.1]

p82

1

pure

(cursor) → Float?

Percentile 82 of the series’ window, interpolated.

[LSER.16.4.1]

p83

1

pure

(cursor) → Float?

Percentile 83 of the series’ window, interpolated.

[LSER.16.4.1]

p84

1

pure

(cursor) → Float?

Percentile 84 of the series’ window, interpolated.

[LSER.16.4.1]

p85

1

pure

(cursor) → Float?

Percentile 85 of the series’ window, interpolated.

[LSER.16.4.1]

p86

1

pure

(cursor) → Float?

Percentile 86 of the series’ window, interpolated.

[LSER.16.4.1]

p87

1

pure

(cursor) → Float?

Percentile 87 of the series’ window, interpolated.

[LSER.16.4.1]

p88

1

pure

(cursor) → Float?

Percentile 88 of the series’ window, interpolated.

[LSER.16.4.1]

p89

1

pure

(cursor) → Float?

Percentile 89 of the series’ window, interpolated.

[LSER.16.4.1]

p90

1

pure

(cursor) → Float?

Percentile 90 of the series’ window, interpolated.

[LSER.16.4.1]

p91

1

pure

(cursor) → Float?

Percentile 91 of the series’ window, interpolated.

[LSER.16.4.1]

p92

1

pure

(cursor) → Float?

Percentile 92 of the series’ window, interpolated.

[LSER.16.4.1]

p93

1

pure

(cursor) → Float?

Percentile 93 of the series’ window, interpolated.

[LSER.16.4.1]

p94

1

pure

(cursor) → Float?

Percentile 94 of the series’ window, interpolated.

[LSER.16.4.1]

p95

1

pure

(cursor) → Float?

Percentile 95 of the series’ window, interpolated.

[LSER.16.4.1]

p96

1

pure

(cursor) → Float?

Percentile 96 of the series’ window, interpolated.

[LSER.16.4.1]

p97

1

pure

(cursor) → Float?

Percentile 97 of the series’ window, interpolated.

[LSER.16.4.1]

p98

1

pure

(cursor) → Float?

Percentile 98 of the series’ window, interpolated.

[LSER.16.4.1]

p99

1

pure

(cursor) → Float?

Percentile 99 of the series’ window, interpolated.

[LSER.16.4.1]

pstdev

1

pure

(cursor) → Float?

Population standard deviation of the series’ window.

[LSER.16.3.1]

pvariance

1

pure

(cursor) → Float?

Population variance of the series’ window.

[LSER.16.3.1]

rate

1

pure

(cursor) → Float?

(last − first) / elapsed seconds over the series’ window.

[LSER.16.9]

stdev

1

pure

(cursor) → Float?

Sample standard deviation of the series’ window.

[LSER.16.3.1]

variance

1

pure

(cursor) → Float?

Sample variance of the series’ window.

[LSER.16.3.1]

(Spec: [LEXP.17.2], [LSER.16])

Applicability#

An aggregation whose type does not match the slot’s is refused with DS_VALIDATE_SERIES_AGG_TYPE_MISMATCH.

Aggregation

Slot value types

Returns

min, max

Float, Int, Duration

the slot’s type, nullable

sum

Float, Int, Duration

the slot’s type

mean, median, stdev, pstdev, pXX

Float, Int, Duration

Float?; Duration? over a Duration slot

variance, pvariance

Float, Int, Duration

Float?

count

any sampled type

Int

count_distinct, count_of

any sampled type

Int

contains

any sampled type

Bool

bool_and, bool_or

Bool

Bool?

first, last

any sampled type

the slot’s type, nullable

rate

Float, Int, Duration

Float?

direction

Float, Int, Duration

Int?

A Duration slot is a slot of the time dimension (Duration). A Duration? read computes the Float and rounds it as a Duration scaled by a Float does (Time and Duration). The sampled types are Float, Int, Bool, String, Time, Date and Duration, a unit-typed slot, and an opaque type over any of them. Returns is the static type of both call forms. Type and time model are two axes, both to be met, and the compiler reports the first that fails. Signal aggregations have their own table.

Refused with DS_VALIDATE_SERIES_AGG_TYPE_MISMATCH

series Reading.label:
    mean sliding 10_min

(Spec: [LSER.17.1], [LSER.17.2], [LSER.17.3], [LSER.17.4], [LSER.17.5], [LSER.17.7], Source: compiler/mercury/src/dsc.series.m)

Name refusals#

Condition

Code

a name that is no aggregation

DS_VALIDATE_SERIES_AGG_NOT_SUPPORTED

pXX with XX outside 1..99

DS_VALIDATE_SERIES_INVALID_QUANTILE

Refused with DS_VALIDATE_SERIES_INVALID_QUANTILE

series Reading.level:
    p100 sliding 10_min

(Spec: [LSER.16.4.1], [LSER.17.6], [LSER.18.1])

Vocabulary#

Descriptive statistics#

Aggregation

Answers

mean

the arithmetic mean

median

the 50th percentile, as p50

min, max

the minimum, the maximum

sum

the sum

count

the sample count

sum over an Int slot accumulates in a 64-bit signed integer, and wraps as Int does. Over a Duration slot it accumulates the same way: a read that finds the total negative raises a ComputationError of kind NOT_REPRESENTABLE (Trap kinds), and a true total of 2⁶⁴ nanoseconds or more wraps and reads as the wrapped value.

min and max order -0 before +0: of the two, min is -0 and max is +0, in either arrival order.

(Spec: [LSER.16.2], [LSER.16.2.2], [LSER.16.4.2], [LSER.17.2])

Dispersion#

Aggregation

Answers

At one sample

stdev

the sample standard deviation

null

pstdev

the population standard deviation

+0

variance

the sample variance

null

pvariance

the population variance

+0

(Spec: [LSER.16.3.1], [LSER.16.3.3])

Quantiles#

pXX

pXX interpolates linearly between the two order statistics that bracket it, for an integer XX in 1..99.

The window’s n samples sort ascending as Float, an Int converting round-to-nearest-even and -0 before +0, as x_0 .. x_{n-1}. With num = (n-1) * XX, lo = num // 100 and frac = num % 100, the result is x_lo when frac = 0, when x_lo = x_{lo+1}, or when x_lo is -inf and x_{lo+1} is not +inf. Otherwise it is x_lo + (frac / 100) * (x_{lo+1} - x_lo), evaluated as correctly rounded operations in the order subtraction, division, multiplication, addition. With n = 1 it is x_0. A bracketing pair of -inf and +inf reads NaN.

(Spec: [LSER.16.4.1], [LSER.17.2])

Cardinality and membership#

Aggregation

Answers

count_distinct(cursor)

the count of distinct values

count_of(cursor, value)

the count of value

contains(cursor, value)

whether value was observed

count_distinct(r)
count_of(r, 1.0)
contains(r, 1.0)

(Spec: [LSER.16.5.1], [LSER.16.6.1], [LSER.16.7.1])

Boolean aggregations#

Aggregation

Answers

bool_and

whether every sample is true

bool_or

whether any sample is true

(Spec: [LSER.16.8], [LSER.16.8.1])

Temporal aggregations#

Aggregation

Answers

Also null when

first

the oldest sample’s value

last

the newest sample’s value

rate

(last - first) / elapsed_seconds

no time elapses between the first and last samples

direction

-1 falling, 0 steady, +1 rising

the window holds one sample

direction is the sign of the two newest samples’ difference, decided by comparing them, with no tolerance. -0 and +0 compare equal. null while cold is Cold read.

r.first
r.last
r.rate
r.direction

(Spec: [LSER.10.9], [LSER.16.9], [LSER.16.9.1])

Computation order#

sum, mean and the dispersion statistics are computed in one order per time model, each step one correctly rounded binary64 operation.

Samples x_1 .. x_n are Float, an Int converting round-to-nearest-even; an Int slot’s sum is the integer sum.

Time model

Sample order

State

all_time

arrival

mu_1 = x_1, M_1 = +0

sliding

live samples, oldest first

two passes

sample

slots 0 to n-1

mu_0 = +0, M_0 = +0

  • sum: S_0 = +0, S_k = S_{k-1} + x_k.

  • all_time, sample: d = x_k - mu_{k-1}, mu_k = mu_{k-1} + d / k, M_k = M_{k-1} + d * (x_k - mu_k). mean is mu_n, and M is M_n.

  • sliding: mean is mu = S_n / n. Q_0 = +0, d = x_k - mu, Q_k = Q_{k-1} + d * d, and M is Q_n.

  • Every time model: variance is M / (n - 1), pvariance is M / n, stdev and pstdev their square roots. On all_time and sliding, a variance not greater than 0 gives a deviation of +0.

(Spec: [LSER.16.3.3])

Result units#

Unit-preserving aggregations#

min, max, mean, median, pXX, stdev, pstdev, sum, first and last return the series slot’s unit, with no annotation.

count returns Int and direction Int?, both dimensionless over every slot. Unit-typed slots states what such a slot holds.

(Spec: [LUNI.9.1], [LUNI.9.3])

Unit-changing aggregations#

integral, variance, pvariance and rate change dimension: over a slot of dimension U, integral is U·s, variance and pvariance U², and rate U/s.

A let whose value reads one of them over a slot that carries a unit, a Duration slot included, is refused with DS_VALIDATE_DIM_AGG_UNANNOTATED, annotated or not, unless the value strips the read: integral(f)::Float, or variance(f)::Float? for the nullable three. The strip is a bare number in the slot’s base unit, times seconds for integral, squared for variance and pvariance, per second for rate, and ::<unit> asserts a unit on it.

A read in a where, an emit slot or an interpolation needs no strip, and neither does a let over a slot with no unit or over onset_rate. The Float and Float? returns are the representation; the dimension is this entry’s.

(Spec: [LUNI.9.2], [LSIG.1.1], [LSER.17.2])