Topology in neuroscience
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

146 lines
38 KiB

{
"cells": [
{
"cell_type": "code",
"execution_count": 4,
"outputs": [],
"source": [
"%matplotlib notebook\n",
"from sym_model import Population\n",
"import umap\n",
"reducer = umap.UMAP()"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
},
{
"cell_type": "code",
"execution_count": 7,
"outputs": [],
"source": [
"res = Population.random(40).sample_responses(1000)"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
},
{
"cell_type": "code",
"execution_count": 8,
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/usr/lib/python3.10/site-packages/umap/umap_.py:132: UserWarning: A large number of your vertices were disconnected from the manifold.\n",
"Disconnection_distance = inf has removed 812116 edges.\n",
"It has fully disconnected 553 vertices.\n",
"You might consider using find_disconnected_points() to find and remove these points from your data.\n",
"Use umap.utils.disconnected_vertices() to identify them.\n",
" warn(\n",
"/usr/lib/python3.10/site-packages/sklearn/manifold/_spectral_embedding.py:259: UserWarning: Graph is not fully connected, spectral embedding may not work as expected.\n",
" warnings.warn(\n"
]
}
],
"source": [
"embedding = reducer.fit_transform(res)"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
},
{
"cell_type": "code",
"execution_count": 11,
"outputs": [
{
"data": {
"text/plain": "<IPython.core.display.Javascript object>",
"application/javascript": "/* Put everything inside the global mpl namespace */\n/* global mpl */\nwindow.mpl = {};\n\nmpl.get_websocket_type = function () {\n if (typeof WebSocket !== 'undefined') {\n return WebSocket;\n } else if (typeof MozWebSocket !== 'undefined') {\n return MozWebSocket;\n } else {\n alert(\n 'Your browser does not have WebSocket support. ' +\n 'Please try Chrome, Safari or Firefox ≥ 6. ' +\n 'Firefox 4 and 5 are also supported but you ' +\n 'have to enable WebSockets in about:config.'\n );\n }\n};\n\nmpl.figure = function (figure_id, websocket, ondownload, parent_element) {\n this.id = figure_id;\n\n this.ws = websocket;\n\n this.supports_binary = this.ws.binaryType !== undefined;\n\n if (!this.supports_binary) {\n var warnings = document.getElementById('mpl-warnings');\n if (warnings) {\n warnings.style.display = 'block';\n warnings.textContent =\n 'This browser does not support binary websocket messages. ' +\n 'Performance may be slow.';\n }\n }\n\n this.imageObj = new Image();\n\n this.context = undefined;\n this.message = undefined;\n this.canvas = undefined;\n this.rubberband_canvas = undefined;\n this.rubberband_context = undefined;\n this.format_dropdown = undefined;\n\n this.image_mode = 'full';\n\n this.root = document.createElement('div');\n this.root.setAttribute('style', 'display: inline-block');\n this._root_extra_style(this.root);\n\n parent_element.appendChild(this.root);\n\n this._init_header(this);\n this._init_canvas(this);\n this._init_toolbar(this);\n\n var fig = this;\n\n this.waiting = false;\n\n this.ws.onopen = function () {\n fig.send_message('supports_binary', { value: fig.supports_binary });\n fig.send_message('send_image_mode', {});\n if (fig.ratio !== 1) {\n fig.send_message('set_device_pixel_ratio', {\n device_pixel_ratio: fig.ratio,\n });\n }\n fig.send_message('refresh', {});\n };\n\n this.imageObj.onload = function () {\n if (fig.image_mode === 'full') {\n // Full images could contain transparency (where diff images\n // almost always do), so we need to clear the canvas so that\n // there is no ghosting.\n fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);\n }\n fig.context.drawImage(fig.imageObj, 0, 0);\n };\n\n this.imageObj.onunload = function () {\n fig.ws.close();\n };\n\n this.ws.onmessage = this._make_on_message_function(this);\n\n this.ondownload = ondownload;\n};\n\nmpl.figure.prototype._init_header = function () {\n var titlebar = document.createElement('div');\n titlebar.classList =\n 'ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix';\n var titletext = document.createElement('div');\n titletext.classList = 'ui-dialog-title';\n titletext.setAttribute(\n 'style',\n 'width: 100%; text-align: center; padding: 3px;'\n );\n titlebar.appendChild(titletext);\n this.root.appendChild(titlebar);\n this.header = titletext;\n};\n\nmpl.figure.prototype._canvas_extra_style = function (_canvas_div) {};\n\nmpl.figure.prototype._root_extra_style = function (_canvas_div) {};\n\nmpl.figure.prototype._init_canvas = function () {\n var fig = this;\n\n var canvas_div = (this.canvas_div = document.createElement('div'));\n canvas_div.setAttribute(\n 'style',\n 'border: 1px solid #ddd;' +\n 'box-sizing: content-box;' +\n 'clear: both;' +\n 'min-height: 1px;' +\n 'min-width: 1px;' +\n 'outline: 0;' +\n 'overflow: hidden;' +\n 'position: relative;' +\n 'resize: both;'\n );\n\n function on_keyboard_event_closure(name) {\n return function (event) {\n return fig.key
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": "<IPython.core.display.HTML object>",
"text/html": "<div id='faad9c51-2393-43da-9161-b80f9328d0da'></div>"
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import matplotlib.pyplot as plt\n",
"%matplotlib notebook\n",
"plt.scatter(\n",
" embedding[:, 0],\n",
" embedding[:, 1])\n",
"plt.show()"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
},
{
"cell_type": "code",
"execution_count": 10,
"outputs": [
{
"data": {
"text/plain": "(1000, 2)",
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAFAAAAAVCAYAAADRhGlyAAAACXBIWXMAAA7EAAAOxAGVKw4bAAADdklEQVRYCe2Y7XEaMRCGL54UQJwOcAc4qSCmA0wHMR0kP+FfxunASQUZuwMnFWRCB9CBCR2Q9xFaWcg6c+EEM8x4Z3QrrVa70nurz2q1WlVxGo/H3bj8kn/EJ4fNSRXRZDL5pGIvEr1kNxHoeoyC9BURBqliIPZe/LMTJB/JAfZW6Vz5ZVLtipJfe/mD+JnStWRzLwustF4w3CKjPnXV3Mb+TvkFZcmnsVmVCbKl+DfkDkAVOsr/Ej9HaOTl31XGGEYB8Y3kTwCU7I/qvojfiVfi2ETWVz6AqHxRPXy1JfUJ8G7E+2ZLeYIBsOj/T5PDVWYMH8SXNoVRvqEyJhSULpVGkv+I6+K86q9U7og78KhTHpApB7ul9fBTiBg/YwykvhKNjIFZlxJjok1lAA7VwIVkqtmwfCm9jVD37X6LX8g20QiV1ltbbf+9kIlZ1E+zSOQRGERoII8VmHVO9GHtC1MsaP1fhg4wzVMyu9RDpfXWVtt/AWouLIi4HFkAxHWMbfhaH+b9xhyPtbbl+QvbdFR/Wlqvgc/GKuobMyNH7kSi+tzsArM+U5jNYZZr3VB26vXq/h7VgFxaz7vdDxNogMfUtZ05dQRmXQBkcLnplzZoU37bsHFpvYZus2psHncC8mu2do2ZA5DIeC56atoH8XPgW9Q9SLu0XuhA6YxAY5dlTayb2rhkDewQga1ITgx8Ijklk8ULtMliXZM11osbl8xrPBzJWLPDmbDGvgs8ACQybAA1ulvFLKisFylZBNomVVov9deqLNA4kZyJh8hTnutbbmxgtgBAQjGnIHFjYr1gM0qJm81UHVj6itJ6zqzstw2ASjZ6Mpa7ygJqbvkhOOYAOKWh0jayBd6iKujLOYfwhTjOHCnPoIZKH9cSdzspqodd7+evONernUhtCSB+LodmrnQhSTZS2QIgtu+Cg3MgVzQaZ0mNrc4Ow7eSEbX34vHtBYM8HvAz2DTg3Bf5QTEV1ZN9rptuQRcHgNxgY/+5/L2EgMj6l1Laf6sHj5F7C9Q710ypd8xvf+r/QKlziDHIT1dphi+mMPTkMr0WH9WX9WuX6NtlkByuHx8T5JipWLfb7OLgoG2YunLIsrF3ki+mOli55csiEMds3eHpCcER0ZUGVHdjKD0MMApPX+FFGi8e3cEBO1N6cHu1J1x4YOV6x6bl6B/ChE7KlbdLiwAAAABJRU5ErkJggg==\n",
"text/latex": "$\\displaystyle \\left( 1000, \\ 2\\right)$"
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"embedding.shape"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 0
}