observer(simecol)
observer()所属R语言包:simecol
Get or Set an Observer Functions to an ‘simObj’ Object
获取或设置一个观察功能的“simObj”对象
译者:生物统计家园网 机器人LoveR
描述----------Description----------
Get or set a user-defined observer to enable user-specified storage of simulation results, visualisation or logging.
获取或设置一个用户自定义的观察员,使用户指定的存储,可视化的仿真结果或记录。
用法----------Usage----------
observer(obj, ...)
observer(obj) <- value
参数----------Arguments----------
参数:obj
A valid simObj instance.
有效的simObj实例。
参数:value
A function specifying an observer, see Details.
指定观察员的功能,请参阅详细信息。
参数:...
Reserved for method consistency.
保留的方法的一致性。
Details
详细信息----------Details----------
The observer can be used with solver iteration or a user-defined solver function. It does not work with differential equations solvers.
观察者可以被用于与解算器iteration或用户定义的求解器的功能。与微分方程的求解器,这是行不通的。
The observer is a function with the following arguments:
观察员是一个函数使用以下参数:
function(state)
function(state)
or:
或:
function(state, time, i, out, y)
function(state, time, i, out, y)
Where state is the actual state of the system, time and i are the simulation time and the indexof the time step respectively, out is the output of the actual simulation collected so far. The original object used in the simulation is passed via y and can be used to get access on parameter values or model equations.
这里“state是实际的系统状态,time和i是仿真时间和分别的IndexOf的时间步长,out收集的实际模拟输出到目前为止。通过y通过模拟中使用的原始对象,可以用来获取参数值或模型方程。
If available, the observer function is called for every time step in the iteration. It can be used for calculations “on the fly” to reduce memory of saved data, for user-specified animation or for logging purposes.
如果可以,观察员函数被调用,每一次的迭代步骤。它可以用来计算“对飞”,以减少内存保存的数据,为用户指定的动画或记录的目的。
If the value returned by observer is a vector, than resulting out will be a data.frame, otherwise it will be a list of all states.
如果观察员返回的值是一个矢量,,比导致out将一个data.frame,否则它会成为所有国家的列表。
值----------Value----------
The observer function either modifies obj or it returns the assigned observer function or NULL (the default).
观察员功能修改obj或返回指定的观察员功能或NULL(默认值)。
参见----------See Also----------
iteration for the iteration solver,
iteration的迭代求解,
parms for accessor and replacement functions of other slots,
parms其他插槽的访问和更换功能,
simecol-package for an overview of the package.
simecol-package的包的概述。
实例----------Examples----------
## load model "diffusion"[#加载模式“扩散”]
data(diffusion)
solver(diffusion) # solver is iteration, supports observer[求解器迭代,支持观察员]
### == Example 1 ===============================================================[##==例1 ============================================ ===================]
## assign an observer for visualisation[#指定一名观察员的可视化]
observer(diffusion) <- function(state) {
## numerical output to the screen[#数值输出到屏幕上]
cat("mean x=", mean(state$x),
", mean y=", mean(state$y),
", sd x=", sd(state$x),
", sd y=", sd(state$y), "\n")
## animation[#动画]
par(mfrow = c(2, 2))
plot(state$x, state$y, xlab = "x", ylab = "y", pch = 16,
col = "red", xlim = c(0, 100))
hist(state$y)
hist(state$x)
## default case: [#默认情况下:]
## return the state --> iteration stores full state in "out"[#返回的状态 - >迭代存储中的“全状态”]
state
}
sim(diffusion)
### == Example 2 ===============================================================[##==例2 ================= ===================]
## an extended observer with full argument list[#扩展的观察员完整的参数列表]
observer(diffusion) <- function(state, time, i, out, y) {
## numerical output to the screen[#数值输出到屏幕上]
cat("index =", i,
", time =", time,
", sd x=", sd(state$x),
", sd y=", sd(state$y), "\n")
## animation[#动画]
par(mfrow = c(2, 2))
plot(state$x, state$y, xlab = "x", ylab = "y", pch = 16,
col = "red", xlim = c(0, 100))
hist(state$y)
hist(state$x)
if (is.matrix(out)) # important because out may be NULL for the first call[重要的,因为出来的第一次调用可能是NULL]
matplot(out[,1], out[,-1]) # dynamic graph of sd in both directions[在两个方向上的动态图形的SD]
## return a vector with summary information[#返回一个向量,其摘要信息]
c(times = time, sdx=sd(state$x), sdy=sd(state$y))
}
diffusion <- sim(diffusion)
### == Restore default =========================================================[##==恢复默认================= =============]
observer(diffusion) <- NULL # delete observer[删除观察员]
diffusion <- sim(diffusion)
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|