-
Notifications
You must be signed in to change notification settings - Fork 10
/
some_tests.jl
152 lines (114 loc) · 3.75 KB
/
some_tests.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
@testitem "fitting archimedians" begin
using Distributions
using Random
MyD = SklarDist(ClaytonCopula(3,7),(LogNormal(),Pareto(),Beta()))
u = rand(MyD,10000)
rand!(MyD,u)
fit(SklarDist{ClaytonCopula,Tuple{LogNormal,Pareto,Beta}},u)
fit(SklarDist{GaussianCopula,Tuple{LogNormal,Pareto,Beta}},u)
@test 1==1
# loglikelyhood(MyD,u)
end
# We could test loklikelyhood for every copula on a standard uniform sample.
# We should also test the fit function on several sklar models.
# and teszt the loglikelyhood of the SlakrDist.
# We should also test other htings ? Dunno what yet.
# We could also test the behavior of Turing models, so that what Herb did will not fade away with releases;
# @testitem "GaussianCopula" begin
# C = GaussianCopula([1 -0.1; -0.1 1])
# M1 = Beta(2,3)
# M2 = LogNormal(2,3)
# D = SklarDist(C,(M1,M2))
# X = rand(D,1000)
# loglikelihood(D,X)
# fit(SklarDist{TCopula,Tuple{Beta,LogNormal}},X) # should give a very high \nu for the student copula.
# end
# Same thing with other models ?
@testitem "testing cdf values at corners" begin
using Distributions
using Random
Copula_Zoo = (
GumbelCopula(2,1.2),
ClaytonCopula(4,7.0),
GaussianCopula([1 0.3; 0.3 1]),
FrankCopula(5,6.0),
AMHCopula(3,0.7)
)
for C in Copula_Zoo
d = length(C)
@test cdf(C,ones(d)) ≈ 1
@test cdf(C,zeros(d)) ≈ 0
end
for C in (TCopula(4,[1 0.5; 0.5 1]),)
d = length(C)
@test_broken cdf(C,ones(d)) ≈ 1
@test_broken cdf(C,zeros(d)) ≈ 0
end
end
@testitem "pdf/cdf archimedean" begin
using Distributions
using Random
x = Normal(0,1); y = Normal(0,2);
C = GumbelCopula(2, 1.2) # a type of Archimedean copula
D = SklarDist(C, (x,y))
pdf(D, ([1.0, 1.0]))
cdf(D, ([1.0, 1.0]))
@test 1==1
end
@testitem "pdf/cdf gaussian" begin
using Distributions
using Random
x = Normal(0, 1)
y = Normal(0, 2)
C = GaussianCopula([1 0.5; 0.5 1])
D = SklarDist(C, (x,y))
pdf(D, ([1.0, 1.0])) # this is fine
cdf(D, ([1.0, 1.0])) # now passes.
@test 1==1
end
@testitem "pdf/cdf student" begin
using Distributions
using Random
x = Normal(0, 1)
y = Normal(0, 2)
C = TCopula(4,[1 0.5; 0.5 1])
D = SklarDist(C, (x,y))
pdf(D, ([1.0, 1.0])) # this is fine
cdf(D, ([1.0, 1.0])) # this produces error due to non-existance of cdf of multivariate student in Distributions.jl
@test 1==1
end
@testitem "bare value gaussian model" begin
using Distributions
using Random
# source: https://discourse.julialang.org/t/cdf-of-a-copula-from-copulas-jl/85786/20
Random.seed!(123)
C1 = GaussianCopula([1 0.5; 0.5 1])
D1 = SklarDist(C1, (Normal(0,1),Normal(0,2)))
@test cdf(D1, [-0.1, 0.1]) ≈ 0.3219002977336174 rtol=1e-3
end
@testitem "working measure" begin
using Distributions
using Random
for C in (ClaytonCopula(4,7.0),GumbelCopula(2, 1.2))
d = length(C)
u = zeros(d)
v = ones(d)
@test Copulas.measure(C,u,v) >= 0
for i in 1:d
u[i] = rand()
v[i] = u[i] + rand()*(1-u[i])
end
@test Copulas.measure(C,u,v) >= 0
end
for C in (TCopula(4,[1 0.5; 0.5 1]),)
d = length(C)
u = zeros(d)
v = ones(d)
@test_broken Copulas.measure(C,u,v) >= 0
for i in 1:d
u[i] = rand()
v[i] = u[i] + rand()*(1-u[i])
end
@test_broken Copulas.measure(C,u,v) >= 0
end
end