sizespectrum / mizer
Showing 1 of 1 files from the diff.
Newly tracked file
R/get_initial_n.R created.

@@ -0,0 +1,45 @@
Loading
1 +
#' Calculate initial population abundances for the community populations
2 +
#' 
3 +
#' This function uses the model parameters and other parameters to calculate 
4 +
#' initial population abundances for the community populations. These initial 
5 +
#' abundances should be reasonable guesses at the equilibrium values. The 
6 +
#' returned population can be passed to the `project` function.
7 +
#' 
8 +
#' @param params The model parameters. An object of type \linkS4class{MizerParams}.
9 +
#' @param a A parameter with a default value of 0.35.
10 +
#' @param n0_mult Multiplier for the abundance at size 0. Default value is
11 +
#'   kappa/1000.
12 +
#' @export
13 +
#' @return A matrix (species x size) of population abundances.
14 +
#' @examples
15 +
#' \dontrun{
16 +
#' params <- newMultispeciesParams(NS_species_params_gears)
17 +
#' init_n <- get_initial_n(params)
18 +
#' }
19 +
get_initial_n <- function(params, n0_mult = NULL, a = 0.35) {
20 +
    if (!is(params,"MizerParams"))
21 +
        stop("params argument must of type MizerParams")
22 +
    no_sp <- nrow(params@species_params)
23 +
    no_w <- length(params@w)
24 +
    initial_n <- array(NA, dim = c(no_sp, no_w))
25 +
    dimnames(initial_n) <- dimnames(params@intake_max)
26 +
    # N = N0 * Winf^(2*n-q-2+a) * w^(-n-a)
27 +
    # Reverse calc n and q from intake_max and search_vol slots (could add get_n function)
28 +
    n <- params@species_params$n[[1]]
29 +
    q <- params@species_params$q[[1]]
30 +
    # Guessing at a suitable n0 value based on kappa - this was figured out 
31 +
    # using trial and error and should be updated
32 +
    if (is.null(n0_mult)) {
33 +
        lambda <- 2 + q - n
34 +
        kappa <- params@cc_pp[1] / (params@w_full[1]^(-lambda))
35 +
        n0_mult <- kappa / 1000
36 +
    }
37 +
    initial_n[] <- unlist(tapply(params@w, 1:no_w, function(wx,n0_mult,w_inf,a,n,q)
38 +
        n0_mult * w_inf^(2 * n - q - 2 + a) * wx^(-n - a),
39 +
        n0_mult = n0_mult, w_inf = params@species_params$w_inf, a=a, n=n, q=q))
40 +
    #set densities at w > w_inf to 0
41 +
    initial_n[unlist(tapply(params@w,1:no_w,function(wx,w_inf) w_inf<wx, w_inf=params@species_params$w_inf))] <- 0
42 +
    # Also any densities at w < w_min set to 0
43 +
    initial_n[unlist(tapply(params@w,1:no_w,function(wx,w_min)w_min>wx, w_min=params@species_params$w_min))] <- 0    
44 +
    return(initial_n)
45 +
}
Files Coverage
R 89.56%
src/inner_project_loop.cpp 100.00%
Project Totals (29 files) 89.58%
Notifications are pending CI completion. Periodically Codecov will check the CI state, when complete notifications will be submitted. Push notifications now.
1
comment: false
2

3
coverage:
4
  status:
5
    project:
6
      default:
7
        target: auto
8
        threshold: 1%
9
    patch:
10
      default:
11
        target: auto
12
        threshold: 1%
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading