-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_sampling_distribution.jl
51 lines (43 loc) · 1.06 KB
/
test_sampling_distribution.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#why my fig2_nonspatial_origins plot have higher plateau than 2019paper?
using Distributions
using Base.Threads
print(rand(Multinomial(100,[0.1,0.3,0.6])))
function simu_p(n)
x=rand(n)
x=x/sum(x)
return x
end
##dif k (the number of categories of probability)
function multi(k)
a=Array{Int}(undef,k,0)
p=simu_p(k)
for i in 1:1000
b=rand(Multinomial(100,p))
a=hcat(a,b)
end
return a
end
using Plots
# plot(a)
a=multi(4)#change input and see
histogram(a'/100,xticks=0:0.05:0.8,bar_width=0.005)
#visually normal distribution
##dif @thread
# using Base.Threads
function multi(k)#k as the number of categories
a=Array{Int}(undef,k,0)
p=simu_p(k)
@threads for i in 1:1000
b=rand(Multinomial(100,p))
a=hcat(a,b)
end
return a
end
a=multi(4)
histogram(a'/100,xticks=0:0.05:0.8,bar_width=0.005)
#samplign seed change every time
pwd()
savefig("..\\photo\\multinomial_distribution_test")
#conclusion:
#seed (sampling pool) change with replication, k. @threads condition too
#visually normal distribution