kernel density

13 views
Skip to first unread message

andrea antonello

unread,
Jul 6, 2011, 7:46:40 AM7/6/11
to jai-...@googlegroups.com
Hi folks,
I wanted to add a kernel density module to the jgrasstools.

For what I see there are already all the different kernels implemented
in the KernelFactory (this is a library!). I was wondering if there is
already also an operator that would calculate the kernel density that
I missed to see? In that case I would just wrap it in jgrasstools, as
I did with many other modules :)

Thanks for any insight,
Ciao,
Andrea

Michael Bedward

unread,
Jul 6, 2011, 8:13:00 AM7/6/11
to jai-...@googlegroups.com
Hi Andrea,

There isn't an operator in JAITools for it (yet). Ian T might be the
best person to talk to since he has a spatial cluster project on the
go:

http://code.google.com/p/spatial-cluster-detection/

Otherwise I'm sure we could cook something up.

Michael

> --
> You received this message because you are subscribed to the Google Groups "jai-tools" group.
> To post to this group, send email to jai-...@googlegroups.com.
> To unsubscribe from this group, send email to jai-tools+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/jai-tools?hl=en.
>
>

andrea antonello

unread,
Jul 6, 2011, 8:17:32 AM7/6/11
to jai-...@googlegroups.com
Hi Michael,

> There isn't an operator in JAITools for it (yet).  Ian T might be the
> best person to talk to since he has a spatial cluster project on the
> go:
>
> http://code.google.com/p/spatial-cluster-detection/

I looked that up already but it looks a bit in progress.

> Otherwise I'm sure we could cook something up.

I am really no expert, but in conjunction with the kernelstats
wouldn't that work somehow?
I have to look up the denisty estimation properly, but I felt it would
be some kind of average on a particular kernel?

Andrea

Michael Bedward

unread,
Jul 6, 2011, 8:30:35 AM7/6/11
to jai-...@googlegroups.com
On 6 July 2011 22:17, andrea antonello <andrea.a...@gmail.com> wrote:
> I am really no expert, but in conjunction with the kernelstats
> wouldn't that work somehow?
> I have to look up the denisty estimation properly, but I felt it would
> be some kind of average on a particular kernel?
>

Mmm... maybe, not sure. It's a bit too late here for sharp thinking.

I visualize it as like a convolution but with the roles of
neighbourhood and key element (aka target) cells reversed. So, if you
were working with point data, the process is to position the kernel
key element over each data point in turn and then add the value of
each kernel cell to the underlying destination image cell.

I could write some example code for this tomorrow if you don't find
anything in the meantime. However right now I have to switch off the
computer for the night, pour myself a whiskey and watch a bit of Le
Tour.

Michael

andrea antonello

unread,
Jul 6, 2011, 8:34:42 AM7/6/11
to jai-...@googlegroups.com
[...]

> Mmm... maybe, not sure. It's a bit too late here for sharp thinking.
>
> I visualize it as like a convolution but with the roles of
> neighbourhood and key element (aka target) cells reversed. So, if you
> were working with point data, the process is to position the kernel
> key element over each data point in turn and then add the value of
> each kernel cell to the underlying destination image cell.

Assuming points rasterized, I thought that would happen with the
KernelStats module. Does that one sum or substitute the values? Or
does it do the key element? It is not late here, but I am gone already
anyways...

> I could write some example code for this tomorrow if you don't find
> anything in the meantime. However right now I have to switch off the
> computer for the night, pour myself a whiskey and watch a bit of Le
> Tour.

Enyoj, I will look a bit deeper into it.

Ciao,
Andrea


>
> Michael

andrea antonello

unread,
Jul 6, 2011, 10:38:22 AM7/6/11
to jai-...@googlegroups.com
Just a note adding info I got out of various docs and Jan's code.

Assuming to have a raster of "point" values, doing kernel density on a
map should be as much as:


for( int c = pRadius; c < cols - pRadius; c++ ) {
for( int r = pRadius; r < rows - pRadius; r++ ) {
double inputValue = inIter.getSampleDouble(c, r, 0);
if (isNovalue(inputValue)) {
continue;
}

int k = 0;
for( int kc = -pRadius; kc <= pRadius; kc++ ) {
for( int kr = -pRadius; kr <= pRadius; kr++, k++ ) {
double outputValue = outIter.getSampleDouble(c
+ kc, r + kr, 0);
if (isNovalue(outputValue)) {
outputValue = 0;
}
outputValue = outputValue + kernelData[k] * inputValue;
outIter.setSample(c + kc, r + kr, 0, outputValue);
}
}
}
}

Were the kernel would be chosen between one of the many you give:

ValueType type = KernelFactory.ValueType.EPANECHNIKOV;
switch( pKernel ) {
case 0:
type = KernelFactory.ValueType.BINARY;
break;
case 1:
type = KernelFactory.ValueType.COSINE;
break;
case 2:
type = KernelFactory.ValueType.DISTANCE;
break;
case 4:
type = KernelFactory.ValueType.GAUSSIAN;
break;
case 5:
type = KernelFactory.ValueType.INVERSE_DISTANCE;
break;
case 6:
type = KernelFactory.ValueType.QUARTIC;
break;
case 7:
type = KernelFactory.ValueType.TRIANGULAR;
break;
case 8:
type = KernelFactory.ValueType.TRIWEIGHT;
break;
}

KernelJAI kernel = KernelFactory.createCircle(pRadius, type);


How does that look to you (and Jan obviously, your suggestion would be
amazing, I just didn't want to bother you since I felt you were moving
:) )?


Ciao,
Andrea

Michael Bedward

unread,
Jul 7, 2011, 12:47:53 AM7/7/11
to jai-...@googlegroups.com
Hi Andrea,

I haven't tested your code but it looks good to me.

This reminds me that I'd like to have a better kernel class in
JAITools. Sometimes it would be good to have the kernel values as type
double or even type int rather than float. The standard Convolve
operator is welded to the KernelJAI.getFloatData method but JAITools
MaskedConvolve could be extended to work with a more flexible kernel
class.

Also, it would be cool and quite easy to add a kernel density operator
that took a Collection of vector points (Coordinates, JTS Points, AWT
Points) rather than a source image of rasterized points. We could get
it to handled line vectors as well.

Michael

Ian Turton

unread,
Jul 7, 2011, 12:50:41 PM7/7/11
to jai-...@googlegroups.com
On 6 July 2011 08:17, andrea antonello <andrea.a...@gmail.com> wrote:
> Hi Michael,
>
>> There isn't an operator in JAITools for it (yet).  Ian T might be the
>> best person to talk to since he has a spatial cluster project on the
>> go:
>>
>> http://code.google.com/p/spatial-cluster-detection/
>
> I looked that up already but it looks a bit in progress.
>

Actually it's pretty much finished, except for the WPS wrapper which I
haven't had a chance to finish off.

>> Otherwise I'm sure we could cook something up.
>
> I am really no expert, but in conjunction with the kernelstats
> wouldn't that work somehow?
> I have to look up the denisty estimation properly, but I felt it would
> be some kind of average on a particular kernel?

What sort of Kernel density do you want?

Ian

andrea antonello

unread,
Jul 8, 2011, 3:40:44 AM7/8/11
to jai-...@googlegroups.com
[...]

>> I looked that up already but it looks a bit in progress.
>>
>
> Actually it's pretty much finished, except for the WPS wrapper which I
> haven't had a chance to finish off.

Sorry, I looked only into the kernel classes and there were some
previous and some based on jaitools, so I figured that there would be
some unused stuff and therefore in transition.

>>> Otherwise I'm sure we could cook something up.
>>
>> I am really no expert, but in conjunction with the kernelstats
>> wouldn't that work somehow?
>> I have to look up the denisty estimation properly, but I felt it would
>> be some kind of average on a particular kernel?
>
> What sort of Kernel density do you want?

Well, to make a generic tool, several would be nice to have. Michael
already has all the ones I read up in wikipedia.
In fact I am getting nice results proceeding with the loop I posted an
email ago.
Were you planning to do something generic in geotools?

Andrea


>
> Ian

Reply all
Reply to author
Forward
0 new messages