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

Revision 923e104aa634230547ba464c6bc8fee07f662ffa authored by Rene Niehus on 03 March 2020, 02:26:02 UTC, committed by GitHub on 03 March 2020, 02:26:02 UTC
Update invasion_analysis.m
1 parent 0cee31f
  • Files
  • Changes
  • c60dd23
  • /
  • invasion_analysis.m
Raw File Download
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.

  • revision
  • directory
  • content
revision badge
swh:1:rev:923e104aa634230547ba464c6bc8fee07f662ffa
directory badge Iframe embedding
swh:1:dir:c60dd23f7004bca655d5420d5ac0c7fc4b795c93
content badge Iframe embedding
swh:1:cnt:b2ea12d75ce4940d14a5d5ac49235bd4f5b02a05
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.

  • revision
  • directory
  • content
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 ...
invasion_analysis.m
% Invasion analysis
clc; clear all
% close all
tic;
%%%%%%%% get filename %%%%%%%%
p = mfilename('fullpath');
[pathstr, name, ext] = fileparts(p); % CHANGE IF YOU RUN IT IN ZOOLOGY
plotting_0 = 0; % no plotting for Zoology server
rpath = [pathstr '/Results/'];
fpath = [pathstr '/graphs/'];

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Settings
% Run description
% set initial condition ODE
Endtime = 48; % given in hours
TIME = [0,Endtime];
dt = 0.1;       % time step
% -----------
param.Ca0 = 0.1; param.Cb0 = param.Ca0; Ta0 = 0; Tb0 = 0;  % define initial conditions
param.N0 = 1;
param.KN = 5; % half-saturation constant for nutrient-dependent growth
param.mu = 10; % max growth rate
param.kay = 30; %0.7; % how many cells are killed per unit toxin
param.D = 0.20; % loss of toxin
% -------------
InitC = [param.Ca0;param.Cb0;Ta0;Tb0;param.N0];


%% Algorithm to get as fast as possible to exact f*
% starts at highest and lowest f
for fresini = [0 1]
    singular = 0; % boolean saying if singular strategy is found
    newres = 1; % is there a new resident strategy
    fres = fresini; % resident strategy
    forward = 1; % indicates is new mutant will be higher or lower than resident
    step = 0.1; % initial step for the mutant. Initially coarse
    nbflip = 0; % record the number of consecutive flips in direction
    minstep = 0.00001; % the precision we want for the strategy value
    %
    while singular ~= 1 % do this while you haven't found the singular strategy
        if newres == 1 % new resident strategy; calculate new residents avarage fitness
            %%%%%%%% local one-on-one competition (ODE solving)%%%%%%%%%%%%
            [t,X] = myODE_solver01([fres 0 0 0 0 0 0 0 0],[fres 0 0 0 0 0 0 0 0],param,InitC,[0,Endtime],dt); % solve ODE b vs b
            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
            wresav = X(1,end); % residents w as final biomass
        end
        fmut = fres + forward*step; % pick an invader that differs from resident according to direction
        if fmut < 0 % if mutant is smaller than 0, set to 0
            fmut = 0;
        end
        if fmut > 1
            fmut = 1; % if mutant is bigger than 1, set to 1
        end
        %%%%%%%% local one-on-one competition (ODE solving)%%%%%%%%%%%%
        [t,X] = myODE_solver01([fmut 0 0 0 0 0 0 0 0],[fres 0 0 0 0 0 0 0 0],param,InitC,[0,Endtime],dt); % solve ODE b vs b
        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        wmut = X(1,end); % record mutant biomass at end of competition
        previousforward = forward; % saver: update previous direction
        previousfres = fres; % saver: update previous resident
        if wmut <= wresav % resident stays the resident
            forward = (-1) * forward; % change the dircetion for mutant
            newres = 0;
        end
        if wmut > wresav % the mutant invades and replaces the resident
            fres = fmut; % the new resident will take the mutant value
            disp(['Resident:' num2str(fres)])
            if fres == 0 || fres == 1
                singular = 1; % you have found a singular strategy
            end
            newres = 1; % we have a new resident
        end
        %
        if forward ~= previousforward % compare with previous direction
            nbflip = nbflip + 1;
        end
        if forward == previousforward % compare with previous direction
            nbflip = 0;
        end
        if previousfres == fres && nbflip > 1 % singular strategy localised
            if step <= minstep % precision high enough
                singular = 1; % we have found an optimal strategy
            end
            if step > minstep % will redo the whole procedure with tinier step
                step = step/10; % increase precision 10 times
                nbflip = 0; % reset the number of consecutive flips
            end
        end
    end % while you search for singular strategy
    fres % record the final fres (ESS)
end
%%
disp(['Done after ' secs2hms(toc)]);
The diff you're trying to view is too large. Only the first 1000 changed files have been loaded.
Showing with 0 additions and 0 deletions (0 / 0 diffs computed)
swh spinner

Computing file changes ...

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

back to top