8
func Movmean(data []float64, window int) ([]float64, error) {
10
return nil, fmt.Errorf("length of slice must be greater than 1")
12
if window > len(data) {
13
return nil, fmt.Errorf("m cannot be greater than length of slice")
20
M := make([]float64, n)
22
for i := 0; i < n; i++ {
26
for j := i - window/2; j < i+window/2+1; j++ {
27
if j >= 0 && j < len(data) {
44
M[i] = sum / float64(count)
49
func MovMeanStd(ts []float64, m int) ([]float64, []float64, error) {
51
return nil, nil, fmt.Errorf("length of slice must be greater than 1")
55
return nil, nil, fmt.Errorf("m cannot be greater than length of slice")
60
c := make([]float64, len(ts)+1)
61
csqr := make([]float64, len(ts)+1)
62
for i = 0; i < len(ts)+1; i++ {
67
c[i] = ts[i-1] + c[i-1]
68
csqr[i] = ts[i-1]*ts[i-1] + csqr[i-1]
72
mean := make([]float64, len(ts)-m+1)
73
std := make([]float64, len(ts)-m+1)
74
for i = 0; i < len(ts)-m+1; i++ {
75
mean[i] = (c[i+m] - c[i]) / float64(m)
76
std[i] = math.Sqrt((csqr[i+m]-csqr[i])/float64(m) - mean[i]*mean[i])