vividcortex / ewma Goto Github PK
View Code? Open in Web Editor NEWExponentially Weighted Moving Average algorithms for Go.
License: MIT License
Exponentially Weighted Moving Average algorithms for Go.
License: MIT License
For some purposes, it's important to be able to set the EWMA's value directly. For example, suppose you keep track of a EWMA and then save it to a database, and later retrieve it and continue to add more values. (We do this at VividCortex.)
We should enhance the interface with an Add(float64)
function, and implement these functions in our two public implementations. The semantics of Add
should be to set the value and mark the EWMA as initialized, in case it has internal tracking of whether it's "warmed up" or not.
These properties let it use less memory. It will also behave differently when it's equal to zero, which is assumed to mean uninitialized, so if a value is likely to actually become zero over time, then any non-zero value will cause a sharp jump instead of a small change.
The disadvantages for SimpleEWMA like the sensitivity for 0 values could be solved by using *float64 for storing the value internally. Could do a PR if desired.
github.com/VividCortex/ewma 1.1.1 does not pass unit tests with Go 1.10:
+ GOPATH=/builddir/build/BUILD/ewma-1.1.1/_build:/usr/share/gocode
+ go test -buildmode pie -compiler gc -ldflags '-extldflags '\''-Wl,-z,relro '\'''
# github.com/VividCortex/ewma
./ewma_test.go:39: Errorf format %d has arg e.Value() of wrong type float64
./ewma_test.go:53: Errorf format %d has arg e.Value() of wrong type float64
./ewma_test.go:83: Errorf format %d has arg e.Value() of wrong type float64
FAIL github.com/VividCortex/ewma [build failed]
Useful for dependency managers like dep.
The readme says
So, for example, if you have a time-series with samples once per second, and you want to get the moving average over the previous minute, you should use an alpha of .032786885. This, by the way, is the constant alpha used for this repository's SimpleEWMA.
That alpha corresponds to N = 60, 2/(N+1) = 2/61 = .032786885.
The actual code uses 2/31:
Lines 8 to 14 in 487e8c9
The readme may be using N with two different meanings in the section on "Choosing Alpha", but I don't think so. I think 2/31 is incorrect.
The comment in the code is also inconsistent with the readme. The readme talks about "N samples", whereas the code talks about "average age".
It's certainly possible I'm misunderstanding something.
Before you file an issue, please consider:
We only accept pull requests for minor fixes or improvements. This includes:
Please open issues to discuss new features. Pull requests for new features will be rejected,
so we recommend forking the repository and making changes in your fork for your use case.
I'm assuming the current state is stable. Could you please add a tag/release? This would make it easier for specifying versions for dep
.
Hello,
I am in the process of packaging ewma for Fedora but I encountered problems running the tests. On both ppc64le and s390x arches, the following test fails:
+ export GOPATH=/builddir/build/BUILDROOT/golang-github-VividCortex-ewma-0-0.1.git4cc8cc5.fc27.ppc64le//usr/share/gocode:/usr/share/gocode
+ GOPATH=/builddir/build/BUILDROOT/golang-github-VividCortex-ewma-0-0.1.git4cc8cc5.fc27.ppc64le//usr/share/gocode:/usr/share/gocode
+ go test -compiler gc -ldflags '' github.com/VividCortex/ewma
--- FAIL: TestSimpleEWMA (0.00s)
ewma_test.go:26: e.Value() is 4734.500946466117, wanted 4734.500946466118
--- FAIL: TestVariableEWMA (0.00s)
ewma_test.go:40: e.Value() is 4734.500946466117, wanted 4734.500946466118
FAIL
FAIL github.com/VividCortex/ewma 0.018s
Could you identify why there is a discrepancy in the value given versus the value expected, only on these two arches while others arches test are fine?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.