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.

560 lines
108 KiB

{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"pycharm": {
"name": "#%% md\n"
}
},
"source": [
"# Tuning Curves"
]
},
{
"cell_type": "markdown",
"metadata": {
"pycharm": {
"name": "#%% md\n"
}
},
"source": [
"**Import everything**"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [],
"source": [
"%matplotlib notebook\n",
"import typing\n",
"\n",
"import matplotlib as mpl\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"\n",
"import ipywidgets as widgets\n",
"import sympy as sp\n",
"sp.init_printing()\n",
"AxOrImg = typing.Union[mpl.axes.Axes, mpl.image.AxesImage]"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [],
"source": [
"k, x0, y0, phi, theta, sigma_x, sigma_y, sigma, x, y = sp.symbols(r'k x_0 y_0 \\phi \\theta \\sigma_x \\sigma_y \\sigma x y')\n",
"defaults = {\n",
" k: 6,\n",
" sigma: 0.2,\n",
" phi: sp.pi / 2,\n",
" theta: 0,\n",
" sigma: 1,\n",
" x0: 0, y0: 0\n",
"}\n",
"sigma_x = sigma_y = sigma"
]
},
{
"cell_type": "markdown",
"metadata": {
"pycharm": {
"name": "#%% md\n"
}
},
"source": [
"#### Formulas"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [
{
"data": {
"text/plain": "cos(\\phi + k⋅(x - x₀)⋅cos(\\theta) + k⋅(y - y₀)⋅sin(\\theta))",
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAZUAAAAVCAYAAACOnHNXAAAACXBIWXMAAA7EAAAOxAGVKw4bAAALeklEQVR4Ae2d65XUNhTHhz1bAIEKAh3wqCDQAYEK2HQAh0/wjUM6SKiAQAch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eeUG5zhMWKDTYbrRil4gttW/nqVhep/zNg6XL9u/yflG4Njcu/3a90NtRmTJ14PVB6MqZPzbYaOytzzfGW5CXZ/lXasafevyrt/V85lCl9WhLf1LHAqbQj1wxes+QWjqPxX2F9pfRhqq5q94vhUVmxz4JH7WfZr7ZMfX7Ct5ivhro4iS1xBypjR2OrcAoCK3fNnQ47idQOJYWhZnmJzDXHW5IXOyt2Lo60o+KZn5fHTirsItHFMVBNm82Ve5X+KxtzYuv/uIardXxicRqBZ4zPIsdc+7XWxZK+2uliNYuKDM8xke86HPFS1H1PSTUYU66x+Jkr4x6ECmU+CLa5g0o2fqbNX3gkwPCjBY7pHLt3SHXYG7sfzA47gDIvHmfOTzNc3LXmbLmFZa3+y48U3gRKONSPaQxCER7ps8hnYaq2s+1n4FrlwlgSU7PD52Tt159mOS7bgMDD/eH9xLDczX5rlJP5aOWVs7F7yRHfinIn1ByPpetr2OwY5Y7pOaYL7H5N9mczwbcUvs3WvGGI4RgqK8ZT6LOMdSz2i9lnSFexupysO/Wr+p8fkUZGZQfAz5in/oXEmFJWXfY9yoxBJDdBJ3Ul9s3a7Jjljhnle/PfY7PfHPvkZI3V/wfyW5BPgYgjWgAAAABJRU5ErkJggg==\n",
"text/latex": "$\\displaystyle \\cos{\\left(\\phi + k \\left(x - x_{0}\\right) \\cos{\\left(\\theta \\right)} + k \\left(y - y_{0}\\right) \\sin{\\left(\\theta \\right)} \\right)}$"
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"grating_f = sp.cos(k * (x - x0) * sp.cos(theta) + k * (y - y0) * sp.sin(theta) + phi)\n",
"receptive_field = 1 / (2 * sp.pi * sigma * sigma) * sp.exp(-(x ** 2 + y ** 2) / (2 * sigma ** 2)) * sp.cos(k * x * sp.cos(theta) + k * y * sp.sin(theta) + phi)\n",
"receptive_field = receptive_field.subs(theta, 0).subs(phi, 0)\n",
"grating_f"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [
{
"data": {
"text/plain": " 2 2 \n - x - y \n ───────── \n 2 \n 2⋅\\sigma \nℯ ⋅cos(k⋅x)\n───────────────────\n 2 \n 2⋅π⋅\\sigma ",
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAJEAAAA3CAYAAAAMnajQAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAJ6UlEQVR4Ae2c7XXUOhCGNzkUkJt0EDrgowKgAyAVJHQAJ7/gHwc6CFTAhQ6AChJuB6GDhHTAfZ9ZjY7stZ3srux4Hc05Wsn6mJFmRqORLO/W379/Z7cN7969e6o+7CjsK9xX+Kq8H4qzw5C0snd+pAjvjaRfKM0/9EUxyvRHYYvnHmBIWj10f3wot0fSpYdJP7BGV8lz7uSQtHL3fZT4RqFEsj6/E+58UPpF8pw1OSStrB0fMbKtMfhEzh8J+ETpE8X/eV5f8ZC0+hrDWPCOwhLBDAkVC/QGBVJ43SeDhqTV5zjGgnsQSyShPdCAHymw87pQwOd5qPxXimeKfymijsNv5VF3aVC752r0WOFC6Y8gUIx1y04L3AVms6F2Z48kxE8KKMoHxc8UsDwGSqfOrmevE5+q8TMQCDc0d0kDPdCaI77DvysrkYTBLupNB+/iWY/qfgr1OA/6Tlp5XW1D9Xm0JK1vqv9VLfGvgEhz/lh+s3MAx7rv8Pbt29fQUPxd4UFIH/VFVzTOHXdK0/NKnFfmQ/lEWAYsEAeJewrnCmeyGL3swoTXHXN8L/yhvg4uhb5A71Zo6Fkvy7Ov8By6xAonQ/dhSHqMdwh6XXRGs8XPOJ+xdo9lfY4U7yu2XVlG/KNBFSxuuqvts2/w0i18hc5Ky5mQ3f5b28ow8j1obBux9KmfdpShuLJB0TOTCPeBI5VLPa90VNLEUeFCia4U+0bJqq2kRE0ESt5wHAiK8lNx69GIyjh7w+/MaokD3ieK8TcNVt7iO4LbiDUAtu3MOI4Zer06chvjuwFNztj8CKOtOsvc+7bCNfKhC/2onJvqE3EGxXkQJ9KYczt7U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DtiCOorlmlmLHhiUkrkYSFFUA5sBoGQdipwNn6+81ALFLl/nBoRoT1AldUoFDWuiyprv3zSag32WhqjnUUlASIv7OrOJ4ZxcKQUBlLzFWSz1+/pM9JkflPKGUdwNGqSPXKU3yepBJJEdhK8417aoGavo5gWUn/OgcfZgGEx/PNV6pVONBzU36t2nQfJ6dEEjiWgf+xrjuvKNali1Ll+CpYK5zkCMrHL6qDt/PYygMtFKxOq95+0s+T8okkVASKI41zXF96nirPfR+EigI1nSmx/FUsi9rxZwfkoWDukDstvkRtWwJVffowKSWSuFiaEC4KUofUmaYMZalbkLrTnOJgaeStPPgBvp2f5OGhjW6Jn/8BCy8ISGIS3qgAAAAASUVORK5CYII=\n",
"text/latex": "$\\displaystyle \\frac{e^{\\frac{- x^{2} - y^{2}}{2 \\sigma^{2}}} \\cos{\\left(k x \\right)}}{2 \\pi \\sigma^{2}}$"
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"receptive_field"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [],
"source": [
"int1 = sp.Integral(grating_f * receptive_field, (x, -1, 1), (y, -1, 1)).subs(defaults)\n",
"# int1.evalf(2).doit()"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [
{
"data": {
"text/plain": " 2 ⎛ 2 ⎞ \n k ⋅⎝cos (\\theta) + 1⎠ \n ───────────────────── \n 2 ⎛ \nℯ ⋅cos(\\phi - k⋅(x₀⋅cos(\\theta) + y₀⋅sin(\\theta)))⋅cosh⎝\\s\n\n \n \n \n 2 2 ⎞\nigma ⋅k ⋅cos(\\theta)⎠",
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAkoAAAApCAYAAADK3AZEAAAACXBIWXMAAA7EAAA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syNWUX1gDWT3zEsdhVXyf9LMdX5iyDlC4bMVYZh9MfN6jJxFjQBgQr5TJUNtZfk0xo/gcPNJMVYQcer+44C5Wyl0Ubwo1P5uZXW2n5rSpmxzkverKC/Jd1kG5a+59AxlEQIwqCxhK0PzgywNLeUwFXcRV16TgYr/abwNQiqlymz95TXzp/uJmlQDBxyx6iMsxLdM4uhA6Cc+7pwzxWeYnoM/e+XRhvL+C+4e+fLfq5Q9O4zPZPg0roHr5F20eQOECoM3ofaRJFflUN+luVxj3V9qQtdhH9cRzbHoPpfX/4m5e1pA8f+uY1HnkM6rr5DBuBavSrZL2DOcyIn9JDzU7F+H/da/qxzLMo32JYUhy5wWBefLThXh88TDxsrDhmDJQ49Qm9KE4xB/VRe9HKqbKi7JJ/W+IOn7aw6rTrBfyq+4IFDHtfubuQn4YvBGPz7zp1RU7opB8Kr+q2JZUa6EppT/jp9VpLmbOOJr3Oq/pZ0k52N+5R9LyCgBwBmeY+DYm7rQz4NGsOp37EpaH9O/KQdMQ1vVke3F87FL42dmQOfu38L3fKRM0aQe71UPjKmY8ZAifjonj8sZpk3/J0LB6zpaKPTc25GE+N180gXOjXoVIaLD2XJP+iiTke7/A5dgwUtGKE66bTAJdAWOkyewZMrDpy6D67IrxKCo8NNPltQDH50NBhflI9eOlnJn+SUf+vyDgYiHVTqwBoX9e/46H7pbNHZczu+f4NMkD0ySuXNwBZ0YhJdKg/dGmxLigcD3mhCx6LTM30y4eBxpcu1TRIoDPww5kpvx47p5xzZUH1JPk3x4ukSOo2
"text/latex": "$\\displaystyle e^{\\frac{k^{2} \\left(\\cos^{2}{\\left(\\theta \\right)} + 1\\right)}{2}} \\cos{\\left(\\phi - k \\left(x_{0} \\cos{\\left(\\theta \\right)} + y_{0} \\sin{\\left(\\theta \\right)}\\right) \\right)} \\cosh{\\left(\\sigma^{2} k^{2} \\cos{\\left(\\theta \\right)} \\right)}$"
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# p = sp.cos(phi) * sp.cos(k*x0*sp.cos(theta) + k*y0*sp.sin(theta)) * sp.exp(k**2 * (sigma_x **2 * (1 + sp.cos(theta))**2 + sigma_y**2 * sp.sin(theta) **2) / 2)\n",
"p = sp.cosh(k**2 * sigma**2 * sp.cos(theta)) * sp.exp(k ** 2 * (1 + sp.cos(theta) ** 2) / 2) * sp.cos(phi - k * (x0 * sp.cos(theta) + y0 * sp.sin(theta)))\n",
"p"
]
},
{
"cell_type": "markdown",
"metadata": {
"pycharm": {
"name": "#%% md\n"
}
},
"source": [
"#### Plot stuff"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [],
"source": [
"def get_orientation_phase_grid(step_phase: float, step_orientation: float) -> np.ndarray:\n",
" \"\"\"\n",
" Returns a grid of x and y values for plotting.\n",
" :param step_phase: step for the phase (phi) - in degrees\n",
" :param step_orientation: step for the orientation (theta) - in degrees\n",
" :return: numpy array of shape (n_orientation, n_phase). Each element is a tuple (theta, phi)\n",
" \"\"\"\n",
" # phase <-> phi\n",
" # orientation <-> theta\n",
" step_phase *= np.pi / 180\n",
" step_orientation *= np.pi / 180\n",
" phi = np.arange(0, 2 * np.pi, step_phase)\n",
" theta = np.arange(0, np.pi, step_orientation)\n",
" return np.array(np.meshgrid(theta, phi)).T.reshape(-1, len(phi), 2)\n",
"\n",
"\n",
"def get_spatial_grid(step_x: float, step_y: float, size: float = 1) -> np.ndarray:\n",
" \"\"\"\n",
" Returns a grid of x and y values for plotting.\n",
" :param step_x: step for the x-coordinate\n",
" :param step_y: step for the y-coordinate\n",
" :param size: size of the grid\n",
" :return: numpy array of shape (2 * size / step_x, 2 * size / step_y). Each element is a tuple (x, y)\n",
" \"\"\"\n",
" x = np.arange(-size, size, step_x)\n",
" y = np.arange(-size, size, step_y)\n",
" return np.array(np.meshgrid(x, y)).T.reshape(-1, len(x), 2)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [],
"source": [
"def eval_func(func: sp.Expr, sub_1: sp.Expr, sub_2: sp.Expr, grid: np.ndarray) -> np.ndarray:\n",
" # return np.array([[float(func.subs(sub_1, x_).subs(sub_2, y_)) for x_, y_ in line] for line in grid])\n",
" func = sp.lambdify([sub_1, sub_2], func, 'numpy')\n",
" return func(grid[:, :, 0], grid[:, :, 1])\n",
"\n",
"def plot_spatial(func: sp.Expr, ax: AxOrImg, step_x: float = 0.05, step_y: float = 0.05, size: float = 1, title: str = None, show: bool = False,\n",
" patch: typing.Optional[typing.Tuple[float, float, float]] = None\n",
" ):\n",
" \"\"\"\n",
" Plots a spatial map of the function.\n",
"\n",
" :param func: function to plot\n",
" :param ax: axes to plot on or the image on axes\n",
" :param step_x: step for the x-coordinate\n",
" :param step_y: step for the y-coordinate\n",
" :param size: size of the grid\n",
" :param title: title of the plot\n",
" :param show: whether to show the plot\n",
" :param patch: optional circle to plot - a tuple (x, y, radius)\n",
" \"\"\"\n",
" grid = get_spatial_grid(step_x, step_y, size)\n",
" image: np.ndarray = eval_func(func, x, y, grid)\n",
" if isinstance(ax, mpl.image.AxesImage):\n",
" ax.set_data(image)\n",
" return ax\n",
" img = ax.imshow(image, extent=[-size, size, -size, size], vmin=-size, vmax=size, cmap='gray')\n",
" ax.invert_yaxis()\n",
" if patch is not None:\n",
" ax.add_patch(plt.Circle(patch[:2], radius=patch[2], color='b', fill=False))\n",
" ax.set_title(title)\n",
" if show:\n",
" plt.show()\n",
" return img\n",
"\n",
"def normalize(img):\n",
" return (img - img.min()) / (img.max() - img.min())\n",
"\n",
"def plot_tuning_curve(func: typing.Union[sp.Expr, typing.Callable], ax: AxOrImg, step_phase: float = 20, step_orientation: float = 15, title: str = None, show: bool = False):\n",
" \"\"\"\n",
" Plots a tuning curve of the function.\n",
"\n",
" :param func: function to plot - sympy or a function of (theta, phi)\n",
" :param ax: axes to plot on or image to update\n",
" :param step_phase: step for the phase (phi) - in degrees\n",
" :param step_orientation: step for the orientation (theta) - in degrees\n",
" :param title: title of the plot\n",
" :param show: whether to show the plot\n",
" \"\"\"\n",
" grid = get_orientation_phase_grid(step_phase, step_orientation)\n",
" if isinstance(func, sp.Expr):\n",
" image: np.ndarray = eval_func(func, theta, phi, grid)\n",
" else:\n",
" image = np.array([[func(theta_val, phi_val) for theta_val, phi_val in line] for line in grid])\n",
" image = normalize(image)\n",
" if isinstance(ax, mpl.image.AxesImage):\n",
" ax.set_data(image)\n",
" return ax\n",
" img = ax.imshow(image, extent=[0, 360, 0, 180], cmap='viridis')\n",
" ax.set_title(title)\n",
" if show:\n",
" plt.show()\n",
" return img"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [],
"source": [
"def plot_gratings(ax: typing.Union[plt.Axes, mpl.image.AxesImage], k_val: float, phi_val: float, theta_val: float, x0_val: float = 0, y0_val: float = 0):\n",
" phi_val *= np.pi / 180\n",
" theta_val *= np.pi / 180\n",
" return plot_spatial(\n",
" # grating_f.evalf(subs={k: k_val, x0: x0_val, y0: y0_val, theta: theta_val, phi: phi_val}),\n",
" grating_f.subs(k, k_val).subs(x0, x0_val).subs(y0, y0_val).subs(theta, theta_val).subs(phi, phi_val),\n",
" ax, step_x=0.05, step_y=0.05, size=1, title='Grating', show=False)\n",
"\n",
"def plot_receptive_field(ax: plt.Axes, k_val: float, phi_val: float, theta_val: float, sigma_val: float = 1):\n",
" phi_val *= np.pi / 180\n",
" theta_val *= np.pi / 180\n",
" return plot_spatial(\n",
" receptive_field.subs(k, k_val).subs(theta, theta_val).subs(phi, phi_val).subs(sigma, sigma_val),\n",
" ax, step_x=0.05, step_y=0.05, size=1, title='Receptive field', show=False)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [],
"source": [
"def get_value(k_val: float = defaults[k], phi_val: float = 90, theta_val: float = 0, x0_val: float = 0, y0_val: float = 0, sigma_val: float = defaults[sigma]):\n",
" phi_val *= np.pi / 180\n",
" theta_val *= np.pi / 180\n",
" grid_size = 0.05\n",
" grid = get_spatial_grid(grid_size, grid_size, 1)\n",
" subs = {\n",
" k: k_val,\n",
" x0: x0_val,\n",
" y0: y0_val,\n",
" theta: theta_val,\n",
" phi: phi_val,\n",
" sigma: sigma_val\n",
" }\n",
" grating_img = eval_func(grating_f.subs(subs), x, y, grid)\n",
" rf_img = eval_func(receptive_field.subs(subs), x, y, grid)\n",
" return np.sum(grating_img * rf_img) * grid_size ** 2"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"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='f13c0382-84d9-433b-a1af-739fb17ba7e3'></div>"
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": "interactive(children=(FloatSlider(value=6.0, description='k', max=10.0, step=0.2), FloatSlider(value=90.0, des…",
"application/vnd.jupyter.widget-view+json": {
"version_major": 2,
"version_minor": 0,
"model_id": "aba71ad883fd429f9b2bac9e1ba7f917"
}
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"fig, ax = plt.subplots(1, 3)\n",
"img_gr = plot_gratings(ax[0], defaults[k], 90, 0, 0, 0)\n",
"img_rf = plot_receptive_field(ax[1], defaults[k], 90, 90, defaults[sigma])\n",
"val = get_value()\n",
"line = ax[2].plot([val, val])[0]\n",
"ax[2].set(ylim=[-0.2, 0.2])\n",
"\n",
"@widgets.interact(\n",
" k_val=widgets.FloatSlider(min=0, max=10, step=0.2, value=defaults[k], description='k'),\n",
" phi_val=widgets.FloatSlider(min=0, max=360, step=10, value=90, description='phi'),\n",
" theta_val=widgets.FloatSlider(min=0, max=180, step=10, value=0, description='theta'),\n",
" x0_val=widgets.FloatSlider(min=-1, max=1, step=0.05, value=0, description='x0'),\n",
" y0_val=widgets.FloatSlider(min=-1, max=1, step=0.05, value=0, description='y0'),\n",
" sigma_val=widgets.FloatSlider(min=0, max=1, step=0.05, value=defaults[sigma], description='sigma'),\n",
")\n",
"def plot_stuff(k_val, phi_val, theta_val, x0_val, y0_val, sigma_val):\n",
" plot_gratings(img_gr, k_val, phi_val, theta_val, x0_val, y0_val)\n",
" plot_receptive_field(img_rf, k_val, phi_val, theta_val, sigma_val)\n",
" val = get_value(k_val, phi_val, theta_val, x0_val, y0_val, sigma_val)\n",
" line.set_ydata([val, val])\n",
" fig.canvas.draw_idle()"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"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='4106d5b0-666f-49c4-a240-3744f7c3f5c3'></div>"
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": "interactive(children=(FloatSlider(value=0.8, description='k', max=10.0, step=0.2), FloatSlider(value=0.8, desc…",
"application/vnd.jupyter.widget-view+json": {
"version_major": 2,
"version_minor": 0,
"model_id": "75bac2ab8604428a9d0928978ef62b80"
}
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"fig, ax = plt.subplots(1, 2)\n",
"DEF_K, DEF_SIGMA, DEF_X = 0.8, 0.05, 0.8\n",
"get_tuning_curve_func = lambda k_val, x0_val, y0_val, sigma_val: lambda theta_val, phi_val: get_value(k_val, phi_val * 180 / np.pi, theta_val * 180 / np.pi, x0_val, y0_val, sigma_val)\n",
"left_img = plot_tuning_curve(get_tuning_curve_func(DEF_K, DEF_X, 0, DEF_SIGMA), ax[0], title='Tuning Curve')\n",
"right_img = plot_tuning_curve(p.subs({k: defaults[k], x0: defaults[x0], y0: defaults[y0], sigma: defaults[sigma]}), ax[1], title='Tuning Curve')\n",
"\n",
"@widgets.interact(\n",
" k_val=widgets.FloatSlider(min=0, max=10, step=0.2, value=DEF_K, description='k'),\n",
" x0_val=widgets.FloatSlider(min=-1, max=1, step=0.05, value=DEF_X, description='x0'),\n",
" y0_val=widgets.FloatSlider(min=-1, max=1, step=0.05, value=0, description='y0'),\n",
" sigma_val=widgets.FloatSlider(min=0, max=1, step=0.05, value=DEF_SIGMA, description='sigma'),\n",
")\n",
"def plot_tuning_curves(k_val, x0_val, y0_val, sigma_val):\n",
" plot_tuning_curve(get_tuning_curve_func(k_val, x0_val, y0_val, sigma_val), left_img, title='Tuning Curve - Numeric')\n",
" plot_tuning_curve(p.subs({k: k_val, x0: x0_val, y0: y0_val, sigma: sigma_val}), right_img, title='Tuning Curve - Analytic')\n",
" fig.canvas.draw_idle()"
]
},
{
"cell_type": "code",
"execution_count": 13,
"outputs": [],
"source": [
"# %matplotlib inline\n",
"func_1 = get_tuning_curve_func(DEF_K, DEF_X, 0, DEF_SIGMA)\n",
"func_2 = p.subs({k: DEF_K, x0: DEF_X, y0: 0, sigma: DEF_SIGMA})\n",
"grid = get_orientation_phase_grid(15, 15)\n",
"img_1 = np.array([[func_1(theta, phi) for theta, phi in line] for line in grid])\n",
"img_2 = eval_func(func_2, theta, phi, grid)\n",
"plt.plot(np.mean(img_2, axis=1))\n",
"plt.show()"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
},
{
"cell_type": "code",
"execution_count": 14,
"outputs": [
{
"data": {
"text/plain": " 2 ⎛ 2 ⎞ \n k ⋅⎝cos (\\theta) + 1⎠ \n ───────────────────── \n 2 ⎛ \nℯ ⋅cos(\\phi - k⋅(x₀⋅cos(\\theta) + y₀⋅sin(\\theta)))⋅cosh⎝\\s\n\n \n \n \n 2 2 ⎞\nigma ⋅k ⋅cos(\\theta)⎠",
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAkoAAAAp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PltZshawJ0uHMwpi95NyMZzjT8avoWzirxsyNWUX1gDWT3zEsdhVXyf9LMdX5iyDlC4bMVYZh9MfN6jJxFjQBgQr5TJUNtZfk0xo/gcPNJMVYQcer+44C5Wyl0Ubwo1P5uZXW2n5rSpmxzkverKC/Jd1kG5a+59AxlEQIwqCxhK0PzgywNLeUwFXcRV16TgYr/abwNQiqlymz95TXzp/uJmlQDBxyx6iMsxLdM4uhA6Cc+7pwzxWeYnoM/e+XRhvL+C+4e+fLfq5Q9O4zPZPg0roHr5F20eQOECoM3ofaRJFflUN+luVxj3V9qQtdhH9cRzbHoPpfX/4m5e1pA8f+uY1HnkM6rr5DBuBavSrZL2DOcyIn9JDzU7F+H/da/qxzLMo32JYUhy5wWBefLThXh88TDxsrDhmDJQ49Qm9KE4xB/VRe9HKqbKi7JJ/W+IOn7aw6rTrBfyq+4IFDHtfubuQn4YvBGPz7zp1RU7opB8Kr+q2JZUa6EppT/jp9VpLmbOOJr3Oq/pZ0k52N+5R9LyCgBwBmeY+DYm7rQz4NGsOp37EpaH9O/KQdMQ1vVke3F87FL42dmQOfu38L3fKRM0aQe71UPjKmY8ZAifjonj8sZpk3/J0LB6zpaKPTc25GE+N180gXOjXoVIaLD2XJP+iiTke7/A5dgwUtGKE66bTAJdAWOkyewZMrDpy6D67IrxKCo8NNPltQDH50NBhflI9eOlnJn+SUf+vyDgYiHVTqwBoX9e/46H7pbNHZczu+f4NMkD0ySuXNwBZ0YhJdKg/dGmxLigcD3mhCx6LTM30y4eBxpcu1TRIoDPww5kpvx47p5xzZUH1JPk3x4ukSOo2
"text/latex": "$\\displaystyle e^{\\frac{k^{2} \\left(\\cos^{2}{\\left(\\theta \\right)} + 1\\right)}{2}} \\cos{\\left(\\phi - k \\left(x_{0} \\cos{\\left(\\theta \\right)} + y_{0} \\sin{\\left(\\theta \\right)}\\right) \\right)} \\cosh{\\left(\\sigma^{2} k^{2} \\cos{\\left(\\theta \\right)} \\right)}$"
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"p"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
},
{
"cell_type": "code",
"execution_count": 14,
"outputs": [],
"source": [],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.5"
}
},
"nbformat": 4,
"nbformat_minor": 1
}