-
Notifications
You must be signed in to change notification settings - Fork 0
/
clupoints_n_1_template.jl
56 lines (46 loc) · 1.97 KB
/
clupoints_n_1_template.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
52
53
54
55
56
# Copyright (c) 2020-2023 Nuno Fachada and contributors
# Distributed under the MIT License (See accompanying file LICENSE or copy
# at http://opensource.org/licenses/MIT)
# Test clupoints_n_1_template
@testset "clupoints_n_1_template" begin
# Number of line directions to test
ndirs = 3
# Number of line centers to test
ncts = 3
# Distance from points to projections will be 10
dist_pt = 10
@testset """
nd=$nd, tpts=$tpts, seed=$(Int(rng.seed[1])), lat_std=$lat_std,
length=$length, dir=$dir, ctr=$ctr"
""" for nd in num_dims,
# Avoid too many points, otherwise testing will be very slow
tpts in filter((x) -> x < 1000, num_points),
rng in rngs,
lat_std in lat_stds,
length in llengths_mus,
dir in get_unitvecs(rng, ndirs, nd),
ctr in get_vecs(rng, ncts, nd)
# Create some point projections
proj_dist_fn2ctr = length .* rand(rng, tpts) .- length / 2
proj = points_on_line(ctr, dir, proj_dist_fn2ctr)
# Very simple dist_fn, always puts points at a distance of dist_pt
dist_fn =
(clu_num_points, ldisp, rg) -> rand(rg, [-dist_pt, dist_pt], clu_num_points, 1)
# Check that the clupoints_n_1_template function runs without warnings
pts = @test_nowarn CluGen.clupoints_n_1_template(
proj, lat_std, dir, dist_fn; rng=rng
)
# Check that number of points is the same as the number of projections
@test size(pts) == size(proj)
# The following checks are only for dimensionality above 1
if nd > 1
# For each vector from projection to point...
for u in eachrow(pts - proj)
# Vector should be approximately orthogonal to the cluster line
@test isapprox(dot(dir, u), 0, atol=1e-7)
# Vector should have a magnitude of approximately dist_pt
@test norm(u) ≈ dist_pt
end
end
end
end