Skip to content
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

Wtih constant data fit(Histogram) sometimes gives a wrong result #804

Closed
vincent-picaud opened this issue Jun 20, 2022 · 6 comments
Closed

Comments

@vincent-picaud
Copy link

vincent-picaud commented Jun 20, 2022

In some circumstances, fit(Histogram) gives a wrong result.

An example that gives the expected result : weight = 5 in [0,1)

julia> using StatsBase

julia> d=zeros(5)
5-element Vector{Float64}:
 0.0
 0.0
 0.0
 0.0
 0.0

julia> StatsBase.fit(Histogram,d)
Histogram{Int64, 1, Tuple{StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}}}
edges:
  0.0:1.0:1.0
weights: [5]
closed: left
isdensity: false

however, with another constant data value the result makes no sense (to me) : weight = 0 in [1.1, 3.1)

julia> d.+=0.1
5-element Vector{Float64}:
 0.1
 0.1
 0.1
 0.1
 0.1

julia> StatsBase.fit(Histogram,d)
Histogram{Int64, 1, Tuple{StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}}}
edges:
  1.1:2.0:3.1
weights: [0]
closed: left
isdensity: false

My Julia version :

julia> versioninfo()
Julia Version 1.7.1
Commit ac5cc99908 (2021-12-22 19:35 UTC)
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: Intel(R) Core(TM) i7-9850H CPU @ 2.60GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-12.0.1 (ORCJIT, skylake)

@vincent-picaud vincent-picaud changed the title With data = [0.9999...,0.9999...] , fit(Histogram) gives a wrong result Wtih constant data fit(Histogram) sometimes gives a wrong result Jun 20, 2022
@devmotion
Copy link
Member

The issue is fixed on the master branch, probably by #792:

julia> ] add StatsBase#master

julia> using StatsBase

julia> d=zeros(5)
5-element Vector{Float64}:
 0.0
 0.0
 0.0
 0.0
 0.0

julia> StatsBase.fit(Histogram,d)
Histogram{Int64, 1, Tuple{StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}}}
edges:
  0.0:1.0:1.0
weights: [5]
closed: left
isdensity: false

julia> d.+=0.1
5-element Vector{Float64}:
 0.1
 0.1
 0.1
 0.1
 0.1

julia> StatsBase.fit(Histogram,d)
Histogram{Int64, 1, Tuple{StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}}}
edges:
  0.1:1.0:1.1
weights: [5]
closed: left
isdensity: false

@devmotion
Copy link
Member

A new release should be available quite soon: #803

@vincent-picaud
Copy link
Author

@devmotion thanks for the quick answer and sorry for not being aware of #803.

@vincent-picaud
Copy link
Author

Should I close the issue?

@devmotion
Copy link
Member

That depends on you 🙂 I think it's OK to keep it open until a new release is available. But if you think your problem is addressed sufficiently since it is fixed on the master branch, feel free to close it.

@vincent-picaud
Copy link
Author

As the problem is fixed I will close it. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants