I am running a simulation task which is supposed to sample data from an exponential distribution, but the results are always larger than correct ones. I converted my julia code to matlab and it produced correct results (without any logic and algorithm changes).
I checked my code until I found something weird similar to this, I wonder if this is a bug in Distributions.jl
:
histogram(rand(Exponential(1e5),1000000),bins=256)
When running this line of code repeatedly in the REPL, I found that it displayed significantly 2 different histograms, and the incorrect one was clearer when I combined them into one plot (see below).
Both p (correct) and q (incorrect) are sampled this way and plotted using histogram()
, and are 1000000-element vector:
julia> q = rand(Exponential(1e5),1000000)
julia> histogram(q, bins=256, label="q") # after trying several times to find incorrect sample
...
julia> p = rand(Exponential(1e5),1000000)
julia> histogram!(p, bins=256, label="p")
Both p and q are 1000000-element vector:
julia> q
1000000-element Vector{Float64}:
36615.51140190222
â‹®
76827.76195613605
julia> p
1000000-element Vector{Float64}:
95336.41621794412
â‹®
160348.4912588241
Here is the corresponding matlab code and result:
>> histogram(exprnd(1e5,1000000,1),256)
It is worth noting that the julia
sample results seem to be too “stable” compared to matlab
. (I find it difficult to explain, but you might understand this after running such code both in julia and matlab. Anyway, this is not the core question I want to ask.)
julia version: v1.7.2
package version: Distributions.jl v0.25.58