-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathsetRateFunction.Rd
93 lines (76 loc) · 3.79 KB
/
setRateFunction.Rd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/extension.R
\name{setRateFunction}
\alias{setRateFunction}
\alias{getRateFunction}
\alias{other_params}
\alias{other_params<-}
\title{Set own rate function to replace mizer rate function}
\usage{
setRateFunction(params, rate, fun)
getRateFunction(params, rate)
other_params(params)
other_params(params) <- value
}
\arguments{
\item{params}{A MizerParams object}
\item{rate}{Name of the rate for which a new function is to be set.}
\item{fun}{Name of the function to use to calculate the rate.}
\item{value}{Values for other parameters}
}
\value{
For \code{setRateFunction()}: An updated MizerParams object
For \code{getRateFunction()}: The name of the registered rate function for
the requested \code{rate}, or the list of all rate functions if called without
\code{rate} argument.
For \code{other_params()}: A named list with all the parameters for which
you have set values.
}
\description{
If the way mizer calculates a fundamental rate entering the model is
not flexible enough for you (for example if you need to introduce time
dependence) then you can write your own functions for calculating that
rate and use \code{setRateFunction()} to register it with mizer.
}
\details{
At each time step during a simulation with the \code{\link[=project]{project()}} function, mizer
needs to calculate the instantaneous values of the various rates. By
default it calls the \code{\link[=mizerRates]{mizerRates()}} function which creates a list with the
following components:
\itemize{
\item \code{encounter} from \code{\link[=mizerEncounter]{mizerEncounter()}}
\item \code{feeding_level} from \code{\link[=mizerFeedingLevel]{mizerFeedingLevel()}}
\item \code{pred_rate} from \code{\link[=mizerPredRate]{mizerPredRate()}}
\item \code{pred_mort} from \code{\link[=mizerPredMort]{mizerPredMort()}}
\item \code{f_mort} from \code{\link[=mizerFMort]{mizerFMort()}}
\item \code{mort} from \code{\link[=mizerMort]{mizerMort()}}
\item \code{resource_mort} from \code{\link[=mizerResourceMort]{mizerResourceMort()}}
\item \code{e} from \code{\link[=mizerEReproAndGrowth]{mizerEReproAndGrowth()}}
\item \code{e_repro} from \code{\link[=mizerERepro]{mizerERepro()}}
\item \code{e_growth} from \code{\link[=mizerEGrowth]{mizerEGrowth()}}
\item \code{rdi} from \code{\link[=mizerRDI]{mizerRDI()}}
\item \code{rdd} from \code{\link[=BevertonHoltRDD]{BevertonHoltRDD()}}
}
For each of these you can substitute your own function. So for example if
you have written your own function for calculating the total mortality
rate and have called it \code{myMort} and have a mizer model stored in a
MizerParams object called \code{params} that you want to run with your new
mortality rate, then you would call
\if{html}{\out{<div class="sourceCode">}}\preformatted{params <- setRateFunction(params, "Mort", "myMort")
}\if{html}{\out{</div>}}
In general if you want to replace a function \code{mizerSomeRateFunc()} with
a function \code{myVersionOfThis()} you would call
\if{html}{\out{<div class="sourceCode">}}\preformatted{params <- setRateFunction(params, "SomeRateFunc", "myVersionOfThis")
}\if{html}{\out{</div>}}
In some extreme cases you may need to swap out the entire \code{mizerRates()}
function for your own function called \code{myRates()}. That you can do with
\if{html}{\out{<div class="sourceCode">}}\preformatted{params <- setRateFunction(params, "Rates", "myRates")
}\if{html}{\out{</div>}}
Your new rate functions may need their own model parameters. These you
can store in \code{other_params(params)}. For example
\if{html}{\out{<div class="sourceCode">}}\preformatted{other_params(params)$my_param <- 42
}\if{html}{\out{</div>}}
Note that your own rate functions need to be defined in the global
environment or in a package. If they are defined within a function then
mizer will not find them.
}