Skip to content

Commit 0394ac8

Browse files
committed
Yay generics!
1 parent c71c411 commit 0394ac8

File tree

5 files changed

+22
-24
lines changed

5 files changed

+22
-24
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jobs:
66
name: CI
77
strategy:
88
matrix:
9-
go: ['1.15', '1.16']
9+
go: ['1.18', '1.19']
1010
os: ['ubuntu-latest', 'windows-latest', 'macOS-latest']
1111
runs-on: ${{ matrix.os }}
1212
steps:

edpelt.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ import (
2626
//
2727
// The implementation is based on the following papers:
2828
//
29-
// [Haynes2017] Kaylea Haynes, Paul Fearnhead, and Idris A. Eckley.
30-
// "A computationally efficient nonparametric approach for changepoint detection."
31-
// Statistics and Computing 27, no. 5 (2017): 1293-1305.
32-
// https://doi.org/10.1007/s11222-016-9687-5
29+
// [Haynes2017] Kaylea Haynes, Paul Fearnhead, and Idris A. Eckley.
30+
// "A computationally efficient nonparametric approach for changepoint detection."
31+
// Statistics and Computing 27, no. 5 (2017): 1293-1305.
32+
// https://doi.org/10.1007/s11222-016-9687-5
3333
//
34-
// [Killick2012] Rebecca Killick, Paul Fearnhead, and Idris A. Eckley.
35-
// "Optimal detection of changepoints with a linear computational cost."
36-
// Journal of the American Statistical Association 107, no. 500 (2012): 1590-1598.
37-
// https://arxiv.org/pdf/1101.1438.pdf
34+
// [Killick2012] Rebecca Killick, Paul Fearnhead, and Idris A. Eckley.
35+
// "Optimal detection of changepoints with a linear computational cost."
36+
// Journal of the American Statistical Association 107, no. 500 (2012): 1590-1598.
37+
// https://arxiv.org/pdf/1101.1438.pdf
3838
func NonParametric(data []float64, minSegment int) []int {
3939
if minSegment < 1 {
4040
panic("minSegment must be positive")
@@ -66,18 +66,18 @@ func NonParametric(data []float64, minSegment int) []int {
6666

6767
// Partial sums for empirical CDF (formula (2.1) from Section 2.1 "Model" in [Haynes2017])
6868
//
69-
// partialSums'[i, tau] = (count(data[j] < t) * 2 + count(data[j] == t) * 1) for j=0..tau-1
70-
// where t is the i-th quantile value (see Section 3.1 "Discrete approximation" in [Haynes2017] for details)
69+
// partialSums'[i, tau] = (count(data[j] < t) * 2 + count(data[j] == t) * 1) for j=0..tau-1
70+
// where t is the i-th quantile value (see Section 3.1 "Discrete approximation" in [Haynes2017] for details)
7171
//
7272
// In order to get better performance, we present
7373
// a two-dimensional array partialSums'[k, n + 1] as a single-dimensional array partialSums[k * (n + 1)].
7474
// We assume that partialSums'[i, tau] = partialSums[i * (n + 1) + tau].
7575
//
76-
// - We use doubled sum values in order to use []int instead of []float64 (it provides noticeable
77-
// performance boost). Thus, multipliers for count(data[j] < t) and count(data[j] == t) are
78-
// 2 and 1 instead of 1 and 0.5 from the [Haynes2017].
79-
// - Note that these quantiles are not uniformly distributed: tails of the data distribution contain more
80-
// quantile values than the center of the distribution
76+
// - We use doubled sum values in order to use []int instead of []float64 (it provides noticeable
77+
// performance boost). Thus, multipliers for count(data[j] < t) and count(data[j] == t) are
78+
// 2 and 1 instead of 1 and 0.5 from the [Haynes2017].
79+
// - Note that these quantiles are not uniformly distributed: tails of the data distribution contain more
80+
// quantile values than the center of the distribution
8181
func edPartialSums(data []float64, k int) []int32 {
8282
n := len(data)
8383
partialSums := make([]int32, k*(n+1))

edpelt_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ func BenchmarkNonParametric(b *testing.B) {
144144
func TestNonParametric_ValidDistinctSortedIndexes(t *testing.T) {
145145
rapid.Check(t, func(t *rapid.T) {
146146
var (
147-
data = rapid.SliceOf(rapid.Float64()).Draw(t, "data").([]float64)
148-
minSegment = rapid.IntMin(1).Draw(t, "minSegment").(int)
147+
data = rapid.SliceOf(rapid.Float64()).Draw(t, "data")
148+
minSegment = rapid.IntMin(1).Draw(t, "minSegment")
149149
)
150150

151151
changes := changepoint.NonParametric(data, minSegment)

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module pgregory.net/changepoint
22

3-
go 1.14
3+
go 1.18
44

5-
require pgregory.net/rapid v0.4.5
5+
require pgregory.net/rapid v0.5.3

go.sum

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
pgregory.net/rapid v0.4.0 h1:/boyXNQlDs1pmk7g1b9u2KrYqXnqjj0ARUDsZj5kapg=
2-
pgregory.net/rapid v0.4.0/go.mod h1:UYpPVyjFHzYBGHIxLFoupi8vwk6rXNzRY9OMvVxFIOU=
3-
pgregory.net/rapid v0.4.5 h1:Dej3+7kpi3p5/9dMouKspRs+K8EALKePW4/UYXKq8/4=
4-
pgregory.net/rapid v0.4.5/go.mod h1:UYpPVyjFHzYBGHIxLFoupi8vwk6rXNzRY9OMvVxFIOU=
1+
pgregory.net/rapid v0.5.3 h1:163N50IHFqr1phZens4FQOdPgfJscR7a562mjQqeo4M=
2+
pgregory.net/rapid v0.5.3/go.mod h1:PY5XlDGj0+V1FCq0o192FdRhpKHGTRIWBgqjDBTrq04=

0 commit comments

Comments
 (0)