I have a very large data set of 150,000 points. I am loading this data set into a FluidDataSet, then converting that to a KDTree. Then I am searching that KDTree with elements that I know are in the set. 90% of the time, it gives me the same incorrect answer - 143100. 10% of the time it gives me the correct answer. So, it is either the same exact wrong answer or the correct answer and nothing else.
Here is the SC code:
~set = FluidDataSet(s, “synth”, 4);
~set.read("/Users/spluta/Documents/SC/FluCoMA/synthAnalysis/synthAnalysisDataSet.json", {“done”.postln})
~setKDTree = FluidKDTree.new();
~setKDTree.fit(“synth”, {“done”.postln})
x = Buffer.read(s, “/Users/spluta/Documents/SC/FluCoMA/synthAnalysis/synthAnalysisVarious.aif”);
x.loadToFloatArray(action:{arg vals; x = vals.clump(4)});
(
var rand;
{
a = Buffer.alloc(s, 4, 1);
b = Buffer.alloc(s, 4, 1);
"index into analysis: ".post;
rand = x.size.rand.postln;
"array at analysis: ".post;
a.setn(0, x[rand].postln);
s.sync;
~setKDTree.kNearest(a, 5, {|thePoint|
"nearest points in KDTree: ".post;
thePoint.postln
});
~set.getPoint(rand.asSymbol, b);
s.sync;
b.loadToFloatArray(action:{arg vals;
"the same point in the FluidDataSet that the KDTree is made from: ".post;
vals.postln
});
}.fork
)
Here is a sampling of the output:
index into analysis: 50163
array at analysis: [ 0.26637315750122, 0.18424999713898, 0.12581014633179, 0.3000465631485 ]
nearest points in KDTree: [ 143100, 90600, 90530, 135525, 98030 ]
the same point in the FluidDataSet that the KDTree is made from: FloatArray[ 0.26637315750122, 0.18424999713898, 0.12581014633179, 0.3000465631485 ]
-> a Routine
index into analysis: 42947
array at analysis: [ 0.10542738437653, 0.12532222270966, 0.039602041244507, 0.062839388847351 ]
nearest points in KDTree: [ 42947, 44072, 54197, 56072, 111577 ]
the same point in the FluidDataSet that the KDTree is made from: FloatArray[ 0.10542738437653, 0.12532222270966, 0.039602041244507, 0.062839388847351 ]
-> a Routine
index into analysis: 51697
array at analysis: [ 0.15139389038086, 0.13631534576416, 0.037152528762817, 0.17713236808777 ]
nearest points in KDTree: [ 143100, 90600, 90530, 135525, 98030 ]
the same point in the FluidDataSet that the KDTree is made from: FloatArray[ 0.15139389038086, 0.13631534576416, 0.037152528762817, 0.17713236808777 ]
-> a Routine
index into analysis: 149183
array at analysis: [ 0.42514955997467, 0.092134237289429, 0.0041602849960327, 0.20018994808197 ]
nearest points in KDTree: [ 143100, 90600, 90530, 135525, 98030 ]
the same point in the FluidDataSet that the KDTree is made from: FloatArray[ 0.42514955997467, 0.092134237289429, 0.0041602849960327, 0.20018994808197 ]
-> a Routine
index into analysis: 6947
array at analysis: [ 0.27852559089661, 0.18011999130249, 0.14657354354858, 0.18381690979004 ]
nearest points in KDTree: [ 6947, 127493, 3577, 44988, 44243 ]
the same point in the FluidDataSet that the KDTree is made from: FloatArray[ 0.27852559089661, 0.18011999130249, 0.14657354354858, 0.18381690979004 ]