Github for code used in papers
some useful (and sometimes fun) MATLAB code
Simulating probability distortion via the Prelec equation - [download]
I’ve been interested in the description-experience gap recently, a phenomenon which suggests that the way we learn about a choice option influences how we perceive it and that this distortion is especially pronounced for low-probability options. Since Kahneman & Tversky’s seminal work on prospect theory, which provided a mathematical framework to understand how probability distortion comes about in the first place, many people have worked to refine it further. Perhaps the most famous and widely used equation is the one-term Prelec equation. In this simulation, I wanted to see how different degrees of probability distortion could lead to different degrees of choice bias in the special situation where the offered options have objectively equal payoff probability but may differ in how they are perceived. There’s a lot more behind this than I’m writing here, so, please feel free to get in touch if you want to know more.
Finding the probability of a probability from strands of binomial inputs - [download]
Have you ever flipped a coin and wondered whether it was fair? We are often confronted with situations where we need to make inferences about the likelihood of different (binomial) outcomes. Here, taking inspiration from 3blue1brown’s excellent YouTube series, I work through some of the basics underlying binomial probability density functions. The linked video(s) are excellent and absolutely worth a watch if you\re interested in such things.
Monte Carlo Simulations of different learning criteria - [download]
Sometimes you might want to use a subject’s local performance to trigger changes in task contingencies (e.g. rule-switching and reversal learning tasks). Assessing the significance of such behavior is not straight-forward because such performance-based criterion end up imposing strong constraints (e.g. getting 8 of the most recent 10 attempts correct has a defined “shape”) near reversals. Ultimately, assessing the significance of such behavior requires you to compare distributions of real behavior against that of a random (binomial) choice process. This code generates different performance-based null distributions according to the user-set criterion which you can then compare against the distributions of real behavior via a 2-sample Kolmorgov-Smirnov test.
Chi Square test with frequencies - [download]
Sometimes you want to compare whether two proportions of things are different, so, naturally, you turn to the Chi Square test. However, MATLAB doesn’t have a built-in function allowing you to compare two proportions, so, I wrote one.
Counting the number of consecutive 1s in an array of 1s and 0s - [download]
Sometimes you are interested in how long a particular event remains the case (i.e. a time-series of logical values where each element indicates with X is/isn’t the case). Here is a handy function which find stretches of 1s in a logical array and gives you the start and end points of each stretch. I find this especially useful when performing sliding-window analyses of neuronal selectivity.
Estimating instantaneous eye/movement speed from video XY coordinates - [download]
Sometimes you want to know how fast a subject/object is moving. This is a routine that estimates the instantaneous movement speed of a tracked object. The function takes X and Y coordinates as inputs, which means you can easily, for example, track a rodent’s speed through a maze or saccade speed of subjects in experiments using eye-trackers.
Simulation of the logistic map - [download]
Some time ago I read a classic Nature paper on recursive dynamics which in turn got me interested in the mathematical concept of chaos. In this script, I generate the logistic map, as described in the linked paper. This was just a fun way to concretely come to understand how very small differences in the starting conditions of an algorithm can lead to incredibly different outputs. Also, interestingly, for anyone interested in fractals, the logistic map is a 2D-look at the Mandelbrot Set. I’m not sure what these things “mean” in the broader sense, but it’s certainly interesting to examine the infinite and beautiful patterns that define the relationships between numbers.