Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

In last December's Science David N. Reshef, et al. proposed an interesting method to detect associations in data (Detecting Novel Associations in Large Data Sets, Science 334, 1518, 2011). Contrary to classical correlation methods, this method is able to detect non-linear relationships.

Mathematica graphics (table from the cited article)

On their website, the authors provide a Java application, MINE, and an interface to the language R. Having no Java experience I never took up JLink but it is my guess that it should be reasonable straightforward to interface MINE with Mathematica. Could someone show me how?

Native implementations of the method in Mathematica are more than welcome too. I'm planning to do that in the near future, but still haven't found time to read the technical report yet.

share|improve this question
add comment

2 Answers

up vote 5 down vote accepted

You don't need JLink for this, because MINE program (Java version) seems to not be able to transmit the results by any data transfer protocol. Rather, you launch it from the command line, as a Java executable (jar file). It takes the name of the input data file as one of the command line parameters, and it writes its output into another file.

I will illustrate the steps needed to run it from Mathematica on Win7, but they should be similar on other systems.

1.Download MINE.jar and an example file (say Spellman.csv), and save them in some directory. I saved them in a directory C:\Temp\MINE

2.Find out the location of the Java runtime coming with Mathematica. One way to do this is to run

Needs["JLink`"]
InstallJava[]

(* 
-->

LinkObject["C:\Program Files\Wolfram Research\Mathematica\8.0\SystemFiles\Java\
Windows-x86-  64\bin\javaw" -classpath ..."]

*)

3.Define these directories:

$MINEDir = "C:\\Temp\\MINE";
$JavaDir = "C:\\Program Files\\Wolfram Research\\Mathematica\\8.0\\SystemFiles
\\Java\\Windows-x86-64\\bin";

4.Set the current directory to be the one with Java installation:

SetDirectory[$JavaDir]

5.Run this command (for example - this corresponds to an example they show):

stringify[s__String] := StringJoin["\"", s, "\""]

Run@StringJoin[
  "javaw -jar ",
  stringify@FileNameJoin[{$MINEDir, "MINE.jar"}],
  " ",
  stringify@FileNameJoin[{$MINEDir, "Spellman.csv"}],
  " 0 cv=0.7"
]

In practice, the string with parameters you will build dynamically, from the parameter values, of course. Since I don't have a good grasp on possible parameters and their values, I refrained from implementing this, but this is straightforward to do. Note that stringify is only needed for Windows (probably), to prevent the Windows shell from mis-interpreting spaces. It should return 0 if executed correctly, and you should also see a command-line window popping up and floating for a second or two, that it takes to compute.

6.This shows the data files:

In[8]:= (dataFiles = FileNames["*.csv",{$MINEDir}])//InputForm
Out[8]//InputForm=
{"C:\\Temp\\MINE\\Spellman.csv", 
 "C:\\Temp\\MINE\\Spellman.csv,mv=0,cv=0.7,B=n^0.6,Results.csv"}

The first one is the original data set. The last one contains the results. It should be possible to automate the identification of which is which.

7.Import the results:

In[9]:= Import["C:\\Temp\\MINE\\Spellman.csv,mv=0,cv=0.7,B=n^0.6,Results.csv"]//Short[#,3]&

Out[9]//Short= {{X var,Y var,MIC (strength),MIC-p^2 (nonlinearity),MAS (non-monotonicity),
MEV (functionality),MCN (complexity),Linear regression (p)},<<4380>>,{time,<<6>>,0.00775905}}

It should be possible to automate all that, this is just to show the basic steps. I must add that the program does not contain an awful lot of documentation, so figuring out the parameters etc may be not completely trivial.

share|improve this answer
    
Thanks Leonid! Did you examine the R interface? I'm not familiar with R but from my superficial examination it looked like it was able to internalize MINE completely. I supposed MMA could do the same with JLink. –  Sjoerd C. de Vries Jan 23 '12 at 21:01
    
@Sjoerd No, I did not. It may be that R interface is able to integrate it more tightly. –  Leonid Shifrin Jan 23 '12 at 21:03
    
@Sjoerd The problem is that this jar file is an executable, but contains no JavaDocs, so there was no way to know which methods are there to input or store data, perform computations, etc. And the Java sources aren't attached either - just bytecode-compiled .class files. If docs and / or sources were present, then things would be different / simpler. –  Leonid Shifrin Jan 23 '12 at 21:13
1  
I think it should be possible to write something that directly feeds and uses the classes in the jar by inspecting the R-code or the python-code which at least to me would be somewhat simpler to understand. But as Leonid said: without docs or sources that will be a lot of difficult but unpleasant work that probably no one will be willing to do just for reputation :-). If I had need for it I'd ask the authors for details, probably offering to make the result publicly available as a motivation for them to cooperate. –  Albert Retey Jan 23 '12 at 21:45
    
@Albert It is fairly easy to use JLink to inspect methods and fields in classes, plus one could probably dig out a Java class decompiler - but as you said, this is still quite a bit of work. –  Leonid Shifrin Jan 23 '12 at 21:49
show 2 more comments

If anyone has an hour or two to spend on this, here is a starting point. Actually having had a look at the python script MINE.py I think it probably wouldn't be too much work (but still more than I'm willing to invest now)...

Needs["JLink`"];

AddToClassPath["C:\\Temp\\MIME\\MINE.jar"];

analyzeClass = LoadJavaClass["main.Analyze"]
Methods[analyzeClass]

analysisClass = LoadJavaClass["analysis.Analysis"]
Methods[analysisClass]
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.