-
Notifications
You must be signed in to change notification settings - Fork 1
/
run_tests.m
43 lines (31 loc) · 1.12 KB
/
run_tests.m
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
function run_tests
%% Testing drnd(values, pmf, N)
N = 100000;
values = [-1, -2, -3];
pmf = [0.1, 0.3, 0.6];
obs = drnd(values, pmf, N);
for i=1:length(values)
epmf(i) = sum(obs==values(i))/N;
end
assert(is_equal(epmf, pmf, 0.01));
%% Testing vMUM standard
[mu, k, p1, p2, p3] = circ_vmum_standard(pi, 10, 0.3, 0.5, 0.2);
assert(is_equal(circ_vmum_pdf(mu, k, p1, p2, p3, linspace(0,2*pi,100)),...
circ_vmum_pdf(pi, 10, 0.3, 0.5, 0.2, linspace(0,2*pi,100))));
[mu, k, p1, p2, p3] = circ_vmum_standard(pi, -10, 0.3, 0.5, 0.2);
assert(is_equal(circ_vmum_pdf(mu, k, p1, p2, p3, linspace(0,2*pi,100)),...
circ_vmum_pdf(pi, -10, 0.3, 0.5, 0.2, linspace(0,2*pi,100))));
%% Testing vM for large kappa
thetas = linspace(-4*pi,4*pi,1000);
vm_uncorrected = circ_vm_pdf(0, 600, thetas, false);
vm_corrected = circ_vm_pdf(0, 600, thetas, true);
assert(is_equal(vm_corrected, vm_uncorrected, 1e-2));
assert(all(not(isnan(circ_vm_pdf(0, 10000, thetas, true)))));
display('All tests passed!');
end
function result = is_equal(a, b, tol)
if nargin == 2
tol = 1e-10;
end
result = all(abs(a-b)<tol);
end