forked from rocketlaunchr/dataframe-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.go
51 lines (38 loc) · 1.25 KB
/
common.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright 2018-20 PJ Engineering and Business Solutions Pty. Ltd. All rights reserved.
package hw
// See: http://www.itl.nist.gov/div898/handbook/pmc/section4/pmc435.htm
func initialTrend(y []float64, period int) float64 {
var sum float64
sum = 0.0
for i := 0; i < period; i++ {
sum += (y[period+i] - y[i]) / float64(period)
}
return sum / float64(period)
}
// See: http://www.itl.nist.gov/div898/handbook/pmc/section4/pmc435.htm
func initialSeasonalComponents(y []float64, period int, tsType Method) []float64 {
nSeasons := len(y) / period
seasonalAverage := make([]float64, nSeasons)
seasonalIndices := make([]float64, period)
// computing seasonal averages
for i := 0; i < nSeasons; i++ {
for j := 0; j < period; j++ {
seasonalAverage[i] += y[(i*period)+j]
}
seasonalAverage[i] /= float64(period)
}
// Calculating initial Seasonal component values
for i := 0; i < period; i++ {
for j := 0; j < nSeasons; j++ {
if tsType == Multiplicative {
// Multiplcative seasonal component
seasonalIndices[i] += y[(j*period)+i] / seasonalAverage[j]
} else {
// Additive seasonal component
seasonalIndices[i] += y[(j*period)+i] - seasonalAverage[j]
}
}
seasonalIndices[i] /= float64(nSeasons)
}
return seasonalIndices
}