gradient(rootSolve)
gradient()所属R语言包:rootSolve
Estimates the gradient matrix for a simple function
一个简单的函数估计的梯度矩阵
译者:生物统计家园网 机器人LoveR
描述----------Description----------
Given a vector of variables (x), and a function (f) that estimates one function value or a set of function values (f(x)), estimates the gradient matrix, containing, on rows i and columns j
变量(x)给定的向量,和一个函数(f)该估计值或一个函数的函数值的一组(f(x)),估计的梯度矩阵,含有,对行i和列Ĵ
The gradient matrix is not necessarily square.
梯度矩阵不一定是正方形。
用法----------Usage----------
gradient(f, x, centered = FALSE, pert = 1e-8, ...)
参数----------Arguments----------
参数:f
function returning one function value, or a vector of function values.
功能返回一个函数值,函数值或一个矢量。
参数:x
either one value or a vector containing the x-value(s) at which the gradient matrix should be estimated.
的任一个值或一个向量,包含的x值(s),在该梯度矩阵,应当估计。
参数:centered
if TRUE, uses a centered difference approximation, else a forward difference approximation.
如果TRUE,采用中心差分近似,否则向前差分近似。
参数:pert
numerical perturbation factor; increase depending on precision of model solution.
数值扰动因子,增加依赖于精确的模型解决方案。
参数:...
other arguments passed to function f.
其他参数传递给函数的f。
Details
详细信息----------Details----------
the function f that estimates the function values will be called as f(x, ...). If x is a vector, then the first argument passed to f should also be a vector.
函数f估计将被调用的函数值,作为函数f(x,...)。 x如果是一个向量,那么第一个参数传递f也应该是一个向量。
The gradient is estimated numerically, by perturbing the x-values.
梯度估计数值,通过扰动的x值。
值----------Value----------
The gradient matrix where the number of rows equals the length of f and the number of columns equals the length of x.
梯度矩阵的行数等于长度f和列的数目等于长度x。
the elements on i-th row and j-th column contain: d((f(x))_i)/d(x_j)
第i行和第j列上的元素包含:d((f(x))_i)/d(x_j)
注意----------Note----------
gradient can be used to calculate so-called sensitivity functions,
gradient可以用来计算所谓的sensitivity functions,
(作者)----------Author(s)----------
Karline Soetaert <karline.soetaert@nioz.nl>
参考文献----------References----------
using R as a simulation platform. Springer.
参见----------See Also----------
jacobian.full, for generating a full and square gradient (jacobian) matrix and where the function call is more complex
jacobian.full,用于产生一个完整的和正方形的梯度(雅可比)矩阵和该函数调用是更复杂的
hessian, for generating the Hessian matrix
hessian,产生Hessian矩阵
实例----------Examples----------
## =======================================================================[#================================================= ======================]
## 1. Sensitivity analysis of the logistic differential equation[#1。MF微分方程的敏感性分析]
## dN/dt = r*(1-N/K)*N , N(t0)=N0.[#的dn / dt = R *(1-N / K)* N,N(T0)= N0。]
## =======================================================================[#================================================= ======================]
# analytical solution of the logistic equation:[Logistic方程的解析解:]
logistic <- function (x, times) {
with (as.list(x),
{
N <- K / (1+(K-N0)/N0*exp(-r*times))
return(c(N = N))
})
}
# parameters for the US population from 1900[从1900年的美国人口参数]
x <- c(N0 = 76.1, r = 0.02, K = 500)
# Sensitivity function: SF: dfi/dxj at[感光度功能:SF:DFI / DXJ]
# output intervals from 1900 to 1950[1900年至1950年的输出间隔]
SF <- gradient(f = logistic, x, times = 0:50)
# sensitivity, scaled for the value of the parameter:[灵敏度,缩放的参数的值:]
# [dfi/(dxj/xj)]= SF*x (columnise multiplication)[[DFI /(DXJ /许继)] = SF * X(columnise乘法)]
sSF <- (t(t(SF)*x))
matplot(sSF, xlab = "time", ylab = "relative sensitivity ",
main = "logistic equation", pch = 1:3)
legend("topleft", names(x), pch = 1:3, col = 1:3)
# mean scaled sensitivity[平均规模灵敏度]
colMeans(sSF)
## =======================================================================[#================================================= ======================]
## 2. Stability of the budworm model, as a function of its[#2。稳定性的的青虫模型,作为它的函数]
## rate of increase.[#的速度递增。]
##[#]
## Example from the book of Soetaert and Herman(2009)[#示例从书的Soetaert和赫尔曼(2009年)]
## A practical guide to ecological modelling,[#实用指南,生态模拟,]
## using R as a simulation platform. Springer[使用R仿真平台。施普林格]
## code and theory are explained in this book[在这本书中#代码和理论解释]
## =======================================================================[#================================================= ======================]
r <- 0.05
K <- 10
bet <- 0.1
alf <- 1
# density-dependent growth and sigmoid-type mortality rate[密度依赖的生长和乙状结肠死亡率]
rate <- function(x, r = 0.05) r*x*(1-x/K) - bet*x^2/(x^2+alf^2)
# Stability of a root ~ sign of eigenvalue of Jacobian [根~符号的雅可比矩阵的特征值的稳定性]
stability <- function (r) {
Eq <- uniroot.all(rate, c(0, 10), r = r)
eig <- vector()
for (i in 1:length(Eq))
eig[i] <- sign (gradient(rate, Eq[i], r = r))
return(list(Eq = Eq, Eigen = eig))
}
# bifurcation diagram[分岔图]
rseq <- seq(0.01, 0.07, by = 0.0001)
plot(0, xlim = range(rseq), ylim = c(0, 10), type = "n",
xlab = "r", ylab = "B*", main = "Budworm model, bifurcation",
sub = "Example from Soetaert and Herman, 2009")
for (r in rseq) {
st <- stability(r)
points(rep(r, length(st$Eq)), st$Eq, pch = 22,
col = c("darkblue", "black", "lightblue")[st$Eigen+2],
bg = c("darkblue", "black", "lightblue")[st$Eigen+2])
}
legend("topleft", pch = 22, pt.cex = 2, c("stable", "unstable"),
col = c("darkblue","lightblue"),
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|