-
Notifications
You must be signed in to change notification settings - Fork 546
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
stat/running: Add running package for computing stats of a running st… #1067
base: master
Are you sure you want to change the base?
Conversation
Currently a mostly complete sketch of how it could look (but needs better comments and tests). I think a good idea would be to have a |
stat/running/running.go
Outdated
// is multiplied by 0.99 for every added value. If Decay is zero, a default | ||
// value of 1 is used (the count is not decayed). | ||
Decay float64 | ||
InitCount float64 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add comments for these fields.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
stat/running/running.go
Outdated
// Reset resets the counter. The next accumulate will use the | ||
// initial mean and count. | ||
func (m *Mean) Reset() { | ||
m.count = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think I understand how these are being used. I was going to suggest
m.count = m.InitCount
m.mean = m.InitMean
but then, the code in AccumWeighted
doesn't make sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
stat/running/running.go
Outdated
|
||
import "math" | ||
|
||
// Mean helps compute running mean |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Mean is a running mean accumulator.
? The "helps" seems odd.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
ping |
Is this still being worked on? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering about the need for the accessors and unexported fields. Would it be reasonable just to have Mean
and Count
? Then the API gets much smaller.
stat/running/running.go
Outdated
return | ||
} | ||
decay := m.decay() | ||
decay = math.Pow(decay, weight) | ||
m.count *= decay | ||
m.mean = (m.mean*m.count + v*weight) / (m.count + weight) | ||
//m.mean = (m.mean*m.count + v*weight) / (m.count + weight) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete this commented out code?
stat/running/running.go
Outdated
@@ -72,3 +81,11 @@ func (m *Mean) decay() float64 { | |||
} | |||
return m.Decay | |||
} | |||
|
|||
func updateMean(mean, count, v, weight float64) float64 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this be used elsewhere?
stat/running/running.go
Outdated
} | ||
|
||
// Stats is an accumulator for running statistics. | ||
type Stats struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More to come?
stat/running/running.go
Outdated
|
||
set bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs a comment.
I'm sorry, the last thing I pushed up was not what I meant to push. I pushed up what I intended now. Doing a refactor which will make it simpler. |
Yep, this is way better, thanks for the comments. |
What about exporting the fields? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests?
|
||
// Accum adds the value to the running total. | ||
func (m *Mean) Accum(v float64) { | ||
m.AccumWeighted(v, 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd do this explicitly here. There are elidable checks and math.Pow
is not cheap.
@btracey Do you want to keep this open? |
import "math" | ||
|
||
// Mean is a running mean accumulator. | ||
type Mean struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we maybe name this type "MeanExpDecay" to leave the floor open for other running mean implementations?
…ream of data
Fixes #1037.
Please take a look.