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

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

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

                                        Count Number of Neighbours on a Rectangular Grid.
                                         算号街坊上的矩形网格。

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

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

This is the base function for the simulation of deterministic and stochastic cellular automata on rectangular
这是基本功能的确定性和随机模拟的元胞自动机上的矩形


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


  neighbours(x, state = NULL, wdist = NULL, tol = 1e-4, bounds = 0)
  neighbors(x, state = NULL, wdist = NULL, tol = 1e-4, bounds = 0)



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

参数:x
Matrix. The cellular grid, in which each cell can have a specific state value, e.g. zero (dead cell) or one (living cell) or the age of an individual.
矩阵。蜂窝网格,其中每个单元可以有一个特定的状态值,例如为零(死单元)或一(活单元),或个人的年龄。


参数:state
A value, whose existence is checked within the neighbourhood of each cell.  
A值,它的存在是附近的每一个单元内检查。


参数:wdist
The neighbourhood weight matrix. It has to be a square matrix with an odd number of rows and columns).  
附近的权重矩阵。它必须是一个方阵具有奇数行和列)。


参数:tol
Tolerance value for the comparision of state with the state of each cell. If tol is a large value, then more than one state can be checked simultaneously.
公差值的比较state每个单元的状态。如果tol是一个较大的值,然后一个以上国家可以同时检查。


参数:bounds
A vector with either one or four values specifying the type of boundaries, where 0 means open boundaries and 1 torus-like boundaries. The values are specified in the order bottom, left,  top, right.
一个向量与一个或四个值的边界类型,其中0表示开边界和1环面边界。值中指定的命令下,左,上,右。


Details

详细信息----------Details----------

The performance of the function depends on the size of the matrices and the type of the boundaries, where open boundaries are faster than torus like boundaries. Function eightneighbours is even faster.
该函数的性能依赖于矩阵的大小和类型的边界,其中开边界是比环面像边界更快。功能eightneighbours,甚至更快。


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

A matrix with the same structure as x with the weighted sum of the neigbours with values between state - tol and state + tol.
A矩阵具有相同的结构作为x的加权总和值之间state - tol和state + tolneigbours的。


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

seedfill, eightneighbours, conway
seedfill,eightneighbours,conway


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


## ==================================================================[#================================================= =================]
## Demonstration of the neighborhood function alone[示范邻域函数]
## ==================================================================[#================================================= =================]

## weight matrix for neighbourhood determination[#附近决心权重矩阵]
wdist <- matrix(c(0.5,0.5,0.5,0.5,0.5,
                  0.5,1.0,1.0,1.0,0.5,
                  0.5,1.0,1.0,1.0,0.5,
                  0.5,1.0,1.0,1.0,0.5,
                  0.5,0.5,0.5,0.5,0.5), nrow=5)

## state matrix                  [#状态矩阵]
n <- 20; m <- 20
x <- matrix(rep(0, m * n), nrow = n)

## set state of some cells to 1[#设置状态的一些单元,以1。]
x[10, 10] <- 1
x[1, 5]   <- 1
x[n, 15]  <- 1
x[5, 2]   <- 1
x[15, m]  <- 1
#x[n, 1]   &lt;- 1 # corner[X [1] N,< -  1#角落]

opar <- par(mfrow = c(2, 2))
## start population[#启动人口]
image(x)
## open boundaries[#开放边界]
image(matrix(neighbours(x, wdist = wdist, bounds = 0), nrow = n))
## torus (donut like)[#花托(甜甜圈想)]
image(matrix(neighbours(x, wdist = wdist, bounds = 1), nrow = n))
## cylinder (left and right boundaries connected)[#气缸(左和右的边界连接)]
image(matrix(neighbours(x, wdist = wdist, bounds = c(0, 1, 0, 1)), nrow = n))
par(opar) # reset graphics area                  [重置图形区域]
                  
## ==================================================================[#================================================= =================]
## The following example demonstrates a "plain implementation" of a[#下面的例子演示了一个实现“纯”的]
## stochastic cellular automaton i.e. without the simecol structure.[#随机元胞自动机,即没有simecol结构。]
##[#]
## A simecol implementation of this can be found in[#一个simecol的执行本可以找到在]
## the example directory of this package (file: stoch_ca.R).[#示例目录这个包(文件:stoch_ca.R)。]
## ==================================================================                  [#================================================= =================]
mycolors <- function(n) {
  col <- c("wheat", "darkgreen")
  if (n>2) col <- c(col, heat.colors(n - 2))
  col
}

pj &lt;- 0.99  # survival probability of juveniles[对青少年的生存概率]
pa &lt;- 0.99  # survival probability of adults[成人的生存概率]
ps &lt;- 0.1   # survival probability of senescent[衰老的生存概率]
ci &lt;- 1.0   # "seeding constant"[“播种不变”]
adult &lt;- 5  # age of adolescence[青春期的年龄]
old   &lt;- 10 # age of senescence[年龄的衰老]

## Define a start population[#定义开始人口]
n <- 80
m <- 80
x <- rep(0, m*n)

## stochastic seed[#随机种子]
## x[round(runif(20,1,m*n))] &lt;- adult[#X [圆(runif(20,1,M * N))] < - 成人]
dim(x)<- c(n, m)

## rectangangular seed in the middle[#rectangangular种子在中间]
x[38:42, 38:42] <- 5

## plot the start population[#图开始人口]
image(x, col = mycolors(2))

## -----------------------------------------------------------------------------[#------------------------------------------------- ----------------------------]
## Simulation loop (hint: increase loop count)[#模拟循环(提示:增加循环计数)]
## -----------------------------------------------------------------------------[#------------------------------------------------- ----------------------------]
for (i in 1:10){

  ## rule 1: reproduction[规则1:复制]
  ## 1.1 which cells are adult? (only adults can generate)[1.1单元是成人的吗? (仅成人可以生成)]
  ad <- ifelse(x >= adult &amp; x < old, x, 0)

  ## 1.2 how much (weighted) adult neighbours has each cell?[#1.2(加权)多少成人的邻居的每一个单元?]
  nb <- neighbours(ad, wdist = wdist)

  ## 1.3 a proportion of the seeds develops juveniles[#1.3的比例的种子开发青少年]
  ## simplified version, you can also use probabilities[#简化版本,你也可以用概率]
  genprob <- nb * runif(nb) * ci
  xgen  <- ifelse(x == 0 &amp; genprob >= 1, 1, 0)

  ## rule 2: growth and survival of juveniles[规则#2:青少年的生长和存活的]
  xsurvj <- ifelse(x >= 1 &amp; x < adult &amp; runif(x) <= pj, x+1, 0)
  ## rule 2: growth and survival of adults[规则#2:成人的生长和存活的]
  xsurva <- ifelse(x >= adult &amp; x < old &amp; runif(x) <= pa, x+1, 0)
  ## rule 2: growth and survival of senescent[#规则2:衰老的生长和存活]
  xsurvs <- ifelse(x >= old &amp; runif(x) <= ps, x+1, 0)

  ## make resulting grid of complete population[#电网的完整的人口]
  x     <- xgen + xsurvj + xsurva + xsurvs

  ## plot resulting grid[#图电网]
  image(x, col = mycolors(max(x) + 1), add = TRUE)
  if (max(x) == 0) stop("extinction", call. = FALSE)
}

## modifications:  pa&lt;-pj&lt;-0.9[#修改:PA <PJ <-0.9]

## additional statistics of population structure[#统计的人口结构]
## with table, hist, mean, sd, ...[#表历史,是什么意思,SD,...]

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


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

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-5-24 04:04 , Processed in 0.034422 second(s), 16 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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