找回密码
 注册
查看: 2750|回复: 0

R语言:deriv()函数中文帮助文档(中英文对照)

[复制链接]
发表于 2012-2-16 19:14:45 | 显示全部楼层 |阅读模式
deriv(stats)
deriv()所属R语言包:stats

                                        Symbolic and Algorithmic Derivatives of Simple Expressions
                                         符号的简单表达式和算法的衍生物

                                         译者:生物统计家园网 机器人LoveR

描述----------Description----------

Compute derivatives of simple expressions, symbolically.
计算简单表达式的衍生工具,象征性的。


用法----------Usage----------


    D (expr, name)
deriv(expr, ...)
deriv3(expr, ...)

## Default S3 method:
deriv(expr, namevec, function.arg = NULL, tag = ".expr",
       hessian = FALSE, ...)
## S3 method for class 'formula'
deriv(expr, namevec, function.arg = NULL, tag = ".expr",
       hessian = FALSE, ...)

## Default S3 method:[默认方法]
deriv3(expr, namevec, function.arg = NULL, tag = ".expr",
       hessian = TRUE, ...)
## S3 method for class 'formula'[类formula的方法]
deriv3(expr, namevec, function.arg = NULL, tag = ".expr",
       hessian = TRUE, ...)



参数----------Arguments----------

参数:expr
A expression or call or (except D) a formula with no lhs.
一个expression或call(除D)与无LHS公式。


参数:name,namevec
character vector, giving the variable names (only one for D()) with respect to which derivatives will be computed.
特征向量,使变量名(只有一个D())将计算的衍生工具方面。


参数:function.arg
If specified and non-NULL, a character vector of arguments for a function return, or a function (with empty body) or TRUE, the latter indicating that a function with argument names namevec should be used.
如果指定和非NULL特征向量参数,函数的返回,或一个函数(空体)或TRUE,后者表示,功能与参数名namevec应使用。


参数:tag
character; the prefix to be used for the locally created variables in result.
字符将用于当地创造的结果变量的前缀。


参数:hessian
a logical value indicating whether the second derivatives should be calculated and incorporated in the return value.
一个逻辑值,指示是否应计算和返回值中的第二个衍生工具。


参数:...
arguments to be passed to or from methods.
参数被传递到或从方法。


Details

详情----------Details----------

D is modelled after its S namesake for taking simple symbolic derivatives.
D是仿照它的同名采取简单的象征性的衍生工具。

deriv is a generic function with a default and a formula method.  It returns a call for computing the expr and its (partial) derivatives, simultaneously.  It uses so-called algorithmic derivatives.  If function.arg is a function, its arguments can have default values, see the fx example below.
deriv是默认formula方法的通用功能。它返回call计算expr“(部分)衍生物的同时。它使用了所谓的算法的衍生工具。如果function.arg是一个函数,其参数可以有默认值,请参阅下面的fx例如。

Currently, deriv.formula just calls deriv.default after extracting the expression to the right of ~.
目前,deriv.formula只是调用deriv.default解压后表达的权利~。

deriv3 and its methods are equivalent to deriv and its methods except that hessian defaults to TRUE for deriv3.
deriv3和它的方法是相当于deriv,其方法除hessian默认TRUEderiv3。

The internal code knows about the arithmetic operators +, -, *, / and ^, and the single-variable functions exp, log, sin, cos, tan, sinh, cosh, sqrt, pnorm, dnorm, asin, acos, atan, gamma, lgamma, digamma and trigamma, as well as psigamma for one or two arguments (but derivative only with respect to the first). (Note that only the standard normal distribution is considered.)
有关算术运算符的内部代码知道+,-,*,/和^,单变量函数exp log,sin,cos,tan,sinh,cosh,sqrt,pnorm,dnorm,asin,acos,atan,gamma,lgamma,digamma和trigamma,以及 psigamma一个或两个参数(但与第一只衍生)。 (注意:只有被认为是标准正态分布)。


值----------Value----------

D returns a call and therefore can easily be iterated for higher derivatives.
D返回一个电话,因此可以很容易地迭代更高的衍生工具。

deriv and deriv3 normally return an expression object whose evaluation returns the function values with a "gradient" attribute containing the gradient matrix.  If hessian is TRUE the evaluation also returns a "hessian" attribute containing the Hessian array.
deriv和deriv3通常返回一个expression对象的评价"gradient"属性,其中包含渐变矩阵函数值返回。如果hessian是TRUE评价也返回一个"hessian"属性,其中包含的Hessian阵。

If function.arg is not NULL, deriv and deriv3 return a function with those arguments rather than an expression.
function.arg如果非NULL,deriv和deriv3返回一个表达式,而不是那些参数的功能。


参考文献----------References----------

Automatic Differentiation of Algorithms: Theory, Implementation, and Application. SIAM proceedings, Philadelphia.
Nonlinear models. Chapter 10 of Statistical Models in S eds J. M. Chambers and T. J. Hastie, Wadsworth & Brooks/Cole.

参见----------See Also----------

nlm and optim for numeric minimization which could make use of derivatives,
nlm和optim数字最小化,这可能使衍生工具的使用,


举例----------Examples----------


## formula argument :[#公式参数:]
dx2x <- deriv(~ x^2, "x") ; dx2x
## Not run: expression({[#无法运行:表达({]
         .value <- x^2
         .grad <- array(0, c(length(.value), 1), list(NULL, c("x")))
         .grad[, "x"] <- 2 * x
         attr(.value, "gradient") <- .grad
         .value
})
## End(Not run)[#结束(不运行)]
mode(dx2x)
x <- -1:2
eval(dx2x)

## Something 'tougher':[#有点强硬“:]
trig.exp <- expression(sin(cos(x + y^2)))
( D.sc <- D(trig.exp, "x") )
all.equal(D(trig.exp[[1]], "x"), D.sc)

( dxy <- deriv(trig.exp, c("x", "y")) )
y <- 1
eval(dxy)
eval(D.sc)

## function returned:[#函数返回:]
deriv((y ~ sin(cos(x) * y)), c("x","y"), func = TRUE)

## function with defaulted arguments:[#函数的默认参数:]
(fx <- deriv(y ~ b0 + b1 * 2^(-x/th), c("b0", "b1", "th"),
             function(b0, b1, th, x = 1:7){} ) )
fx(2,3,4)

## Higher derivatives[#高等教育衍生物]
deriv3(y ~ b0 + b1 * 2^(-x/th), c("b0", "b1", "th"),
     c("b0", "b1", "th", "x") )

## Higher derivatives:[#高等教育衍生物:]
DD <- function(expr,name, order = 1) {
   if(order < 1) stop("'order' must be >= 1")
   if(order == 1) D(expr,name)
   else DD(D(expr, name), name, order - 1)
}
DD(expression(sin(x^2)), "x", 3)
## showing the limits of the internal "simplify()" :[#显示内部的“简化()”的限制:]
## Not run: [#无法运行:]
-sin(x^2) * (2 * x) * 2 + ((cos(x^2) * (2 * x) * (2 * x) + sin(x^2) *
    2) * (2 * x) + sin(x^2) * (2 * x) * 2)

## End(Not run)[#结束(不运行)]

转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。


注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|小黑屋|生物统计家园 网站价格

GMT+8, 2025-1-24 09:26 , Processed in 0.020897 second(s), 15 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表