This chapter describes the mine C library. These functions and structures are declared in the header file mine.h, located in the minepy/libmine/ folder. You need to add #include "mine.h" in your C source files and link your program with core.c and mine.c.
The mine_problem structure describes the problem.
typedef struct mine_problem {
int n;
double *x;
double *y;
} mine_problem;
where of x and y are the two variables of length n.
The mine_parameter structure describes the MINE parameters.
typedef struct mine_parameter {
double alpha;
double c;
} mine_parameter;
where alpha is the exponent in B(n) = n^alpha and must be in (0,1], and c determines how many more clumps there will be than columns in every partition. c = 15 meaning that when trying to draw Gx grid lines on the x-axis, the algorithm will start with at most 15*Gx clumps. c must be > 0.
The mine_score structure describes the maximum normalized mutual information scores.
typedef struct mine_score {
int m;
int *p;
double **I;
} mine_score;
where I[i][j] contains the score using a grid partitioning x-values into i+2 bins and y-values into j+2 bins. p and I are of length m and each I[i] is of length p[i].
This function computes the maximum normalized mutual information scores and returns a mine_score structure.
This function checks the parameters. It should be called before calling mine_compute_score(). It returns NULL if the parameters are feasible, otherwise an error message is returned.
Returns the Maximal Information Coefficient (MIC).
Returns the Maximum Asymmetry Score (MAS).
Returns the Maximum Edge Value (MEV).
Returns the Minimum Cell Number (MCN).
This function frees the memory used by a mine_score and destroys the score structure.
The example is located in examples/c_example.c.
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include "mine.h"
int
main (int argc, char **argv)
{
double PI;
int i;
mine_problem prob;
mine_parameter param;
mine_score *score;
char *ret;
PI = 3.14159265;
/* set the parameters */
param.alpha = 0.6;
param.c = 15;
/* check the parameters */
if ((ret=check_parameter(¶m)))
{
printf("ERROR: %s\n", ret);
return 1;
}
/* build the problem */
prob.n = 1001;
prob.x = (double *) malloc (prob.n * sizeof (double));
prob.y = (double *) malloc (prob.n * sizeof (double));
for (i=0; i<prob.n; i++)
{
/* build x = [0, 0.001, ..., 1] */
prob.x[i] = (double) i / (double) (prob.n-1);
/* build y = sin(10 * pi * x) + x */
prob.y[i] = sin(10 * PI * prob.x[i]) + prob.x[i];
}
/* compute score */
score = mine_compute_score(&prob, ¶m);
/* print mine statistics */
printf ("MIC: %lf\n", mic(score));
printf ("MAS: %lf\n", mas(score));
printf ("MEV: %lf\n", mev(score));
printf ("MCN: %lf\n", mcn(score));
/* free score */
mine_free_score(&score);
/* free prob */
free(prob.x);
free(prob.y);
return 0;
}
To compile the example, open a terminal, go into the example (examples/) folder and run:
$ gcc c_example.c ../minepy/libmine/core.c \
../minepy/libmine/mine.c -I../minepy/libmine/ -lm
or
$ gcc c_example.c -O3 ../minepy/libmine/core.c \
../minepy/libmine/mine.c -I../minepy/libmine/ -lm
for an extensive optimization. Run the example by typing:
$ ./a.out
MIC: 0.999999
MAS: 0.728144
MEV: 0.999999
MCN: 4.584963