Update dataest examples to interface changes

nix
Owen Green 6 years ago
parent 11c3f8818d
commit 603d309f0d

@ -150,7 +150,8 @@ FluidBufCompose.process(s,~loader.buffer,a,(b-a),numChans: 1, destination: ~targ
//find its nearest neighbours
~friends = Array;
~tree.kNearest(~flatbuf[0],5,{|x| ~friends = x.postln;})
~tree.numNeighbours = 5;
~tree.kNearest(~flatbuf[0],{|x| ~friends = x.postln;})
// play them in a row
(

@ -16,12 +16,12 @@ Routine{
~tree = FluidKDTree.new(s)
~tree.fit(~ds,action:{"Done indexing".postln})
k = 5; //play with this
~tree.numNeighbours = 5; //play with this
(
Routine{
10.do{|i|
~point.set(0,i);
~tree.kNearest(~point, k, {|x| "Neighbours for a value of % are ".postf(i); x.postln});
~tree.kNearest(~point, {|x| "Neighbours for a value of % are ".postf(i); x.postln});
s.sync;
}
}.play
@ -29,9 +29,9 @@ Routine{
/*** KMEANS ***/
~kmeans = FluidKMeans.new(s)
~nClusters = 2; //play with this
~kmeans.fit(~ds,~nClusters,100,action:{|x| "Done fitting with these number of items per cluster ".post;x.postln;})
~kmeans = FluidKMeans.new(s,maxIter:100)
~kmeans.numClusters = 2; //play with this
~kmeans.fit(~ds,action:{|x| "Done fitting with these number of items per cluster ".post;x.postln;})
(
Routine{

@ -18,13 +18,13 @@ Routine{
~tree = FluidKDTree.new(s)
~tree.fit(~ds,action:{"Done indexing".postln})
k = 5; //play with this
~tree.numNeighbours = 5; //play with this
(
Routine{
15.do{|i|
~point.set(0,i);
~tree.kNearest(~point, k, {|x| "Neighbours for a value of % are ".postf(i); x.post;" with respective distances of ".post;});
~tree.kNearestDist(~point,k,{|x| x.postln});
~tree.kNearest(~point, {|x| "Neighbours for a value of % are ".postf(i); x.post;" with respective distances of ".post;});
~tree.kNearestDist(~point, {|x| x.postln});
s.sync;
}
}.play
@ -33,9 +33,9 @@ Routine{
/*** KMEANS ***/
~kmeans = FluidKMeans.new(s)
~nClusters = 2; //play with this
~kmeans.fit(~ds,~nClusters,100,action:{|x| "Done fitting with these number of items per cluster ".post;x.postln;})
~kmeans = FluidKMeans.new(s,maxIter:100)
~kmeans.numClusters = 2; //play with this
~kmeans.fit(~ds, action:{|x| "Done fitting with these number of items per cluster ".post;x.postln;})
(
Routine{

@ -3,7 +3,7 @@
~simpleOutput = FluidLabelSet(s,\simpleOutput);
b = Buffer.alloc(s,2);
~knn = FluidKNNClassifier(s);
k = 3
~knn.numNeighbours = 3
)
(
@ -22,7 +22,7 @@ v.mouseDownAction = {|view, x, y|myx=x;myy=y;w.refresh;
// myx.postln;myy.postln;
Routine{
b.setn(0,[myx,myy]);
~knn.predictPoint(b, k, action: {|x|x.postln;});
~knn.predictPoint(b, action: {|x|x.postln;});
s.sync;
}.play;};

@ -13,12 +13,11 @@
~ds.print
//fun with kdtree to see it actually works
~kdtree = FluidKDTree.new(s)
~kdtree = FluidKDTree.new(s,numNeighbours:5)
~kdtree.fit(~ds,{\done.postln;})
~target = Buffer.loadCollection(s,(4).dup(10));
~kdtree.kNearest(~target,5,{|a|a.postln;})
~kdtree.kNearestDist(~target,5,{|a|a.postln;})
~kdtree.kNearest(~target, {|a|a.postln;})
~kdtree.kNearestDist(~target, {|a|a.postln;})
/////////////////////////////////////////////
@ -39,7 +38,7 @@
~ls.print
// testin with a classifier toy example
~classifier = FluidKNNClassifier.new(s);
~classifier = FluidKNNClassifier.new(s, numNeighbours:2);
~classifier.fit(~ds,~ls, {\done.postln;})
~classifier.predictPoint(~target,2,action: {|x|x.postln;})
~classifier.predictPoint(~target, action: {|x|x.postln;})

@ -73,10 +73,10 @@ Routine{
~dataset.getPoint("point-7",~query_buf);
// find the 2 points with the shortest distances in the dataset
~tree = FluidKDTree.new(s);
~tree = FluidKDTree.new(s,numNeighbours:2);
~tree.fit(~dataset)
~tree.kNearest(~query_buf,2, {|x| ("Labels:" + x).postln});
~tree.kNearestDist(~query_buf,2, {|x| ("Distances:" + x).postln});
~tree.kNearest(~query_buf, {|x| ("Labels:" + x).postln});
~tree.kNearestDist(~query_buf, {|x| ("Distances:" + x).postln});
// its nearest neighbourg is itself: it should be itself and the distance should be 0. The second point is depending on your input dataset.
// normalise that point (~query_buf) to be at the right scale
@ -85,10 +85,10 @@ Routine{
~normbuf.getn(0,~nb_of_dim,{arg vec;vec.postln;});
// make a tree of the normalized database and query with the normalize buffer
~normtree = FluidKDTree.new(s);
~normtree = FluidKDTree.new(s,numNeighbours:2);
~normtree.fit(~normed_dataset)
~normtree.kNearest(~normbuf,2, {|x| ("Labels:" + x).postln});
~normtree.kNearestDist(~normbuf,2, {|x| ("Distances:" + x).postln});
~normtree.kNearest(~normbuf, {|x| ("Labels:" + x).postln});
~normtree.kNearestDist(~normbuf, {|x| ("Distances:" + x).postln});
// its nearest neighbourg is still itself as it should be, but the 2nd neighbourg will probably have changed. The distance is now different too
// standardize that same point (~query_buf) to be at the right scale
@ -97,10 +97,10 @@ Routine{
~stdbuf.getn(0,~nb_of_dim,{arg vec;vec.postln;});
// make a tree of the standardized database and query with the normalize buffer
~stdtree = FluidKDTree.new(s);
~stdtree = FluidKDTree.new(s, numNeighbours: 2);
~stdtree.fit(~standardized_dataset)
~stdtree.kNearest(~stdbuf,2, {|x| ("Labels:" + x).postln});
~stdtree.kNearestDist(~stdbuf,2, {|x| ("Distances:" + x).postln});
~stdtree.kNearest(~stdbuf, {|x| ("Labels:" + x).postln});
~stdtree.kNearestDist(~stdbuf, {|x| ("Distances:" + x).postln});
// its nearest neighbourg is still itself as it should be, but the 2nd neighbourg will probably have changed yet again. The distance is also different too
// where it starts to be interesting is when we query points that are not in our original dataset
@ -113,6 +113,7 @@ Routine{
~standardize.transformPoint(~query_buf,~stdbuf);
//query the single nearest neighbourg via 3 different data scaling. Depending on the random source at the begining, you will get small to large differences between the 3 answers!
~tree.kNearest(~query_buf,1, {|x| ("Original:" + x).post;~tree.kNearestDist(~query_buf,1, {|x| (" with a distance of " + x).postln});});
~normtree.kNearest(~normbuf,1, {|x| ("Normalized:" + x).post;~normtree.kNearestDist(~normbuf,1, {|x| (" with a distance of " + x).postln});});
~stdtree.kNearest(~stdbuf,1, {|x| ("Standardized:" + x).post; ~stdtree.kNearestDist(~stdbuf,1, {|x| (" with a distance of " + x).postln});});
[~tree,~normtree,~stdtree].do{|t| t.numNeighbours =1 };
~tree.kNearest(~query_buf, {|x| ("Original:" + x).post;~tree.kNearestDist(~query_buf,1, {|x| (" with a distance of " + x).postln});});
~normtree.kNearest(~normbuf, {|x| ("Normalized:" + x).post;~normtree.kNearestDist(~normbuf,1, {|x| (" with a distance of " + x).postln});});
~stdtree.kNearest(~stdbuf, {|x| ("Standardized:" + x).post; ~stdtree.kNearestDist(~stdbuf,1, {|x| (" with a distance of " + x).postln});});

@ -44,11 +44,11 @@ Routine{
// query 512 points along the line (slow because of all that sync'ing)
(
k = 1; // change to see how many points the system uses to regress
~knn.numNeighbours = 1; // change to see how many points the system uses to regress
Routine{
512.do{|i|
b.set(0,i*61);
~knn.predictPoint(b,k,action:{|d|~mappingresult.set(i,d);});
~knn.predictPoint(b,action:{|d|~mappingresult.set(i,d);});
s.sync;
i.postln;
}

Loading…
Cancel
Save