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 / ddm_lik_pure_python.py
Created March 22, 2021 21:56
Pure Python implementation of the full DDM log-likelihood function with exponential contaminants
"""Attempts to implement DDM likelihoods in Python.
"""
from math import pi, sqrt, log, ceil, floor, exp, sin, fabs, inf
def simpson_1d(x, v, sv, a, z, t, err, lb_z, ub_z, n_sz, lb_t, ub_t, n_st):
n = max(n_st, n_sz)
@sammosummo
sammosummo / ddm_in_aesara.py
Last active January 2, 2023 07:44
Aesara/Theano implementation of the WFTP distribution
"""Aesara/Theano functions for calculating the probability density of the Wiener
diffusion first-passage time (WFPT) distribution used in drift diffusion models (DDMs).
"""
import arviz as az
import matplotlib.pyplot as plt
import numpy as np
import pymc3 as pm
from pymc3.distributions import draw_values, generate_samples
@sammosummo
sammosummo / ddm_in_jax.py
Created March 31, 2021 20:18
JAX implementation of the full DDM log likelihood function
"""JAX functions for calculating the probability density of the Wiener diffusion first-
passage time (WFPT) distribution used in drift diffusion models (DDMs).
"""
import jax
import jax.numpy as jnp
def jax_wfpt_pdf_sv(x, v, sv, a, z, t):
"""Probability density function of the WFPT distribution with drift rates normally
@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 / ddm_lik_numba.py
Created March 22, 2021 22:01
Python implementation (via Numba) of the full DDM log likelihood function
"""Attempts to implement DDM likelihoods in Python.
"""
from math import pi, sqrt, log, ceil, floor, exp, sin, fabs, inf
from numba import jit, vectorize
@jit(nopython=True)
def simpson_1d(x, v, sv, a, z, t, err, lb_z, ub_z, n_sz, lb_t, ub_t, n_st):
@sammosummo
sammosummo / qt_audio_example.py
Created June 12, 2019 12:13
Display a GUI and play pure tones with PyQt5
from math import pi, sin
import struct, sys
from PyQt5.QtCore import QBuffer, QByteArray, QIODevice, Qt
from PyQt5.QtWidgets import (
QApplication,
QFormLayout,
QLineEdit,
QHBoxLayout,
QPushButton,
@sammosummo
sammosummo / pure_tones.py
Created March 22, 2019 22:33
Defines a function to play pure tones.
"""Contains a function to generate pure tones.
"""
import numpy as np
import sounddevice as sd
a0 = 1e-5 # reference amplitude
sr = 44100 # sample rate
@sammosummo
sammosummo / play_tone.py
Created March 17, 2019 17:22
Simply generates a pure tone using numpy and plays it via sounddevice.
"""Simply generates a pure tone using numpy and plays it via sounddevice.
As always, make sure your volume settings are low before running this script, especially
if you are using headphones!
"""
import numpy as np
import sounddevice as sd
@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 / sounds.py
Created December 13, 2018 14:03
Simple script for generating and playing sounds in Python 3
import numpy as np
import simpleaudio as sa
samplerate = 44100
ref_amplitude = 1e-5
level = 80
ref_rms = ref_amplitude / np.sqrt(2)
rms = 10 ** (level / 20) * ref_rms
amplitude = rms * np.sqrt(2)
# or more simply ...