3ef342295e6f2f605e2662df8eb07c91424d42bb
[ppam-mpi.git] / code / test / Algorithm / t.compute_coefficients.c
1 #include "Algorithm/compute_coefficients.h"
2 #include "Util/types.h"
3 #include "lut.h"
4 #include <math.h>
5 #include <stdlib.h>
6
7 void t_compute_coefficients1()
8 {
9 uint32_t nbSeries = 3;
10 uint32_t nbValues = 10;
11 Real curves[] =
12 {
13 1.0,2.0,3.0,4.0,1.0,2.0,3.0,4.0,1.0,2.0,
14 3.0,4.0,1.0,2.0,3.0,4.0,1.0,1.0,2.0,3.0,
15 3.0,1.0,0.0,8.0,2.0,4.0,2.0,0.0,3.0,3.0
16 };
17
18 PowerCurve* powerCurves = (PowerCurve*)malloc(nbSeries*sizeof(PowerCurve));
19 for (int i=0; i<nbSeries; i++)
20 {
21 powerCurves[i].ID = i;
22 powerCurves[i].values = curves + i * nbValues;
23 }
24
25 // Expected energy matrix: (to change...)
26 // 1.2829311 2.8197073 2.7653092 0.5390868
27 // 1.433019 3.319643 2.078569 1.248209
28 // 1.4532363 6.1433038 5.2052217 0.3447528
29
30 uint32_t nbReducedCoordinates = 4; //2^4 > 10, 2^3 < 10
31 Real* reducedCoordinates = (Real*)malloc(nbSeries * nbReducedCoordinates * sizeof(Real));
32 Real epsilon = 1e-4;
33 compute_coefficients(powerCurves, nbSeries, nbValues, reducedCoordinates, 0, nbReducedCoordinates);
34 free(powerCurves);
35
36 //~ LUT_ASSERT(fabs(reducedCoordinates[0] - 1.2829311) < epsilon);
37 //~ LUT_ASSERT(fabs(reducedCoordinates[1] - 2.8197073) < epsilon);
38 //~ LUT_ASSERT(fabs(reducedCoordinates[2] - 2.7653092) < epsilon);
39 //~ LUT_ASSERT(fabs(reducedCoordinates[3] - 0.5390868) < epsilon);
40 //~
41 //~ LUT_ASSERT(fabs(reducedCoordinates[4] - 1.433019) < epsilon);
42 //~ LUT_ASSERT(fabs(reducedCoordinates[5] - 3.319643) < epsilon);
43 //~ LUT_ASSERT(fabs(reducedCoordinates[6] - 2.078569) < epsilon);
44 //~ LUT_ASSERT(fabs(reducedCoordinates[7] - 1.248209) < epsilon);
45 //~
46 //~ LUT_ASSERT(fabs(reducedCoordinates[8] - 1.4532363) < epsilon);
47 //~ LUT_ASSERT(fabs(reducedCoordinates[9] - 6.1433038) < epsilon);
48 //~ LUT_ASSERT(fabs(reducedCoordinates[10] - 5.2052217) < epsilon);
49 //~ LUT_ASSERT(fabs(reducedCoordinates[11] - 0.3447528) < epsilon);
50
51 free(reducedCoordinates);
52 }
53
54 void t_compute_coefficients2()
55 {
56 uint32_t nbSeries = 3;
57 uint32_t nbValues = 20;
58 Real curves[] =
59 {
60 0.07291223,0.3468863,0.8648239,0.2348877,0.4315312,0.7036144,0.2431289,0.01040031,0.1178515,0.03080914,0.3673594,0.3738354,0.6695186,0.9140619,0.3102869,0.6374112,0.843919,0.2661967,0.1571974,0.7748992,
61 0.8818654,0.6703627,0.8847847,0.03184918,0.997876,0.7612137,0.6387965,0.296034,0.5018912,0.7942868,0.1095461,0.3727642,0.2351644,0.5057783,0.7287164,0.340264,0.08904832,0.5050351,0.1371493,0.8821361,
62 0.1844872,0.5861217,0.7114864,0.8779052,0.5999996,0.2707162,0.9586406,0.6902478,0.2514943,0.8113025,0.2820882,0.5661663,0.9571422,0.6838519,0.998652,0.6126693,0.9178886,0.7810725,0.7895782,0.181061
63 };
64
65 PowerCurve* powerCurves = (PowerCurve*)malloc(nbSeries*sizeof(PowerCurve));
66 for (int i=0; i<nbSeries; i++)
67 {
68 powerCurves[i].ID = i;
69 powerCurves[i].values = curves + i * nbValues;
70 }
71
72 //~ // Expected energy matrix:
73 //~ // ...TODO
74
75 uint32_t nbReducedCoordinates = 5; //2^5 > 20, 2^4 < 20
76 Real* reducedCoordinates = (Real*)malloc(nbSeries * nbReducedCoordinates * sizeof(Real));
77 Real epsilon = 1e-4;
78 compute_coefficients(powerCurves, nbSeries, nbValues, reducedCoordinates, 0, nbReducedCoordinates);
79 free(powerCurves);
80
81 //~ LUT_ASSERT(fabs(reducedCoordinates[0] - 1.2829311) < epsilon);
82 //~ LUT_ASSERT(fabs(reducedCoordinates[1] - 2.8197073) < epsilon);
83 //~ LUT_ASSERT(fabs(reducedCoordinates[2] - 2.7653092) < epsilon);
84 //~ LUT_ASSERT(fabs(reducedCoordinates[3] - 0.5390868) < epsilon);
85 //~ LUT_ASSERT(fabs(reducedCoordinates[4] - 0.5390868) < epsilon);
86 //~
87 //~ LUT_ASSERT(fabs(reducedCoordinates[5] - 3.319643) < epsilon);
88 //~ LUT_ASSERT(fabs(reducedCoordinates[6] - 2.078569) < epsilon);
89 //~ LUT_ASSERT(fabs(reducedCoordinates[7] - 1.248209) < epsilon);
90 //~ LUT_ASSERT(fabs(reducedCoordinates[8] - 1.4532363) < epsilon);
91 //~ LUT_ASSERT(fabs(reducedCoordinates[9] - 6.1433038) < epsilon);
92 //~
93 //~ LUT_ASSERT(fabs(reducedCoordinates[10] - 5.2052217) < epsilon);
94 //~ LUT_ASSERT(fabs(reducedCoordinates[11] - 0.3447528) < epsilon);
95 //~ LUT_ASSERT(fabs(reducedCoordinates[12] - 0.3447528) < epsilon);
96 //~ LUT_ASSERT(fabs(reducedCoordinates[13] - 1.248209) < epsilon);
97 //~ LUT_ASSERT(fabs(reducedCoordinates[14] - 1.248209) < epsilon);
98
99 free(reducedCoordinates);
100 }