gen.gradient(SpatioTemporal)
gen.gradient()所属R语言包:SpatioTemporal
Compute Finite Difference Gradient and Hessians.
计算有限差分梯度和粗麻布。
译者:生物统计家园网 机器人LoveR
描述----------Description----------
Computes finite difference gradient and/or hessian. gen.gradient function does forward, backward or central differences, the gen.hessian function uses only central differences.
计算有限差分梯度和/或麻。 gen.gradient函数不向前,向后或中央的差异,gen.hessian功能只使用中央的差异。
用法----------Usage----------
gen.gradient(x, func, h = 0.001, diff.type = 0)
gen.hessian(x, func, h = 0.001)
参数----------Arguments----------
参数:x
Point at which to compute the gradient or hessian.
在计算梯度或麻点。
参数:func
A function that takes only x as an input argument. Use <br> function(x){my.func(x,other.input)} to create a temporary function, see the example.
只需要x作为输入参数的函数。使用参考function(x){my.func(x,other.input)}创建一个临时的功能,请参阅示例。
参数:h
Step length for the finite difference.
步长的有限差分法。
参数:diff.type
Type of finite difference, positive values gives forward differences, 0 gives central differences, and negative values gives backward differences.
类型的有限差分法,正面的价值观提供了前进的差异,0给中央的差异,而负值使落后的差异。
值----------Value----------
gen.gradient returns the gradient as a vector. gen.hessian returns the hessian matrix.
gen.gradient返回的梯度为向量。 gen.hessian返回Hessian矩阵。
(作者)----------Author(s)----------
Johan Lindstr枚m
参见----------See Also----------
Used by loglike.grad, loglike.hessian, loglike.naive.grad, and <br> loglike.naive.hessian.
用于loglike.grad,loglike.hessian,loglike.naive.grad,和<br> loglike.naive.hessian。
实例----------Examples----------
#create a two variable function[创建两个变量的函数]
f.test <- function(x){sin(x[1])*cos(x[2])}
#compute the gradient using forward difference[使用前向差分计算梯度]
gen.gradient(c(.5,.5), f.test, diff.type=1)
#and central difference[中央差]
gen.gradient(c(.5,.5), f.test, diff.type=0)
#compared to the true value[的真值相比]
c(cos(.5)*cos(.5),-sin(.5)*sin(.5))
#Compute the Hessian[计算的Hessian]
gen.hessian(c(.5,.5), f.test, h=1e-4)
#and compare to the true value[和比较的真正价值]
matrix(c(-sin(.5)*cos(.5),-cos(.5)*sin(.5),
-cos(.5)*sin(.5),-sin(.5)*cos(.5)),2,2)
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|