From 2ef9d586358f8d42a23a6f87d6ceac6f57741e5a Mon Sep 17 00:00:00 2001 From: Owen Green Date: Wed, 20 May 2020 20:44:10 +0100 Subject: [PATCH 1/6] Add dump in the dataset help file, and I really am on leave, honest --- .../HelpSource/Classes/FluidDataSet.schelp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/release-packaging/HelpSource/Classes/FluidDataSet.schelp b/release-packaging/HelpSource/Classes/FluidDataSet.schelp index 418158e..4a3733d 100644 --- a/release-packaging/HelpSource/Classes/FluidDataSet.schelp +++ b/release-packaging/HelpSource/Classes/FluidDataSet.schelp @@ -144,4 +144,16 @@ Routine{ } }.play ) + +//Inspect the dataset using print (abbreviated output) or dump (JSON output) + +~ds.print //to post window by default, but you can supply a custom action instead +~ds.dump //likewise +//for example +~ds.dump{|j| + ~dict = j.parseJSON +} +//Now we have a Dictionary of our data and IDs +~dict.postcs + :: From f27989dd84b72bb8bfffcdbc322455505e50b4e5 Mon Sep 17 00:00:00 2001 From: Pierre Alexandre Tremblay Date: Wed, 20 May 2020 22:39:02 +0100 Subject: [PATCH 2/6] typo found --- release-packaging/HelpSource/Classes/FluidKNNRegressor.schelp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/release-packaging/HelpSource/Classes/FluidKNNRegressor.schelp b/release-packaging/HelpSource/Classes/FluidKNNRegressor.schelp index 7eb7625..e5d576c 100644 --- a/release-packaging/HelpSource/Classes/FluidKNNRegressor.schelp +++ b/release-packaging/HelpSource/Classes/FluidKNNRegressor.schelp @@ -15,7 +15,7 @@ The server to run this model on. INSTANCEMETHODS:: METHOD:: fit -Map a source link::Classes/FluidDataSet:: to a target; they must be the same size, but can have different dimesionality +Map a source link::Classes/FluidDataSet:: to a target; they must be the same size, but can have different dimensionality ARGUMENT:: sourceDataset Source data ARGUMENT:: targetDataset From af9ac0332a8824c5a0acc15199e95662c304b666 Mon Sep 17 00:00:00 2001 From: Pierre Alexandre Tremblay Date: Wed, 20 May 2020 23:05:02 +0100 Subject: [PATCH 3/6] commenting the buffer input to FluidKMeans to avoid errors. --- release-packaging/Classes/FluidKMeans.sc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/release-packaging/Classes/FluidKMeans.sc b/release-packaging/Classes/FluidKMeans.sc index 22b95f7..daf8d61 100644 --- a/release-packaging/Classes/FluidKMeans.sc +++ b/release-packaging/Classes/FluidKMeans.sc @@ -14,8 +14,9 @@ FluidKMeans : FluidManipulationClient { fit{|dataset,k, maxIter = 100, buffer, action| buffer = buffer ? -1; this.k = k; - this.prSendMsg(\fit,[dataset.asSymbol, k,maxIter, buffer.asUGenInput],action,[numbers(FluidMessageResponse,_,k,_)]); - } + // this.prSendMsg(\fit,[dataset.asSymbol, k,maxIter, buffer.asUGenInput],action,[numbers(FluidMessageResponse,_,k,_)]); + this.prSendMsg(\fit,[dataset.asSymbol, k,maxIter],action,[numbers(FluidMessageResponse,_,k,_)]); + } fitPredict{|dataset,labelset, k, maxIter = 100, action| this.k = k; From 82f3efe98df6ccda647ddc686164c7af92f16252 Mon Sep 17 00:00:00 2001 From: Pierre Alexandre Tremblay Date: Wed, 20 May 2020 23:05:24 +0100 Subject: [PATCH 4/6] updating the Example folder - part 1 --- release-packaging/Examples/dataset/myfirstdataset.scd | 6 +++--- .../Examples/dataset/super-simple-1D-example.scd | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/release-packaging/Examples/dataset/myfirstdataset.scd b/release-packaging/Examples/dataset/myfirstdataset.scd index 508fd85..0c821de 100644 --- a/release-packaging/Examples/dataset/myfirstdataset.scd +++ b/release-packaging/Examples/dataset/myfirstdataset.scd @@ -22,14 +22,14 @@ FileDialog.new(fileMode:2,okFunc:{|x| ~path = x[0]; ) //STEP 2: Make a FluidDataSet -~dataset = FluidDataSet.new(s,"mfccs", 96) //12 dims * 4 stats * 2 derivatives +~dataset = FluidDataSet.new(s,"mfccs"); //STEP 3A: EITHER populate the dataset like so (and cry about how long the data point assembly takes) ( Routine{ var tmpMFCCs = Buffer.new(s); var tmpStats = Buffer.new(s); - var tmpFlat = Buffer.alloc(s,12 * 4 * 2, 1); + var tmpFlat = Buffer.alloc(s,12 * 4 * 2, 1);//12 dims * 4 stats * 2 derivatives s.sync; ~audioBuffers.do{|b| ("Analyzing" + b.path).postln; @@ -61,7 +61,7 @@ Routine{ var tmpStats = Buffer.new(s); var langStats; var langFlat; - var tmpFlat = Buffer.alloc(s,12 * 4 * 2, 1); + var tmpFlat = Buffer.alloc(s,12 * 4 * 2, 1); //12 dims * 4 stats * 2 derivatives s.sync; ~audioBuffers.do{|b| ("Analyzing" + b.path).postln; diff --git a/release-packaging/Examples/dataset/super-simple-1D-example.scd b/release-packaging/Examples/dataset/super-simple-1D-example.scd index 0e6a240..43fa2f9 100644 --- a/release-packaging/Examples/dataset/super-simple-1D-example.scd +++ b/release-packaging/Examples/dataset/super-simple-1D-example.scd @@ -1,5 +1,5 @@ s.reboot -~ds = FluidDataSet.new(s,\simple1data,1) +~ds = FluidDataSet.new(s,\simple1data) ~point = Buffer.alloc(s,1,1) ( Routine{ @@ -50,8 +50,9 @@ Routine{ ( Routine{ var n; - ~labels.size({|x| n = x.asInt}); - n.asInt.do{|i| + ~labels.size({|x| n = x.asInteger;}); + n.postln; + n.do{|i| ~labels.getLabel(i.asString,action: {|l|("Label for" + i ++ ":" + l).postln}); } }.play From e89df42917878ab8df5aa1f5498f37da32d2ba09 Mon Sep 17 00:00:00 2001 From: Pierre Alexandre Tremblay Date: Wed, 20 May 2020 23:15:45 +0100 Subject: [PATCH 5/6] updating examples --- .../Examples/dataset/super-simple-1D-example.scd | 13 +++++-------- .../dataset/super-simple-1D-example2.scd | 16 ++++++++-------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/release-packaging/Examples/dataset/super-simple-1D-example.scd b/release-packaging/Examples/dataset/super-simple-1D-example.scd index 43fa2f9..3e8d2b6 100644 --- a/release-packaging/Examples/dataset/super-simple-1D-example.scd +++ b/release-packaging/Examples/dataset/super-simple-1D-example.scd @@ -30,8 +30,8 @@ Routine{ /*** KMEANS ***/ ~kmeans = FluidKMeans.new(s) -~nClusters = 4; //play with this -~kmeans.fit(~ds,~nClusters,100,action:{"Done fitting".postln}) +~nClusters = 2; //play with this +~kmeans.fit(~ds,~nClusters,100,action:{|x| "Done fitting with these number of items per cluster ".post;x.postln;}) ( Routine{ @@ -50,12 +50,9 @@ Routine{ ( Routine{ var n; - ~labels.size({|x| n = x.asInteger;}); - n.postln; - n.do{|i| + ~labels.size({|x| + x.asInteger.do{|i| ~labels.getLabel(i.asString,action: {|l|("Label for" + i ++ ":" + l).postln}); - } + };}); }.play ) - - diff --git a/release-packaging/Examples/dataset/super-simple-1D-example2.scd b/release-packaging/Examples/dataset/super-simple-1D-example2.scd index a74a305..5a22bb9 100644 --- a/release-packaging/Examples/dataset/super-simple-1D-example2.scd +++ b/release-packaging/Examples/dataset/super-simple-1D-example2.scd @@ -1,5 +1,5 @@ s.reboot -~ds = FluidDataSet.new(s,\simple1data,1) +~ds = FluidDataSet.new(s,\simple1data) ~point = Buffer.alloc(s,1,1) ( Routine{ @@ -34,7 +34,8 @@ Routine{ ~kmeans = FluidKMeans.new(s) ~nClusters = 2; //play with this -~kmeans.fit(~ds,~nClusters,100,action:{"Done fitting".postln}) +~kmeans.fit(~ds,~nClusters,100,action:{|x| "Done fitting with these number of items per cluster ".post;x.postln;}) + ( Routine{ 10.do{|i| @@ -48,14 +49,13 @@ Routine{ ~labels = FluidLabelSet(s,\simple1label); ~kmeans.predict(~ds,~labels, {|x| ("Size of each cluster" + x).postln}) -( + +s( Routine{ var n; - ~labels.size({|x| n = x.asInt}); - n.asInt.do{|i| + ~labels.size({|x| + x.asInteger.do{|i| ~labels.getLabel(i.asString,action: {|l|("Label for" + i ++ ":" + l).postln}); - } + };}); }.play ) - - From 95f3f7411b697b9ed21279bd24b03c777ca265b1 Mon Sep 17 00:00:00 2001 From: Pierre Alexandre Tremblay Date: Wed, 20 May 2020 23:30:28 +0100 Subject: [PATCH 6/6] corrected help typo and updated the last examples --- .../dataset/super-simple-classifier-example.scd | 6 +++--- ...-simple-normalization-standardization-example.scd | 12 ++++++------ .../HelpSource/Classes/FluidKNNClassifier.schelp | 3 --- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/release-packaging/Examples/dataset/super-simple-classifier-example.scd b/release-packaging/Examples/dataset/super-simple-classifier-example.scd index 8c58f29..855035f 100644 --- a/release-packaging/Examples/dataset/super-simple-classifier-example.scd +++ b/release-packaging/Examples/dataset/super-simple-classifier-example.scd @@ -1,6 +1,6 @@ ( -~simpleInput = FluidDataSet(s,\simpleInput,2); -~simpleOutput = FluidLabelSet(s,\simpleOutput,2); +~simpleInput = FluidDataSet(s,\simpleInput); +~simpleOutput = FluidLabelSet(s,\simpleOutput); b = Buffer.alloc(s,2); ~knn = FluidKNNClassifier(s); k = 3 @@ -23,7 +23,7 @@ v.mouseDownAction = {|view, x, y|myx=x;myy=y;w.refresh; Routine{ b.setn(0,[myx,myy]); s.sync; - ~knn.predictPoint(b, k, {|x|x.postln;}); + ~knn.predictPoint(b, k, action: {|x|x.postln;}); }.play;}; //custom redraw function diff --git a/release-packaging/Examples/dataset/super-simple-normalization-standardization-example.scd b/release-packaging/Examples/dataset/super-simple-normalization-standardization-example.scd index 62193a4..8604714 100644 --- a/release-packaging/Examples/dataset/super-simple-normalization-standardization-example.scd +++ b/release-packaging/Examples/dataset/super-simple-normalization-standardization-example.scd @@ -39,7 +39,7 @@ ~normed_dataset = FluidDataSet(s,\normed,~nb_of_dim); // normalize the full dataset -~normalize.normalize(~dataset,~normed_dataset,{"done".postln;}); +~normalize.transform(~dataset,~normed_dataset,{"done".postln;}); // look at a point to see that it has points in it ~normed_dataset.getPoint("point-0",~query_buf,{~query_buf.getn(0,~nb_of_dim,{|x|x.postln;});}); @@ -54,7 +54,7 @@ // standardize the full dataset ~standardized_dataset = FluidDataSet(s,\standardized,~nb_of_dim); -~standardize.standardize(~dataset,~standardized_dataset,{"done".postln;}); +~standardize.transform(~dataset,~standardized_dataset,{"done".postln;}); // look at a point to see that it has points in it ~standardized_dataset.getPoint("point-0",~query_buf,{~query_buf.getn(0,~nb_of_dim,{|x|x.postln;});}); @@ -79,7 +79,7 @@ // normalise that point (~query_buf) to be at the right scale ~normbuf = Buffer.alloc(s,~nb_of_dim); -~normalize.normalizePoint(~query_buf,~normbuf); +~normalize.transformPoint(~query_buf,~normbuf); ~normbuf.getn(0,~nb_of_dim,{arg vec;vec.postln;}); // make a tree of the normalized database and query with the normalize buffer @@ -91,7 +91,7 @@ // standardize that same point (~query_buf) to be at the right scale ~stdbuf = Buffer.alloc(s,~nb_of_dim); -~standardize.standardizePoint(~query_buf,~stdbuf); +~standardize.transformPoint(~query_buf,~stdbuf); ~stdbuf.getn(0,~nb_of_dim,{arg vec;vec.postln;}); // make a tree of the standardized database and query with the normalize buffer @@ -107,8 +107,8 @@ ~query_buf.fill(0,~nb_of_dim,50); // normalize and standardize the query buffer. Note that we do not need to fit since we have not added a point to our reference dataset -~normalize.normalizePoint(~query_buf,~normbuf); -~standardize.standardizePoint(~query_buf,~stdbuf); +~normalize.transformPoint(~query_buf,~normbuf); +~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});}); diff --git a/release-packaging/HelpSource/Classes/FluidKNNClassifier.schelp b/release-packaging/HelpSource/Classes/FluidKNNClassifier.schelp index eac0ecb..d76b446 100644 --- a/release-packaging/HelpSource/Classes/FluidKNNClassifier.schelp +++ b/release-packaging/HelpSource/Classes/FluidKNNClassifier.schelp @@ -105,9 +105,6 @@ fork{ } ) -//Dims of kmeans should match dataset -~kmeans.cols - //Return labels of clustered points ( ~assignments = Array.new(~testpoints.size);