微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

R中相关随机游走的边界限制

如何解决R中相关随机游走的边界限制

我需要为我的相关随机游走创建一个边界。此边界基于我的研究区域(光栅文件)的掩码。在我的 for 循环中,我想添加一个 HttpServletRequest 循环,只要栅格的值为 0(而不是 1)就会中断。我该怎么办?我使用了 repeat{} 包。

circular

运动功能

walk <- function(x0,y0,head0,n,parameterMu,parameterRho,parameterMean,parameterSd)
{
  # Get nr of individuals,call it k
  k = length(x0)

  # Create list to hold data
  all.paths <- list()
  
  for (j in 1:k)
  {
    # Create structure to hold data
    steps <- data.frame(matrix(0,6))
    colnames(steps) <- c("id","x","y","steplength","heading","turningangle")
    
    # Insert the id,starting location and heading
    steps[,"id"] = j
    steps[1,"x"] = x0[j]
    steps[1,"y"] = y0[j]
    steps[1,"heading"] = head0[j]
    
    # Simulate steps
    for(i in 2:n)
    {
      repeat{
      # Draw step length and turning angle,compute heading
      steplength = rnorm(n = 1,mean = parameterMean,sd = parameterSd)
      turningangle = as.numeric(rwrappedcauchy(n = 1,mu = parameterMu,rho = parameterRho))
      newbearing = as.numeric(circular(steps[i-1,"heading"]) + circular(turningangle)) %% (2*pi)
      
      # Get new location
      next.xy <- movement(x0=steps[i-1,"x"],y0=steps[i-1,"y"],step=steplength,heading=newbearing)
      
      # Set boundary
      if ??? break    
      }   

      # Store output (xy on row i,steplength/heading on row i-1)
      steps[i,"x"] <- next.xy[1,"x"]
      steps[i,"y"] <- next.xy[1,"y"]
      steps[i,"steplength"] <- next.xy[1,"step"]
      steps[i,"heading"] <- newbearing
      steps[i,"turningangle"] <- turningangle
    }
    
    # Store trajectory in list
    all.paths[[j]] <- steps
  }
  
  # Return output
  return(all.paths)
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。