4D interpolation from scattered points

620 views
Skip to first unread message

Yakir Gagnon

unread,
May 13, 2015, 8:33:08 AM5/13/15
to julia...@googlegroups.com
I have a bunch (~1000) of x,y,z and a corresponding value, V. One unique V for each x,y,z. I want to interpolate and extrapolate "wildly" (so I really don't care about how accurate or correct it is). The x,y,z I have are not regularly spaced or anything. They're scattered across some range (they all share similar ranges), and I want to know what value (i.e. new V) I should be getting at new and regularly spaced x,y,z. I think Matlab's griddata would do what I want.
I tired following the "lower-level" functionality from Grid.jl, Interpolations.jl, and Dierckx.jl, but couldn't figure out how to get this to work. 
I think I need to fit some curve to my scattered points and then use that to find the values at the new xyz (at least that's how I think griddata works)... Any good simple ideas out there?

René Donner

unread,
May 13, 2015, 8:56:49 AM5/13/15
to julia...@googlegroups.com
You could use an ensemble regression approach - see https://github.com/rened/ExtremelyRandomizedTrees.jl#regression for a 1D to 1D example. For your data you could use this (ndims == 2, for visualization):

using ExtremelyRandomizedTrees, FunctionalDataUtils

# train model
ndim = 2
nsamples = 1000

data = 5+5*randn(ndim, nsamples)
targets = sum(data,1)
targets += randn(size(targets))

model = ExtraTrees(data, targets, regression = true)

# predict
a = meshgrid(1:20, 1:30)   # a is 2 x 20*30
result = reshape(predict(model, a), 20, 30)

using Images
convert(Image,asimagesc(result))

J Luis

unread,
May 13, 2015, 9:26:07 AM5/13/15
to julia...@googlegroups.com
Matlab does that with the interp3 function that, I believe, uses the qhull C lib. At least it used to use it and Octave does.
It would be nice to have a wrapper for this lib.

Nils Gudat

unread,
May 13, 2015, 9:30:07 AM5/13/15
to julia...@googlegroups.com
Have you looked at ApproXD.jl?
I wrote a gist comparing the functionality of Grid.jl, Dierckx.jl, ApproXD.jl and NumericalMath.jl a while ago (here), the ApproXD example in there generalizes easily to three dimensions.

Tim Holy

unread,
May 13, 2015, 9:31:05 AM5/13/15
to julia...@googlegroups.com
On Wednesday, May 13, 2015 06:26:07 AM J Luis wrote:
> Matlab does that with the interp3 function that, I believe, uses the qhull
> <http://www.qhull.org/>C lib. At least it used to use it and Octave does.
> It would be nice to have a wrapper for this lib.

There's a PyCall based wrapper here:
https://github.com/davidavdav/CHull.jl

--Tim

Yuuki Soho

unread,
May 13, 2015, 12:42:21 PM5/13/15
to julia...@googlegroups.com
Something simple you can do is to compute the distance from your new point to all the other points, and do a weighted average of their values depending on the distance,
using for example Gaussian weights.

Luke Stagner

unread,
May 13, 2015, 2:19:18 PM5/13/15
to julia...@googlegroups.com
Message has been deleted

Yakir Gagnon

unread,
May 13, 2015, 8:05:55 PM5/13/15
to julia...@googlegroups.com
Thanks a ton people!!!

ExtremelyRandomizedTrees.jl: Might be really good, but errored a lot on version 4.
ApproXD.jl: Very cool, I'll come back to that later, but for now: "What Lininterp cannot do: Multidimensional extrapolation" which I need (and accept is prone to silliness). Plus, according to the examples, the known xdata needs to be on a grid. My x,y,z are not equally spaced that way, they are scattered.
compute the distances: I started with that, and in light of these results I might fall back to doing just that. 
Polyharmonic Splines: does exactly what I want, but not faster than just distances (but probably a lot more accurate). 
CHull.jl: might be awesome for this, but I didn't quickly see how I can use it to interpolate and extrapolate.

I feel like I owe you guys some background: I have some color-map functions that take a value, let's call it X (for some 0<X<1 and for some -pi/2<X<pi/2) and return an RGB. I need to use these to convert images that have colors that are similar (but not always identical) to the RGB values from these color-maps back to the value (X) that would have resulted in said RGB (so it's like the inverse of those color-map functions). After much trial and error, I think that since the images I want to convert this way are all 8-bit, the fastest way would be to construct a lookup table for all 2^(8*3) possible RGB combinations. This table (Dict) will take any RGB value from those images I need to convert and return X. This makes sense because I have only 4 such color-map functions, and potentially endless amounts of images to convert (currently a couple of tera). 
So I think I'll use simple distances, run that once, save those lookup tables and use them again and again on new images. 

René Donner

unread,
May 14, 2015, 3:01:03 AM5/14/15
to julia...@googlegroups.com
> ExtremelyRandomizedTrees.jl: Might be really good, but errored a lot on version 4.

Sorry, the fixes for 0.4 were only in master - I tagged a new version (0.0.11) just now.

I use it mostly on 0.4, actually - if you find any issues please let me know!

Yakir Gagnon

unread,
May 18, 2015, 8:05:39 AM5/18/15
to julia...@googlegroups.com

I feel like I owe you all another explanation:

It’s all fixed and done. What I realized I needed was to dither an image. I had a bunch of RGB values that I wanted to fixate to a set number of other discrete RGB. imagemagick does exactly that with the -remap some_colormap.png command, where some_colormap is an image with the RGB values you want to describe the image with. This operation is super fast and does exactly what I want.

Thanks for the effort though! and I’m bound to revisit some of these packages/suggestions in the future!



Yakir Gagnon
The Queensland Brain Institute (Building #79)
The University of Queensland
Brisbane QLD 4072
Australia
work +61 (0)733 654 089

Florian Oswald

unread,
May 18, 2015, 10:42:13 AM5/18/15
to julia...@googlegroups.com
Hi there,
xdata (or any other grid) does not need to be on a grid, that's just the way the example is written. but no extrapolation, that's right.
Reply all
Reply to author
Forward
0 new messages