Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

https://github.com/nwbarendregt/AdaptNormThresh
12 July 2025, 11:20:19 UTC
  • Code
  • Branches (1)
  • Releases (0)
  • Visits
    • Branches
    • Releases
    • HEAD
    • refs/heads/main
    • 2878a3d9f5a3b9b89a0084a897bef3414e9de4a2
    No releases to show
  • bbb89f8
  • /
  • Figure 6 -- Tokens Task Data Analysis
  • /
  • Model_Fit_UGM.m
Raw File Download
Take a new snapshot of a software origin

If the archived software origin currently browsed is not synchronized with its upstream version (for instance when new commits have been issued), you can explicitly request Software Heritage to take a new snapshot of it.

Use the form below to proceed. Once a request has been submitted and accepted, it will be processed as soon as possible. You can then check its processing state by visiting this dedicated page.
swh spinner

Processing "take a new snapshot" request ...

Permalinks

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
  • revision
  • snapshot
origin badgecontent badge Iframe embedding
swh:1:cnt:cdc7847c7ff438a7b13ab69ca88755f8196937e3
origin badgedirectory badge Iframe embedding
swh:1:dir:d615f04e1fe23058870cce8c51d6ba6cdac3dbd8
origin badgerevision badge
swh:1:rev:2878a3d9f5a3b9b89a0084a897bef3414e9de4a2
origin badgesnapshot badge
swh:1:snp:a568cc5cff39965992895669038ed8c43a59eedd
Citations

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
  • revision
  • snapshot
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Tip revision: 2878a3d9f5a3b9b89a0084a897bef3414e9de4a2 authored by nwbarendregt on 03 May 2022, 15:08:29 UTC
Add files via upload
Tip revision: 2878a3d
Model_Fit_UGM.m
% Model_Fit_UGM.m
% Takes chain data from MCMC routine (Posterior_Sample_UGM.m), generates
% the model posterior, and finds the maximum-likelihood model fit from
% Barendregt et al., 2022.

clear

% Load MCMC and subject data:
load('model_fit_UGM.mat'); subs = 20; speeds = 2;
load('trials.mat')

% Define task parameters to simulate model:
Nt = 15;

% Define binning for empirical model posterior:
nbin = [32 32 32 32 32];

for speed_ind = 1:speeds
    for sub_ind = 1:subs

        % Pull task data from MCMC data:
        speed = model_fit_UGM(sub_ind,speed_ind).speed; t_d = speed/1000;
        post_samp = model_fit_UGM(sub_ind,speed_ind).samples;

        % Load subject data:
        Sub_ID = model_fit_UGM(sub_ind,speed_ind).idSubject;
        Sub_T = trials.nDecisionToken((trials.nSpeedFast == speed) & (trials.idSubject == Sub_ID));
        Sub_Data = histcounts(Sub_T,-0.5:1:(Nt+0.5),'normalization','probability');

        % Load and format stimulus data:
        Sub_stim = trials.sTokenDirs((trials.nSpeedFast == speed) & (trials.idSubject == Sub_ID));
        stim = NaN(length(Sub_stim),Nt);
        for i = 1:length(Sub_stim)
            stim(i,:) = str2num(strtrim(regexprep(Sub_stim{i},'.{1}','$0 ')));
            stim(i,:) = 2*(stim(i,:)-1)-1;
        end

        % Construct empirical model posterior as multi-dimensional
        % histogram:
        edges = {linspace(0.9*min(post_samp(:,1)),1.1*max(post_samp(:,1)),nbin(1)+1),...
            linspace(0.9*min(post_samp(:,2)),1.1*max(post_samp(:,2)),nbin(2)+1),...
            linspace(0.9*min(post_samp(:,3)),1.1*max(post_samp(:,3)),nbin(3)+1),...
            linspace(0.9*min(post_samp(:,4)),1.1*max(post_samp(:,4)),nbin(4)+1),...
            linspace(0.9*min(post_samp(:,5)),1.1*max(post_samp(:,5)),nbin(5)+1)};
        [post,~,mid,~] = histcn(post_samp,edges{1},edges{2},edges{3},edges{4},edges{5});

        % Find maximum-likelihood parameters:
        [~,I] = max(post,[],'all','linear');
        [th_I,a_I,sigma_I,tau_I,mn_I] = ind2sub(size(post),I);
        MLE = [mid{1}(th_I) mid{2}(a_I) mid{3}(sigma_I) mid{4}(tau_I) mid{5}(mn_I)];
        model_fit_UGM(sub_ind,speed_ind).MLE = MLE;

        % Pre-allocate storage of empirical RT distribution generated from
        % maximum-likelihood parameters:
        Fit_Data = zeros(1,Nt+1);
        for i = 1:50
            Fit_Data_T = NaN(1,length(Sub_T));

            % Generage synthetic response data using sampled model and subject
            % stimulus:
            for j = 1:length(Sub_T)
                T = tok_sim_UGM(Nt,MLE(1),MLE(2),MLE(3),MLE(4),stim(j,:));
                Fit_Data_T(j) = round(MLE(5)*randn+T);
                while (Fit_Data_T(j) > Nt) || (Fit_Data_T(j) < 0)
                    Fit_Data_T(j) = round(MLE(5)*randn+T);
                end
            end

            % Average RT distribution over many (50, found experimentally
            % by tuning) realizations:
            Fit_Data = Fit_Data+histcounts(Fit_Data_T,-0.5:1:(Nt+0.5));
        end

        % Add small non-zero entries to compute likelihood of sampled model:
        Fit_Data(Fit_Data == 0) = eps; Fit_Data = Fit_Data/sum(Fit_Data,'all');

        % Store RT distribution:
        model_fit_UGM(sub_ind,speed_ind).Fit = Fit_Data;

        % Compute AICc:
        L = sum(log(Fit_Data(Sub_T+1)));
        model_fit_UGM(sub_ind,speed_ind).AICc = 2*length(nbin)-2*L+...
            (2*length(nbin)^2+2*length(nbin))/(length(Sub_T)-length(nbin)-1);
    end
end
% save('model_fit_UGM.mat','model_fit_UGM')

back to top

Software Heritage — Copyright (C) 2015–2025, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Contact— JavaScript license information— Web API