KNNClassifier / Regressor review

nix
Gerard 6 years ago
parent b2338ed9d9
commit d96dbb8791

@ -1,30 +1,29 @@
FluidKNNClassifier : FluidManipulationClient { FluidKNNClassifier : FluidManipulationClient {
*new {|server| *new {|server|
var uid = UniqueID.next; var uid = UniqueID.next;
^super.new(server,uid)!?{|inst|inst.init(uid);inst} ^super.new(server,uid)!?{|inst|inst.init(uid);inst}
} }
init {|uid| init {|uid|
id = uid; id = uid;
} }
fit{|dataset, labelset, action| fit{|dataset, labelset, action|
this.prSendMsg(\fit,[dataset.asSymbol, labelset.asSymbol], action); this.prSendMsg(\fit,[dataset.asSymbol, labelset.asSymbol], action);
} }
predict{ |dataset, labelset, k, uniform = 0, action| predict{|dataset, labelset, k, uniform = 0, action|
this.prSendMsg(\predict, this.prSendMsg(\predict,
[dataset.asSymbol, labelset.asSymbol, k, uniform], [dataset.asSymbol, labelset.asSymbol, k, uniform],
action); action);
} }
predictPoint { |buffer, k, uniform = 0, action| predictPoint {|buffer, k, uniform = 0, action|
this.prSendMsg(\predictPoint, this.prSendMsg(\predictPoint,
[buffer.asUGenInput, k,uniform], action, [buffer.asUGenInput, k, uniform], action,
[string(FluidMessageResponse,_,_)] [string(FluidMessageResponse,_,_)]
); );
} }
} }

@ -1,29 +1,29 @@
FluidKNNRegressor : FluidManipulationClient { FluidKNNRegressor : FluidManipulationClient {
*new {|server| *new {|server|
var uid = UniqueID.next; var uid = UniqueID.next;
^super.new(server,uid)!?{|inst|inst.init(uid);inst} ^super.new(server,uid)!?{|inst|inst.init(uid);inst}
} }
init {|uid| init {|uid|
id = uid; id = uid;
} }
fit{|sourceDataset, targetDataset, action| fit{|sourceDataset, targetDataset, action|
this.prSendMsg(\fit, this.prSendMsg(\fit,
[sourceDataset.asSymbol, targetDataset.asSymbol], [sourceDataset.asSymbol, targetDataset.asSymbol],
action action
); );
} }
predict{ |sourceDataset, targetDataset, k, uniform = 0, action| predict{ |sourceDataset, targetDataset, k, uniform = 0, action|
this.prSendMsg(\predict, this.prSendMsg(\predict,
[sourceDataset.asSymbol, targetDataset.asSymbol, k, uniform], [sourceDataset.asSymbol, targetDataset.asSymbol, k, uniform],
action); action);
} }
predictPoint { |buffer, k, uniform = 0, action| predictPoint { |buffer, k, uniform = 0, action|
this.prSendMsg(\predictPoint, [buffer.asUGenInput, k,uniform], action, this.prSendMsg(\predictPoint, [buffer.asUGenInput, k, uniform], action,
[number(FluidMessageResponse,_,_)]); [number(FluidMessageResponse,_,_)]);
} }
} }

@ -4,6 +4,8 @@ categories:: Classification, KNN
related:: Classes/FluidKNNRegressor, Classes/FluidDataSet, Classes/FluidLabelSet related:: Classes/FluidKNNRegressor, Classes/FluidDataSet, Classes/FluidLabelSet
DESCRIPTION:: DESCRIPTION::
A nearest-neighbor classifier using link::Classes/FluidKDTree:: . Each point is assigned the class that is most common among its nearest neighbors.
https://scikit-learn.org/stable/modules/neighbors.html#classification
CLASSMETHODS:: CLASSMETHODS::
@ -15,7 +17,7 @@ The server to make the model on
INSTANCEMETHODS:: INSTANCEMETHODS::
METHOD:: fit METHOD:: fit
Fit the model to a source link::Classes/FluidDataSet:: and a target link::Classes/FluidLabelSet:: . These need to be the sime size Fit the model to a source link::Classes/FluidDataSet:: and a target link::Classes/FluidLabelSet::. These need to be the same size
ARGUMENT:: dataset ARGUMENT:: dataset
Source data Source data
ARGUMENT:: labelset ARGUMENT:: labelset
@ -32,7 +34,7 @@ place to write labels
ARGUMENT:: k ARGUMENT:: k
the number of neighours to consider the number of neighours to consider
ARGUMENT:: uniform ARGUMENT:: uniform
true / false: whether the neighbours shold be weighted by distance true / false: whether the neighbours should be weighted by distance
ARGUMENT:: action ARGUMENT:: action
Run when done Run when done
@ -43,7 +45,7 @@ A data point
ARGUMENT:: k ARGUMENT:: k
Number of neighbours to consider Number of neighbours to consider
ARGUMENT:: uniform ARGUMENT:: uniform
true / false: whether the neighbours shold be weighted by distance true / false: whether the neighbours should be weighted by distance (default) or uniformly
ARGUMENT:: action ARGUMENT:: action
Run when done, passes predicted label as argument Run when done, passes predicted label as argument

@ -4,6 +4,9 @@ categories:: Regression
related:: Classes/FluidKNNClassifier, Classes/FluidDataSet related:: Classes/FluidKNNClassifier, Classes/FluidDataSet
DESCRIPTION:: DESCRIPTION::
A nearest-neighbor regressor. A continuous value is predicted for each point as the (weighted) average value of its nearest neighbors.
https://scikit-learn.org/stable/modules/neighbors.html#regression
CLASSMETHODS:: CLASSMETHODS::
@ -15,7 +18,7 @@ The server to run this model on.
INSTANCEMETHODS:: INSTANCEMETHODS::
METHOD:: fit METHOD:: fit
Map a source link::Classes/FluidDataSet:: to a target; they must be the same size, but can have different dimensionality Map a source link::Classes/FluidDataSet:: to a one-dimensional target; both datasets need to have the same number of points.
ARGUMENT:: sourceDataset ARGUMENT:: sourceDataset
Source data Source data
ARGUMENT:: targetDataset ARGUMENT:: targetDataset
@ -44,7 +47,7 @@ data point
ARGUMENT:: k ARGUMENT:: k
number of neigbours to consider in mapping, min 1 number of neigbours to consider in mapping, min 1
ARGUMENT:: uniform ARGUMENT:: uniform
Whether to weight neighbours by distance when producing new point Whether the neighbours should be weighted by distance (default) or uniformly
ARGUMENT:: action ARGUMENT:: action
Run when done Run when done
@ -105,4 +108,4 @@ fork{
) )
//We should see a single cycle of a chirp //We should see a single cycle of a chirp
~outputdata.plot; ~outputdata.plot;
:: ::

Loading…
Cancel
Save