Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
manuscript_code
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maria Voigt
manuscript_code
Commits
dcf0e3a4
Commit
dcf0e3a4
authored
8 years ago
by
Maria Voigt
Browse files
Options
Downloads
Patches
Plain Diff
adding comments and doubts to abundance-pred
parent
02cab083
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/prediction/abundance_prediction.R
+6
-5
6 additions, 5 deletions
src/prediction/abundance_prediction.R
with
6 additions
and
5 deletions
src/prediction/abundance_prediction.R
+
6
−
5
View file @
dcf0e3a4
...
@@ -65,7 +65,7 @@ coeffs[is.na(coeffs) == T] <- 0
...
@@ -65,7 +65,7 @@ coeffs[is.na(coeffs) == T] <- 0
predictor_names_coeffs
<-
gsub
(
"coeff_"
,
""
,
names
(
coeffs
))
predictor_names_coeffs
<-
gsub
(
"coeff_"
,
""
,
names
(
coeffs
))
#UNDERSTAND HERE WHAT IS HAPPENING
#UNDERSTAND HERE WHAT IS HAPPENING
#interaction_terms_names <- predictor_names_coeffs[predictor_names_coeffs %in%
#interaction_terms_names <- predictor_names_coeffs[predictor_names_coeffs %in%
# paste0("year:", predictor_names_coeffs)]
# paste0("year:", predictor_names_coeffs)]
#interaction_terms_names <- gsub("year:", "", interaction_terms_names)
#interaction_terms_names <- gsub("year:", "", interaction_terms_names)
#quadratic_terms_names <- predictor_names_coeffs[predictor_names_coeffs %in%
#quadratic_terms_names <- predictor_names_coeffs[predictor_names_coeffs %in%
# paste0("I(", predictor_names_coeffs, "^2)")]
# paste0("I(", predictor_names_coeffs, "^2)")]
...
@@ -81,6 +81,7 @@ predictor_names <- predictor_names[!grepl("year[:punct:]*", predictor_names)]
...
@@ -81,6 +81,7 @@ predictor_names <- predictor_names[!grepl("year[:punct:]*", predictor_names)]
predictor_names
<-
c
(
"year"
,
predictor_names
)
predictor_names
<-
c
(
"year"
,
predictor_names
)
# predictors for year on grid
# predictors for year on grid
print
(
paste
(
"these are predictor names: "
,
predictor_names
))
predictors_path
<-
path.to.current
(
indir_predictors
,
paste0
(
"predictors_abundance_"
,
predictors_path
<-
path.to.current
(
indir_predictors
,
paste0
(
"predictors_abundance_"
,
year_to_predict
),
"rds"
)
year_to_predict
),
"rds"
)
print
(
paste
(
"this is predictors path"
,
predictors_path
))
print
(
paste
(
"this is predictors path"
,
predictors_path
))
...
@@ -117,10 +118,10 @@ names(predictor_estimates) <- c("intercept", predictor_names,
...
@@ -117,10 +118,10 @@ names(predictor_estimates) <- c("intercept", predictor_names,
# Alternative here to loop through id, which is added to predictor_estimates
# Alternative here to loop through id, which is added to predictor_estimates
# more correct in terms of being sure that the right thing is done,
# more correct in terms of being sure that the right thing is done,
# but takes a bit longer (52s, to 35s for 100 rows)
# but takes a bit longer (52s, to 35s for 100 rows)
## PLUS PAY ATTENTION, IF PREDICTIONS NOT SAME NROW--> VALUES GET RECYCLED
## PLUS PAY ATTENTION, IF PREDICTIONS NOT SAME NROW--> VALUES GET RECYCLED
print
(
paste
(
"1. start pred_per_cell"
,
Sys.time
()))
print
(
paste
(
"1. start pred_per_cell"
,
Sys.time
()))
pred_per_cell
<-
foreach
(
i
=
1
:
nrow
(
predictor_estimates
),
.combine
=
c
)
%dopar%
{
pred_per_cell
<-
foreach
(
i
=
1
:
nrow
(
predictor_estimates
),
.combine
=
c
)
%dopar%
{
# pred_per_cell <- foreach(i = 1:100, .combine = c) %dopar% {
# pred_per_cell <- foreach(i = 1:100, .combine = c) %dopar% {
t_predictor_estimates
<-
t
(
predictor_estimates
[
i
,
])
t_predictor_estimates
<-
t
(
predictor_estimates
[
i
,
])
pred_estimates_wcoeffs
<-
data.frame
(
mapply
(
`*`
,
coeffs
,
t_predictor_estimates
,
SIMPLIFY
=
F
))
pred_estimates_wcoeffs
<-
data.frame
(
mapply
(
`*`
,
coeffs
,
t_predictor_estimates
,
SIMPLIFY
=
F
))
pred_estimates_sum
<-
apply
(
pred_estimates_wcoeffs
,
1
,
sum
)
pred_estimates_sum
<-
apply
(
pred_estimates_wcoeffs
,
1
,
sum
)
...
@@ -131,7 +132,7 @@ t_predictor_estimates <- t( predictor_estimates[i, ])
...
@@ -131,7 +132,7 @@ t_predictor_estimates <- t( predictor_estimates[i, ])
print
(
paste
(
Sys.time
(),
"2. finished dopar loop"
))
print
(
paste
(
Sys.time
(),
"2. finished dopar loop"
))
# is this correct -> ????
pred_per_cell
<-
as.data.frame
(
cbind
(
predictors
$
id
,
pred_per_cell
))
pred_per_cell
<-
as.data.frame
(
cbind
(
predictors
$
id
,
pred_per_cell
))
names
(
pred_per_cell
)
<-
c
(
"id"
,
"abundance_pred"
)
names
(
pred_per_cell
)
<-
c
(
"id"
,
"abundance_pred"
)
...
@@ -143,7 +144,7 @@ print(paste(Sys.time(), "sum predicted for ", year_to_predict,
...
@@ -143,7 +144,7 @@ print(paste(Sys.time(), "sum predicted for ", year_to_predict,
sum
(
pred_per_cell
$
abundance_pred
)))
sum
(
pred_per_cell
$
abundance_pred
)))
print
(
paste
(
Sys.time
(),
"range predicted for "
,
year_to_predict
,
print
(
paste
(
Sys.time
(),
"range predicted for "
,
year_to_predict
,
range
(
pred_per_cell
$
abundance_pred
)))
range
(
pred_per_cell
$
abundance_pred
)))
# has to be between 0 and 1
save.image
(
file.path
(
outdir
,
paste0
(
"abundance_pred_image_"
,
year_to_predict
,
"_"
,
save.image
(
file.path
(
outdir
,
paste0
(
"abundance_pred_image_"
,
year_to_predict
,
"_"
,
Sys.Date
(),
".RData"
)))
Sys.Date
(),
".RData"
)))
...
...
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