Is original wolfAlps module unstable with changed parameter (MeanPixelQuality)?

23 views
Skip to first unread message

C M

unread,
Dec 17, 2019, 12:36:00 PM12/17/19
to SpaDES Users
Hi everyone,

I am still trying to get rid of various errors in my adaption of wolfAlps. Now I have one that also seems to appear in the original wolfAlps module if MeanPixelQuality
is higher. I tried

MeanPixelQuality = 0.94 instead of 0.84.

This leads to the error
 "'vec' must be sorted non-decreasingly and not contain NAs"

I am pretty sure that things break down in line 635 / 636 of the original wolfAlps.R. 

# Now each wolf has its subset of cells as potential next locations for dispersal
   
# Probability of going to the potential next locations regarding their directions
    headDispersers
<- of(agents = dispersers, var = "heading")
    nextLocs
[,nextAngle:={
      dnorm
(mean = 0, sd = params(sim)$wolfAlps$sigma, # calculate the probability using the Normal distribution of ...
            subHeadings
(angle1 = headDispersers[id], # ... the rotation of each wolf's heading to ...
                        angle2
= towards(agents = turtle(sim$wolves, who = whoDispersers[id]), # ... the direction towards each of its next potential locations
                                         agents2
= cbind(x = x, y = y))
           
)
     
)}, by = id] # data.table use of by = id, so each of the above happens within each id


   
# Probability of going to the potential next locations regarding habitat suitability
    data
.table::set(nextLocs,,"suitabilityValGood", sim$suitabilityValGood[nextLocs$indices])


   
# Probability of going to the potential next locations regarding the directions, habitat suitability and other wolves presence
    data
.table::set(nextLocs,,"prob", nextLocs$nextAngle * nextLocs$suitabilityValGood * nextLocs$empty)
    probLoc
<- runif(n = NLcount(dispersers), min = 0, max = 1)
    setkeyv
(nextLocs, c("id"))
   
# Selected next potential locations, based on probLoc
    nextLocs <- nextLocs[,.SD[findInterval(probLoc[id], cumsum(prob/sum(prob))) + 1],
                         
by = id, .SDcols = c("x", "y", "prob")]

    selectedLocID
<- as.matrix(nextLocs)[,c(2,3,1), drop = FALSE]

Do you have an idea on why this happens? I first thought cumsum() might get too large, but prints of it seemed fine to me. 

Thank you for any advice :)
Clara



C M

unread,
Dec 19, 2019, 11:26:15 AM12/19/19
to SpaDES Users
So I always get

Error in findInterval(probLoc[id], cumsum(prob/sum(prob))) : 
  'vec' must be sorted non-decreasingly and not contain NAs 

Do you think:
 1) Choosing MeanPixelQuality = 0.94 instead of 0.84. is invalid? And thus this error is not a problem? Since there are only very few raster cells with habitatsuitability >= 0.94. 
or 
 2) it is a valid choice and should just result in a strong barrier effect of any but the best habitat suitability, leading to long searches with therefore high mortality?

The latter is what I think should happen, but I might be wrong. Shouldn't there be a criterium that the doubling of steplength only can happen maybe 3-4 times, and if this doesn't result in any suitable cell the disperser dies? I am not at all sure, but I think the error might occur because of indefinite doubling of steplength. 
Message has been deleted

C M

unread,
Dec 20, 2019, 9:16:54 AM12/20/19
to SpaDES Users
A dirty fix would be this:


so I changed line 634 to

 nextLocs <- nextLocs[,.SD[findInterval(probLoc[id], sort (cumsum(prob/sum(prob)))) + 1],
by = id, .SDcols = c("x", "y", "prob")]

Now it seems to run further,  even though cumsum should already be non-decreasing on its own. 

sarah.b...@gmail.com

unread,
Dec 26, 2019, 5:52:43 AM12/26/19
to SpaDES Users
Hi Clara,
Do you use the version currently on GitHub or a version a bit modified? Because I downloaded the wolfAlps module on GitHub and ran it a few times by modifying only MeanPixelQuality to 0.94 and I don't have any error.

Sarah
Reply all
Reply to author
Forward
0 new messages