johnmyleswhite / StreamStats.jl

Compute statistics over data streams in pure Julia
Other
48 stars 7 forks source link

Use immutable stats objects #26

Closed petercolberg closed 8 years ago

petercolberg commented 8 years ago

Now that Julia 0.4.0 has been released, this seems a good opportunity to introduce some breaking changes to the StreamStats package that will make it suitable for a broader range of use cases.

As a proof of concept, I revised Moments to use an immutable type.

Moments may be used as a scalar (bits) type as before:

stat = zero(StreamStats.Moments)
for n = 1:1000
  stat += rand()
end
println(stat)

Values are accumulated using the + operator, which allows for an in-place update syntax.

Moments may be used in an array, and the stats elements may be accumulated using sum():

stats = zeros(StreamStats.Moments, 2, 100)
for i = 1:100
  for n = 1:1000
    stats[1, i] += rand()
    stats[2, i] += rand()
  end
end
println(sum(stats))
joshday commented 8 years ago

Hi Peter. If this is something you'd like to pursue, an ImmutableOnlineStats package that extends OnlineStats would be pretty cool. There are still things changing with OnlineStats, but you're right that this looks like too big of a breaking change.