Create userdata without user values in Lua 5.4
[liba.git] / test / rbf.h
blob3fc448b66166c5f10e2134663cef738bcd7d3421
1 #define MAIN_(x) A_CAST_2(x, _rbf)
2 #include "test.h"
3 #include "a/tf.h"
4 #include "a/rbf.h"
5 #include "a/math.h"
7 int MAIN(int argc, char *argv[]) // NOLINT(misc-definitions-in-headers)
9 test_init(argc, argv, 1);
11 a_tf_s tf;
13 static a_float_t num[] = {A_FLOAT_C(6.59492796e-05), A_FLOAT_C(6.54019884e-05)};
14 static a_float_t den[] = {A_FLOAT_C(-1.97530991), A_FLOAT_C(0.97530991)};
15 static a_float_t input[A_LEN(num)];
16 static a_float_t output[A_LEN(den)];
17 a_tf_init(&tf, A_LEN(num), num, input, A_LEN(den), den, output);
19 a_rbf_s ctx;
21 static a_float_t input[2];
22 static a_float_t center[10] = {-1, A_FLOAT_C(-0.5), 0, A_FLOAT_C(0.5), 1, -10, 5, 0, 5, 10};
23 static a_float_t height[5] = {A_FLOAT_C(1.5), A_FLOAT_C(1.5), A_FLOAT_C(1.5), A_FLOAT_C(1.5), A_FLOAT_C(1.5)};
24 static a_float_t hidden[5];
25 static a_float_t weight[5];
26 static a_float_t deltaw[5];
27 static a_float_t output[1];
28 ctx.input_p = input;
29 ctx.input_n = 2;
30 ctx.center_p = center;
31 ctx.center_n = 10;
32 ctx.height_p = height;
33 ctx.height_n = 1;
34 ctx.hidden_p = hidden;
35 ctx.hidden_n = 5;
36 ctx.output_p = output;
37 ctx.output_n = 1;
38 ctx.weight = weight;
39 ctx.deltaw = deltaw;
40 ctx.learn = A_FLOAT_C(0.5);
41 ctx.alpha = A_FLOAT_C(0.05);
42 a_rbf_zero(&ctx);
45 for (unsigned int i = 0; i < 1000; ++i)
47 ctx.input_p[0] = a_float_sin(A_FLOAT_C(0.002) * A_FLOAT_PI * a_float_c(, i));
48 ctx.input_p[1] = *tf.output;
49 a_rbf_tune(&ctx, ctx.input_p);
50 a_tf_iter(&tf, *a_rbf_iter(&ctx));
51 debug(A_FLOAT_PRI("+", "f ") A_FLOAT_PRI("+", "f ") A_FLOAT_PRI("+", "f ") A_FLOAT_PRI("+", "f\n"),
52 A_FLOAT_C(0.002) * A_FLOAT_PI * a_float_c(, i), *ctx.input_p, *ctx.output_p, *tf.output);
55 return 0;