edits to learning files with the new syntax

nix
Pierre Alexandre Tremblay 5 years ago
parent a60104d536
commit 2a57d0a127

@ -5,9 +5,8 @@ s.reboot
Routine{ Routine{
10.do{|i| 10.do{|i|
~point.set(0,i); ~point.set(0,i);
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
~ds.addPoint(i.asString,~point,{("addPoint"+i).postln}); s.sync; //but we need to sync to make sure everything is done on the DataSet before the next iteration
s.sync;
} }
}.play }.play
) )
@ -22,7 +21,6 @@ Routine{
Routine{ Routine{
10.do{|i| 10.do{|i|
~point.set(0,i); ~point.set(0,i);
s.sync;
~tree.kNearest(~point, {|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; s.sync;
} }
@ -39,7 +37,6 @@ Routine{
Routine{ Routine{
10.do{|i| 10.do{|i|
~point.set(0,i); ~point.set(0,i);
s.sync;
~kmeans.predictPoint(~point,{|x| ("Predicted Cluster for a value of " + i ++ ":" + x).postln}); ~kmeans.predictPoint(~point,{|x| ("Predicted Cluster for a value of " + i ++ ":" + x).postln});
s.sync; s.sync;
} }
@ -73,4 +70,4 @@ Routine{
"Label for entry % is %\n".postf(key, x["data"][key][0]); "Label for entry % is %\n".postf(key, x["data"][key][0]);
} }
} }
) )

@ -1,5 +1,5 @@
s.reboot s.reboot
~ds = FluidDataSet.new(s,\simple1data) ~ds = FluidDataSet.new(s)
~point = Buffer.alloc(s,1,1) ~point = Buffer.alloc(s,1,1)
( (
Routine{ Routine{
@ -41,8 +41,8 @@ Routine{
Routine{ Routine{
15.do{|i| 15.do{|i|
~point.set(0,i); ~point.set(0,i);
s.sync;
~kmeans.predictPoint(~point,{|x| ("Predicted Cluster for a value of " + i ++ ":" + x).postln}); ~kmeans.predictPoint(~point,{|x| ("Predicted Cluster for a value of " + i ++ ":" + x).postln});
s.sync;
} }
}.play }.play
) )

@ -1,6 +1,6 @@
( (
~simpleInput = FluidDataSet(s,\simpleInput); ~simpleInput = FluidDataSet(s);
~simpleOutput = FluidLabelSet(s,\simpleOutput); ~simpleOutput = FluidLabelSet(s);
b = Buffer.alloc(s,2); b = Buffer.alloc(s,2);
~knn = FluidKNNClassifier(s); ~knn = FluidKNNClassifier(s);
~knn.numNeighbours = 3 ~knn.numNeighbours = 3
@ -54,6 +54,7 @@ Routine{
~simpleOutput.addLabel((i+50).asString,"Red",{("Added Output" + (i+50)).postln}); ~simpleOutput.addLabel((i+50).asString,"Red",{("Added Output" + (i+50)).postln});
s.sync; s.sync;
} }
\done.postln;
}.play; }.play;
) )

@ -9,9 +9,10 @@ n = 200
// creates the dataset with these associated indices and values // creates the dataset with these associated indices and values
( (
~simpleInput = FluidDataSet(s,\simpleInput); ~simpleInput = FluidDataSet(s);
~simpleOutput = FluidDataSet(s,\simpleOutput); ~simpleOutput = FluidDataSet(s);
b = Buffer.alloc(s,1,1); b = Buffer.alloc(s,1);
c = Buffer.alloc(s,1);
~mappingviz = Buffer.alloc(s,512); ~mappingviz = Buffer.alloc(s,512);
) )
@ -19,12 +20,11 @@ b = Buffer.alloc(s,1,1);
Routine{ Routine{
n.do{|i| n.do{|i|
b.set(0,~idx[i]); b.set(0,~idx[i]);
c.set(0,~data[i]);
~simpleInput.addPoint(i.asString,b,{("Added Input" + i).postln}); ~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; 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 }.play
) )

@ -1,7 +1,7 @@
( (
// set some variables // set some variables
~nb_of_dim = 10; ~nb_of_dim = 10;
~dataset = FluidDataSet(s,\test,~nb_of_dim); ~dataset = FluidDataSet(s);
) )
( (
@ -14,6 +14,7 @@ Routine{
s.sync; s.sync;
}); });
buf.free; buf.free;
\done.postln;
}.play }.play
) )
@ -38,7 +39,7 @@ Routine{
~normalize.fit(~dataset,{"done".postln;}); ~normalize.fit(~dataset,{"done".postln;});
// making an empty 'normed_dataset' which is required for the normalize function // 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 the full dataset
~normalize.transform(~dataset,~normed_dataset,{"done".postln;}); ~normalize.transform(~dataset,~normed_dataset,{"done".postln;});
@ -55,7 +56,7 @@ Routine{
~standardize.fit(~dataset,{"done".postln;}); ~standardize.fit(~dataset,{"done".postln;});
// standardize the full dataset // standardize the full dataset
~standardized_dataset = FluidDataSet(s,\standardized,~nb_of_dim); ~standardized_dataset = FluidDataSet(s);
~standardize.transform(~dataset,~standardized_dataset,{"done".postln;}); ~standardize.transform(~dataset,~standardized_dataset,{"done".postln;});
// look at a point to see that it has points in it // look at a point to see that it has points in it

@ -41,4 +41,12 @@
~classifier = FluidKNNClassifier.new(s, numNeighbours:2); ~classifier = FluidKNNClassifier.new(s, numNeighbours:2);
~classifier.fit(~ds,~ls, {\done.postln;}) ~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);})
}
)
Loading…
Cancel
Save