Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
ECheynet authored May 23, 2020
1 parent 212baab commit 5cec0f3
Show file tree
Hide file tree
Showing 13 changed files with 272 additions and 31 deletions.
Binary file modified ChineseProvinces.mlx
Binary file not shown.
Binary file modified Documentation.mlx
Binary file not shown.
Binary file modified Example_Country.mlx
Binary file not shown.
Binary file modified Example_US_cities.mlx
Binary file not shown.
Binary file modified Example_province_region.mlx
Binary file not shown.
Binary file modified FrenchRegions.mlx
Binary file not shown.
Binary file modified ItalianRegions.mlx
Binary file not shown.
Binary file modified UncertaintiesIssues.mlx
Binary file not shown.
254 changes: 254 additions & 0 deletions dummy.csv

Large diffs are not rendered by default.

43 changes: 15 additions & 28 deletions fit_SEIQRDP.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function [alpha1,beta1,gamma1,delta1,Lambda1,Kappa1,lambdaFun,kappaFun,varargout] = fit_SEIQRDP(Q,R,D,Npop,E0,I0,time,guess,varargin)
function [alpha1,beta1,gamma1,delta1,Lambda1,Kappa1,lambdaFun,kappaFun] = fit_SEIQRDP(Q,R,D,Npop,E0,I0,time,guess,varargin)
% [alpha1,beta1,gamma1,delta1,Lambda1,Kappa1,lambdaFun,varargout] =
% fit_SEIQRDP(Q,R,D,Npop,E0,I0,time,guess,varargin) estimates the
% parameters used in the SEIQRDP function, used to model the time-evolution
Expand Down Expand Up @@ -30,12 +30,8 @@
% kappa: scalar [1x1]: fitted mortality rate
% lambdaFun: anonymous function giving the time-dependant recovery rate
% kappaFun: anonymous function giving the time-dependant death rate
% optional:
% - residual
% - Jacobian
% - The function @SEIQRDP_for_fitting
%
% Author: E. Cheynet - UiB - last modified 30-04-2020
% Author: E. Cheynet - UiB - last modified 23-05-2020
%
% see also SEIQRDP.m

Expand Down Expand Up @@ -100,21 +96,28 @@
%% Main fitting

modelFun1 = @SEIQRDP_for_fitting; % transform a nested function into anonymous function
lambdaMax = [1 5 100]; % lambdaMax(3) has the dimension of a time
lambdaMin = [0 0 0]; % lambdaMax(3) has the dimension of a time

if isempty(R)
% Significantly constraint the death rate
kappaMax = guess(8:10)*1.05; % Constrain the guess if no R available
kappaMin = guess(8:10)*0.95; % Constrain the guess if no R available
lambdaMax = [1 1 100]; % bound the guess around the initial fit
lambdaMin = [0 0 0]; % bound the guess around the initial fit
else
kappaMax = guess(8:10)*3; % bound the guess around the initial fit
kappaMin = guess(8:10)/3; % bound the guess around the initial fit
lambdaMax = guess(5:7)*3; % bound the guess around the initial fit
lambdaMin = guess(5:7)/3; % bound the guess around the initial fit

if lambdaMax(3)<1e-2
lambdaMax(3) = 100;
lambdaMin(3) = 0;
end
end
ub = [1, 5, 1, 1, lambdaMax, kappaMax]; % upper bound of the parameters
lb = [0, 0, 0, 0, lambdaMin, kappaMin]; % lower bound of the parameters
% call Lsqcurvefit
[Coeff,~,residual,~,~,~,jacobian] = lsqcurvefit(@(para,t) modelFun1(para,t),...
[Coeff] = lsqcurvefit(@(para,t) modelFun1(para,t),...
guess,tTarget(:)',input,lb,ub,options);


Expand All @@ -126,22 +129,6 @@
Lambda1 = abs(Coeff(5:7));
Kappa1 = abs(Coeff(8:10));

%% optional outputs
if nargout ==8
varargout{1} = residual;
elseif nargout==9
varargout{1} = residual;
varargout{2} = jacobian;
elseif nargout==10
varargout{1} = residual;
varargout{2} = jacobian;
varargout{3} = modelFun1;
elseif nargout>9
error('Too many outputs specified')
end



%% nested functions

function [output] = SEIQRDP_for_fitting(para,t0)
Expand Down Expand Up @@ -277,7 +264,7 @@
% myFun1 = @(a,t) a(1).*exp(-a(2)*(t+(a(3))));

myFun1 = @(a,t) a(1)./(exp(a(2)*(t-a(3))) + exp(-a(2)*(t-a(3))));
myFun2 = @(a,t) a(1).*exp(-a(2)*(t-a(3)).^2);
myFun2 = @(a,t) a(1).*exp(-(a(2)*(t-a(3))).^2);
myFun3 = @(a,t) a(1) + exp(-a(2)*(t+a(3)));

rate = (diff(D)./median(diff(tTarget(:))))./Q(2:end);
Expand Down Expand Up @@ -361,9 +348,9 @@
rate(abs(rate)>1|abs(rate)==0)=nan;

[coeff1,r1] = lsqcurvefit(@(para,t) myFun1(para,t),...
[0.01,0.01,1],x(~isnan(rate)),rate(~isnan(rate)),[0 0 0],[1 1 100],opt);
guess(5:7),x(~isnan(rate)),rate(~isnan(rate)),[0 0 0],[1 1 100],opt);
[coeff2,r2] = lsqcurvefit(@(para,t) myFun2(para,t),...
[0.01,0.01,min(x(~isnan(rate)))],x(~isnan(rate)),rate(~isnan(rate)),[0 0 0],[1 1 100],opt);
guess(5:7),x(~isnan(rate)),rate(~isnan(rate)),[0 0 0],[1 1 100],opt);


% figure;plot(x,rate,x,myFun1(coeff1,x),'r',x,myFun2(coeff2,x),'g--')
Expand Down
6 changes: 3 additions & 3 deletions getMultipleWaves.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@

%% Simulate first wave
% Initial conditions
E0 = Confirmed(indT1(1)); % Initial number of exposed cases. Unknown but unlikely to be zero.
I0 = Confirmed(indT1(1)); % Initial number of infectious cases. Unknown but unlikely to be zero.
Q0 = Active(indT1(1));
Q0 = Active(indT1(1));
E0 = 0.5*Q0; % Initial number of exposed cases. Unknown but unlikely to be zero.
I0 = 5*E0; % Initial number of infectious cases. Unknown but unlikely to be zero.
R0 = Recovered(indT1(1));
D0 = Deaths(indT1(1));

Expand Down
Binary file modified simulateMultipleWaves.mlx
Binary file not shown.
Binary file modified uncertainties.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5cec0f3

Please sign in to comment.