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

R语言 smcUtils包 resample()函数中文帮助文档(中英文对照)

  [复制链接]
发表于 2012-9-30 10:19:10 | 显示全部楼层 |阅读模式
resample(smcUtils)
resample()所属R语言包:smcUtils

                                        Resample
                                         重新取样

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

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

A set of resampling functions with unbiased number of replicates.
重采样功能不带偏见的一些重复的一组。


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


resample(weights, num.samples=length(weights),
         method = c("multinomial","residual","stratified","systematic","branching"),
         nonuniformity = c("none","ess","cov","entropy"), threshold = NULL,
         resample.function = multinomial.resample)



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

参数:weights
a vector of normalized weights
一个归一化的权重向量


参数:num.samples
a scalar indicating the number of samples to return (for "branching.resample", "num.samples" is the expected number of samples as the actual number is random)
表示的样本数返回(branching.resample,num.samples是一个标量,预期数目的样本的实际数目是随机的)


参数:method
a character string indicating the resampling method to use. One of ""multinomial"" (default), ""residual"", ""stratified"", ""systematic"", or ""branching"", can be abbreviated.
重采样方法使用一个字符串,指示。之一的“多元”(默认)“,”残“”,“分层”,“系统”,或“分支”,可以缩写。


参数:nonuniformity
a character string indicating which hueristic to use for measuring weight nonuniformity. One of ""none"" (default), ""ess"", ""cov"", or ""entropy"", can be abbreviated. If "none", resampling will always be performed.
一个字符串,表示这hueristic用于测量重量不均匀。的一个“没有”(默认值),“”ESS的“,”覆盖“,或”“熵”,可以缩写。如果“无”,将始终进行重采样。


参数:threshold
a scalar indicating when to resample. If "nonuniformity="none"", resampling is always performed regardless of threshold. If "nonuniformity="ess"" or "entropy", resampling is performed when "nonuniformity<threshold". If "nonuniformity="cov"", resampling is performed when 'nonuniformity> threshold'. The default threshold is "0.5*num.samples" for "ess" and "cov", and "0.5*log2(num.samples)" for "entropy".
一个标量时重新取样。如果不均匀=“无”,重采样总是不管阈值。如果不均匀=“ESS的”或“熵”,重采样时,进行不均<阈值。如果不均匀=“覆盖”,重采样时的不均匀性“>”阈值“。预设的阈值是0 .5 * num.samples“,”ESS“和”覆盖“,0 .5 *为log2(num.samples)”,“熵”。


参数:resample.function
the resampling function to use on the remainder (only used when method = "residual")
重采样功能使用上的余数(仅使用方法=“剩余”)


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

<table summary="R valueblock"> <tr valign="top"><td>weights</td> <td> the component weights</td></tr> <tr valign="top"><td>indices</td> <td> an integer vector containing the indices of resampled components. If no resampling was performed, then "indices=1:length(weights)".</td></tr> </table>
<table summary="R valueblock"> <tr valign="top"> <TD> weights</ TD> <TD>成分的权重</ TD> </ TR> <TR VALIGN =“顶” > <TD> indices</ TD> <TD>指数重采样组件包含一个整数向量。如果不进行重采样,然后指数= 1:长度(权重)。</ TD> </ TR> </ TABLE>


(作者)----------Author(s)----------


Jarad Niemi



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

resampling
resampling


实例----------Examples----------


ws = renormalize.weights(runif(10))
resample(ws)

## A more involved example, comparing particle filtering with the Kalman filter[#A更复杂的例子,比较粒子滤波与卡尔曼滤波]
# Generate data from a local level linear model[从地方一级线性模型生成数据]
N = 1000; W = 1^2; V = 1; m0 = 0; C0 = 1
true.x = rep(NA,N); true.x[1] = rnorm(1,m0,sqrt(C0))
for (i in 2:N) true.x[i] = rnorm(1,true.x[i-1],sqrt(W)) # Evolve x[进化x]
y = rnorm(N,true.x,sqrt(V))                             # Noisy data[噪声数据]

# Run a particle filter[运行颗粒过滤器]
J = 1e2
x  = matrix(NA,N,J); x[1,]  = rnorm(J,m0,C0) # Sample from the prior for x[从现有为x的样品]
ws = matrix(NA,N,J); ws[1,] = renormalize.weights(dnorm(y[1],x[1,],sqrt(V),log=TRUE))

# Run a Kalman filter[运行一个卡尔曼滤波器]
m = rep(NA,N); m[1] = m0 # Kalman filter expectation[卡尔曼滤波器的期望]
M = rep(NA,N); M[1] = C0 # Kalman filter variance[卡尔曼滤波方差]

for (i in 2:N) {
  # Particle filter[粒子过滤器]
  component   = resample(ws[i-1,],J,"stratified","ess",0.8*J)
  x[i,]       = rnorm(J,x[i-1,component$indices],sqrt(W))
  log.weights = log(component$weights)+dnorm(y[i],x[i,],sqrt(V),log=TRUE)
  ws[i,]      = renormalize.weights(log.weights,log=TRUE)

  # Kalman filter[卡尔曼滤波器]
  K    = (M[i-1]+W)/(M[i-1]+W+V) # Adaptive coefficient[自适应系数]
  m[i] = K*y[i]+(1-K)*m[i-1]
  M[i] = K*M[i-1]
}

pf.m = apply(x*ws,1,sum)
plot(m,type='l',ylim=range(pf.m,m),xlab='t',ylab='x')
lines(pf.m,col='red')
legend("bottomleft",inset=0.01,c("Kalman filter mean","Particle filter mean"),
       col=c("black","red"),lty=rep(1,2),bg="white")

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


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

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-11-23 11:06 , Processed in 0.027133 second(s), 15 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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