|
58 | 58 |
|
59 | 59 | test_metricity(BhattacharyyaDist(), x, y, z)
|
60 | 60 | test_metricity(HellingerDist(), x, y, z)
|
61 |
| - |
| 61 | + |
| 62 | + x₁ = rand(T, 2) |
| 63 | + x₂ = rand(T, 2) |
| 64 | + x₃ = rand(T, 2) |
| 65 | + |
| 66 | + test_metricity(Haversine(6371.), x₁, x₂, x₃) |
| 67 | + |
62 | 68 | k = rand(1:3, n)
|
63 | 69 | l = rand(1:3, n)
|
64 | 70 | m = rand(1:3, n)
|
|
154 | 160 | @test wcityblock(x, y, w) ≈ dot(abs.(x - vec(y)), w)
|
155 | 161 | @test wminkowski(x, y, w, 2) ≈ weuclidean(x, y, w)
|
156 | 162 | end
|
157 |
| - |
| 163 | + |
158 | 164 |
|
159 | 165 | # Test weighted Hamming distances with even weights
|
160 | 166 | a = T.([1.0, 2.0, 1.0, 3.0, 2.0, 1.0])
|
|
187 | 193 | end
|
188 | 194 | @test kl_divergence(p, q) ≈ klv
|
189 | 195 | @test typeof(kl_divergence(p, q)) == T
|
190 |
| - |
| 196 | + |
191 | 197 |
|
192 | 198 | @test renyi_divergence(p, r, 0) ≈ -log(scale)
|
193 | 199 | @test renyi_divergence(p, r, 1) ≈ -log(scale)
|
@@ -272,6 +278,16 @@ end # testset
|
272 | 278 | end
|
273 | 279 | end #testset
|
274 | 280 |
|
| 281 | +@testset "haversine" begin |
| 282 | + for T in (Float64, F64) |
| 283 | + @test haversine([-180.,0.], [180.,0.], 1.) ≈ 0 atol=1e-10 |
| 284 | + @test haversine([0.,-90.], [0.,90.], 1.) ≈ π atol=1e-10 |
| 285 | + @test haversine((-180.,0.), (180.,0.), 1.) ≈ 0 atol=1e-10 |
| 286 | + @test haversine((0.,-90.), (0.,90.), 1.) ≈ π atol=1e-10 |
| 287 | + @test_throws ArgumentError haversine([0.,-90., 0.25], [0.,90.], 1.) |
| 288 | + end |
| 289 | +end |
| 290 | + |
275 | 291 | @testset "bhattacharyya / hellinger" begin
|
276 | 292 | for T in (Float64, F64)
|
277 | 293 | x, y = T.([4.0, 5.0, 6.0, 7.0]), T.([3.0, 9.0, 8.0, 1.0])
|
|
0 commit comments