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 2 -- Known Reward Thresholds
  • /
  • RC_Threshold_Motifs.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:dbc58be789e64a49de25a8a6342ac72c3a3d9a4f
directory badge
swh:1:dir:c289392a1a31e5d3a4f39269e7a145198df6d2ce

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 ...
RC_Threshold_Motifs.m
% RC_Threshold_Motifs.m
% Script used to generate data for Fig. 1C in Barendregt et al., 2022.

clear

% Define simulation parameters:
T = 5; dt = 0.005;  t_i = 1;
dg = 0.001;
m = 5; c = @(t) 1;

% Define pre- and post-change rewards:
R_1 = linspace(1,10); R_2 = linspace(1,10);

% Pre-allocate threshold classification matrix and threshold storage:
type = NaN(length(R_1),length(R_2));
thresh = NaN(length(R_1),length(R_2),T/5/dt+1);

for i = 1:length(R_1)
    type_i = NaN(1,length(R_2));
    thresh_i = NaN(length(R_2),201);
    for j = 1:length(R_2)
        
        % Construct reward timeseries:
        R = NaN(1,T/dt+1); R(1:100) = R_1(i); R(101:end) = R_2(j);

        % Calculate normative thresholds using Bellman's equation:
        theta = RC_Bellmans(T,dt,t_i,dg,m,c,R); theta = theta(1:(T/5/dt+1));
        thresh_i(j,:) = theta;

        % Classify threshold motif:
        if theta(1)==0
            type_i(j) = 1; % Motif vi (trival thresholds)
        elseif sum(diff(theta)==0)==(length(theta)-1)
            type_i(j) = 5; % Motif iii
        elseif (sum(diff(theta)<=0)==(length(theta)-1))
            type_i(j) = 2; % Motif v
        elseif (sum(theta(1:100)==Inf)==100 && sum(diff(theta(101:end))==0)==(length(theta(101:end))-1))
            type_i(j) = 3; % Motif i
        else
            type_i(j) = 4; % Motif ii and iv
        end
    end
    type(i,:) = type_i;
    thresh(i,:,:) = thresh_i;
end

save('RC_Threshold_Motifs.mat');

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