KDTreee help file review

nix
Gerard 6 years ago
parent d5f692cf0e
commit c3e90529aa

@ -56,60 +56,50 @@ A function that will run when the query returns, whose argument is an array of d
EXAMPLES:: EXAMPLES::
code:: code::
//Make some 2D points and place into a dataset
s.reboot;
(
~points = 100.collect{ [ 1.0.linrand,1.0.linrand] };
~dataset= FluidDataSet(s,\kdtree_help_rand2d);
~tmpbuf = Buffer.alloc(s,2);
fork{
s.bind{
~dataset.ready.wait;
~points.do{|x,i|
(""++(i+1)++"/100").postln;
~tmpbuf.setn(0,x);
~dataset.addPoint(i,~tmpbuf);
s.sync
};
"Data loaded".postln;
}
}
)
//Make a new tree, and fit it to the dataset
// Make a dataset of random 23D points
s.boot;
( (
fork{ fork{
~tree = FluidKDTree(s); ~ds = FluidDataSet.new(s,\kdtree_help_rand2d);
~tree.ready.wait; d = Dictionary.with(
s.sync; *[\cols -> 2,\data -> Dictionary.newFrom(
~tree.fit(~dataset); 100.collect{|i| [i, [ 1.0.linrand,1.0.linrand]]}.flatten)]);
s.sync;
~ds.load(d, {~ds.print});
} }
) )
//Dims of tree should match dataset // Make a new tree, and fit it to the dataset
~tree.cols ~tree = FluidKDTree(s);
//Return labels of k nearest points to new data //Fit it to the dataset
( ~tree.fit(~ds);
~testpoint = [ 1.0.linrand,1.0.linrand ];
("\n\nTest point:" + ~testpoint).postln; // Should be 100 points, 2 columns
~tmpbuf.setn(0,~testpoint); ~tree.size;
~tree.cols;
//Return labels of k nearest points to a new point
~p = [ 1.0.linrand,1.0.linrand ];
~tmpbuf = Buffer.loadCollection(s, ~p, 1, {
~tree.kNearest(~tmpbuf,5, { |a|~nearest = a;})
});
// Labels of nearest points
~nearest.postln;
// Values
fork{ fork{
~tree.kNearest(~tmpbuf,5, { |a| ~nearest.do{|n|
("Labels of nearest points" + a).postln; ~ds.getPoint(n, ~tmpbuf, {~tmpbuf.getn(0, 2, {|x|x.postln})});
"Nearest points".postln; s.sync;
a.do{|l| }
~dataset.getPoint(l,~tmpbuf,action:{
~tmpbuf.loadToFloatArray(action:{ |point|
point.postln;
})
});
s.sync;
}
});
} }
)
//or the distances //Distances of the nearest points
~tree.kNearestDist(~tmpbuf,5, { |a| a.postln }); ~tree.kNearestDist(~tmpbuf, 5, { |a| a.postln });
:: ::

Loading…
Cancel
Save