This chapter describes the mine C++ wrapper. The class is declared in the header file cppmine.h, located in the minepy/libmine/ folder. You need to add #include "cppmine.h" in your C++ source files and link your program with core.c, mine.c and cppmine.c.
MINE constructor.
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 constructor throws an exception when the parameters are invalid.
MINE destructor.
Computes the maximum normalized mutual information scores the between variables x and y of length n.
Returns the Maximal Information Coefficient (MIC).
Returns the Maximum Asymmetry Score (MAS).
Returns the Maximum Edge Value (MEV).
Returns the Minimum Cell Number (MCN).
The example is located in examples/cpp_example.cpp.
#include <cstdlib>
#include <cmath>
#include <iostream>
#include "cppmine.h"
using namespace std;
int
main (int argc, char **argv)
{
double PI;
int i, n;
double *x, *y;
MINE *mine;
PI = 3.14159265;
/* build the MINE object with exceptions management */
try {
mine = new MINE(0.6, 15);
}
catch (char *s) {
cout << "WARNING: " << s << "\n";
cout << "MINE will be set with the default parameters, alpha=0.6 and c=15" << "\n";
mine = new MINE(0.6, 15);
}
/* build the problem */
n = 1001;
x = new double [n];
y = new double [n];
for (i=0; i<n; i++)
{
/* build x = [0, 0.001, ..., 1] */
x[i] = (double) i / (double) (n-1);
/* build y = sin(10 * pi * x) + x */
y[i] = sin(10 * PI * x[i]) + x[i];
}
/* compute score */
mine->compute_score(x, y, n);
/* print mine statistics */
cout << "MIC: " << mine->get_mic() << "\n";
cout << "MAS: " << mine->get_mas() << "\n";
cout << "MEV: " << mine->get_mev() << "\n";
cout << "MCN: " << mine->get_mcn() << "\n";
/* delete the mine object */
delete mine;
/* free the problem */
delete [] x;
delete [] y;
return 0;
}
To compile the example, open a terminal, go into the example (examples/) folder and run:
$ g++ -O3 -Wall -Wno-write-strings cpp_example.cpp ../minepy/libmine/cppmine.cpp \
../minepy/libmine/core.c ../minepy/libmine/mine.c -I../minepy/libmine/
Run the example by typing:
$ ./a.out
MIC: 0.999999
MAS: 0.728144
MEV: 0.999999
MCN: 4.584963
The example is located in examples/cpp_example2.cpp.
#include <cstdlib>
#include <cmath>
#include <iostream>
#include "cppmine.h"
using namespace std;
int
main (int argc, char **argv)
{
int n = 7;
double x[] = {1.,2.,3.,4.,5.,6.,7.};
double y[] = {1.,2.,3.,4.,3.,2.,1.};
/*
build the MINE object with default
parameters (alpha=0.6 and c=15)
*/
MINE mine;
/* compute score */
mine.compute_score(x, y, n);
/* print MIC */
cout << "MIC: " << mine.get_mic() << "\n";
return 0;
}
To compile the example, open a terminal, go into the example (examples/) folder and run:
$ g++ -O3 -Wall -Wno-write-strings cpp_example2.cpp ../minepy/libmine/cppmine.cpp \
../minepy/libmine/core.c ../minepy/libmine/mine.c -I../minepy/libmine/
Run the example by typing:
$ ./a.out
MIC: 0.291692