-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.m
32 lines (25 loc) · 1.11 KB
/
bootstrap.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
function [fi,betai,res,ei] = bootstrap(t,y,f,te,bmin,beta,bmax,data,labels,model,usrfn,dtype,M,nit,tol,factor)
%Choose between bootstrapping or naive
if M>0
%Bootstrap (fit M new curves with mean from model, f, and given/estimated dispersion, D)
%Previous fit for beta is, of course, used as initial value
%Index of dispersion
D = get_iod(y,f,factor);
%Resample and refit M times
[fi,betai] = fit_boots(t,f,bmin,beta,bmax,data,labels,model,usrfn,dtype,M,D,nit,tol);
%Residuals from the mean of the M samples
res=(y-squeeze(mean(fi,2))).^2;
%Extrapolate all the M fittings of the model
ei = evaluate_boots(te,betai,model,usrfn,data,"CUMUL");
else
%Naive (or pretend your fit doesn't just depend from the given data)
%Residuals
res=(y-f).^2;
%Just extrapolate the fitted model
e = evaluate_model(te,beta,model,usrfn,data,"CUMUL");
%Reshape as if M=1
fi = reshape(f,size(f,1),1,size(f,2));
ei = reshape(e,size(e,1),1,size(e,2));
betai = reshape(beta,size(beta,1),1,size(beta,2));
end
end