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
.
See the C API documentation.
-
class
MINE
¶ -
MINE
::
MINE
(double alpha, double c, int est)¶ Constructor. Throws an exception when the parameters are invalid.
-
MINE
::
~MINE
()¶ Destructor.
-
void
MINE
::
compute_score
(double *x, double *y, int n)¶
-
void
MINE
::
mic
()¶
-
void
MINE
::
mas
()¶
-
void
MINE
::
mev
()¶
-
void
MINE
::
mcn
(double eps)¶
-
void
MINE
::
mcn_general
()¶
-
void
MINE
::
tic
(int norm)¶
-
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, EST_MIC_APPROX);
}
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, EST_MIC_APPROX);
}
/* 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";
cout << "TIC: " << mine->tic(FALSE) << "\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:
MIC: 0.999999
MAS: 0.728144
MEV: 0.999999
MCN (eps=0): 4.58496
MCN (eps=1-MIC): 4.58496
TIC: 67.5236
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, EST_MIC_APPROX);
/* 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