bluegreen-labs / skytrackr

A Sky Illuminance Location Tracker
https://bluegreen-labs.github.io/skytrackr/
GNU Affero General Public License v3.0
0 stars 0 forks source link

Spatially constrained priors #1

Closed khufkens closed 11 months ago

khufkens commented 1 year ago

Sampler is optional

# From BT docs on createPrior
density = function(par){
  d1 = dunif(par[1], -2,6, log =TRUE)
  d2 = dnorm(par[2], mean= 2, sd = 3, log =TRUE)
  return(d1 + d2)
}

sampler = function(n=1){
  d1 = runif(n, -2,6)
  d2 = rnorm(n, mean= 2, sd = 3)
  return(cbind(d1,d2))
}

prior <- createPrior(density = density, sampler = sampler, 
                     lower = c(-10,-20), upper = c(10,20), best = NULL)

Random sampling within an sf polygon

h = st_sample(sfc, 100, type = "hexagonal")

Can probably be combined to form a density function (however the third parameter is not spatially defined so needs a normal setup).

khufkens commented 1 year ago

Can also be done by constraining the objective function. In this case memoise needs to be used to ensure speed in calculation or provisioning of the spatial mask.