{
  "id": 7317,
  "title": "Beat the Correlation Benchmark ~0.87337 AUC [Python]",
  "url": "/competitions/connectomics/discussion/7317",
  "author_name": "",
  "post_date": "2014-03-08T19:00:28.227Z",
  "votes": 6,
  "comment_count": 9,
  "views": 2615,
  "content": "<p>I wrote Python scripts to parse the data (brainparse.py) and to make predictions (model.py) based on Pearson Correlation with Discretization.</p>\n<p>It scores&nbsp;~0.87337 AUC (13th) on the leaderboard and thus beats the provided Correlation Benchmark.</p>\n<p>You can find full model code and a description at my new site:&nbsp;http://mlwave.com/kaggle-connectomics-python-benchmark-code/</p>\n<p>If something is unclear, please ask. The code runs in <span style=\"text-decoration: line-through\">under 6 hours</span>&nbsp;<del>38 minutes</del> 30 minutes on the validation set (1000 neurons) on my laptop.</p>\n<p>Next to the benchmark two scripts are provided to visualize and animate the neural networks.</p>\n<p><img src=\"http://i.imgur.com/HtNzVgA.gif\" alt width=\"140\" height=\"140\"><img src=\"http://i.imgur.com/thIa4fo.png\" alt width=\"315\" height=\"236\"></p>",
  "messages": [
    {
      "id": "40025",
      "postDate": "03/08/2014 19:00:28",
      "content": "<p>I wrote Python scripts to parse the data (brainparse.py) and to make predictions (model.py) based on Pearson Correlation with Discretization.</p>\n<p>It scores&nbsp;~0.87337 AUC (13th) on the leaderboard and thus beats the provided Correlation Benchmark.</p>\n<p>You can find full model code and a description at my new site:&nbsp;http://mlwave.com/kaggle-connectomics-python-benchmark-code/</p>\n<p>If something is unclear, please ask. The code runs in <span style=\"text-decoration: line-through\">under 6 hours</span>&nbsp;<del>38 minutes</del> 30 minutes on the validation set (1000 neurons) on my laptop.</p>\n<p>Next to the benchmark two scripts are provided to visualize and animate the neural networks.</p>\n<p><img src=\"http://i.imgur.com/HtNzVgA.gif\" alt width=\"140\" height=\"140\"><img src=\"http://i.imgur.com/thIa4fo.png\" alt width=\"315\" height=\"236\"></p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "40029",
      "postDate": "03/09/2014 00:29:46",
      "content": "<p>Excellent stuff, Triskelion! Great blog and code, thanks!</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "40065",
      "postDate": "03/10/2014 00:27:27",
      "content": "<p>I tried to improve the score with&nbsp;<a href=\"https://code.google.com/p/pyentropy/\">PyEntropy</a>. Ran it with the pt-method (Panzeri-Treves bias correction). Took under <span style=\"text-decoration: line-through\">20 hours</span>&nbsp;(10 hours wrapping <a href=\"http://stackoverflow.com/questions/11241523/why-does-python-code-run-faster-in-a-function\">code in function</a>) and did not improve the Correlation Benchmark (but close).</p>\n<p>Looks like an interesting and related package:&nbsp;<a href=\"http://robince.github.io/pyentropy/\">PyEntropy&nbsp;project page</a>&nbsp;and I may try other methods/approaches with this to get something more similar to the GTE benchmark in Python.</p>\n<p><code>s = DiscreteSystem(neuron_activities[neuron_i_id],(1,100), neuron_activities[neuron_j_id],(1,100))<br> s.calculate_entropies(method='pt', calc=['HX', 'HXY'])<br> corr = str(s.I())</code></p>\n<p><sub>I tried (1,1000) but execution time would be multiple days.</sub></p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "40072",
      "postDate": "03/10/2014 08:42:49",
      "content": "<p>Created tremendous speed-up by using numpy arrays over dictionaries/lists.</p>\n<p>The Python correlation benchmark now runs in 38 minutes on a laptop over 1000 neurons (1 million connection estimations). It uses less than 1 GB of memory.&nbsp;</p>\n<p>To quickly update brainparse.py change:</p>\n<p><code>discretized[k] = [1 if f &gt; threshold else 0 for f in list(np.diff(v,axis=0))]</code></p>\n<p>to:</p>\n<p><code>discretized[k] = np.array([1 if f &gt; threshold else 0 for f in list(np.diff(v,axis=0))])</code></p>\n<p>or download the updated version at&nbsp;https://github.com/MLWave/Kaggle_Connectomics</p>\n<p>I'm still looking for further speedups. Also to make the code run on multiple machines at once..</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "40106",
      "postDate": "03/10/2014 17:33:34",
      "content": "<p>I tried using <a href=\"http://code.google.com/p/information-dynamics-toolkit/\">information-dynamics-toolkit</a> , which is written in Java, via JPype, but it's just too slow to be practical. I suspect plenty of time is lost on converting Python (numpy) arrays to Java. I guess rewriting the main program in Java would make much more sense in order to use the library but I'm personally not very keen on it.</p>\n<p>Later I found <a href=\"https://pypi.python.org/pypi/bctpy\">bctpy</a> which is a Python port of the <a href=\"https://sites.google.com/site/bctnet/\">Brain Connectivity Toolbox</a> (Matlab library). I haven't had time to try to use it yet, but it looks promising. It's a beta quality software, according to its author, and still under active development, apparently. </p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "40116",
      "postDate": "03/10/2014 19:59:56",
      "content": "<p>Running a XOR on the descretized time series you can beat the plain correlation benchmark in a few minutes ~0.83686.</p>\n<p>a = [1,0,0,1]</p>\n<p>b = [1,0,1,1]</p>\n<p>XOR score a_b = 3/4 = 0.75</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "40126",
      "postDate": "03/10/2014 23:42:16",
      "content": "<p>This is an interesting remark.</p>\n<p>If I understand it correctly you use the (complement of the) XOR on the binarized signal as an ultra-fast implementation of a coincidence detector. In this sense you expect to fall close to correlation with discretization, which is also very related to a count of coincidences, taking into account however the actual rates of different neurons:</p>\n<p>CC (S_i, S_j) = &lt;S_i S_j&gt; - &lt;S_i&gt;&lt;S_j&gt;</p>\n<p>The XOR detector lacks this correction term, therefore I am not surprised that it performs WORSE than correlation with discretization. Is performance is largely due just to the discretization itself, in the same way in which discretization boosts performance of Pearson correlation with respect to the non-discretized case.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "40128",
      "postDate": "03/11/2014 00:09:50",
      "content": "<p>Please also note: the goal of the challenge is not only to improve on correlation and evaluate statistical dependencies that hint on non-directed connectivity. The goal is also to find the directions of the connections. Solving the orientation problem will probably differentiate the top ranking participants.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "40158",
      "postDate": "03/11/2014 10:19:22",
      "content": "<p>Using&nbsp;stats.pointbiserialr over&nbsp;stats.pearsonr you get the same results, but in 30 minutes.</p>\n<p>Twiddling with the binary threshold can improve the benchmark score.</p>\n<p>Using np.correlate the script runs in 5 minutes (from raw data files to submission) and gives ~0.83 AUC. XOR was faster and performed a little better.</p>\n<p>Now working on local validation.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "40305",
      "postDate": "03/13/2014 21:45:00",
      "content": "<p>If you change the threshold to 0.127 you can increase the benchmark score. Locally you can find this value by a brute force search, but every set/neural net seems to give a higher AUC with a different threshold. There is no guarantee that the 0.127 threshold will also increase the private leaderboard score. I am trying to find a good average threshold that will work for most neural nets. I suspect it is somewhere near 0.12.</p>\n<p>Tried smoothing/denoising the signal with numpy.convolve&nbsp;(moving average) and&nbsp;http://wiki.scipy.org/Cookbook/SignalSmooth. Was able to produce reasonable graphs like below, but didn't improve the correlation score yet. Are any other competitors trying smoothing methods over binary discretization? Is this path leading anywhere?</p>\n<p><img src=\"http://i.imgur.com/ycf8aAi.png\" alt=\"denoised neuron activities signal\" width=\"682\" height=\"512\"></p>",
      "rawMarkdown": "",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 40029,
      "author_name": "piotrkuchta",
      "author_url": "",
      "post_date": "03/09/2014 00:29:46",
      "content": "<p>Excellent stuff, Triskelion! Great blog and code, thanks!</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 40065,
      "author_name": "triskelion",
      "author_url": "",
      "post_date": "03/10/2014 00:27:27",
      "content": "<p>I tried to improve the score with&nbsp;<a href=\"https://code.google.com/p/pyentropy/\">PyEntropy</a>. Ran it with the pt-method (Panzeri-Treves bias correction). Took under <span style=\"text-decoration: line-through\">20 hours</span>&nbsp;(10 hours wrapping <a href=\"http://stackoverflow.com/questions/11241523/why-does-python-code-run-faster-in-a-function\">code in function</a>) and did not improve the Correlation Benchmark (but close).</p>\n<p>Looks like an interesting and related package:&nbsp;<a href=\"http://robince.github.io/pyentropy/\">PyEntropy&nbsp;project page</a>&nbsp;and I may try other methods/approaches with this to get something more similar to the GTE benchmark in Python.</p>\n<p><code>s = DiscreteSystem(neuron_activities[neuron_i_id],(1,100), neuron_activities[neuron_j_id],(1,100))<br> s.calculate_entropies(method='pt', calc=['HX', 'HXY'])<br> corr = str(s.I())</code></p>\n<p><sub>I tried (1,1000) but execution time would be multiple days.</sub></p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 40072,
      "author_name": "triskelion",
      "author_url": "",
      "post_date": "03/10/2014 08:42:49",
      "content": "<p>Created tremendous speed-up by using numpy arrays over dictionaries/lists.</p>\n<p>The Python correlation benchmark now runs in 38 minutes on a laptop over 1000 neurons (1 million connection estimations). It uses less than 1 GB of memory.&nbsp;</p>\n<p>To quickly update brainparse.py change:</p>\n<p><code>discretized[k] = [1 if f &gt; threshold else 0 for f in list(np.diff(v,axis=0))]</code></p>\n<p>to:</p>\n<p><code>discretized[k] = np.array([1 if f &gt; threshold else 0 for f in list(np.diff(v,axis=0))])</code></p>\n<p>or download the updated version at&nbsp;https://github.com/MLWave/Kaggle_Connectomics</p>\n<p>I'm still looking for further speedups. Also to make the code run on multiple machines at once..</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 40106,
      "author_name": "piotrkuchta",
      "author_url": "",
      "post_date": "03/10/2014 17:33:34",
      "content": "<p>I tried using <a href=\"http://code.google.com/p/information-dynamics-toolkit/\">information-dynamics-toolkit</a> , which is written in Java, via JPype, but it's just too slow to be practical. I suspect plenty of time is lost on converting Python (numpy) arrays to Java. I guess rewriting the main program in Java would make much more sense in order to use the library but I'm personally not very keen on it.</p>\n<p>Later I found <a href=\"https://pypi.python.org/pypi/bctpy\">bctpy</a> which is a Python port of the <a href=\"https://sites.google.com/site/bctnet/\">Brain Connectivity Toolbox</a> (Matlab library). I haven't had time to try to use it yet, but it looks promising. It's a beta quality software, according to its author, and still under active development, apparently. </p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 40116,
      "author_name": "triskelion",
      "author_url": "",
      "post_date": "03/10/2014 19:59:56",
      "content": "<p>Running a XOR on the descretized time series you can beat the plain correlation benchmark in a few minutes ~0.83686.</p>\n<p>a = [1,0,0,1]</p>\n<p>b = [1,0,1,1]</p>\n<p>XOR score a_b = 3/4 = 0.75</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 40126,
      "author_name": "salviati1",
      "author_url": "",
      "post_date": "03/10/2014 23:42:16",
      "content": "<p>This is an interesting remark.</p>\n<p>If I understand it correctly you use the (complement of the) XOR on the binarized signal as an ultra-fast implementation of a coincidence detector. In this sense you expect to fall close to correlation with discretization, which is also very related to a count of coincidences, taking into account however the actual rates of different neurons:</p>\n<p>CC (S_i, S_j) = &lt;S_i S_j&gt; - &lt;S_i&gt;&lt;S_j&gt;</p>\n<p>The XOR detector lacks this correction term, therefore I am not surprised that it performs WORSE than correlation with discretization. Is performance is largely due just to the discretization itself, in the same way in which discretization boosts performance of Pearson correlation with respect to the non-discretized case.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 40128,
      "author_name": "iguyon",
      "author_url": "",
      "post_date": "03/11/2014 00:09:50",
      "content": "<p>Please also note: the goal of the challenge is not only to improve on correlation and evaluate statistical dependencies that hint on non-directed connectivity. The goal is also to find the directions of the connections. Solving the orientation problem will probably differentiate the top ranking participants.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 40158,
      "author_name": "triskelion",
      "author_url": "",
      "post_date": "03/11/2014 10:19:22",
      "content": "<p>Using&nbsp;stats.pointbiserialr over&nbsp;stats.pearsonr you get the same results, but in 30 minutes.</p>\n<p>Twiddling with the binary threshold can improve the benchmark score.</p>\n<p>Using np.correlate the script runs in 5 minutes (from raw data files to submission) and gives ~0.83 AUC. XOR was faster and performed a little better.</p>\n<p>Now working on local validation.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 40305,
      "author_name": "triskelion",
      "author_url": "",
      "post_date": "03/13/2014 21:45:00",
      "content": "<p>If you change the threshold to 0.127 you can increase the benchmark score. Locally you can find this value by a brute force search, but every set/neural net seems to give a higher AUC with a different threshold. There is no guarantee that the 0.127 threshold will also increase the private leaderboard score. I am trying to find a good average threshold that will work for most neural nets. I suspect it is somewhere near 0.12.</p>\n<p>Tried smoothing/denoising the signal with numpy.convolve&nbsp;(moving average) and&nbsp;http://wiki.scipy.org/Cookbook/SignalSmooth. Was able to produce reasonable graphs like below, but didn't improve the correlation score yet. Are any other competitors trying smoothing methods over binary discretization? Is this path leading anywhere?</p>\n<p><img src=\"http://i.imgur.com/ycf8aAi.png\" alt=\"denoised neuron activities signal\" width=\"682\" height=\"512\"></p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "40025": "",
    "40029": "",
    "40065": "",
    "40072": "",
    "40106": "",
    "40116": "",
    "40126": "",
    "40128": "",
    "40158": "",
    "40305": ""
  },
  "source": "meta"
}