Last active
October 12, 2021 20:01
-
-
Save da5nsy/d228e581af239868e88adb082c8c73fb to your computer and use it in GitHub Desktop.
This is a MWE for the problem shared at https://twitter.com/da5nsy/status/1442881125639143424
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
clear, clc, close all | |
nTrials = 1000;%30000; | |
nOptions = 3; | |
choices = randi(nOptions,[nTrials,1]); % random (integer) from 1:nOptions, nTrials times | |
loglikelihood = 0; | |
for trial = 1:nTrials | |
randFixed = rand(4,1); % random (uniformally) from 0:1, 4 times | |
bigNumber = 20; %for example | |
for iteration = 1:bigNumber | |
x = randFixed(1) + randn; % random (normally distributed) | |
y1 = randFixed(2) + randn; | |
y2 = randFixed(3) + randn; | |
y3 = randFixed(4) + randn; | |
[~, results(iteration)] = min(abs(x-[y1,y2,y3])); | |
end | |
probs(trial,1:nOptions) = histcounts(results,0.5:3.5)/bigNumber; | |
loglikelihood = loglikelihood + log(probs(trial,choices(trial))); | |
end | |
disp(loglikelihood) | |
% rough check math | |
disp(log(1/nOptions) * nTrials) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment