@@ -14,27 +14,32 @@ import (
14
14
// a slice of values).
15
15
type thrashing struct {
16
16
vs []float64 // the time series input
17
- // Runs are the maximal-length subsequences (computed in slice order) of
18
- // values within which all first differences have the same sign. For example,
19
- // the sequence [1,2,3,2,3,2,1] has the runs [1,2,3], [2,3], [2,1].
20
- // The number of runs equals one plus the number of sign changes in the first
21
- // differences.
22
- runs int
17
+
23
18
// tdtv is the trend-discounting total variation. It's close to the total
24
19
// variation if the time series has no preferred trend (i.e. upwards or
25
20
// downwards), but if there is a clear trend, the tdtv will be much smaller,
26
21
// counting mainly the movement against the trend. see tdtv for details.
27
- tdtv float64
28
- uptv , dntv float64 // upwards and downwards total variations (both nonnegative)
22
+ tdtv float64
29
23
// normTV is a normalization factor for the total variation. By default, it is
30
24
// initialized to the range of the input values, i.e. max - min (or 1 if max
31
25
// == min). `tdtv/normTV` then measures how many times thrashing has "swept out"
32
26
// the effective range of values the time series has taken on.
33
27
// `tdtv/normTV` can grow arbitrarily large if the time series oscillates
34
28
// frequently (and enough datapoints are present). To get a sense of a
35
29
// "thrashing rate", `tdtv/(normTV*T)` or `tdtv/(normTV*runs) could be of
36
- // interest.
30
+ // interest in the future .
37
31
normTV float64
32
+
33
+ // uptv and dntv are the upwards and downwards total variations (both
34
+ // nonnegative). They're kept for informational purposes only.
35
+ uptv , dntv float64
36
+ // Runs are the maximal-length subsequences (computed in slice order) of
37
+ // values within which all first differences have the same sign. For example,
38
+ // the sequence [1,2,3,2,3,2,1] has the runs [1,2,3], [2,3], [2,1].
39
+ // The number of runs equals one plus the number of sign changes in the first
40
+ // differences.
41
+ // This is for informational purposes only.
42
+ runs int
38
43
}
39
44
40
45
func (th thrashing ) String () string {
@@ -163,6 +168,10 @@ func extrema(vs []float64) (vmin, vmax, vrange float64) {
163
168
// assumed to be for the same metric.
164
169
type ThrashingSlice []thrashing
165
170
171
+ // normalize installs a common normTV for all thrashing structs in the slice by
172
+ // computing the extrema (min/max) over all of the datapoints in the underlying
173
+ // time series data. Each thrashing's normTV is replaced by this common
174
+ // normalization factor.
166
175
func (ths ThrashingSlice ) normalize () {
167
176
vmin := math .Inf (1 )
168
177
vmax := math .Inf (- 1 )
0 commit comments