C++ API

This chapter describes the mine C++ wrapper. The class is declared in the header file cppmine.h, located in the libmine/ folder. You need to add #include "cppmine.h" in your C++ source files and link your program with mine.c and cppmine.c.

class MINE
MINE::MINE(double alpha, double 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 x grid lines on the x-axis, the algorithm will start with at most 15 x clumps. c must be > 0.

The constructor throws an exception when the parameters are invalid.

MINE::~MINE()

MINE destructor.

void MINE::compute_score(double* x, double* y, int n)

Computes the maximum normalized mutual information scores the between variables x and y of length n. It rhrows an exception if an error occurs.

void MINE::mic()

Returns the Maximal Information Coefficient (MIC).

void MINE::mas()

Returns the Maximum Asymmetry Score (MAS).

void MINE::mev()

Returns the Maximum Edge Value (MEV).

void MINE::mcn(double eps)

Returns the Minimum Cell Number (MCN) with \epsilon \geq 0.

void MINE::mcn_general()

Returns the Minimum Cell Number (MCN) with \epsilon=1 - \mathrm{MIC}.

Example

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 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 with exceptions management */
  try
    {
      mine->compute_score(x, y, n);
    }
  catch (char *s)
    {
      cout << "ERROR: " << s << "\n";
      return 1;
    }

  /* print mine statistics */
  try
    {
      cout << "MIC: " << mine->mic() << "\n";
      cout << "MAS: " << mine->mas() << "\n";
      cout << "MEV: " << mine->mev() << "\n";
      cout << "MCN (eps=0): " << mine->mcn(0) << "\n";
      cout << "MCN (eps=1-MIC): " << mine->mcn_general() << "\n";
    }
  catch (char *s)
    {
      cout << "ERROR: " << s << "\n";
      return 1;
    }
  
  /* 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 ../libmine/cppmine.cpp \
../libmine/mine.c -I../libmine/

Run the example by typing:

$ ./a.out
MIC: 0.999999
MAS: 0.728144
MEV: 0.999999
MCN (eps=0): 4.58496
MCN (eps=1-MIC): 4.58496

A more simple example

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 */
  MINE mine(0.6, 15);

  /* compute score */
  mine.compute_score(x, y, n);
  
  /* print MIC */
  cout << "MIC: " << mine.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 ../libmine/cppmine.cpp \
../libmine/mine.c -I../libmine/

Run the example by typing:

$ ./a.out
MIC: 0.291692

Table Of Contents

Previous topic

C API

Next topic

Python API

This Page