Skip to content

Instantly share code, notes, and snippets.

@aernesto
Created March 25, 2019 21:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aernesto/79ec6754eb2d5601b61f8af431083346 to your computer and use it in GitHub Desktop.
Save aernesto/79ec6754eb2d5601b61f8af431083346 to your computer and use it in GitHub Desktop.
Relationship between percent correct and proportion choose 'right' in 2AFC tasks
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"toc": true
},
"source": [
"<h1>Table of Contents<span class=\"tocSkip\"></span></h1>\n",
"<div class=\"toc\"><ul class=\"toc-item\"></ul></div>"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {},
"outputs": [],
"source": [
"from IPython.display import HTML\n",
"from ipywidgets import interact\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<script>\n",
"code_show=true; \n",
"function code_toggle() {\n",
" if (code_show){\n",
" $('div.input').hide();\n",
" } else {\n",
" $('div.input').show();\n",
" }\n",
" code_show = !code_show\n",
"} \n",
"$( document ).ready(code_toggle);\n",
"</script>\n",
"<a href=\"javascript:code_toggle()\">Toggle code cells ON/OFF</a>."
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"HTML('''<script>\n",
"code_show=true; \n",
"function code_toggle() {\n",
" if (code_show){\n",
" $('div.input').hide();\n",
" } else {\n",
" $('div.input').show();\n",
" }\n",
" code_show = !code_show\n",
"} \n",
"$( document ).ready(code_toggle);\n",
"</script>\n",
"<a href=\"javascript:code_toggle()\">Toggle code cells ON/OFF</a>.''')"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"plt.rcParams['figure.figsize'] = [10, 5]\n",
"plt.rcParams.update({'font.size': 19})"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"def F_W(x, a, b):\n",
" return 1-np.exp(-((x/a)**b))"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"def psi(x, l, g, F, a, b):\n",
" return g+(1-g-l)*F(x, a, b)"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "057e5f09c1f341c481dd80466be86c35",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"A Jupyter Widget"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"@interact\n",
"def psi_corr(threshold=(.01, 100, 1), slope=(.01, 20, 1), lapse=(0,.1,.01)):\n",
" g=1/2\n",
" x = np.linspace(0,100,200)\n",
"# fig=plt.figure(figsize=(18, 16), dpi= 80, facecolor='w', edgecolor='k')\n",
" _, ax = plt.subplots()\n",
" ax.plot(x, 100 * psi(x, lapse, g, F_W, threshold, slope), linewidth=3)\n",
" ax.plot([threshold, threshold], [50, 100*psi(threshold, lapse, g, F_W, threshold, slope)], color='green')\n",
" ax.set(xlim=(0, 100), ylim=(50,100),\n",
" xlabel=\"coherence\",\n",
" ylabel=\"percent correct\",\n",
" title=\"Weibull + lapses\")"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [],
"source": [
"def F_L(x, a, b):\n",
"# print('F_l called, ndim(x) is ', np.ndim(x))\n",
" exp_arg = -b*(x-a)\n",
" # set upper and lower bounds for argument to exponential\n",
"# ub = 13\n",
"# lb = -13\n",
"# if np.ndim(exp_arg) == 0: # exp_arg is a scalar\n",
"# exp_arg = ub if exp_arg > ub else exp_arg\n",
"# exp_arg = lb if exp_arg < lb else exp_arg \n",
"# else:\n",
"# exp_arg[exp_arg > ub] = ub\n",
"# exp_arg[exp_arg < lb] = lb\n",
" return 1/(1+np.exp(exp_arg))"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "acfa8ea900d240f3a272178fccc1ec48",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"A Jupyter Widget"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"@interact\n",
"def psi_choice(threshold=(-100, 100, 1), slope=(.01, .8, .05), lapse=(0,.1,.01)):\n",
" g=lapse\n",
" x = np.linspace(-100,100,200)\n",
" _, ax = plt.subplots()\n",
" ax.plot(x, 100 * psi(x, lapse, g, F_L, threshold, slope), linewidth=3)\n",
" ax.plot([threshold, threshold], [0, 100*psi(threshold, lapse, g, F_L, threshold, slope)], color='green')\n",
" ax.set(xlim=(-100, 100), ylim=(0,100),\n",
" xlabel=\"signed coherence\",\n",
" ylabel=\"percent choose 'right'\",\n",
" title=\"Logistic + lapses\")"
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {},
"outputs": [],
"source": [
"# @interact\n",
"# def psi_choice(threshold=(-100, 100, 1), slope=(.01, .8, .05), lapse=(0,.1,.01)):\n",
"# g1=1/2\n",
"# g2=lapse\n",
"# x1 = np.linspace(0,100, 200)\n",
"# x2 = np.linspace(-100,100,200)\n",
"# _, (ax1,ax2) = plt.subplots(1,2)\n",
"# ax1.plot(x1, 100 * psi(x1, lapse, g1, F_W, threshold, slope), linewidth=3)\n",
"# ax1.plot([threshold, threshold], [50, 100*psi(threshold, lapse, g1, F_W, threshold, slope)], color='green')\n",
"# ax1.set(xlim=(0, 100), ylim=(50,100),\n",
"# xlabel=\"coherence\",\n",
"# ylabel=\"percent correct\",\n",
"# title=\"Weibull + lapses\")\n",
"# ax2.plot(x2, 100 * psi(x2, lapse, g2, F_L, threshold, slope), linewidth=3)\n",
"# ax2.plot([threshold, threshold], [0, 100*psi(threshold, lapse, g2, F_L, threshold, slope)], color='green')\n",
"# ax2.set(xlim=(-100, 100), ylim=(0,100),\n",
"# xlabel=\"signed coherence\",\n",
"# ylabel=\"percent choose 'right'\",\n",
"# title=\"Logistic + lapses\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "r-env (&Py3.7.2)",
"language": "python",
"name": "r-env"
},
"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.6.5"
},
"toc": {
"base_numbering": 1,
"nav_menu": {},
"number_sections": true,
"sideBar": true,
"skip_h1_title": true,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": true,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": true
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment