@@ -79,28 +79,29 @@ func computeThrashing(values []float64) thrashing {
79
79
// in the dominant direction (if there is one). If no direction is dominant, the
80
80
// result roughly matches the total variation.
81
81
//
82
- // The inputs tu and td are the upwards and (positive) downwards total
83
- // variations, respectively.
82
+ // The inputs u and d are the upwards and (positive) downwards total variations,
83
+ // respectively.
84
84
//
85
85
// Properties:
86
- // - symmetric in tu, td
87
- // - min(u,d) <= tdtv(tu,td ) <= tu+td
86
+ // - tdtv(u,d) = tdtv(d,u) (symmetry)
87
+ // - min(u,d) <= tdtv(u,d ) <= u+d
88
88
// - tdtv(u,0) = tdtv(0,u) = 0
89
- // - tdtv(u,u) = 2t
90
- // - tdtv(ku,kd ) = k* tdtv(u,d) for k>= 0
91
- // - tdtv(l*ku, kd ) > tdtv(ku ) for l>1 (same for kd )
92
- func tdtv (tu , td float64 ) float64 {
93
- tmin := min (tu , td )
89
+ // - tdtv(u,u) = 2⋅u
90
+ // - tdtv(k⋅u,k⋅d ) = k⋅ tdtv(u,d) for k≥ 0
91
+ // - tdtv(l⋅u, d ) > tdtv(u ) for l>1 (same in second argument )
92
+ func tdtv (u , d float64 ) float64 {
93
+ tmin := min (u , d )
94
94
if tmin == 0 {
95
95
// There's only one direction of movement, so we discount all variation.
96
96
return 0
97
97
}
98
- frac := tmin / max (tu , td ) // in [0, 1]
98
+ frac := tmin / max (u , d ) // in [0, 1]
99
99
// The exponent can't exceed 1 because that would violate the scaling property
100
- // (last property above). For the endpoint 1, tdtv=2min(tu,td). The choice of
101
- // 0.8 is somewhat arbitrary, but gives a reasonable trade-off.
100
+ // (last property above). For the endpoint exponent 1, tdtv=2⋅min(u,d), and for
101
+ // the endpoint exponent 0, we get the (vanilla) total variation u+d.
102
+ // The choice of 0.8 is somewhat arbitrary, but gives a reasonable trade-off.
102
103
alpha := math .Pow (frac , 0.8 )
103
- return alpha * (tu + td ) + (1 - alpha )* tmin
104
+ return alpha * (u + d ) + (1 - alpha )* tmin
104
105
}
105
106
106
107
func extrema (vs []float64 ) (vmin , vmax , vrange float64 ) {
0 commit comments