add FluidKNNClassifier / FluidKNNRegressor

nix
Gerard 6 years ago
parent c6087b160e
commit c3f240148d

@ -0,0 +1,19 @@
FluidKNNClassifier : FluidManipulationClient {
fit{|dataset, labelset, action|
this.pr_sendMsg(\fit,[dataset.asString, labelset.asString], action);
}
predict{ |dataset, labelset, k, action|
this.pr_sendMsg(\predict,
[dataset.asString, labelset.asString, k],
action, [string(FluidMessageResponse,_,_)]
);
}
predictPoint { |buffer, k, action|
this.pr_sendMsg(\predictPoint,
[buffer.asUGenInput, k], action,
[number(FluidMessageResponse,_,_)]
);
}
}

@ -0,0 +1,20 @@
FluidKNNRegressor : FluidManipulationClient {
fit{|sourceDataset, targetDataset, action|
this.pr_sendMsg(\fit,
[sourceDataset.asString, targetDataset.asString],
action
);
}
predict{ |sourceDataset, targetDataset, k, action|
this.pr_sendMsg(\predict,
[sourceDataset.asString, targetDataset.asString, k],
action,
[string(FluidMessageResponse,_,_)]);
}
predictPoint { |buffer, k, action|
this.pr_sendMsg(\predictPoint, [buffer.asUGenInput, k], action,
[number(FluidMessageResponse,_,_)]);
}
}

@ -2,7 +2,7 @@
~simpleInput = FluidDataSet(s,\simpleInput,2);
~simpleOutput = FluidLabelSet(s,\simpleOutput,2);
b = Buffer.alloc(s,2);
~knn = FluidKNN(s);
~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.classifyPoint(b, ~simpleOutput, k, {|x|x.postln;});
~knn.predictPoint(b, k, {|x|x.postln;});
}.play;};
//custom redraw function
@ -58,6 +58,6 @@ Routine{
)
// fit the dataset
~knn.fit(~simpleInput,action:{"fitting done".postln})
~knn.fit(~simpleInput,~simpleOutput, action:{"fitting done".postln})
// now click on the grid and read the estimated class according to the nearest K neighbours.

@ -36,8 +36,8 @@ Routine{
~mappingresult = Buffer.alloc(s,512);
//make the process then fit the data
~knn = FluidKNN(s)
~knn.fit(~simpleInput,action:{"fitting done".postln})
~knn = FluidKNNRegressor(s)
~knn.fit(~simpleInput, ~simpleOutput, action:{"fitting done".postln})
// query 512 points along the line (slow because of all that sync'ing)
(
@ -46,7 +46,7 @@ Routine{
512.do{|i|
b.set(0,i*61);
s.sync;
~knn.regressPoint(b,~simpleOutput,k,action:{|d|~mappingresult.set(i,d);});
~knn.predictPoint(b,k,action:{|d|~mappingresult.set(i,d);});
s.sync;
i.postln;
}

Loading…
Cancel
Save