31 int main(
int argc,
char** argv) {
33 fprintf(stdout,
"Usage: test_DLT_naive m bw loops\n");
37 int m = atoi(argv[1]);
38 int bw = atoi(argv[2]);
39 int loops = atoi(argv[3]);
41 double* samples = (
double*)malloc(
sizeof(
double) * 2 * bw);
42 double* coeffs = (
double*)malloc(
sizeof(
double) * (bw - m));
43 double* new_coeffs = (
double*)malloc(
sizeof(
double) * (bw - m));
45 double* relerror = (
double*)malloc(
sizeof(
double) * loops);
46 double* curmax = (
double*)malloc(
sizeof(
double) * loops);
48 double* plm = (
double*)malloc(
sizeof(
double) * 2 * bw * (bw - m));
49 double* workspace = (
double*)malloc(
sizeof(
double) * 18 * bw);
52 double* weights = (
double*)malloc(
sizeof(
double) * 4 * bw);
59 double sum_error = 0.0;
60 double sum_relerror = 0.0;
62 double total_time_f = 0.0;
63 double total_time_i = 0.0;
65 for (
int k = 0; k < loops; ++k) {
67 for (
int i = 0; i < (bw - m); ++i)
68 coeffs[i] = 2.0 * (drand48() - 0.5);
73 total_time_i += (
csecond() - time_start);
77 DLTNaive(samples, bw, m, weights, new_coeffs, plm, workspace);
78 total_time_f += (
csecond() - time_start);
84 for (
int i = 0; i < bw - m; ++i) {
85 double tmp_error = fabs(coeffs[i] - new_coeffs[i]);
86 double tmp_relerror = tmp_error / (fabs(coeffs[i]) + pow(10.0, -50.0));
87 curmax[k] = fmax(curmax[k], tmp_error);
88 relerror[k] = fmax(relerror[k], tmp_relerror);
91 sum_error += curmax[k];
92 sum_relerror += relerror[k];
95 double avg_error = sum_error / loops;
96 double avg_relerror = sum_relerror / loops;
97 double stddev_error = 0.0;
98 double stddev_relerror = 0.0;
99 for (
int i = 0; i < loops; ++i) {
100 stddev_error += pow(avg_error - curmax[i], 2.0);
101 stddev_relerror += pow(avg_relerror - relerror[i], 2.0);
105 stddev_error = sqrt(stddev_error / (loops - 1));
106 stddev_relerror = sqrt(stddev_relerror / (loops - 1));
109 fprintf(stdout,
"bw = %d\tm = %d\n", bw, m);
110 fprintf(stdout,
"loops = %d\n", loops);
112 fprintf(stdout,
"Average r-o error:\t\t %.4e\t", sum_error / loops);
113 fprintf(stdout,
"std dev: %.4e\n", stddev_error);
114 fprintf(stdout,
"Average (r-o)/o error:\t\t %.4e\t", sum_relerror / loops);
115 fprintf(stdout,
"std dev: %.4e\n\n", stddev_relerror);
117 fprintf(stdout,
"average forward time = %.4e\n", total_time_f / loops);
118 fprintf(stdout,
"average inverse time = %.4e\n", total_time_i / loops);