-
Notifications
You must be signed in to change notification settings - Fork 0
/
cluster_get_scale_dependency.m
114 lines (94 loc) · 3.93 KB
/
cluster_get_scale_dependency.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
%% Script for cluster: get effect of biases on biodiversity trends
% Returns estimates of biodiversity change in randomly-selected, abundance-
% biased, and community-biased sites for three change regimes
% no change, richness increase, and richness decrease, across gradients in
% either
function cluster_get_scale_dependency(outputdir, JOB_NAME, JOB_ID, change_rate, nsamples, variable, nvar, start_coordinates)
% Parse input arguments from strings to numbers
nsamples = str2num(nsamples);
change_rate = str2num(change_rate); % relative change rate
nvar = str2num(nvar); % number of grain sizes
% Print Toolboxes
ver()
% Get current date
date_current = datestr(now, 'dd/mm/yy-HH:MM');
%% Default parameterization
% Landscape (c = length of quadratic grid, g = length of quadratic grain)
c = 100;
g = 5;
% Species abundance distribution parameters
Stot = 100;
mu = 4;
var = 1.5;
% Simulation parameters
tend = 20;
timelag = 0;
doAR = 0;
%% Generate results
% define variation vector for the chosen variable
switch variable
case 'g' % vary grain size
% vary g such that relative g (to c) will be equidistant
% % v_vec = round(linspace(1, 50, nvar));
gsquare_vec = linspace(0.1, 1, nvar);
v_vec = unique(round(sqrt(gsquare_vec*c*c/100)));
case 'gfull' % vary grain size (wider range of g)
gsquare_vec = [0.1 0.25 0.5 1 2 5 10 20 50];
v_vec = round(sqrt(gsquare_vec*c*c/100));
variable = 'g';
case 'c' % vary landscape size
csquare_vec = linspace(50*50, 250*250, nvar);
v_vec = g*round(sqrt(csquare_vec)/g); % round to next multiple of g
case 'cg_factor' % vary factor between landscape and grain size
v_vec = linspace(0.5, 2.5, nvar);
case 'Stot' % vary total number of species
v_vec = round(linspace(50, 150, nvar));
case 'mu' % vary mean of SAD
v_vec = linspace(3, 5, nvar);
case 'var' % vary variance of SAD
v_vec = linspace(1, 2, nvar);
case 'tend' % vary sampling duration
v_vec = round(linspace(5, 50, nvar));
case 'timelag' % vary time lag between sampling events
v_vec = round(linspace(0, 10, nvar));
case 'pct_trunc' % vary percentage of time series truncated
v_vec = 0:5:50;
case 'change_rate' % vary rate of biodiversity change
v_vec = linspace(0, 0.0025*10, nvar);
end
% No change
if ~strcmp(variable, 'change_rate')
change = 'none';
[var_none, grain2mean_none] = get_parameter_variation(Stot, c, g, tend, nsamples,...
change, 0, v_vec, variable, doAR, 'mu', mu, 'var', var, 'timelag', timelag, start_coordinates);
fprintf('\nfinished variation of "no change".')
end
% S increase
change = 'S';
[var_Sinc, grain2mean_Sinc] = get_parameter_variation(Stot, c, g, tend, nsamples,...
change, change_rate, v_vec, variable, doAR, 'mu', mu, 'var', var, 'timelag', timelag, start_coordinates);
fprintf('\nfinished variation of "S increase".')
% S decrease
change = 'S';
[var_Sdec, grain2mean_Sdec] = get_parameter_variation(Stot, c, g, tend, nsamples,...
change, -change_rate, v_vec, variable, doAR, 'mu', mu, 'var', var, 'timelag', timelag, start_coordinates);
fprintf('\nfinished variation of "S decrease".')
fprintf('\n\n Finished successfully.\n\n')
%% Generate logfile and save results to workspace
% Save to workspace
workspacefilename = sprintf('%s/workspace_%s_%s_%s', outputdir, JOB_NAME, JOB_ID, variable);
save(workspacefilename)
% Generate logfile
logfilename = sprintf('%s/%s_%s_%s.out', outputdir, JOB_NAME, JOB_ID, variable);
fprintf(logfilename)
logfile = fopen(logfilename, 'w');
fprintf(logfile, 'doAR: %d\n', doAR);
fprintf(logfile, 'Stot: %d\n', Stot);
fprintf(logfile, 'c: %d\n', c);
fprintf(logfile, 'g: %d\n', g);
fprintf(logfile, 'timelag: %d\n', timelag);
fprintf(logfile, 'tend: %d\n', tend);
fprintf(logfile, 'change_rate: %1.4f\n', change_rate);
fprintf(logfile, 'nsamples: %d\n', nsamples);
fclose(logfile);
end