From fc0f762a3d21bf81116e513859c2ff370baa8844 Mon Sep 17 00:00:00 2001 From: Pierre Alexandre Tremblay Date: Wed, 4 Dec 2019 14:05:45 +0000 Subject: [PATCH] updated super simple examples with comments and new interface --- .../dataset/super-simple-1D-example.scd | 4 +- .../dataset/super-simple-1D-example2.scd | 6 +- .../super-simple-regressor-example.scd | 65 ++++++++++++------- 3 files changed, 47 insertions(+), 28 deletions(-) diff --git a/release-packaging/ignore/Examples/dataset/super-simple-1D-example.scd b/release-packaging/ignore/Examples/dataset/super-simple-1D-example.scd index 1306e25..0e6a240 100644 --- a/release-packaging/ignore/Examples/dataset/super-simple-1D-example.scd +++ b/release-packaging/ignore/Examples/dataset/super-simple-1D-example.scd @@ -13,7 +13,7 @@ Routine{ /*** KDTREE ***/ ~tree = FluidKDTree.new(s) -~tree.index(~ds,action:{"Done indexing".postln}) +~tree.fit(~ds,action:{"Done indexing".postln}) k = 5; //play with this ( @@ -32,6 +32,7 @@ Routine{ ~kmeans = FluidKMeans.new(s) ~nClusters = 4; //play with this ~kmeans.fit(~ds,~nClusters,100,action:{"Done fitting".postln}) + ( Routine{ 10.do{|i| @@ -45,6 +46,7 @@ Routine{ ~labels = FluidLabelSet(s,\simple1label); ~kmeans.predict(~ds,~labels, {|x| ("Size of each cluster" + x).postln}) + ( Routine{ var n; diff --git a/release-packaging/ignore/Examples/dataset/super-simple-1D-example2.scd b/release-packaging/ignore/Examples/dataset/super-simple-1D-example2.scd index 30b0a31..a74a305 100644 --- a/release-packaging/ignore/Examples/dataset/super-simple-1D-example2.scd +++ b/release-packaging/ignore/Examples/dataset/super-simple-1D-example2.scd @@ -15,15 +15,15 @@ Routine{ /*** KDTREE ***/ ~tree = FluidKDTree.new(s) -~tree.index(~ds,action:{"Done indexing".postln}) +~tree.fit(~ds,action:{"Done indexing".postln}) k = 5; //play with this ( Routine{ 10.do{|i| - ~point.set(0,i*10); + ~point.set(0,i*2); s.sync; - ("Neighbours for point" + (i*10)).postln; + ("Neighbours for point" + (i*2)).postln; ~tree.kNearest(~point, k, {|x| ("Labels:" + x).postln}); ~tree.kNearestDist(~point,k,{|x| ("Distances:" + x).postln}) } diff --git a/release-packaging/ignore/Examples/dataset/super-simple-regressor-example.scd b/release-packaging/ignore/Examples/dataset/super-simple-regressor-example.scd index 8c3f600..e8c4e95 100644 --- a/release-packaging/ignore/Examples/dataset/super-simple-regressor-example.scd +++ b/release-packaging/ignore/Examples/dataset/super-simple-regressor-example.scd @@ -1,46 +1,63 @@ s.reboot - ~urn = { |n=31416, min=0,max=31415| (min..max).scramble.keep(n) }; +// creates 200 indices, then values of the output of a fundion with a predictable shape of a sinewave n = 200 ~idx = ~urn.value(n) ~data = n.collect{|i|sin(~idx[i]/5000)} + +// creates the dataset with these associated indices and values ( ~simpleInput = FluidDataSet(s,\simpleInput,1); ~simpleOutput = FluidDataSet(s,\simpleOutput,1); b = Buffer.alloc(s,1,1); -~mappingviz = Buffer.alloc(s,31416,1); +~mappingviz = Buffer.alloc(s,512); ) + ( Routine{ -n.do{|i| - b.set(0,~idx[i]); - s.sync; - ~simpleInput.addPoint(i.asString,b,{("Added Input" + i).postln}); - b.set(0,~data[i]); - s.sync; - ~simpleOutput.addPoint(i.asString,b,{("Added Output" + i).postln}); - ~mappingviz.set(~idx[i].asInt,~data[i]) - } + n.do{|i| + b.set(0,~idx[i]); + s.sync; + ~simpleInput.addPoint(i.asString,b,{("Added Input" + i).postln}); + b.set(0,~data[i]); + s.sync; + ~simpleOutput.addPoint(i.asString,b,{("Added Output" + i).postln}); + ~mappingviz.set((~idx[i]/61).asInt,~data[i]) + } }.play ) -( -~simpleInput.clear; -~simpleOutput.clear; -) -3%2 + +//look at the seeing material ~mappingviz.plot(minval:-1,maxval:1) -~mappingresult = Buffer.alloc(s,31416,1); +//create a buffer to query +~mappingresult = Buffer.alloc(s,512); +//make the process then fit the data ~knn = FluidKNN(s) -~knn.index(~simpleInput,action:{"index done".postln}) +~knn.fit(~simpleInput,action:{"fitting done".postln}) + +// 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 +Routine{ + 512.do{|i| + b.set(0,i*61); + s.sync; + ~knn.regressPoint(b,~simpleOutput,k,action:{|d|~mappingresult.set(i,d);}); + s.sync; + i.postln; + } +}.play +) + +// look at the interpolated values +~mappingresult.plot - 512.do{|i| - b.set(0,i); - ~knn.regress(b,~simpleOutput,1,action:{|d|~mappingresult.set(i,d)}); - // if(i%512 == 0, {i.postln; s.sync},{}); -} -) \ No newline at end of file +// clears both datasets +( +~simpleInput.clear; +~simpleOutput.clear; +)