[R] Fast evaluation of functions in 3D domains

David Winsemius dwinsemius at comcast.net
Mon Mar 23 22:50:11 CET 2015


On Mar 23, 2015, at 3:44 AM, <Lluis.Hurtado at uv.es> <Lluis.Hurtado at uv.es> wrote:

> Dear all,
> 
> I am currently working with the spatstat package with 3D samples. I am trying to 
> evaluate a non analytical function over the window that encloses the sample and I 
> need to know which is the fastest way of doing it.
> 
> The function input is a 3 coordinate position in the window (x,y,z) and a list of 
> parameters (a,b,c). The output is a numerical value. 
> 
> n <- function(x,y,z,a,b,c)

Perhaps:

dfrm <- as.data.frame.table(your_volume_matrix) 
n.out <- with(dfrm,  mapply( n, x=x, y=y, z=z, MoreArgs=list(a=a,b=b,c=c) ) _
dim(n.out) <- dim(your_volume_matrix)

You don't describe the form of this "3 coordinate position in the window (x,y,z)" so perhaps the arguments will need to be extracted. I took a WAG at one approach. If it's not in long-form, you need configure the array indices for either a volume or surface into a dataframe, perhaps with `expand.grid` or `as.data.frame.table`.

 You also don't describe the sort of integration you imagine. Why not a simple sum of that result divided by the volume? I cannot imagine any faster procedure.


> But I need to do it over the whole volume.
> 
> For 2 dimensions it can be done with
> 
> A <- as.im(function,window,parameters)
> norm <- integral.im(A)
> 
> For 3 dimensions I have tried to pass an array of a grid covering the window (like a 
> quadrature scheme) and then summing up the output array, but I would like to know if 
> there is any faster way of integrating the function.
> 
> Thank you very much,
> 
> Lluís Hurtado
> IFCA
> www.ifca.unican.es
> 
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius
Alameda, CA, USA



More information about the R-help mailing list