229 std::array<std::vector<double>, N> X = {
230 std::vector<double>({0, 1}), std::vector<double>({1, -2}),
231 std::vector<double>({2, 3}), std::vector<double>({3, -1}),
232 std::vector<double>({4, 1}), std::vector<double>({6, -5}),
233 std::vector<double>({-7, -3}), std::vector<double>({-8, 5}),
234 std::vector<double>({-9, 2}), std::vector<double>({-10, -15})};
235 std::array<int, N> y = {1, -1, 1, -1, -1,
238 std::cout <<
"------- Test 1 -------" << std::endl;
239 std::cout <<
"Model before fit: " << ada << std::endl;
242 std::cout <<
"Model after fit: " << ada << std::endl;
244 int predict = ada.
predict({5, -3});
245 std::cout <<
"Predict for x=(5,-3): " << predict;
246 assert(predict == -1);
247 std::cout <<
" ...passed" << std::endl;
250 std::cout <<
"Predict for x=(5,8): " << predict;
251 assert(predict == 1);
252 std::cout <<
" ...passed" << std::endl;
267 std::array<std::vector<double>, N> X;
268 std::array<int, N> Y{};
273 int range2 = range >> 1;
274 for (
int i = 0; i < N; i++) {
275 double x0 = (
static_cast<double>(std::rand() % range) - range2) / 100.f;
276 double x1 = (
static_cast<double>(std::rand() % range) - range2) / 100.f;
277 X[i] = std::vector<double>({x0, x1});
278 Y[i] = (x0 + 3. * x1) > -1 ? 1 : -1;
281 std::cout <<
"------- Test 2 -------" << std::endl;
282 std::cout <<
"Model before fit: " << ada << std::endl;
285 std::cout <<
"Model after fit: " << ada << std::endl;
287 int N_test_cases = 5;
288 for (
int i = 0; i < N_test_cases; i++) {
289 double x0 = (
static_cast<double>(std::rand() % range) - range2) / 100.f;
290 double x1 = (
static_cast<double>(std::rand() % range) - range2) / 100.f;
292 int predict = ada.
predict({x0, x1});
294 std::cout <<
"Predict for x=(" << x0 <<
"," << x1 <<
"): " << predict;
296 int expected_val = (x0 + 3. * x1) > -1 ? 1 : -1;
297 assert(predict == expected_val);
298 std::cout <<
" ...passed" << std::endl;
318 std::array<std::vector<double>, N> X;
319 std::array<int, N> Y{};
324 int range2 = range >> 1;
325 for (
int i = 0; i < N; i++) {
326 double x0 = (
static_cast<double>(std::rand() % range) - range2) / 100.f;
327 double x1 = (
static_cast<double>(std::rand() % range) - range2) / 100.f;
328 double x2 = (
static_cast<double>(std::rand() % range) - range2) / 100.f;
329 X[i] = std::vector<double>({x0, x1, x2, x0 * x0, x1 * x1, x2 * x2});
330 Y[i] = ((x0 * x0) + (x1 * x1) + (x2 * x2)) <= 1.f ? 1 : -1;
333 std::cout <<
"------- Test 3 -------" << std::endl;
334 std::cout <<
"Model before fit: " << ada << std::endl;
337 std::cout <<
"Model after fit: " << ada << std::endl;
339 int N_test_cases = 5;
340 for (
int i = 0; i < N_test_cases; i++) {
341 double x0 = (
static_cast<double>(std::rand() % range) - range2) / 100.f;
342 double x1 = (
static_cast<double>(std::rand() % range) - range2) / 100.f;
343 double x2 = (
static_cast<double>(std::rand() % range) - range2) / 100.f;
345 int predict = ada.
predict({x0, x1, x2, x0 * x0, x1 * x1, x2 * x2});
347 std::cout <<
"Predict for x=(" << x0 <<
"," << x1 <<
"," << x2
350 int expected_val = ((x0 * x0) + (x1 * x1) + (x2 * x2)) <= 1.f ? 1 : -1;
351 assert(predict == expected_val);
352 std::cout <<
" ...passed" << std::endl;