@@ -19,145 +19,147 @@ using RobustModels:
19
19
emp_norm (l:: LossFunction ) = 2 * quadgk (x -> exp (- RobustModels. rho (l, x)), 0 , Inf )[1 ]
20
20
21
21
22
+ @testset " Losses and estimators" begin
22
23
23
- @testset " Methods loss functions: $(name) " for name in losses
24
- typeloss = getproperty (RobustModels, Symbol (name * " Loss" ))
25
- l = typeloss ()
26
-
27
- @testset " Methods estimators: $(estimator) " for estimator in (
28
- nothing , " M" , " S" , " MM" , " Tau" , " GeneralizedQuantile"
29
- )
30
- # Check LossFunction methods
31
- if isnothing (estimator)
32
- estimator_name = " Loss function"
33
- typest = typeloss
34
-
35
- # Check AbstractEstimator methods
36
- else
37
- estimator_name = " $(estimator) Estimator"
38
- T = getproperty (RobustModels, Symbol (estimator * " Estimator" ))
39
- if estimator in (" S" , " MM" , " Tau" )
40
- if ! in (name, bounded_losses)
41
- @test_throws TypeError T{typeloss}
42
- continue
43
- end
44
- end
45
- typest = T{typeloss}
46
- end
47
- est = typest ()
48
- @test_nowarn println (est)
49
-
50
- if ! isnothing (estimator)
51
- if estimator == " Tau"
52
- # @test isa(loss(est), Tuple{BoundedLossFunction, BoundedLossFunction})
53
- @test isa (loss (est), CompositeLossFunction)
54
- @test typeof (first (loss (est))) == typeloss
55
- @test typeof (last (loss (est))) == typeloss
56
- else
57
- @test typeof (loss (est)) == typeloss
58
- end
59
- end
24
+ @testset " loss functions: $(name) " for name in losses
25
+ typeloss = getproperty (RobustModels, Symbol (name * " Loss" ))
26
+ l = typeloss ()
60
27
61
- @testset " Bounded $(estimator_name) : $(name ) " begin
62
- if name in bounded_losses
63
- @test isbounded (est )
64
- else
65
- @test ! isbounded (est )
66
- end
67
- end
28
+ @testset " Methods estimators : $(estimator ) " for estimator in (
29
+ nothing , " M " , " S " , " MM " , " Tau " , " GeneralizedQuantile "
30
+ )
31
+ # Check LossFunction methods
32
+ if isnothing (estimator )
33
+ estimator_name = " Loss function "
34
+ typest = typeloss
68
35
69
- @testset " Convex $(estimator_name) : $(name) " begin
70
- if name in convex_losses
71
- @test isconvex (est)
36
+ # Check AbstractEstimator methods
72
37
else
73
- @test ! isconvex (est)
38
+ estimator_name = " $(estimator) Estimator"
39
+ T = getproperty (RobustModels, Symbol (estimator * " Estimator" ))
40
+ if estimator in (" S" , " MM" , " Tau" )
41
+ if ! in (name, bounded_losses)
42
+ @test_throws TypeError T{typeloss}
43
+ continue
44
+ end
45
+ end
46
+ typest = T{typeloss}
47
+ end
48
+ est = typest ()
49
+ @test_nowarn show (devnull , est)
50
+
51
+ if ! isnothing (estimator)
52
+ if estimator == " Tau"
53
+ # @test isa(loss(est), Tuple{BoundedLossFunction, BoundedLossFunction})
54
+ @test isa (loss (est), CompositeLossFunction)
55
+ @test typeof (first (loss (est))) == typeloss
56
+ @test typeof (last (loss (est))) == typeloss
57
+ else
58
+ @test typeof (loss (est)) == typeloss
59
+ end
74
60
end
75
- end
76
-
77
- @testset " $(estimator_name) values: $(name) " begin
78
- ρ = rho (est, 1 )
79
- ψ = psi (est, 1 )
80
- ψp = psider (est, 1 )
81
- w = weight (est, 1 )
82
-
83
- vals = estimator_values (est, 1 )
84
- @test length (vals) == 3
85
- @test vals[1 ] ≈ ρ rtol = 1e-6
86
- @test vals[2 ] ≈ ψ rtol = 1e-6
87
- @test vals[3 ] ≈ w rtol = 1e-6
88
- end
89
61
90
- # Only for LossFunction
91
- if isnothing (estimator)
92
- @testset " Loss methods: $(name) " begin
93
- @test loss (est) == est
62
+ @testset " Bounded $(estimator_name) : $(name) " begin
63
+ if name in bounded_losses
64
+ @test isbounded (est)
65
+ else
66
+ @test ! isbounded (est)
67
+ end
68
+ end
94
69
95
- # estimator_bound
96
- if ! isconvex (est)
97
- @test isfinite (RobustModels . estimator_bound ( est) )
70
+ @testset " Convex $(estimator_name) : $(name) " begin
71
+ if name in convex_losses
72
+ @test isconvex ( est)
98
73
else
99
- @test ! isfinite (RobustModels . estimator_bound ( est) )
74
+ @test ! isconvex ( est)
100
75
end
76
+ end
77
+
78
+ @testset " $(estimator_name) values: $(name) " begin
79
+ ρ = rho (est, 1 )
80
+ ψ = psi (est, 1 )
81
+ ψp = psider (est, 1 )
82
+ w = weight (est, 1 )
83
+
84
+ vals = estimator_values (est, 1 )
85
+ @test length (vals) == 3
86
+ @test vals[1 ] ≈ ρ rtol = 1e-6
87
+ @test vals[2 ] ≈ ψ rtol = 1e-6
88
+ @test vals[3 ] ≈ w rtol = 1e-6
89
+ end
101
90
102
- # tuning_constant
103
- @test isfinite (RobustModels. tuning_constant (est))
91
+ # Only for LossFunction
92
+ if isnothing (estimator)
93
+ @testset " Loss methods: $(name) " begin
94
+ @test loss (est) == est
104
95
105
- @testset " Estimator norm: $(name) " begin
106
- if ! isbounded (est)
107
- @test emp_norm (est) ≈ RobustModels. estimator_norm (est) rtol = 1e-5
96
+ # estimator_bound
97
+ if ! isconvex (est)
98
+ @test isfinite ( RobustModels. estimator_bound (est))
108
99
else
109
- @test ! isfinite (RobustModels. estimator_norm (est))
100
+ @test ! isfinite (RobustModels. estimator_bound (est))
110
101
end
111
- end
112
102
113
- if ! in (name, (" L2" , " L1" ))
114
- @testset " Estimator high efficiency: $(name) " begin
115
- vopt = estimator_high_efficiency_constant (typest)
116
- if name != " HardThreshold"
117
- v = efficiency_tuning_constant (typest; eff= 0.95 , c0= 0.9 * vopt)
118
- @test isapprox (v, vopt; rtol= 1e-3 )
103
+ # tuning_constant
104
+ @test isfinite (RobustModels. tuning_constant (est))
105
+
106
+ @testset " Estimator norm: $(name) " begin
107
+ if ! isbounded (est)
108
+ @test emp_norm (est) ≈ RobustModels. estimator_norm (est) rtol = 1e-5
109
+ else
110
+ @test ! isfinite (RobustModels. estimator_norm (est))
119
111
end
120
112
end
121
- end
122
113
123
- if isbounded (est)
124
- @testset " Estimator high breakdown point: $(name) " begin
125
- vopt = estimator_high_breakdown_point_constant (typest)
126
- v = breakdown_point_tuning_constant (typest; bp= 0.5 , c0= 1.1 * vopt)
127
- @test isapprox (v, vopt; rtol= 1e-3 )
114
+ if ! in (name, (" L2" , " L1" ))
115
+ @testset " Estimator high efficiency: $(name) " begin
116
+ vopt = estimator_high_efficiency_constant (typest)
117
+ if name != " HardThreshold"
118
+ v = efficiency_tuning_constant (typest; eff= 0.95 , c0= 0.9 * vopt)
119
+ @test isapprox (v, vopt; rtol= 1e-3 )
120
+ end
121
+ end
128
122
end
129
123
130
- @testset " τ-Estimator high efficiency: $(name) " begin
131
- vopt = estimator_tau_efficient_constant (typest)
132
- if name != " HardThreshold "
133
- v = tau_efficiency_tuning_constant (typest; eff = 0.95 , c0= 1.1 * vopt)
124
+ if isbounded (est)
125
+ @testset " Estimator high breakdown point: $(name) " begin
126
+ vopt = estimator_high_breakdown_point_constant (typest)
127
+ v = breakdown_point_tuning_constant (typest; bp = 0.5 , c0= 1.1 * vopt)
134
128
@test isapprox (v, vopt; rtol= 1e-3 )
135
129
end
130
+
131
+ @testset " τ-Estimator high efficiency: $(name) " begin
132
+ vopt = estimator_tau_efficient_constant (typest)
133
+ if name != " HardThreshold"
134
+ v = tau_efficiency_tuning_constant (typest; eff= 0.95 , c0= 1.1 * vopt)
135
+ @test isapprox (v, vopt; rtol= 1e-3 )
136
+ end
137
+ end
136
138
end
137
139
end
138
140
end
139
- end
140
141
141
- if typest <: AbstractQuantileEstimator
142
- @testset " MQuantile: $(name) " begin
143
- τ = 0.5
144
- qest1 = GeneralizedQuantileEstimator (l, τ)
145
- qest2 = GeneralizedQuantileEstimator {typeloss} (τ)
146
- @test qest1 == qest2
147
- if name == " L2"
148
- qest4 = ExpectileEstimator (τ)
149
- @test qest1 == qest4
150
- elseif name == " L1"
151
- qest4 = RobustModels. QuantileEstimator (τ)
152
- @test qest1 == qest4
153
- end
142
+ if typest <: AbstractQuantileEstimator
143
+ @testset " MQuantile: $(name) " begin
144
+ τ = 0.5
145
+ qest1 = GeneralizedQuantileEstimator (l, τ)
146
+ qest2 = GeneralizedQuantileEstimator {typeloss} (τ)
147
+ @test qest1 == qest2
148
+ if name == " L2"
149
+ qest4 = ExpectileEstimator (τ)
150
+ @test qest1 == qest4
151
+ elseif name == " L1"
152
+ qest4 = RobustModels. QuantileEstimator (τ)
153
+ @test qest1 == qest4
154
+ end
154
155
155
- @testset " Pass through of methods" for fun in (rho, psi, psider, weight)
156
- ρ1 = fun (est, 1 )
157
- ρ2 = fun (qest1, 1 )
158
- @test ρ1 == ρ2
159
- end
156
+ @testset " Pass through of methods" for fun in (rho, psi, psider, weight)
157
+ ρ1 = fun (est, 1 )
158
+ ρ2 = fun (qest1, 1 )
159
+ @test ρ1 == ρ2
160
+ end
160
161
162
+ end
161
163
end
162
164
end
163
165
end
0 commit comments