Giter Club home page Giter Club logo

Comments (4)

joshday avatar joshday commented on June 19, 2024 1

A few things:

1) Thanks for the report! I was able to make a simpler example:

julia> typeof(Group([Mean() for _ in 1:1375]...))
Group{NTuple{1375, Mean{Float64, EqualWeight}}, Union{NTuple{1375, Number}, NamedTuple{names, R} where R<:NTuple{1375, Number}, AbstractVector{<:Number}} where names}

julia> typeof(Group([Mean() for _ in 1:1376]...))
ERROR: StackOverflowError:
Stacktrace:
 [1] promote_type(::Type, ::Type, ::Type, ::Type, ::Vararg{Type}) (repeats 1368 times)
   @ Base ./promotion.jl:293
 [2] Group(stats::NTuple{1376, Mean{Float64, EqualWeight}})
   @ OnlineStatsBase ~/.julia/dev/OnlineStatsBase/src/stats.jl:368
 [3] Group(::Mean{Float64, EqualWeight}, ::Vararg{Mean{Float64, EqualWeight}})
   @ OnlineStatsBase ~/.julia/dev/OnlineStatsBase/src/stats.jl:372

I am at a loss as to why 1375 would be different than 1376. However, there is a one-line fix in OnlineStatsBase that I'll add:

# don't do this.  See below
julia> typeof(Group([Mean() for _ in 1:999999]...))
Group{NTuple{999999, Mean{Float64, EqualWeight}}, Union{Tuple{Number}, NamedTuple{names, R} where R<:Tuple{Number}, AbstractVector{<:Number}} where names}

2) For large numbers of stats in a Group, use a Vector:

julia> typeof(Group([Mean() for _ in 1:999999]))
Group{Vector{Mean{Float64, EqualWeight}}, Union{Tuple{Number}, NamedTuple{names, R} where R<:Tuple{Number}, AbstractVector{<:Number}} where names}

I'll have to do some benchmarking. There may be no benefit for using tuples even for a smaller number of stats.

3) If you already have a Variance, don't add in a Mean

A Variance needs to calculate the mean internally, so you're adding unnecessary compute by including a Mean as well. You can do:

o = fit!(Variance(), randn(100))

mean(o)

from onlinestats.jl.

joshday avatar joshday commented on June 19, 2024

Eh, I lied. My "fix" broke other stuff. This may be some internal Julia limitation on tuple sizes. I'll look into it.

from onlinestats.jl.

joshday avatar joshday commented on June 19, 2024

Figured it out. This is the culprit, which lives in Base:

promote_type(T, S, U, V...) = (@inline; promote_type(T, promote_type(S, U, V...)))

For a large number of arguments, e.g. promote_type(many_things...), this method is called over and over so we hit a stack overflow. Fortunately, changing some OnlineStatsBase code from promote_type(types...) to reduce(promote_type, types) fixes everything.


Re: Vectors vs. Tuples as the Group container: Tuples are faster for a small number of items.

from onlinestats.jl.

joshday avatar joshday commented on June 19, 2024

new OnlineStatsBase release is pending.

from onlinestats.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.