-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBest_match_unit.c
89 lines (68 loc) · 1.89 KB
/
Best_match_unit.c
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
#include "Best_match_unit.h"
struct bmu *best_match_unit;
struct bmu *first_node;
struct bmu *last_node;
double bestM_act;
int number_of_bmu_nodes = 0;
void find_bmu_linked_list(struct node ** node_map, int NODE_MAP_HEIGHT, int NODE_MAP_LENGTH)
{
first_node = NULL;
last_node = NULL;
for (int i = 0; i < NODE_MAP_HEIGHT; ++i) {
for (int j = 0; j < NODE_MAP_LENGTH; ++j) {
add_bmu_node(i, j, node_map[i][j].act);
}
}
};
void add_bmu_node(int i, int j, double act)
{
if(first_node == NULL){
bestM_act = act;
first_node = malloc(sizeof(struct bmu));
first_node->i = i;
first_node->j = j;
last_node = first_node;
number_of_bmu_nodes = 1;
}
else if(act < bestM_act){
bestM_act = act;
first_node->i = i;
first_node->j = j;
last_node = first_node;
first_node->next = NULL;
number_of_bmu_nodes = 1;
}
else if(act == bestM_act){
last_node->next = malloc(sizeof(struct bmu));
last_node = last_node->next;
last_node->i = i;
last_node->j = j;
number_of_bmu_nodes++;
}
}
struct bmu * get_bmu_node()
{
if(number_of_bmu_nodes == 0) {
printf("nigga u're fucked!!\n");
return NULL;
}
if(number_of_bmu_nodes == 1) {
return first_node;
}
// get random bmu
int randN = get_random_int(0, number_of_bmu_nodes);
struct bmu * iterator = first_node;
for (int i = 0; i < randN; ++i) {
iterator = iterator->next;
}
//printf("%d %d\n", iterator->i, iterator->j);
//printf("%d %d\n", first_node[randN].i, first_node[randN].j);
return iterator;
}
void print_bmu(struct bmu *_bmu, struct node ** node_map)
{
printf("%d %d act: %f <-%s \n",
_bmu->i, _bmu->j,
node_map[_bmu->i][_bmu->j].act,
node_map[_bmu->i][_bmu->j].label);
}