Created
September 24, 2024 19:51
-
-
Save lschwetlick/b6168ed60668076e0d0c510811c40fd3 to your computer and use it in GitHub Desktop.
psignifit_issue_demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "cells": [ | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "import psignifit\n", | |
| "from psignifit import psigniplot\n", | |
| "import numpy as np\n", | |
| "from matplotlib import pyplot as plt" | |
| ], | |
| "outputs": [], | |
| "execution_count": 22, | |
| "metadata": { | |
| "collapsed": true, | |
| "jupyter": { | |
| "source_hidden": false, | |
| "outputs_hidden": false | |
| }, | |
| "nteract": { | |
| "transient": { | |
| "deleting": false | |
| } | |
| }, | |
| "execution": { | |
| "iopub.status.busy": "2024-09-24T19:43:08.833Z", | |
| "iopub.execute_input": "2024-09-24T19:43:08.836Z", | |
| "iopub.status.idle": "2024-09-24T19:43:08.840Z", | |
| "shell.execute_reply": "2024-09-24T19:43:08.843Z" | |
| } | |
| } | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "width = 10\n", | |
| "stim_range = [14, 14 + width * 3]\n", | |
| "threshold = 30\n", | |
| "eta = 0.3\n", | |
| "\n", | |
| "lambda_ = 0.1\n", | |
| "gamma = 0.5 # guess rate\n", | |
| "nsteps = 4\n", | |
| "num_trials = 30\n", | |
| "sigmoid = \"norm\"\n", | |
| "\n", | |
| "options = {}\n", | |
| "options['sigmoid'] = sigmoid \n", | |
| "options['experiment_type'] = 'yes/no'\n", | |
| "options['fixed_parameters'] = {'gamma': 0.5}\n", | |
| "options['stimulus_range'] = stim_range\n", | |
| "options['CI_method'] = 'percentiles'" | |
| ], | |
| "outputs": [], | |
| "execution_count": 33, | |
| "metadata": { | |
| "collapsed": true, | |
| "jupyter": { | |
| "source_hidden": false, | |
| "outputs_hidden": false | |
| }, | |
| "nteract": { | |
| "transient": { | |
| "deleting": false | |
| } | |
| }, | |
| "execution": { | |
| "iopub.status.busy": "2024-09-24T19:47:56.458Z", | |
| "iopub.execute_input": "2024-09-24T19:47:56.461Z", | |
| "iopub.status.idle": "2024-09-24T19:47:56.471Z", | |
| "shell.execute_reply": "2024-09-24T19:47:56.473Z" | |
| } | |
| } | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "seed = 123123180" | |
| ], | |
| "outputs": [], | |
| "execution_count": 34, | |
| "metadata": { | |
| "collapsed": true, | |
| "jupyter": { | |
| "source_hidden": false, | |
| "outputs_hidden": false | |
| }, | |
| "nteract": { | |
| "transient": { | |
| "deleting": false | |
| } | |
| }, | |
| "execution": { | |
| "iopub.status.busy": "2024-09-24T19:47:56.867Z", | |
| "iopub.execute_input": "2024-09-24T19:47:56.876Z", | |
| "iopub.status.idle": "2024-09-24T19:47:56.881Z", | |
| "shell.execute_reply": "2024-09-24T19:47:56.884Z" | |
| } | |
| } | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "print(seed)\n", | |
| "random_state = np.random.RandomState(seed)\n", | |
| "\n", | |
| "stimulus_level = np.linspace(stim_range[0], stim_range[1], nsteps)\n", | |
| "perccorr = psignifit.tools.psychometric_with_eta(stimulus_level, threshold, width, gamma, lambda_, sigmoid, eta, random_state=random_state)\n", | |
| "ntrials = np.ones(nsteps) * num_trials\n", | |
| "hits = (perccorr * ntrials).astype(int)\n", | |
| "data = np.dstack([stimulus_level, hits, ntrials]).squeeze()\n", | |
| "\n", | |
| "res = psignifit.psignifit(data, **options)\n", | |
| "#print(res.parameter_estimate[\"threshold\"], res.confidence_intervals[\"threshold\"])\n", | |
| "\n", | |
| "for i in res.confidence_intervals[\"threshold\"]:\n", | |
| " assert res.parameter_estimate[\"threshold\"]>i[0]\n", | |
| " assert res.parameter_estimate[\"threshold\"]<i[1]\n", | |
| " " | |
| ], | |
| "outputs": [ | |
| { | |
| "output_type": "stream", | |
| "name": "stdout", | |
| "text": [ | |
| "123123180\n" | |
| ] | |
| }, | |
| { | |
| "output_type": "error", | |
| "ename": "AssertionError", | |
| "evalue": "", | |
| "traceback": [ | |
| "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", | |
| "\u001b[0;31mAssertionError\u001b[0m Traceback (most recent call last)", | |
| "Cell \u001b[0;32mIn[35], line 15\u001b[0m\n\u001b[1;32m 13\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m i \u001b[38;5;129;01min\u001b[39;00m res\u001b[38;5;241m.\u001b[39mconfidence_intervals[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mthreshold\u001b[39m\u001b[38;5;124m\"\u001b[39m]:\n\u001b[1;32m 14\u001b[0m \u001b[38;5;28;01massert\u001b[39;00m res\u001b[38;5;241m.\u001b[39mparameter_estimate[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mthreshold\u001b[39m\u001b[38;5;124m\"\u001b[39m]\u001b[38;5;241m>\u001b[39mi[\u001b[38;5;241m0\u001b[39m]\n\u001b[0;32m---> 15\u001b[0m \u001b[38;5;28;01massert\u001b[39;00m res\u001b[38;5;241m.\u001b[39mparameter_estimate[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mthreshold\u001b[39m\u001b[38;5;124m\"\u001b[39m]\u001b[38;5;241m<\u001b[39mi[\u001b[38;5;241m1\u001b[39m]\n", | |
| "\u001b[0;31mAssertionError\u001b[0m: " | |
| ] | |
| } | |
| ], | |
| "execution_count": 35, | |
| "metadata": { | |
| "collapsed": true, | |
| "jupyter": { | |
| "source_hidden": false, | |
| "outputs_hidden": false | |
| }, | |
| "nteract": { | |
| "transient": { | |
| "deleting": false | |
| } | |
| }, | |
| "execution": { | |
| "iopub.status.busy": "2024-09-24T19:47:57.088Z", | |
| "iopub.execute_input": "2024-09-24T19:47:57.096Z", | |
| "iopub.status.idle": "2024-09-24T19:47:31.178Z", | |
| "shell.execute_reply": "2024-09-24T19:47:31.182Z" | |
| } | |
| } | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "print(res.parameter_estimate[\"threshold\"])" | |
| ], | |
| "outputs": [ | |
| { | |
| "output_type": "stream", | |
| "name": "stdout", | |
| "text": [ | |
| "32.93912458971731\n" | |
| ] | |
| } | |
| ], | |
| "execution_count": 36, | |
| "metadata": { | |
| "collapsed": true, | |
| "jupyter": { | |
| "source_hidden": false, | |
| "outputs_hidden": false | |
| }, | |
| "nteract": { | |
| "transient": { | |
| "deleting": false | |
| } | |
| }, | |
| "execution": { | |
| "iopub.status.busy": "2024-09-24T19:47:58.656Z", | |
| "iopub.execute_input": "2024-09-24T19:47:58.658Z", | |
| "iopub.status.idle": "2024-09-24T19:47:58.667Z", | |
| "shell.execute_reply": "2024-09-24T19:47:58.671Z" | |
| } | |
| } | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "print(res.confidence_intervals[\"threshold\"])" | |
| ], | |
| "outputs": [ | |
| { | |
| "output_type": "stream", | |
| "name": "stdout", | |
| "text": [ | |
| "[[24.60496885313708, 35.73536759413769], [25.309362325079807, 33.726255527766014], [26.941014699095206, 31.988957664460678]]\n" | |
| ] | |
| } | |
| ], | |
| "execution_count": 37, | |
| "metadata": { | |
| "collapsed": true, | |
| "jupyter": { | |
| "source_hidden": false, | |
| "outputs_hidden": false | |
| }, | |
| "nteract": { | |
| "transient": { | |
| "deleting": false | |
| } | |
| }, | |
| "execution": { | |
| "iopub.status.busy": "2024-09-24T19:47:59.287Z", | |
| "iopub.execute_input": "2024-09-24T19:47:59.289Z", | |
| "iopub.status.idle": "2024-09-24T19:47:59.300Z", | |
| "shell.execute_reply": "2024-09-24T19:47:59.303Z" | |
| } | |
| } | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [], | |
| "outputs": [], | |
| "execution_count": null, | |
| "metadata": { | |
| "collapsed": true, | |
| "jupyter": { | |
| "source_hidden": false, | |
| "outputs_hidden": false | |
| }, | |
| "nteract": { | |
| "transient": { | |
| "deleting": false | |
| } | |
| } | |
| } | |
| } | |
| ], | |
| "metadata": { | |
| "kernel_info": { | |
| "name": "datana" | |
| }, | |
| "language_info": { | |
| "name": "python", | |
| "version": "3.10.6", | |
| "mimetype": "text/x-python", | |
| "codemirror_mode": { | |
| "name": "ipython", | |
| "version": 3 | |
| }, | |
| "pygments_lexer": "ipython3", | |
| "nbconvert_exporter": "python", | |
| "file_extension": ".py" | |
| }, | |
| "kernelspec": { | |
| "argv": [ | |
| "/Users/lisa/Documents/virtual_envs/datana/bin/python3", | |
| "-m", | |
| "ipykernel_launcher", | |
| "-f", | |
| "{connection_file}" | |
| ], | |
| "display_name": "datana", | |
| "language": "python", | |
| "metadata": { | |
| "debugger": true | |
| }, | |
| "name": "datana" | |
| }, | |
| "nteract": { | |
| "version": "0.28.0" | |
| } | |
| }, | |
| "nbformat": 4, | |
| "nbformat_minor": 0 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment