| 151 | // ---------------------------------------------------------------------------------------- |
| 152 | |
| 153 | void test_trust_region_sub_problem() |
| 154 | { |
| 155 | dlog << LINFO << "subproblem test 1"; |
| 156 | { |
| 157 | matrix<double,2,2> B; |
| 158 | B = 1, 0, |
| 159 | 0, 1; |
| 160 | |
| 161 | matrix<double,2,1> g, p, ans; |
| 162 | g = 0; |
| 163 | |
| 164 | ans = 0; |
| 165 | |
| 166 | solve_trust_region_subproblem(B,g,1,p, 0.001, 10); |
| 167 | |
| 168 | DLIB_TEST(length(p-ans) < 1e-10); |
| 169 | solve_trust_region_subproblem(B,g,1,p, 0.001, 1); |
| 170 | DLIB_TEST(length(p-ans) < 1e-10); |
| 171 | } |
| 172 | |
| 173 | dlog << LINFO << "subproblem test 2"; |
| 174 | { |
| 175 | matrix<double,2,2> B; |
| 176 | B = 1, 0, |
| 177 | 0, 1; |
| 178 | |
| 179 | B *= 0.1; |
| 180 | |
| 181 | matrix<double,2,1> g, p, ans; |
| 182 | g = 1; |
| 183 | |
| 184 | ans = -g / length(g); |
| 185 | |
| 186 | solve_trust_region_subproblem(B,g,1,p, 1e-6, 20); |
| 187 | |
| 188 | DLIB_TEST(length(p-ans) < 1e-4); |
| 189 | } |
| 190 | |
| 191 | dlog << LINFO << "subproblem test 3"; |
| 192 | { |
| 193 | matrix<double,2,2> B; |
| 194 | B = 0, 0, |
| 195 | 0, 0; |
| 196 | |
| 197 | matrix<double,2,1> g, p, ans; |
| 198 | g = 1; |
| 199 | |
| 200 | ans = -g / length(g); |
| 201 | |
| 202 | solve_trust_region_subproblem(B,g,1,p, 1e-6, 20); |
| 203 | |
| 204 | dlog << LINFO << "ans: " << trans(ans); |
| 205 | dlog << LINFO << "p: " << trans(p); |
| 206 | DLIB_TEST(length(p-ans) < 1e-4); |
| 207 | } |
| 208 | return; |
| 209 | |
| 210 | dlog << LINFO << "subproblem test 4"; |
no test coverage detected