/ani/mrses

To get this branch, use:
bzr branch http://de.suren.me/webbzr/ani/mrses
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <assert.h>

#include "mrses.h"

#define ITERATIONS 5000

#define PROPERTIES 2048
#define SAMPLES1 50
#define SAMPLES2 40

#define WIDTH 5
#define TESTS 10000

//#define SINGULAR

//#define SINGLE_MODE 1
typedef uint32_t *uint32_p;

int ptr_compare(void *a, void *b) {
    return **(uint32_t**)b - **(uint32_t**)a;
}

int main() {
    MRSESContext ctx;
    MRSESDataType a[SAMPLES1 * PROPERTIES];
    MRSESDataType b[SAMPLES2 * PROPERTIES];
    
    MRSESDataType a_mean[PROPERTIES];
    MRSESDataType b_mean[PROPERTIES];

#ifdef SINGLE_MODE
    MRSESIntType tests[TESTS * WIDTH];
    MRSESDataType results[TESTS];
#else
    uint32_t hist[PROPERTIES];
    uint32_p sort[PROPERTIES];
    float sum;
#endif /* SINGLE_MODE */
    
    MRSESDataType val;

    int i,j;    
    int max_mode;
    
    for (i = 0; i < PROPERTIES; i++) {
	if ((i>3)&&(i<13)&&((i%2)==0)) max_mode = 1;
	else max_mode = 0;

	a_mean[i] = 0;
	for (j = 0; j < SAMPLES1; j++) {
#ifdef SINGULAR
	    if (i == 20) val = 0;
	    else val = ((MRSESDataType)random()) / RAND_MAX;

	    if (max_mode) {
		if ((i == 6)||(i == 8)) val = 9;
		else val += 9;
	    }
#else /* SINGULAR */
	    val = ((MRSESDataType)random()) / RAND_MAX;
	    if (max_mode) val += 9;
#endif /* SINGULAR */

	    a [ i * SAMPLES1 + j ] = val;
	    a_mean[i] += val; 
	}
	a_mean[i] /= SAMPLES1;

	a_mean[i] = 0;
	for (j = 0; j < SAMPLES2; j++) {
	    val = ((MRSESDataType)random()) / RAND_MAX;
	    b [ i * SAMPLES2 + j ] = val;
	    b_mean[i] += val; 
	}
	b_mean[i] /= SAMPLES2;
    }

    
    ctx = mrses_create_context();
    mrses_init_context(ctx, PROPERTIES, SAMPLES1, a, SAMPLES2, b);
    mrses_set_distance_mode(ctx, 0);
    mrses_prepare(ctx, WIDTH, TESTS);

#ifdef SINGLE_MODE
    assert((TESTS + WIDTH) < PROPERTIES);
    
    for (i = 1 ; i < TESTS ; i ++ ) {
	for (j = 0; j < WIDTH ; j ++) {
	    tests[i * WIDTH + j] = i + j;
	}
    }
    
    assert((4 + 2 * WIDTH) < PROPERTIES);
    
    for (j = 0; j < WIDTH ; j ++) {
	tests[j] = 4 + j * 2;
    }

    for (i = 0; i < ITERATIONS; i++) {    
	mrses_compute(ctx, TESTS, tests, results);
    }
    //mrses_compute(ctx, 1, tests, results);
#else /* SINGLE_MODE */
    mrses_iterate(ctx, ITERATIONS, TESTS, NULL);
    
    mrses_get_results(ctx, hist);
    
    for (i = 0, sum = 0; i < PROPERTIES; i++) {
	sort[i] = hist + i;
	sum += hist[i];
    }
/*    
    printf("%f\n", sum);
    for (i = 4; i < 13; i+=2) {
	printf("%i - %i\n", i+1, hist[i]);
    }
*/    
    qsort(sort, PROPERTIES, sizeof(uint32_t*), (int (*)(const void*,const void*))ptr_compare);
    
    for (i = 0; i < WIDTH; i++) {
	j = sort[i] - hist;
	printf("%6i  ", j + 1);
    }
    printf("\n");
    for (i = 0; i < WIDTH; i++) {
	printf("%6.2f%% ", 100*WIDTH*(*sort[i])/sum);
    }
    printf("\n");
#endif /* SINGLE_MODE */

    mrses_destroy_context(ctx);

    return (0);
}