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_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 / 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 / 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 / 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 / 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 ...
@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.
@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