fix duplicate rma value

This commit is contained in:
narumi 2023-10-24 16:37:44 +08:00
parent 4c1654652e
commit 22a7232e8b

View File

@ -34,23 +34,20 @@ func RMA2(source types.Float64Source, window int, adjust bool) *RMAStream {
func (s *RMAStream) Calculate(x float64) float64 {
lambda := 1 / float64(s.window)
tmp := 0.0
if s.counter == 0 {
s.sum = 1
tmp = x
s.previous = x
} else {
if s.Adjust {
s.sum = s.sum*(1-lambda) + 1
tmp = s.previous + (x-s.previous)/s.sum
s.previous = s.previous + (x-s.previous)/s.sum
} else {
tmp = s.previous*(1-lambda) + x*lambda
s.previous = s.previous*(1-lambda) + x*lambda
}
}
s.counter++
s.Slice.Push(tmp)
s.previous = tmp
return tmp
return s.previous
}
func (s *RMAStream) Truncate() {