-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tuneParams()
can now keep the yield matched to observations.
- Loading branch information
1 parent
3eb2b59
commit a7b87e6
Showing
6 changed files
with
66 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
Package: mizerExperimental | ||
Type: Package | ||
Title: Extends the mizer package with experimental features | ||
Version: 2.4.0.9004 | ||
Version: 2.4.0.9005 | ||
Author: Various contributors | ||
Maintainer: Gustav Delius <[email protected]> | ||
Description: This mizer extension package collects contributions from the mizer | ||
|
@@ -36,6 +36,7 @@ Suggests: | |
Collate: | ||
alignResource.R | ||
manipulateParams.R | ||
matchYield.R | ||
mizerExperimental-package.R | ||
plotDiet.R | ||
plotBiomassFlux.R | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#' Match observed yields | ||
#' | ||
#' This function matches the observed yields of all the gears for all the | ||
#' species by scaling the catchabilities by the ratio between current modelled | ||
#' yield and observed yield. | ||
#' | ||
#' @param params A MizerParams object | ||
#' @return A MizerParams object with updated catchabilities | ||
#' @export | ||
matchYield <- function(params) { | ||
gp <- params@gear_params | ||
if (is.null(gp$yield_observed)) { | ||
stop("You need to specify `yield_observed` in the gear parameter dataframe.") | ||
} | ||
gp <- gp[!is.na(gp$yield_observed), ] | ||
yields <- getYieldGear(params) | ||
for (i in seq_len(nrow(gp))) { | ||
gear <- as.character(gp$gear[i]) | ||
species <- as.character(gp$species[i]) | ||
ratio <- gp$yield_observed[i] / yields[gear, species] | ||
if (!is.nan(ratio)) { | ||
gear_params(params)[i, "catchability"] <- gp$catchability[i] * ratio | ||
} | ||
} | ||
return(params) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
test_that("matchYield works", { | ||
params <- NS_params | ||
initial_effort(params) <- 1 | ||
yields <- getYieldGear(params) | ||
gp <- params@gear_params | ||
# Add yield_observed column but make it twice too large | ||
for (i in seq_len(nrow(gp))) { | ||
species <- as.character(gp$species[i]) | ||
gear <- as.character(gp$gear[i]) | ||
gp$yield_observed[i] <- yields[gear, species] * 2 | ||
} | ||
gear_params(params) <- gp | ||
p <- matchYield(params) | ||
expect_equal(getYieldGear(params) * 2, getYieldGear(p)) | ||
}) |