|
125 | 125 | bt = [true, false, true]
|
126 | 126 | bf = [false, true, true]
|
127 | 127 | @test rogerstanimoto(bt, bf) == 4.0 / 5.0
|
| 128 | + @test braycurtis(bt, bf) == 0.5 |
| 129 | + |
128 | 130 | for T in (Float64, F64)
|
129 | 131 |
|
130 | 132 | for (_x, _y) in (([4.0, 5.0, 6.0, 7.0], [3.0, 9.0, 8.0, 1.0]),
|
|
135 | 137 | @test jaccard(x, y) == 13.0 / 28
|
136 | 138 | @test cityblock(x, y) == 13.0
|
137 | 139 | @test chebyshev(x, y) == 6.0
|
| 140 | + @test braycurtis(x, y) == 1. - (30./43.) |
138 | 141 | @test minkowski(x, y, 2) == sqrt(57.0)
|
139 | 142 | @test_throws DimensionMismatch cosine_dist(1.0:2, 1.0:3)
|
140 | 143 | @test cosine_dist(x, y) ≈ (1.0 - 112. / sqrt(19530.0))
|
|
177 | 180 | @inferred evaluate(Jaccard(), [1, 2, 3], [1, 2, 3])
|
178 | 181 | @inferred evaluate(Jaccard(), [true, false, true], [false, true, true])
|
179 | 182 |
|
| 183 | + # Test Bray-Curtis. Should be 1 if no elements are shared, 0 if all are the same |
| 184 | + @test braycurtis([1,0,3],[0,1,0]) == 1.0 |
| 185 | + @test braycurtis(rand(10), zeros(10)) == 1.0 |
| 186 | + @test braycurtis([1,0],[1,0]) == 0.0 |
| 187 | + |
180 | 188 | # Test KL, Renyi and JS divergences
|
181 | 189 | r = rand(T, 12)
|
182 | 190 | p = copy(r)
|
@@ -232,12 +240,16 @@ end #testset
|
232 | 240 | @test isa(cityblock(a, b), T)
|
233 | 241 | @test chebyshev(a, b) == 0.0
|
234 | 242 | @test isa(chebyshev(a, b), T)
|
| 243 | + @test braycurtis(a, b) == 0.0 |
| 244 | + @test isa(braycurtis(a, b), T) |
235 | 245 | @test minkowski(a, b, 2) == 0.0
|
236 | 246 | @test isa(minkowski(a, b, 2), T)
|
237 | 247 | @test hamming(a, b) == 0.0
|
238 | 248 | @test isa(hamming(a, b), Int)
|
239 | 249 | @test renyi_divergence(a, b, 1.0) == 0.0
|
240 | 250 | @test isa(renyi_divergence(a, b, 2.0), T)
|
| 251 | + @test braycurtis(a, b) == 0.0 |
| 252 | + @test isa(braycurtis(a, b), T) |
241 | 253 |
|
242 | 254 | w = T[]
|
243 | 255 | @test isa(whamming(a, b, w), T)
|
|
384 | 396 |
|
385 | 397 | test_colwise(BhattacharyyaDist(), X, Y, T)
|
386 | 398 | test_colwise(HellingerDist(), X, Y, T)
|
| 399 | + test_colwise(BrayCurtis(), X, Y, T) |
387 | 400 |
|
388 | 401 | w = rand(T, m)
|
389 | 402 |
|
|
456 | 469 |
|
457 | 470 | test_pairwise(BhattacharyyaDist(), X, Y, T)
|
458 | 471 | test_pairwise(HellingerDist(), X, Y, T)
|
| 472 | + test_pairwise(BrayCurtis(), X, Y, T) |
459 | 473 |
|
460 | 474 | w = rand(m)
|
461 | 475 |
|
|
0 commit comments