Skip to content

Instantly share code, notes, and snippets.

View sammosummo's full-sized avatar
🐍
Working on Charlie3

Sam Mathias sammosummo

🐍
Working on Charlie3
View GitHub Profile
@sammosummo
sammosummo / equal_loudness_contours.py
Created May 25, 2015 13:12
Contains functions for generating and using equal-loudness contours for side-presented steady pure tones according to the ISO/IEC 226 standard.
"""Contains functions for generating and using equal-loudness contours for
side-presented steady pure tones according to the ISO/IEC 226 standard.
"""
__author__ = 'Sam Mathias'
__version__ = 1.0
@sammosummo
sammosummo / example.py
Created May 25, 2015 15:27
NumPy docstring example
"""This is the docstring for the example.py module. Modules names should
have short, all-lowercase names. The module name may have underscores if
this improves readability.
Every module should have a docstring at the very top of the file. The
module's docstring may extend over multiple lines. If your docstring does
extend over multiple lines, the closing three quotation marks must be on
a line by itself, preferably preceeded by a blank line.
"""
@sammosummo
sammosummo / staircase.py
Created September 22, 2015 15:25
Implementation of Kaernbach's (1991) adaptive staircase procedure in Python.
# -*- coding: utf-8 -*-
"""
Created on Tue Dec 10 17:41:11 2013
@author: smathias
"""
import matplotlib.pyplot as plt
import numpy as np
class Kaernbach1991:
@sammosummo
sammosummo / huggins.py
Created September 22, 2015 15:31
Function for creating Huggins pitch stimuli.
# -*- coding: utf-8 -*-
"""
Created on Wed Nov 20 15:22:22 2013
@author: smathias
"""
import brian
import brian.hears as b
import numpy as np
@sammosummo
sammosummo / yesno.py
Last active May 26, 2017 14:34
Bayesian hierarchical generalised linear signal detection models for yes-no experiments using PyMC3
"""Bayesian hierarchical generalised linear signal detection models for
yes-no experiments.
"""
import numpy as np
import pandas as pd
import patsy
import pymc3 as pm
import theano
import theano.tensor as T
@sammosummo
sammosummo / bh_wm_cap.py
Created September 13, 2016 18:41
Bayesian model of working-memory capacity.
"""Model of working-memory capacity for change-detection tasks.
This script implements a "slots-based" model of working memory capacity based
on the Cowan formula, modified to allow lapses and formalized in a Bayesian
framework.
Data are organised into a pandas data frame in which each row represents a
subject, and columns contain covariates or observations. "Covariates" can be
categorical or continuous. "Observations" are counts of trials and are named
`{x}_{y}` where `{x}` is a single uppercase letter indicating the count type
@sammosummo
sammosummo / bhlr.py
Created October 27, 2017 17:44
Bayesian hierarchical logistic regression
"""Simple fully contained script to fit a Bayesian hierarchical logistic
regression model using PyMC3.
"""
import theano
import matplotlib
matplotlib.use('Agg') # seems to be necessary on Unix
import numpy as np
import pandas as pd
import pymc3 as pm
@sammosummo
sammosummo / irn.py
Created November 21, 2017 16:34
Iterated rippled noise
import numpy as np
import brian
import brian.hears as hears
def irn(dur, f, g, n, method='s'):
"""Generate IRN with a duration dur in seconds, a pitch at f (either a
single value for a flat pitch, or an iterable for a contour) in Hz, a gain
of g (-1 <= g <= 1) and n iterations. Since this is done in the time
domain, processing time gets longer with larger n."""
x = hears.whitenoise(dur * brian.second) #input signal
@sammosummo
sammosummo / ripple.py
Created December 22, 2017 18:36
Ripple sounds
# -*- coding: utf-8 -*-
from warnings import warn
import numpy as np
from scipy.signal import butter, lfilter
from scipy.stats import norm, uniform
import matplotlib.pyplot as plt
import brian
import brian.hears as hears
@sammosummo
sammosummo / ddm_figure.py
Created January 27, 2018 16:15
Creates a simple DDM figure
import hddm
import numpy as np
from scipy.stats import norm
import matplotlib.pyplot as plt
from matplotlib.gridspec import GridSpec
from tqdm import tqdm
def setupfig():
"""Tweak for the target journal.