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

R语言 simecol包 initialize-methods()函数中文帮助文档(中英文对照)

[复制链接]
发表于 2012-9-30 02:37:05 | 显示全部楼层 |阅读模式
initialize-methods(simecol)
initialize-methods()所属R语言包:simecol

                                        Methods for Function ‘initialize’ in Package ‘simecol’
                                         方法功能初始化在包simecol“

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

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

This function is used to initialize objects derived from the simObj superclass, it is by default automatically called during object creation and by sim.
此功能用于初始化来自simObj超类的对象,它是由默认的过程中会自动调用对象的创建和sim。


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


## S4 method for signature 'simObj'
initialize(.Object, ...)



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

参数:.Object
simObj instance which is to be re-initialized.  
simObj实例,这将重新初始化。


参数:...
provided for compatibility with the default method of initialize, or slots of the object which is to be created (in case of new).  
提供兼容性的默认方法initialize,或插槽的对象是要创建的(new)的情况下。


方法----------Methods----------




.Object = "ANY" Generic function: see new.
对象=“ANY”通用功能:new。

The initialize function is normally called implicitly by new to create new objects. It may also be called explicitly to return a cloned and re-initialized object.
initialize功能通常被称为隐式new创建新的对象。它也可以被称为显式地返回一个克隆和重新初始化的对象。

The simecol version of initialize provides an additonal mechanism to call a user specified function provided in the initfun slot of a simObj instance that can perform computations during the object creation process. The initfunc must have obj as its only argument and must return the modified version of this obj, see examples below. As a side effect end to ensure consistency, initialize clears outputs stored in slot out from former simulations.
simecol版本的initialize提供了一个产生额外的机制,调用用户指定的函数在initfun插槽的simObj实例,可以在对象创建过程中进行计算。 initfunc必须有obj作为其唯一的参数,并且必须返回修改后的版本的这obj,见下面的例子。作为一个副作用结束,以确保一致性,initialize清除存储在插槽out前模拟输出。


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

simObj, new
simObj,new


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


## Note: new calls initialize and initialize calls initfunc(obj)[#注:新的呼叫初始化和初始化呼叫initfunc(OBJ)]
lv_efr <- new("odeModel",
  main = function (time, init, parms, ...) {
    x <- init
    p <- parms
    S <- approxTime1(inputs, time, rule=2)["s.in"]
    dx1 <-   S * p["k1"] * x[1] - p["k2"] * x[1] * x[2]
    dx2 <-     - p["k3"] * x[2] + p["k2"] * x[1] * x[2]
    list(c(dx1, dx2))
  },
  parms  = c(k1=0.2, k2=0.2, k3=0.2),
  times  = c(from=0, to=100, by=0.5),
  init   = c(prey=0.5, predator=1),
  solver = "lsoda",
  initfunc = function(obj) {
    tt <- fromtoby(times(obj))
    inputs(obj) <- as.matrix(data.frame(
            time = tt,
            s.in = pmax(rnorm(tt, mean=1, sd=0.5), 0)
          ))
    obj
  }
)
plot(sim(lv_efr))                     # initialize called automatically[初始化会自动调用]
plot(sim(lv_efr))                     # automatic initialization, different figure[自动初始化,不同的数字]

lv_efr&lt;- initialize(lv_efr)           # re-initialize manually[重新初始化手动]
plot(sim(lv_efr, initialize = FALSE)) # simulation with that configuration[模拟与配置]
   


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


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

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-5-23 23:05 , Processed in 0.024151 second(s), 16 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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