From 2a57d0a12782c7464e7fce8c018f42b1f973e7ae Mon Sep 17 00:00:00 2001 From: Pierre Alexandre Tremblay Date: Sun, 13 Dec 2020 20:40:32 +0000 Subject: [PATCH] edits to learning files with the new syntax --- .../1-learning examples/1a-starting-1D-example.scd | 9 +++------ .../2a-starting-1D-example2.scd | 4 ++-- .../1-learning examples/3a-classifier-example.scd | 5 +++-- .../1-learning examples/4-regressor-example.scd | 14 +++++++------- ...5-normalization-and-standardization-example.scd | 7 ++++--- .../7a-making-datasets-with-json.scd | 10 +++++++++- 6 files changed, 28 insertions(+), 21 deletions(-) diff --git a/release-packaging/Examples/dataset/1-learning examples/1a-starting-1D-example.scd b/release-packaging/Examples/dataset/1-learning examples/1a-starting-1D-example.scd index 7e51dcf..5c72f38 100644 --- a/release-packaging/Examples/dataset/1-learning examples/1a-starting-1D-example.scd +++ b/release-packaging/Examples/dataset/1-learning examples/1a-starting-1D-example.scd @@ -5,9 +5,8 @@ s.reboot Routine{ 10.do{|i| ~point.set(0,i); - s.sync; - ~ds.addPoint(i.asString,~point,{("addPoint"+i).postln}); - s.sync; + ~ds.addPoint(i.asString,~point,{("addPoint"+i).postln}); //because buffer.set do an immediate update in the RT thread we can take for granted it'll be updated when we call addPoint + s.sync; //but we need to sync to make sure everything is done on the DataSet before the next iteration } }.play ) @@ -22,7 +21,6 @@ Routine{ Routine{ 10.do{|i| ~point.set(0,i); - s.sync; ~tree.kNearest(~point, {|x| "Neighbours for a value of % are ".postf(i); x.postln}); s.sync; } @@ -39,7 +37,6 @@ Routine{ Routine{ 10.do{|i| ~point.set(0,i); - s.sync; ~kmeans.predictPoint(~point,{|x| ("Predicted Cluster for a value of " + i ++ ":" + x).postln}); s.sync; } @@ -73,4 +70,4 @@ Routine{ "Label for entry % is %\n".postf(key, x["data"][key][0]); } } -) \ No newline at end of file +) diff --git a/release-packaging/Examples/dataset/1-learning examples/2a-starting-1D-example2.scd b/release-packaging/Examples/dataset/1-learning examples/2a-starting-1D-example2.scd index 5e6517f..a6475b3 100644 --- a/release-packaging/Examples/dataset/1-learning examples/2a-starting-1D-example2.scd +++ b/release-packaging/Examples/dataset/1-learning examples/2a-starting-1D-example2.scd @@ -1,5 +1,5 @@ s.reboot -~ds = FluidDataSet.new(s,\simple1data) +~ds = FluidDataSet.new(s) ~point = Buffer.alloc(s,1,1) ( Routine{ @@ -41,8 +41,8 @@ Routine{ Routine{ 15.do{|i| ~point.set(0,i); - s.sync; ~kmeans.predictPoint(~point,{|x| ("Predicted Cluster for a value of " + i ++ ":" + x).postln}); + s.sync; } }.play ) diff --git a/release-packaging/Examples/dataset/1-learning examples/3a-classifier-example.scd b/release-packaging/Examples/dataset/1-learning examples/3a-classifier-example.scd index eb0855a..f9af7c8 100644 --- a/release-packaging/Examples/dataset/1-learning examples/3a-classifier-example.scd +++ b/release-packaging/Examples/dataset/1-learning examples/3a-classifier-example.scd @@ -1,6 +1,6 @@ ( -~simpleInput = FluidDataSet(s,\simpleInput); -~simpleOutput = FluidLabelSet(s,\simpleOutput); +~simpleInput = FluidDataSet(s); +~simpleOutput = FluidLabelSet(s); b = Buffer.alloc(s,2); ~knn = FluidKNNClassifier(s); ~knn.numNeighbours = 3 @@ -54,6 +54,7 @@ Routine{ ~simpleOutput.addLabel((i+50).asString,"Red",{("Added Output" + (i+50)).postln}); s.sync; } + \done.postln; }.play; ) diff --git a/release-packaging/Examples/dataset/1-learning examples/4-regressor-example.scd b/release-packaging/Examples/dataset/1-learning examples/4-regressor-example.scd index 313fdad..c8ef312 100644 --- a/release-packaging/Examples/dataset/1-learning examples/4-regressor-example.scd +++ b/release-packaging/Examples/dataset/1-learning examples/4-regressor-example.scd @@ -9,9 +9,10 @@ n = 200 // creates the dataset with these associated indices and values ( -~simpleInput = FluidDataSet(s,\simpleInput); -~simpleOutput = FluidDataSet(s,\simpleOutput); -b = Buffer.alloc(s,1,1); +~simpleInput = FluidDataSet(s); +~simpleOutput = FluidDataSet(s); +b = Buffer.alloc(s,1); +c = Buffer.alloc(s,1); ~mappingviz = Buffer.alloc(s,512); ) @@ -19,12 +20,11 @@ b = Buffer.alloc(s,1,1); Routine{ n.do{|i| b.set(0,~idx[i]); + c.set(0,~data[i]); ~simpleInput.addPoint(i.asString,b,{("Added Input" + i).postln}); + ~simpleOutput.addPoint(i.asString,c,{("Added Output" + i).postln}); + ~mappingviz.set((~idx[i]/61).asInteger,~data[i]); s.sync; - b.set(0,~data[i]); - ~simpleOutput.addPoint(i.asString,b,{("Added Output" + i).postln}); - s.sync; - ~mappingviz.set((~idx[i]/61).asInteger,~data[i]) } }.play ) diff --git a/release-packaging/Examples/dataset/1-learning examples/5-normalization-and-standardization-example.scd b/release-packaging/Examples/dataset/1-learning examples/5-normalization-and-standardization-example.scd index fc78214..6e305b8 100644 --- a/release-packaging/Examples/dataset/1-learning examples/5-normalization-and-standardization-example.scd +++ b/release-packaging/Examples/dataset/1-learning examples/5-normalization-and-standardization-example.scd @@ -1,7 +1,7 @@ ( // set some variables ~nb_of_dim = 10; -~dataset = FluidDataSet(s,\test,~nb_of_dim); +~dataset = FluidDataSet(s); ) ( @@ -14,6 +14,7 @@ Routine{ s.sync; }); buf.free; + \done.postln; }.play ) @@ -38,7 +39,7 @@ Routine{ ~normalize.fit(~dataset,{"done".postln;}); // making an empty 'normed_dataset' which is required for the normalize function -~normed_dataset = FluidDataSet(s,\normed,~nb_of_dim); +~normed_dataset = FluidDataSet(s); // normalize the full dataset ~normalize.transform(~dataset,~normed_dataset,{"done".postln;}); @@ -55,7 +56,7 @@ Routine{ ~standardize.fit(~dataset,{"done".postln;}); // standardize the full dataset -~standardized_dataset = FluidDataSet(s,\standardized,~nb_of_dim); +~standardized_dataset = FluidDataSet(s); ~standardize.transform(~dataset,~standardized_dataset,{"done".postln;}); // look at a point to see that it has points in it diff --git a/release-packaging/Examples/dataset/1-learning examples/7a-making-datasets-with-json.scd b/release-packaging/Examples/dataset/1-learning examples/7a-making-datasets-with-json.scd index fd11823..01b29e9 100644 --- a/release-packaging/Examples/dataset/1-learning examples/7a-making-datasets-with-json.scd +++ b/release-packaging/Examples/dataset/1-learning examples/7a-making-datasets-with-json.scd @@ -41,4 +41,12 @@ ~classifier = FluidKNNClassifier.new(s, numNeighbours:2); ~classifier.fit(~ds,~ls, {\done.postln;}) -~classifier.predictPoint(~target, action: {|x|x.postln;}) +// run many times for random pleasure +( +fork{ + var value = 7.rand; + ~ds.getPoint(("entry-"++value).asSymbol,~target); + s.sync; + ~classifier.predictPoint(~target, action: {|x|"entry % is an % entry.\n".postf(value,x);}) +} +) \ No newline at end of file