File tree Expand file tree Collapse file tree 3 files changed +22
-2
lines changed
src/SimpleGraphs/generators Expand file tree Collapse file tree 3 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -114,7 +114,7 @@ function randbn(
114
114
log_q = log (1.0 - p)
115
115
x = 0
116
116
sum = 0.0
117
- while true
117
+ for _ in 1 : n
118
118
sum += log (rand (rng)) / (n - x)
119
119
sum < log_q && break
120
120
x += 1
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ using Compat
11
11
using DelimitedFiles
12
12
using Base64
13
13
using Random
14
- using Statistics: mean
14
+ using Statistics: mean, std
15
15
using StableRNGs
16
16
17
17
const testdir = dirname (@__FILE__ )
Original file line number Diff line number Diff line change 364
364
@test isvalid_simplegraph (rog3)
365
365
@test ! is_cyclic (rog3)
366
366
end
367
+
368
+ @testset " randbn" begin
369
+ for i in 0 : 10
370
+ @test Graphs. SimpleGraphs. randbn (i, 0.0 ; rng= rng) == 0
371
+ @test Graphs. SimpleGraphs. randbn (i, 1.0 ; rng= rng) == i
372
+ end
373
+ N = 30
374
+ s1 = zeros (N)
375
+ s2 = zeros (N)
376
+ for i in 1 : N
377
+ s1[i] = Graphs. SimpleGraphs. randbn (5 , 0.3 )
378
+ s2[i] = Graphs. SimpleGraphs. randbn (3 , 0.7 )
379
+ end
380
+ μ1 = mean (s1)
381
+ μ2 = mean (s2)
382
+ sv1 = std (s1)
383
+ sv2 = std (s2)
384
+ @test μ1 - sv1 <= 0.3 * 5 <= μ1 + sv1 # since the stdev of μ1 is around sv1/sqrt(N), this should rarely fail
385
+ @test μ2 - sv2 <= 0.7 * 3 <= μ2 + sv2
386
+ end
367
387
end
You can’t perform that action at this time.
0 commit comments