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

  • bbb89f8
  • /
  • Figure 6 -- Tokens Task Data Analysis
  • /
  • MCMC_NB.m
Raw File Download

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
content badge
swh:1:cnt:9bae555cbb433d679767268442971f0849e61f42
directory badge
swh:1:dir:d615f04e1fe23058870cce8c51d6ba6cdac3dbd8

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
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
MCMC_NB.m
% MCMC_NB.m
% Evolves parameter chains for NB model using MCMC from 
% Barendregt et al., 2022.

function [theta,L] = MCMC_NB(theta_p,L_p,Nt,t_d,R_i,tol,Sub_T,stim,S,prior)

% Draw proposed new state from Gaussian proposal distribution:
theta = mvnrnd(theta_p,S);
if (theta(1) > prior(1)) && (theta(2) > prior(2)) &&...
        (theta(3) > prior(3)) && (theta(4) > prior(4)) % Reject new state if parameters are negative.

    % Construct model from drawn parameters:
    thresh_g = tok_Bellmans_g(Nt,t_d,theta(1),R_i,@(t) theta(2),tol);

    % Pre-allocate storage of average synthetic data generated from 
    % sampled model:
    Synth_Data = zeros(1,Nt+1);
    for n = 1:50

        % Pre-allocate storage of synthetic data generated from sampled 
        % model: 
        T_Data = NaN(1,length(Sub_T));

        % Generage synthetic response data using sampled model and subject
        % stimulus:
        for l = 1:length(Sub_T)
            [T,~] = tok_sim_norm(Nt,thresh_g,theta(3),stim(l,:));
            T_Data(l) = round(theta(4)*randn+T);
            while (T_Data(l) > Nt) || (T_Data(l) < 0)
                T_Data(l) = round(theta(4)*randn+T);
            end
        end

        % Average synthetic data over many (50, found experimentally by 
        % tuning) realizations:
        Synth_Data = Synth_Data+histcounts(T_Data,-0.5:1:(Nt+0.5),'normalization','probability');
    end

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

    % Compute likelihood of proposed sample:
    L = sum(log(Synth_Data(Sub_T+1)));

    % Compute Hastings ratio and determine if proposed sample is accepted:
    h = exp(L-L_p); U = rand;
    if U > h
        theta = theta_p; L = L_p;
    end
else
    theta = theta_p; L = L_p;
end
end

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— Content policy— Contact— JavaScript license information— Web API