Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Minor changes#217

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
stineb wants to merge5 commits intogeco-bern:master
base:master
Choose a base branch
Loading
fromstineb:master
Open
Show file tree
Hide file tree
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
added verbose option for calibration
  • Loading branch information
@stineb
stineb committedAug 8, 2024
commit31e69d3ca271c2980b4444ffb5f39cfe73eab4bb
18 changes: 17 additions & 1 deletionR/cost_likelihood_biomee.R
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,6 +16,9 @@
#' @param targets A character vector indicating the target variables for which the
#' optimization will be done. This should be a subset of \code{c("GPP", "LAI",
#' "Density", "Biomass")}.
#' @param verbose A logical specifying whether to print parameter and log-likelihood
#' values during each iteration of the calibration as message. Defaults to
#' \code{FALSE}
#'
#' @return The log-likelihood of the simulated
#' targets by the biomee model versus the observed targets.
Expand DownExpand Up@@ -46,7 +49,8 @@ cost_likelihood_biomee <- function(
par,
obs,
drivers,
targets
targets,
verbose = FALSE
){

# predefine variables for CRAN check compliance
Expand DownExpand Up@@ -108,6 +112,18 @@ cost_likelihood_biomee <- function(
if(is.nan(ll) || is.na(ll) | ll == 0){
ll <- -Inf
}

if (verbose){
message(
paste("Par = ", paste(drivers$params_species, collapse = ", "))
)
message(
paste("Log-likelihood = ", ll)
)
message(
paste("--------------------------")
)
}

return(ll)
}
18 changes: 17 additions & 1 deletionR/cost_likelihood_pmodel.R
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -28,6 +28,9 @@
#' \code{FALSE}.
#' @param ncores An integer specifying the number of cores used for parallel
#' computing. Defaults to 2.
#' @param verbose A logical specifying whether to print parameter and log-likelihood
#' values during each iteration of the calibration as message. Defaults to
#' \code{FALSE}
#'
#' @return The log-likelihood of the observed target values, assuming that they
#' are independent, normally distributed and centered on the predictions
Expand DownExpand Up@@ -78,7 +81,8 @@ cost_likelihood_pmodel <- function(
targets,
par_fixed = NULL, # non-calibrated model parameters
parallel = FALSE,
ncores = 2
ncores = 2,
verbose = FALSE
){
# predefine variables for CRAN check compliance
sitename <- data <- gpp_mod <- NULL
Expand DownExpand Up@@ -215,6 +219,18 @@ cost_likelihood_pmodel <- function(

# trap boundary conditions
if(is.nan(ll) | is.na(ll) | ll == 0){ll <- -Inf}

if (verbose){
message(
paste("Par = ", paste(params_modl, collapse = ", "))
)
message(
paste("Log-likelihood = ", ll)
)
message(
paste("--------------------------")
)
}

return(ll)
}
Expand Down
18 changes: 17 additions & 1 deletionR/cost_rmse_biomee.R
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,6 +12,9 @@
#' @param obs A nested data frame of observations, following the structure of \code{biomee_validation},
#' for example.
#' @param drivers A nested data frame of driver data, for example \code{biomee_gs_leuning_drivers}.
#' @param verbose A logical specifying whether to print parameter and cost (RMSE)
#' values during each iteration of the calibration as message. Defaults to
#' \code{FALSE}
#'
#' @return The root mean squared error (RMSE) between the observed and simulated
#' values of \code{'GPP','LAI','Density'} and \code{'Biomass'} (all variables
Expand All@@ -38,7 +41,8 @@
cost_rmse_biomee <- function(
par,
obs,
drivers
drivers,
verbose = FALSE
){

# predefine variables for CRAN check compliance
Expand DownExpand Up@@ -85,5 +89,17 @@ cost_rmse_biomee <- function(
## Calculate cost (RMSE) across the N targets
cost <- mean(dff$error_rel^2, na.rm = TRUE)

if (verbose){
message(
paste("Par = ", paste(drivers$params_species, collapse = ", "))
)
message(
paste("RMSE = ", cost)
)
message(
paste("--------------------------")
)
}

return(cost)
}
18 changes: 17 additions & 1 deletionR/cost_rmse_pmodel.R
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -27,6 +27,9 @@
#' \code{FALSE}.
#' @param ncores An integer specifying the number of cores used for parallel
#' computing. Defaults to 2.
#' @param verbose A logical specifying whether to print parameter and cost (RMSE)
#' values during each iteration of the calibration as message. Defaults to
#' \code{FALSE}
#'
#' @return The root mean squared error (RMSE) between observed values and P-model
#' predictions. The RMSE is computed for each target separately and then aggregated
Expand DownExpand Up@@ -75,7 +78,8 @@ cost_rmse_pmodel <- function(
target_weights = NULL, # if using several targets, how are the individual
# RMSE weighted? named vector
parallel = FALSE,
ncores = 2
ncores = 2,
verbose = FALSE
){

# predefine variables for CRAN check compliance
Expand DownExpand Up@@ -204,6 +208,18 @@ cost_rmse_pmodel <- function(
}else{
cost <- mean(rmse, na.rm = TRUE)
}

if (verbose){
message(
paste("Par = ", paste(params_modl, collapse = ", "))
)
message(
paste("RMSE = ", cost)
)
message(
paste("--------------------------")
)
}

return(cost)
}
6 changes: 5 additions & 1 deletionman/cost_likelihood_biomee.Rd
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

7 changes: 6 additions & 1 deletionman/cost_likelihood_pmodel.Rd
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

6 changes: 5 additions & 1 deletionman/cost_rmse_biomee.Rd
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

7 changes: 6 additions & 1 deletionman/cost_rmse_pmodel.Rd
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

3 changes: 2 additions & 1 deletionvignettes/new_cost_function.Rmd
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -61,7 +61,8 @@ pars_calib_rmse <- calib_sofun(
tau_acclim = 30.0,
kc_jmax = 0.41
),
targets = "gpp" # define target variable GPP
targets = "gpp", # define target variable GPP
verbose = FALSE # set to TRUE to print parameter and cost values during each iteration of the calibration
)
```

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp