aib.c File Reference
Detailed Description
For internal use only.
Definition in file aib.c.
#include "aib.h"
#include <stdio.h>
#include <stdlib.h>
#include <float.h>
#include <math.h>
Go to the source code of this file.
Defines | |
#define | BETA_MAX DBL_MAX |
The maximum value which beta may take. | |
Functions | |
void | vl_aib_normalize_P (double *P, vl_uint nelem) |
Normalizes an array of probabilities to sum to 1. | |
vl_uint * | vl_aib_new_nodelist (vl_uint nentries) |
Allocates and creates a list of nodes. | |
double * | vl_aib_new_Px (double *Pcx, vl_uint nvalues, vl_uint nlabels) |
Allocates and creates the marginal distribution Px. | |
double * | vl_aib_new_Pc (double *Pcx, vl_uint nvalues, vl_uint nlabels) |
Allocates and creates the marginal distribution Pc. | |
void | vl_aib_min_beta (VlAIB *aib, vl_uint *besti, vl_uint *bestj, double *minbeta) |
Find the two nodes which have minimum beta. | |
void | vl_aib_merge_nodes (VlAIB *aib, vl_uint i, vl_uint j, vl_uint new) |
Merges two nodes i,j in the internal datastructure. | |
void | vl_aib_update_beta (VlAIB *aib) |
Updates aib->beta and aib->bidx according to aib->which . | |
void | vl_aib_calculate_information (VlAIB *aib, double *I, double *H) |
Calculates the current information and entropy. | |
VlAIB * | vl_aib_new (double *Pcx, vl_uint nvalues, vl_uint nlabels) |
Allocates and initializes the internal data structure. | |
void | vl_aib_delete (VlAIB *aib) |
Deletes AIB data structure. | |
VL_EXPORT void | vl_aib_process (VlAIB *aib) |
Runs AIB on Pcx. |
Define Documentation
#define BETA_MAX DBL_MAX |
For internal use only.
Definition at line 122 of file aib.c.
Referenced by vl_aib_merge_nodes(), vl_aib_new(), and vl_aib_process().
Function Documentation
void vl_aib_calculate_information | ( | VlAIB * | aib, | |
double * | I, | |||
double * | H | |||
) |
For internal use only.
- Parameters:
-
aib A pointer to the internal data structure I The current mutual information (out). H The current entropy (out).
Definition at line 432 of file aib.c.
References _VlAIB::nentries, _VlAIB::nlabels, _VlAIB::Pc, _VlAIB::Pcx, and _VlAIB::Px.
Referenced by vl_aib_process().
void vl_aib_delete | ( | VlAIB * | aib | ) |
For internal use only.
- Parameters:
-
aib A pointer to the internal data structure i The index of one member of the pair to merge j The index of the other member of the pair to merge new The index of the new node which corresponds to the union of (i, j).
ij
, moving the node stored in last position (called lastnode
) back to jth position and the entry at the end.After the nodes have been merged, it updates which nodes should be considered on the next iteration based on which beta values could potentially change. The merged node will always be part of this list.
Definition at line 267 of file aib.c.
References _VlAIB::beta, BETA_MAX, _VlAIB::bidx, _VlAIB::nentries, _VlAIB::nlabels, _VlAIB::nwhich, _VlAIB::Px, and _VlAIB::which.
Referenced by vl_aib_process().
For internal use only.
- Parameters:
-
aib A pointer to the internal data structure besti The index of one member of the pair which has mininum beta bestj The index of the other member of the pair which minimizes beta minbeta The minimum beta value corresponding to (i, j)
Definition at line 228 of file aib.c.
References _VlAIB::beta, _VlAIB::bidx, and _VlAIB::nentries.
Referenced by vl_aib_process().
- Parameters:
-
Pcx A pointer to a 2D array of probabilities nvalues The number of rows in the array nlabels The number of columns in the array
Allocates memory for the following:
- Px (nvalues*sizeof(double))
- Pc (nlabels*sizeof(double))
- nodelist (nvalues*sizeof(vl_uint))
- which (nvalues*sizeof(vl_uint))
- beta (nvalues*sizeof(double))
- bidx (nvalues*sizeof(vl_uint))
- parents ((2*nvalues-1)*sizeof(vl_uint))
- costs (nvalues*sizeof(double))
Since it simply copies to pointer to Pcx, the total additional memory requirement is:
(3*nvalues+nlabels)*sizeof(double) + 4*nvalues*sizeof(vl_uint)
- Returns:
- An allocated and initialized VlAIB pointer
Definition at line 484 of file aib.c.
References _VlAIB::beta, BETA_MAX, _VlAIB::bidx, _VlAIB::costs, _VlAIB::nentries, _VlAIB::nlabels, _VlAIB::nodes, _VlAIB::nvalues, _VlAIB::nwhich, _VlAIB::parents, _VlAIB::Pc, _VlAIB::Pcx, _VlAIB::Px, vl_aib_new_nodelist(), vl_aib_new_Pc(), vl_aib_new_Px(), vl_aib_normalize_P(), vl_malloc(), and _VlAIB::which.
For internal use only.
- Parameters:
-
nentries The size of the list which will be created
- Returns:
- an array containing elements 0...nentries
Definition at line 153 of file aib.c.
References vl_malloc().
Referenced by vl_aib_new().
For internal use only.
- Parameters:
-
Pcx A two-dimensional array of probabilities nvalues The number of rows in Pcx nlabels The number of columns in Pcx
- Returns:
- an array of size nlabels which contains the marginal distribution over the columns
Definition at line 200 of file aib.c.
References vl_malloc().
Referenced by vl_aib_new().
For internal use only.
- Parameters:
-
Pcx A two-dimensional array of probabilities nvalues The number of rows in Pcx nlabels The number of columns in Pcx
- Returns:
- an array of size nvalues which contains the marginal distribution over the rows.
Definition at line 175 of file aib.c.
References vl_malloc().
Referenced by vl_aib_new().
void vl_aib_normalize_P | ( | double * | P, | |
vl_uint | nelem | |||
) |
For internal use only.
- Parameters:
-
P The array of probabilities nelem The number of elements in the array
- Returns:
- Modifies P to contain values which sum to 1
Definition at line 134 of file aib.c.
Referenced by vl_aib_new().
VL_EXPORT void vl_aib_process | ( | VlAIB * | aib | ) |
- Parameters:
-
aib AIB object to process
x
that causes the smallest decrease in mutual information between the random variables x
and c
.
Merge operations are arranged in a binary tree. The nodes of the tree correspond to the original feature values and any other value obtained as a result of a merge operation. The nodes are indexed in breadth-first order, starting from the leaves. The first index is zero. In this way, the leaves correspond directly to the original feature values. In total there are 2*nvalues-1
nodes.
The results may be accessed through vl_aib_get_parents which returns an array with one element per tree node. Each element is the index the parent node. The root parent is equal to zero. The array has 2*nvalues-1
elements.
Feature values with null probability are ignored by the algorithm and their nodes have parents indexing a non-existent tree node (a value bigger than 2*nvalues-1
).
Then the function will also compute the information level after each merge. vl_get_costs will return a vector with the information level after each merge. cost has nvalues
entries: The first is the value of the cost functional before any merge, and the others are the cost after the nvalues-1
merges.
Definition at line 581 of file aib.c.
References BETA_MAX, _VlAIB::costs, _VlAIB::nodes, _VlAIB::nvalues, _VlAIB::nwhich, _VlAIB::parents, vl_aib_calculate_information(), vl_aib_merge_nodes(), vl_aib_min_beta(), vl_aib_update_beta(), VL_NAN_D, and VL_PRINTF.
void vl_aib_update_beta | ( | VlAIB * | aib | ) |
For internal use only.
- Parameters:
-
aib AIB data structure.
beta
[i] and bidx
[i] for the nodes i
listed in aib->which
. beta
[i] is the minimal variation of mutual information (or other score) caused by merging entry i
with another entry and bidx
[i] is the index of this best matching entry.
Notice that for each entry i
that we need to update, a full scan of all the other entries must be performed.
Definition at line 346 of file aib.c.
References _VlAIB::beta, _VlAIB::bidx, _VlAIB::nentries, _VlAIB::nlabels, _VlAIB::nwhich, _VlAIB::Pcx, _VlAIB::Px, vl_free(), vl_malloc(), and _VlAIB::which.
Referenced by vl_aib_process().