-
Notifications
You must be signed in to change notification settings - Fork 13
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
Add fit!(o, y, n)
to fit multiple observations of the same value
#40
Conversation
Other things to check:
|
src/stats.jl
Outdated
function _fit!(o::Mean{T}, y, n) where {T} | ||
o.n += n | ||
o.μ = smooth(o.μ, y, n / o.n) | ||
end |
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 won't be correct for Mean{T,W}
when W
is something other than EqualWeight
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.
Does this imply there is also a problem with _merge!(o::Mean, o2::Mean)
? My thinking is along the lines that fitting y
k
times is equivalent to merging two means where the second one has k
values and a mean of y
. What is the appropriate way to deal with weights? Like this?
function _fit!(o::Mean{T}, y, n) where {T}
o.n += n
o.μ = smooth(o.μ, y, o.weight(o.n / n))
end
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.
Never mind, in testing that doesn't work. I can define a special version for Mean
with equal weight, and then use the generic fallback otherwise
I'll merge when CI goes green! |
This closes #284 that I opened. It's a minimum implementation where simple stats such as
Sum
,Mean
, andCountMap
(and a few others) can efficiently update their sufficient stats given a value and the number of times it was observed.Methods without a specialized update will fall back to
If you prefer to use
fitn!(o, y, n)
, then I can make the change and update the pull request.