Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cats
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
BDC
cats
Commits
61c6b31d
Commit
61c6b31d
authored
2 years ago
by
Andreas Gattringer
Browse files
Options
Downloads
Patches
Plain Diff
made Leslie-matrix consistent with start-of-year conditions
+ fixed a bug in juvenile survival rate calculation
parent
a8f7717d
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/cats/lambda/leslie_matrix.c
+83
-24
83 additions, 24 deletions
src/cats/lambda/leslie_matrix.c
with
83 additions
and
24 deletions
src/cats/lambda/leslie_matrix.c
+
83
−
24
View file @
61c6b31d
...
@@ -60,7 +60,7 @@ get_rate_for_matrix(enum cats_vital_rate_id rate_type,
...
@@ -60,7 +60,7 @@ get_rate_for_matrix(enum cats_vital_rate_id rate_type,
cats_dt_rates
rate
=
calculate_rate
(
info
,
N
,
param
,
l_param
->
grid
,
l_param
->
row
,
l_param
->
col
,
&
override
);
cats_dt_rates
rate
=
calculate_rate
(
info
,
N
,
param
,
l_param
->
grid
,
l_param
->
row
,
l_param
->
col
,
&
override
);
if
(
print
)
{
if
(
print
)
{
log_message
(
LOG_INFO
,
"%s: %Lf (maximum %Lf) for population %Lf/%Lf"
,
log_message
(
LOG_INFO
,
"%s: %Lf (maximum %Lf) for
adult
population
density
%Lf/%Lf"
,
info
->
name
,
rate
,
info
->
max_rate
,
N
,
K
);
info
->
name
,
rate
,
info
->
max_rate
,
N
,
K
);
}
}
...
@@ -68,10 +68,22 @@ get_rate_for_matrix(enum cats_vital_rate_id rate_type,
...
@@ -68,10 +68,22 @@ get_rate_for_matrix(enum cats_vital_rate_id rate_type,
}
}
double
*
double
*
create_leslie_matrix
(
struct
cats_configuration
*
conf
,
struct
lambda_parameters
*
l_param
,
bool
silent
,
int32_t
*
N_out
)
create_leslie_matrix
(
struct
cats_configuration
*
conf
,
struct
lambda_parameters
*
l_param
,
bool
silent
,
int32_t
*
N_out
)
{
{
#define LM_START
#ifndef LM_START
log_message
(
LOG_IMPORTANT
,
"using method LM_MID (old)"
);
#else
//log_message(LOG_IMPORTANT, "using method LM_START (new)");
#endif
assert
(
N_out
!=
NULL
);
assert
(
N_out
!=
NULL
);
const
int32_t
species_id
=
l_param
->
species_id
;
const
int32_t
species_id
=
l_param
->
species_id
;
const
int32_t
mat_max
=
get_vital_age_from_param
(
&
conf
->
param
[
species_id
],
VA_AGE_OF_MATURITY_MAX
);
const
int32_t
mat_max
=
get_vital_age_from_param
(
&
conf
->
param
[
species_id
],
VA_AGE_OF_MATURITY_MAX
);
...
@@ -108,33 +120,35 @@ create_leslie_matrix(struct cats_configuration *conf, struct lambda_parameters *
...
@@ -108,33 +120,35 @@ create_leslie_matrix(struct cats_configuration *conf, struct lambda_parameters *
cats_dt_rates
germination_to_adult_survival
=
get_rate_for_matrix
(
VR_GERMINATION_TO_ADULT_SURVIVAL
,
cats_dt_rates
germination_to_adult_survival
=
get_rate_for_matrix
(
VR_GERMINATION_TO_ADULT_SURVIVAL
,
l_param
,
l_param
,
print_rate
);
print_rate
);
cats_dt_rates
juvenile_
survival
=
get_juvenile_tr_from_germination_to_adult_survival
(
cats_dt_rates
juvenile_
transition_rate
=
get_juvenile_tr_from_germination_to_adult_survival
(
germination_to_adult_survival
,
&
conf
->
param
[
species_id
]);
germination_to_adult_survival
,
&
conf
->
param
[
species_id
]);
// printf("%Lf %Lf\n", juvenile_survival, germination_to_adult_survival);
// printf("%Lf %Lf\n", juvenile_survival, germination_to_adult_survival);
fflush
(
stdout
);
fflush
(
stdout
);
cats_dt_rates
hapaxanthy_survival
=
1
.
0
;
cats_dt_rates
hapaxanthy_survival
=
1
.
0
;
if
(
l_param
->
param
->
hapaxanthy
>
0
.
0
)
{
if
(
l_param
->
param
->
hapaxanthy
>
0
.
0
)
{
hapaxanthy_survival
=
(
1
.
0
-
l_param
->
param
->
hapaxanthy
);
hapaxanthy_survival
=
(
1
.
0
-
l_param
->
param
->
hapaxanthy
)
*
flowering_frequency
;
assert
(
hapaxanthy_survival
>=
0
);
assert
(
hapaxanthy_survival
>=
0
);
assert
(
hapaxanthy_survival
<=
1
.
0
);
assert
(
hapaxanthy_survival
<=
1
.
0
);
log_message
(
LOG_INFO
,
"hapaxanthy survival: %Lf
"
,
hapaxanthy_survival
);
log_message
(
LOG_INFO
,
"hapaxanthy survival: %Lf
, times flowering frequency %Lf"
,
(
1
.
0
-
l_param
->
param
->
hapaxanthy
)
,
hapaxanthy_survival
);
}
}
if
(
print_rate
)
{
if
(
print_rate
)
{
log_message
(
LOG_INFO
,
"juvenile transition: %Lf"
,
juvenile_
survival
);
log_message
(
LOG_INFO
,
"juvenile transition: %Lf"
,
juvenile_
transition_rate
);
log_message
(
LOG_INFO
,
"local dispersal %Lf"
,
local_dispersal
);
log_message
(
LOG_INFO
,
"local dispersal %Lf"
,
local_dispersal
);
}
}
double
m0
=
(
double
)
age_specific_maturation_rate
(
0
,
juvenile_survival
,
mat_min
,
mat_max
);
double
d
=
(
double
)
(
flowering_frequency
*
seed_yield
*
local_dispersal
);
double
m0
=
(
double
)
age_specific_maturation_rate
(
0
,
juvenile_transition_rate
,
mat_min
,
mat_max
);
double
dl
=
(
double
)
(
flowering_frequency
*
seed_yield
*
local_dispersal
);
if
(
print_rate
)
{
if
(
print_rate
)
{
for
(
int32_t
i
=
0
;
i
<
mat_max
+
1
;
i
++
)
{
for
(
int32_t
i
=
0
;
i
<
mat_max
+
1
;
i
++
)
{
log_message
(
LOG_RAW
,
"m%d = %f
\n
"
,
i
,
log_message
(
LOG_RAW
,
"m%d = %f
\n
"
,
i
,
(
double
)
age_specific_maturation_rate
(
i
,
juvenile_
survival
,
mat_min
,
mat_max
));
(
double
)
age_specific_maturation_rate
(
i
,
juvenile_
transition_rate
,
mat_min
,
mat_max
));
}
}
log_message
(
LOG_RAW
,
"d = %f
\n
"
,
d
);
log_message
(
LOG_RAW
,
"d = %f
\n
"
,
d
l
);
}
}
// special case:
// special case:
...
@@ -154,34 +168,47 @@ create_leslie_matrix(struct cats_configuration *conf, struct lambda_parameters *
...
@@ -154,34 +168,47 @@ create_leslie_matrix(struct cats_configuration *conf, struct lambda_parameters *
//return x;
//return x;
}
}
// FIRST ROW: transition to seeds
1
// FIRST ROW: transition to seeds
0
// seeds: Si -> S
1
// seeds: Si -> S
0
for
(
int32_t
s
=
0
;
s
<
seed_persistence
;
s
++
)
{
for
(
int32_t
s
=
0
;
s
<
seed_persistence
;
s
++
)
{
assert
(
s
<
N
);
assert
(
s
<
N
);
matrix
[
0
*
N
+
s
]
=
(
double
)
(
germination_rate
*
m0
*
d
*
seed_surviva
l
);
matrix
[
0
*
N
+
s
]
=
(
double
)
(
seed_survival
*
germination_rate
*
m0
*
dl
);
}
}
// juveniles: Ji -> S
1
// juveniles: Ji -> S
0
for
(
int32_t
j
=
0
;
j
<
mat_max
;
j
++
)
{
for
(
int32_t
j
=
0
;
j
<
mat_max
;
j
++
)
{
int32_t
col
=
seed_persistence
+
j
;
int32_t
col
=
seed_persistence
+
j
;
assert
(
col
<
N
);
assert
(
col
<
N
);
cats_dt_rates
m
=
age_specific_maturation_rate
(
j
+
1
,
juvenile_survival
,
mat_min
,
mat_max
);
cats_dt_rates
m
=
age_specific_maturation_rate
(
j
+
1
,
juvenile_transition_rate
,
mat_min
,
mat_max
);
matrix
[
0
*
N
+
col
]
=
(
double
)
(
m
*
d
*
seed_survival
);
#ifndef LM_START
matrix
[
0
*
N
+
col
]
=
(
double
)
(
m
*
dl
*
seed_survival
);
#else
cats_dt_rates
juvenile_survival_rate
=
age_modified_juvenile_survival_rate
(
juvenile_transition_rate
,
j
,
mat_min
,
mat_max
);
matrix
[
0
*
N
+
col
]
=
(
double
)
(
juvenile_survival_rate
*
m
*
dl
);
#endif
}
}
// adults: A -> S
1
// adults: A -> S
0
for
(
int32_t
a
=
seed_persistence
+
mat_max
;
a
<
N
;
a
++
)
{
for
(
int32_t
a
=
seed_persistence
+
mat_max
;
a
<
N
;
a
++
)
{
assert
(
a
==
N
-
1
);
assert
(
a
==
N
-
1
);
matrix
[
0
*
N
+
a
]
=
(
double
)
(
clonal_growth
*
d
*
seed_survival
);
#ifndef LM_START
matrix
[
0
*
N
+
a
]
=
(
double
)
(
clonal_growth
*
dl
*
seed_survival
);
#else
matrix
[
0
*
N
+
a
]
=
(
double
)
(
adult_survival
*
clonal_growth
*
dl
);
#endif
}
}
// SEED ROWS: S_i -> S_{i+1}
// SEED ROWS: S_i -> S_{i+1}
for
(
int32_t
s
=
1
;
s
<
seed_persistence
;
s
++
)
{
for
(
int32_t
s
=
1
;
s
<
seed_persistence
;
s
++
)
{
matrix
[
s
*
N
+
(
s
-
1
)]
=
(
double
)
((
1
.
0
-
germination_rate
)
*
seed_survival
);
matrix
[
s
*
N
+
(
s
-
1
)]
=
(
double
)
(
seed_survival
*
(
1
.
0
-
germination_rate
));
}
}
// JUVENILE ROW 1:
// JUVENILE ROW 1:
Si -> J0
for
(
int32_t
s
=
0
;
s
<
seed_persistence
;
s
++
)
{
for
(
int32_t
s
=
0
;
s
<
seed_persistence
;
s
++
)
{
int32_t
row
=
seed_persistence
;
int32_t
row
=
seed_persistence
;
if
(
row
*
N
+
s
<
N
*
N
)
{
if
(
row
*
N
+
s
<
N
*
N
)
{
...
@@ -192,17 +219,31 @@ create_leslie_matrix(struct cats_configuration *conf, struct lambda_parameters *
...
@@ -192,17 +219,31 @@ create_leslie_matrix(struct cats_configuration *conf, struct lambda_parameters *
log_message
(
LOG_RAW
,
"row = %d
\n
"
,
row
);
log_message
(
LOG_RAW
,
"row = %d
\n
"
,
row
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
matrix
[
row
*
N
+
s
]
=
(
double
)
(
germination_rate
*
(
1
.
0
-
m0
)
*
juvenile_survival
);
#ifndef LM_START
cats_dt_rates
juvenile_survival_rate
=
age_modified_juvenile_survival_rate
(
juvenile_transition_rate
,
0
,
mat_min
,
mat_max
);
matrix
[
row
*
N
+
s
]
=
(
double
)
(
germination_rate
*
(
1
.
0
-
m0
)
*
juvenile_survival_rate
);
#else
matrix
[
row
*
N
+
s
]
=
(
double
)
(
seed_survival
*
germination_rate
*
(
1
.
0
-
m0
));
#endif
}
}
// JUVENILE ROWS J
2
...: J_i -> J_{i+1}
// JUVENILE ROWS J
1+
...: J_i -> J_{i+1}
for
(
int32_t
j
=
0
;
j
<
mat_max
;
j
++
)
{
for
(
int32_t
j
=
0
;
j
<
mat_max
;
j
++
)
{
cats_dt_rates
juvenile_survival_rate
=
age_modified_juvenile_survival_rate
(
juvenile_transition_rate
,
j
,
mat_min
,
mat_max
);
int32_t
row
=
j
+
seed_persistence
+
1
;
int32_t
row
=
j
+
seed_persistence
+
1
;
int32_t
col
=
j
+
seed_persistence
;
int32_t
col
=
j
+
seed_persistence
;
assert
(
row
<
N
);
assert
(
row
<
N
);
cats_dt_rates
m
=
age_specific_maturation_rate
(
j
+
1
,
juvenile_survival
,
mat_min
,
mat_max
);
cats_dt_rates
m
=
age_specific_maturation_rate
(
j
+
1
,
juvenile_transition_rate
,
mat_min
,
mat_max
);
matrix
[
row
*
N
+
col
]
=
(
double
)
((
1
.
0
-
m
)
*
juvenile_survival
);
#ifndef LM_START
matrix
[
row
*
N
+
col
]
=
(
double
)
((
1
.
0
-
m
)
*
juvenile_survival_rate
);
#else
matrix
[
row
*
N
+
col
]
=
(
double
)
(
juvenile_survival_rate
*
(
1
.
0
-
m
));
#endif
}
}
...
@@ -210,18 +251,36 @@ create_leslie_matrix(struct cats_configuration *conf, struct lambda_parameters *
...
@@ -210,18 +251,36 @@ create_leslie_matrix(struct cats_configuration *conf, struct lambda_parameters *
int32_t
row
=
seed_persistence
+
mat_max
;
int32_t
row
=
seed_persistence
+
mat_max
;
assert
(
row
==
N
-
1
);
assert
(
row
==
N
-
1
);
for
(
int32_t
s
=
0
;
s
<
seed_persistence
;
s
++
)
{
for
(
int32_t
s
=
0
;
s
<
seed_persistence
;
s
++
)
{
#ifndef LM_START
matrix
[
row
*
N
+
s
]
=
(
double
)
(
germination_rate
*
m0
*
adult_survival
);
matrix
[
row
*
N
+
s
]
=
(
double
)
(
germination_rate
*
m0
*
adult_survival
);
#else
matrix
[
row
*
N
+
s
]
=
(
double
)
(
seed_survival
*
germination_rate
*
m0
*
hapaxanthy_survival
);
#endif
}
}
for
(
int32_t
j
=
0
;
j
<
mat_max
;
j
++
)
{
for
(
int32_t
j
=
0
;
j
<
mat_max
;
j
++
)
{
int32_t
col
=
seed_persistence
+
j
;
int32_t
col
=
seed_persistence
+
j
;
cats_dt_rates
m
=
age_specific_maturation_rate
(
j
+
1
,
juvenile_survival
,
mat_min
,
mat_max
);
cats_dt_rates
m
=
age_specific_maturation_rate
(
j
+
1
,
juvenile_transition_rate
,
mat_min
,
mat_max
);
#ifndef LM_START
assert
(
col
<
N
-
1
);
assert
(
col
<
N
-
1
);
matrix
[
row
*
N
+
col
]
=
(
double
)
(
m
*
adult_survival
);
matrix
[
row
*
N
+
col
]
=
(
double
)
(
m
*
adult_survival
);
#else
cats_dt_rates
juvenile_survival_rate
=
age_modified_juvenile_survival_rate
(
juvenile_transition_rate
,
j
,
mat_min
,
mat_max
);
assert
(
col
<
N
-
1
);
matrix
[
row
*
N
+
col
]
=
(
double
)
(
juvenile_survival_rate
*
m
*
hapaxanthy_survival
);
#endif
}
}
// LAST ENTRY
// LAST ENTRY
#ifndef LM_START
matrix
[
row
*
N
+
N
-
1
]
=
(
double
)
(
clonal_growth
*
adult_survival
*
hapaxanthy_survival
);
matrix
[
row
*
N
+
N
-
1
]
=
(
double
)
(
clonal_growth
*
adult_survival
*
hapaxanthy_survival
);
#else
matrix
[
row
*
N
+
N
-
1
]
=
(
double
)
(
adult_survival
*
clonal_growth
*
hapaxanthy_survival
);
#endif
return
matrix
;
return
matrix
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment