Handling labels


String-label conversion

These functions convert strings to numbers representing the label and vice versa. An empty string or NULL string will get you the empty label (EMPTY_LABEL) which is also the same as no label. Converting EMPTY_LABEL to string gives a NULL pointer.
int find_conv_to_ind(char *lab)
Give the corresponding index; if the label is not yet there, add it to table. No label or empty label gives EMPTY_LABEL.

char *find_conv_to_lab(int ind)
Give the corresponding label; if the index is not yet there, return NULL. Empty label also returns NULL.

Manipulating labels

Labes are stored in the following way: If there is only one label, store it in the labels pointer. If there are multiple labels, the labels entry is a pointer to an array of labels. The num_labs field in the entry tells the number of labels in that entry.
int set_entry_label(struct data_entry *entry, int label)
Sets the label on one data entry. All previous labels are discarded.

int get_entry_labels(struct data_entry *entry, int i)
Get i:th label from entry (i starts from 0).

int get_entry_label(struct data_entry *entry)
Gets the first label from entry.

int add_entry_label(struct data_entry *entry, int label)
Add a label to entry. The new label will be added to the end of the list of labels for the etry. Returns non-zero on error.

int copy_entry_labels(struct data_entry *dest, struct data_entry *source)
Copy all labels from one entry (source) to the other (dest). All previous labels in dest are discarded.

Hitlist

Hitlist is a list of [label,frequency] pairs that is kept sorted so that the label with the highest frequency is always the first in the list. The label used here can be any long integer value.

The hitlist structures are defided as below:

  struct hit_entry {
    struct hit_entry *next, *prev;
    long label; 
    long freq;    /* frequency of this label */
  };

  struct hitlist {
    struct hit_entry *head, *tail;
    long entries;  /* number of entries */
  };
The hit_entrys are stored in a double-linked list and hitlist is the list header. Hitlist.entries is the number of hit_entrys in the list and head and tail are pointers to the first and the last entries in the list. In hit_entry, next and prev are pointers to the next and previus entry. Label is the label of this entry and freq is the number of hits it has.
struct hitlist *new_hitlist(void)
Initializes a new hitlist for use.

void clear_hitlist(struct hitlist *hl)
Deletes all entries from the hitlist.

void free_hitlist(struct hitlist *hl)
Deallocates a hitlist.

struct hit_entry *find_hit(struct hitlist *hl, long label)
Find a hit_entry corresponding to a certain label from list. Returns NULL if there is no entry for the label.

long add_hit(struct hitlist *hl, long label)
Add a hit in the list for label. Returns the number of hits for this label after this hit has been added.

long hitlist_label_freq(struct hitlist *hl, long label)
Returns the number of hits for label. If the label is not in the list returns 0.

SOM/LVQ Programming info / SOM/LVQ Home Page / Neural Networks Research Centre