diff --git a/release-packaging/Classes/FluidDTW.sc b/release-packaging/Classes/FluidDTW.sc new file mode 100644 index 00000000..964f18fc --- /dev/null +++ b/release-packaging/Classes/FluidDTW.sc @@ -0,0 +1,32 @@ +FluidDTW : FluidModelObject { + + var <>constraint, <>constraintParam; + + *new {|server, constraint = 0, constraintParam = 0| + ^super.new(server,[constraint, constraintParam]) + .constraint_(constraint) + .constraintParam_(constraintParam); + } + + prGetParams{^[this.id,this.constraint,this.constraintParam];} + + costMsg{|dataSeries, id1, id2| + ^this.prMakeMsg(\cost, this.id, dataSeries.id, id1.asSymbol, id2.asSymbol) + } + + cost{|dataSeries, id1, id2, action| + actions[\cost] = [string(FluidMessageResponse,_,_),action]; + this.prSendMsg(this.costMsg(dataSeries, id1.asSymbol, id2.asSymbol)); + } + + bufCostMsg{|buffer1, buffer2| + ^this.prMakeMsg(\bufCost, this.id, + this.prEncodeBuffer(buffer1), + this.prEncodeBuffer(buffer2)); + } + + bufCost{|buffer1, buffer2, action| + actions[\bufCost] = [string(FluidMessageResponse,_,_),action]; + this.prSendMsg(this.bufCostMsg(buffer1,buffer2)); + } +} diff --git a/release-packaging/Classes/FluidDTWClassifier.sc b/release-packaging/Classes/FluidDTWClassifier.sc new file mode 100644 index 00000000..1f15729b --- /dev/null +++ b/release-packaging/Classes/FluidDTWClassifier.sc @@ -0,0 +1,63 @@ +FluidDTWClassifier : FluidModelObject { + + var <>numNeighbours, <>constraint, <>constraintParam; + + *new {|server, numNeighbours = 3, constraint = 0, constraintParam = 0| + ^super.new(server,[numNeighbours, constraint, constraintParam]) + .numNeighbours_(numNeighbours) + .constraint_(constraint) + .constraintParam_(constraintParam); + } + + prGetParams{^[this.id,this.numNeighbours,this.constraint,this.constraintParam];} + + fitMsg{|dataSeries, labelSet| + ^this.prMakeMsg(\fit, id, dataSeries.id, labelSet.id) + } + + fit{|dataSeries, labelSet, action| + actions[\fit] = [nil,action]; + this.prSendMsg(this.fitMsg(dataSeries, labelSet)); + } + + predictMsg{|dataSeries, labelSet| + ^this.prMakeMsg(\predict, id, dataSeries.id, labelSet.id) + } + + predict{|dataSeries, labelSet, action| + actions[\predict] = [nil, action]; + this.prSendMsg(this.predictMsg(dataSeries, labelSet)); + } + + predictSeriesMsg{|buffer| + ^this.prMakeMsg(\predictSeries, id, this.prEncodeBuffer(buffer)) + } + + predictSeries {|buffer, action| + actions[\predictSeries] = [string(FluidMessageResponse,_,_),action]; + this.prSendMsg(this.predictSeriesMsg(buffer)); + } + + // kr{|trig, inputBuffer,outputBuffer| + // ^FluidDTWClassifierQuery.kr(trig, + // this, this.numNeighbours, + // this.prEncodeBuffer(inputBuffer), + // this.prEncodeBuffer(outputBuffer)); + // } + +} + +// FluidDTWClassifierQuery : FluidRTMultiOutUGen { +// +// *kr{ |trig, model,numNeighbours = 3,inputBuffer, outputBuffer | +// ^this.multiNew('control',trig, model.asUGenInput, +// numNeighbours, +// inputBuffer.asUGenInput, outputBuffer.asUGenInput) +// } +// +// init { arg ... theInputs; +// inputs = theInputs; +// ^this.initOutputs(1, rate); +// } +// } + diff --git a/release-packaging/Classes/FluidDTWRegressor.sc b/release-packaging/Classes/FluidDTWRegressor.sc new file mode 100644 index 00000000..63ff06a8 --- /dev/null +++ b/release-packaging/Classes/FluidDTWRegressor.sc @@ -0,0 +1,65 @@ +FluidDTWRegressor : FluidModelObject { + + var <>numNeighbours, <>constraint, <>constraintParam; + + *new {|server, numNeighbours = 3, constraint = 0, constraintParam = 0| + ^super.new(server,[numNeighbours, constraint, constraintParam]) + .numNeighbours_(numNeighbours) + .constraint_(constraint) + .constraintParam_(constraintParam); + } + + prGetParams{^[this.id,this.numNeighbours,this.constraint,this.constraintParam];} + + fitMsg{|dataSeries, dataSet| + ^this.prMakeMsg(\fit,this.id,dataSeries.id,dataSet.id) + } + + fit{|dataSeries, dataSet, action| + actions[\fit] = [nil,action]; + this.prSendMsg(this.fitMsg(dataSeries, dataSet)); + } + + predictMsg{ |dataSeries, dataSet| + ^this.prMakeMsg(\predict,this.id,dataSeries.id,dataSet.id) + } + + predict{ |dataSeries, dataSet, action| + actions[\predict] = [nil, action]; + this.prSendMsg(this.predictMsg(dataSeries, dataSet)); + } + + predictSeriesMsg { |sourceBuffer, targetBuffer| + ^this.prMakeMsg(\predictSeries,id, + this.prEncodeBuffer(sourceBuffer), + this.prEncodeBuffer(targetBuffer), + ["/b_query", targetBuffer.asUGenInput]); + } + + predictSeries { |sourceBuffer, targetBuffer, action| + actions[\predictSeries] = [nil,{action.value(targetBuffer)}]; + this.predictSeriesMsg(sourceBuffer, targetBuffer); + this.prSendMsg(this.predictSeriesMsg(sourceBuffer, targetBuffer)); + } + + // kr{|trig, inputBuffer, outputBuffer, numNeighbours| + // ^FluidKNNRegressorQuery.kr(K2A.ar(trig), + // this, numNeighbours??{this.numNeighbours}, + // this.prEncodeBuffer(inputBuffer), + // this.prEncodeBuffer(outputBuffer)); + // } +} + +// FluidDTWRegressorQuery : FluidRTMultiOutUGen { +// +// *kr{ |trig, model,numNeighbours = 3,inputBuffer, outputBuffer | +// ^this.multiNew('control',trig, model.asUGenInput, +// numNeighbours, +// inputBuffer.asUGenInput, outputBuffer.asUGenInput) +// } +// +// init { arg ... theInputs; +// inputs = theInputs; +// ^this.initOutputs(1, rate); +// } +// } \ No newline at end of file diff --git a/release-packaging/Classes/FluidDataSeries.sc b/release-packaging/Classes/FluidDataSeries.sc new file mode 100644 index 00000000..707fe427 --- /dev/null +++ b/release-packaging/Classes/FluidDataSeries.sc @@ -0,0 +1,158 @@ + +FluidDataSeries : FluidDataObject +{ + *new{|server| ^super.new(server) } + + addSeriesMsg{|identifier,buffer| + buffer = this.prEncodeBuffer(buffer); + ^this.prMakeMsg(\addSeries,id,identifier.asSymbol,buffer); + } + + addSeries{|identifier, buffer, action| + actions[\addSeries] = [nil,action]; + this.prSendMsg(this.addSeriesMsg(identifier,buffer)); + } + + getSeriesMsg{|identifier,buffer| + buffer = this.prEncodeBuffer(buffer); + ^this.prMakeMsg(\getSeries,id,identifier.asSymbol,buffer,["/b_query",buffer.asUGenInput]); + } + + getSeries{|identifier, buffer, action| + actions[\getSeries] = [nil,action]; + this.prSendMsg(this.getSeriesMsg(identifier,buffer)); + } + + updateSeriesMsg{|identifier,buffer| + buffer = this.prEncodeBuffer(buffer); + ^this.prMakeMsg(\updateSeries,id,identifier.asSymbol,buffer,["/b_query",buffer.asUGenInput]); + } + + updateSeries{|identifier, buffer, action| + actions[\updateSeries] = [nil,action]; + this.prSendMsg(this.updateSeriesMsg(identifier,buffer)); + } + + setSeriesMsg{|identifier,buffer| + buffer = this.prEncodeBuffer(buffer); + ^this.prMakeMsg(\setSeries,id,identifier.asSymbol,buffer,["/b_query",buffer.asUGenInput]); + } + + setSeries{|identifier, buffer, action| + actions[\setSeries] = [nil,action]; + this.prSendMsg(this.setSeriesMsg(identifier,buffer)); + } + + deleteSeriesMsg{|identifier| ^this.prMakeMsg(\deleteSeries,id,identifier.asSymbol);} + + deleteSeries{|identifier, action| + actions[\deleteSeries] = [nil,action]; + this.prSendMsg(this.deleteSeriesMsg(identifier)); + } + + addFrameMsg{|identifier,buffer| + buffer = this.prEncodeBuffer(buffer); + ^this.prMakeMsg(\addFrame,id,identifier.asSymbol,buffer); + } + + addFrame{|identifier, buffer, action| + actions[\addFrame] = [nil,action]; + this.prSendMsg(this.addFrameMsg(identifier,buffer)); + } + + getFrameMsg{|identifier,time,buffer| + buffer = this.prEncodeBuffer(buffer); + ^this.prMakeMsg(\getFrame,id,identifier.asSymbol,time.asInteger,buffer,["/b_query",buffer.asUGenInput]); + } + + getFrame{|identifier, time, buffer, action| + actions[\getFrame] = [nil,action]; + this.prSendMsg(this.getFrameMsg(identifier,time,buffer)); + } + + updateFrameMsg{|identifier,time,buffer| + buffer = this.prEncodeBuffer(buffer); + ^this.prMakeMsg(\updateFrame,id,identifier.asSymbol,time.asInteger,buffer,["/b_query",buffer.asUGenInput]); + } + + updateFrame{|identifier, time, buffer, action| + actions[\updateFrame] = [nil,action]; + this.prSendMsg(this.updateFrameMsg(identifier,time,buffer)); + } + + setFrameMsg{|identifier,time,buffer| + buffer = this.prEncodeBuffer(buffer); + ^this.prMakeMsg(\setFrame,id,identifier.asSymbol,time.asInteger,buffer,["/b_query",buffer.asUGenInput]); + } + + setFrame{|identifier, time, buffer, action| + actions[\setFrame] = [nil,action]; + this.prSendMsg(this.setFrameMsg(identifier,time,buffer)); + } + + deleteFrameMsg{|identifier,time| ^this.prMakeMsg(\deleteFrame,id,identifier.asSymbol,time.asInteger);} + + deleteFrame{|identifier, time, action| + actions[\deleteFrame] = [nil,action]; + this.prSendMsg(this.deleteFrameMsg(identifier,time)); + } + + clearMsg { ^this.prMakeMsg(\clear,id); } + + clear { |action| + actions[\clear] = [nil,action]; + this.prSendMsg(this.clearMsg); + } + + mergeMsg{|sourceDataSeries, overwrite = 0| + ^this.prMakeMsg(\merge,id,sourceDataSeries.asUGenInput,overwrite); + } + + merge{|sourceDataSeries, overwrite = 0, action| + actions[\merge] = [nil,action]; + this.prSendMsg(this.mergeMsg(sourceDataSeries,overwrite)); + } + + printMsg { ^this.prMakeMsg(\print,id); } + + print { |action=(postResponse)| + actions[\print] = [string(FluidMessageResponse,_,_),action]; + this.prSendMsg(this.printMsg); + } + + getIdsMsg{|labelSet| + ^this.prMakeMsg(\getIds, id, labelSet.asUGenInput); + } + + getIds{|labelSet, action| + actions[\getIds] = [nil,action]; + this.prSendMsg(this.getIdsMsg(labelSet)); + } + + getDataSetMsg{|time, destDataSet| + ^this.prMakeMsg(\getDataSet, id, time, destDataSet.asUGenInput); + } + + getDataSet{|time, destDataSet, action| + actions[\getDataSet] = [nil,action]; + this.prSendMsg(this.getDataSetMsg(time, destDataSet)); + } + + kNearestMsg{|buffer,k| + ^this.prMakeMsg(\kNearest,id, this.prEncodeBuffer(buffer),k); + } + + kNearest{ |buffer, k, action| + actions[\kNearest] = [strings(FluidMessageResponse,_,_),action]; + this.prSendMsg(this.kNearestMsg(buffer,k)); + } + + kNearestDistMsg{|buffer,k| + ^this.prMakeMsg(\kNearestDist,id, this.prEncodeBuffer(buffer),k); + } + + kNearestDist{ |buffer, k, action| + actions[\kNearestDist] = [strings(FluidMessageResponse,_,_),action]; + this.prSendMsg(this.kNearestDistMsg(buffer,k)); + } +} diff --git a/release-packaging/Classes/FluidLSTM.sc b/release-packaging/Classes/FluidLSTM.sc new file mode 100644 index 00000000..16a9a13f --- /dev/null +++ b/release-packaging/Classes/FluidLSTM.sc @@ -0,0 +1,284 @@ +FluidLSTMRegressor : FluidModelObject { + var <>hiddenLayers, <>maxIter, <>learnRate, <>momentum, <>batchSize, <>validation; + + *new {|server, hiddenLayers = #[10] , maxIter = 5, learnRate = 0.01, momentum = 0.9, batchSize = 50, validation = 0.2| + + ^super.new(server, [hiddenLayers.size] ++ hiddenLayers ++ [maxIter, learnRate, momentum, batchSize, validation]) + .hiddenLayers_(hiddenLayers) + .maxIter_(maxIter) + .learnRate_(learnRate) + .momentum_(momentum) + .batchSize_(batchSize) + .validation_(validation); + } + + prGetParams{ + ^[this.id, this.hiddenLayers.size] ++ this.hiddenLayers ++ [this.maxIter, this.learnRate, this.momentum, this.batchSize, this.validation] + } + + clearMsg{ ^this.prMakeMsg(\clear, id) } + + clear{ |action| + actions[\clear] = [nil, action]; + this.prSendMsg(this.clearMsg); + } + + fitMsg{|sourceDataSeries, targetDataSet| + ^this.prMakeMsg(\fit,id,sourceDataSeries.id, targetDataSet.id); + } + + fit{|sourceDataSeries, targetDataSet, action| + actions[\fit] = [numbers(FluidMessageResponse,_,1,_),action]; + this.prSendMsg(this.fitMsg(sourceDataSeries,targetDataSet)); + } + + predictMsg{|sourceDataSeries, targetDataSet| + ^this.prMakeMsg(\predict,id,sourceDataSeries.id, targetDataSet.id); + } + + predict{|sourceDataSeries, targetDataSet, action| + actions[\predict] = [nil,action]; + this.prSendMsg(this.predictMsg(sourceDataSeries,targetDataSet)); + } + + predictSeriesMsg { |sourceBuffer, targetBuffer| + ^this.prMakeMsg(\predictSeries,id, + this.prEncodeBuffer(sourceBuffer), + this.prEncodeBuffer(targetBuffer), + ["/b_query", targetBuffer.asUGenInput]); + } + + predictSeries { |sourceBuffer, targetBuffer, action| + actions[\predictSeries] = [nil,{action.value(targetBuffer)}]; + this.prSendMsg(this.predictSeriesMsg(sourceBuffer, targetBuffer)); + } + + read { |filename, action| + actions[\read] = [numbers(FluidMessageResponse,_,nil,_), { + |data| + this.prUpdateParams(data); + action.value; + }]; + this.prSendMsg(this.readMsg(filename)); + } + + // kr{|trig, inputBuffer,outputBuffer, tapIn = 0, tapOut = -1| + // var params; + // tapIn = tapIn ? this.tapIn; + // tapOut = tapOut ? this.tapOut; + // + // this.tapIn_(tapIn).tapOut_(tapOut); + // + // params = [this.prEncodeBuffer(inputBuffer), + // this.prEncodeBuffer(outputBuffer),this.tapIn,this.tapOut]; + // + // ^FluidLSTMRegressorQuery.kr(trig,this, *params); + // } + + prUpdateParams{|data| + var rest = data.keep(-5); + this.hiddenLayers_(data.drop(1).drop(-5).copy); + [\maxIter_, \learnRate_, \momentum_, \batchSize_, \validation_] + .do{|prop,i| + this.performList(prop,rest[i]); + }; + } +} + +// FluidLSTMRegressorQuery : FluidRTMultiOutUGen { +// *kr{ |trig, model, inputBuffer,outputBuffer, tapIn = 0, tapOut = -1| +// ^this.multiNew('control',trig, model.asUGenInput, +// tapIn, tapOut, +// inputBuffer.asUGenInput, outputBuffer.asUGenInput) +// } +// +// init { arg ... theInputs; +// inputs = theInputs; +// ^this.initOutputs(1, rate); +// } +// } + +FluidLSTMClassifier : FluidModelObject { + var <>hiddenLayers, <>maxIter, <>learnRate, <>momentum, <>batchSize, <>validation; + + *new {|server, hiddenLayers = #[10], maxIter = 5, learnRate = 0.01, momentum = 0.9, batchSize = 50, validation = 0.2| + ^super.new(server,[hiddenLayers.size] ++ hiddenLayers ++ [maxIter, learnRate, momentum, batchSize, validation]) + .hiddenLayers_(hiddenLayers) + .maxIter_(maxIter) + .learnRate_(learnRate) + .momentum_(momentum) + .batchSize_(batchSize) + .validation_(validation); + } + + prGetParams{ + ^[this.id, this.hiddenLayers.size] ++ this.hiddenLayers ++ [this.maxIter, this.learnRate, this.momentum, this.batchSize, this.validation]; + } + + clearMsg{ ^this.prMakeMsg(\clear,id) } + + clear{ |action| + actions[\clear] = [nil,action]; + this.prSendMsg(this.clearMsg); + } + + fitMsg{|sourceDataSeries, targetLabelSet| + ^this.prMakeMsg(\fit,id,sourceDataSeries.id, targetLabelSet.id); + } + + fit{|sourceDataSeries, targetLabelSet, action| + actions[\fit] = [numbers(FluidMessageResponse,_,1,_),action]; + this.prSendMsg(this.fitMsg(sourceDataSeries,targetLabelSet)); + } + + predictMsg{|sourceDataSeries, targetLabelSet| + ^this.prMakeMsg(\predict,id,sourceDataSeries.id, targetLabelSet.id); + } + + predict{ |sourceDataSeries, targetLabelSet, action| + actions[\predict]=[nil,action]; + this.prSendMsg(this.predictMsg(sourceDataSeries,targetLabelSet)); + } + + predictSeriesMsg { |sourceBuffer| + ^this.prMakeMsg(\predictSeries,id,this.prEncodeBuffer(sourceBuffer)) + } + + predictSeries { |sourceBuffer, action| + actions[\predictSeries] = [string(FluidMessageResponse,_,_),action]; + this.prSendMsg(this.predictSeriesMsg(sourceBuffer)); + } + + read { |filename, action| + actions[\read] = [numbers(FluidMessageResponse,_,nil,_), { + |data| + this.prUpdateParams(data); + action.value; + }]; + this.prSendMsg(this.readMsg(filename)); + } + + prUpdateParams{|data| + var rest = data.keep(-5); + this.hiddenLayers_(data.drop(1).drop(-5).copy); + [\maxIter_, \learnRate_, \momentum_, \batchSize_, \validation_] + .do{|prop,i| + this.performList(prop,rest[i]); + }; + } + + // kr{|trig, inputBuffer,outputBuffer| + // + // var params = [this.prEncodeBuffer(inputBuffer), + // this.prEncodeBuffer(outputBuffer)]; + // + // ^FluidLSTMClassifierQuery.kr(trig,this, *params); + // } +} + +// FluidLSTMClassifierQuery : FluidRTMultiOutUGen { +// *kr{ |trig, model, inputBuffer,outputBuffer| +// ^this.multiNew('control',trig, model.asUGenInput, +// inputBuffer.asUGenInput, outputBuffer.asUGenInput) +// } +// +// init { arg ... theInputs; +// inputs = theInputs; +// ^this.initOutputs(1, rate); +// } +// } + +FluidLSTMForecaster : FluidModelObject { + var <>hiddenLayers, <>maxIter, <>learnRate, <>momentum, <>batchSize, <>validation, <>forecastLength; + + *new {|server, hiddenLayers = #[10], maxIter = 5, learnRate = 0.01, momentum = 0.9, batchSize = 50, validation = 0.2, forecastLength = 0| + ^super.new(server,[hiddenLayers.size] ++ hiddenLayers ++ [maxIter, learnRate, momentum, batchSize, validation, forecastLength]) + .hiddenLayers_(hiddenLayers) + .maxIter_(maxIter) + .learnRate_(learnRate) + .momentum_(momentum) + .batchSize_(batchSize) + .validation_(validation) + .forecastLength_(forecastLength); + } + + prGetParams{ + ^[this.id, this.hiddenLayers.size] ++ this.hiddenLayers ++ [this.maxIter, this.learnRate, this.momentum, this.batchSize, this.validation, this.forecastLength]; + } + + clearMsg{ ^this.prMakeMsg(\clear,id) } + + clear{ |action| + actions[\clear] = [nil,action]; + this.prSendMsg(this.clearMsg); + } + + fitMsg{|sourceDataSeries| + ^this.prMakeMsg(\fit,id,sourceDataSeries.id); + } + + fit{|sourceDataSeries, action| + actions[\fit] = [numbers(FluidMessageResponse,_,1,_),action]; + this.prSendMsg(this.fitMsg(sourceDataSeries)); + } + + predictMsg{|sourceDataSeries, targetDataSeries, forecastLength| + ^this.prMakeMsg(\predict,id,sourceDataSeries.id, targetDataSeries.id, forecastLength); + } + + predict{ |sourceDataSeries, targetDataSeries, forecastLength, action| + actions[\predict]=[nil,action]; + this.prSendMsg(this.predictMsg(sourceDataSeries, targetDataSeries, forecastLength ? this.forecastLength)); + } + + predictSeriesMsg { |sourceBuffer, targetBuffer, forecastLength| + ^this.prMakeMsg(\predictSeries,id, + this.prEncodeBuffer(sourceBuffer), + this.prEncodeBuffer(targetBuffer), + forecastLength, + ["/b_query", targetBuffer.asUGenInput]); + } + + predictSeries { |sourceBuffer, targetBuffer, forecastLength, action| + actions[\predictSeries] = [nil,{action.value(targetBuffer)}]; + this.prSendMsg(this.predictSeriesMsg(sourceBuffer, targetBuffer, forecastLength ? this.forecastLength)); + } + + read { |filename, action| + actions[\read] = [numbers(FluidMessageResponse,_,nil,_), { + |data| + this.prUpdateParams(data); + action.value; + }]; + this.prSendMsg(this.readMsg(filename)); + } + + prUpdateParams{|data| + var rest = data.keep(-5); + this.hiddenLayers_(data.drop(1).drop(-5).copy); + [\maxIter_, \learnRate_, \momentum_, \batchSize_, \validation_] + .do{|prop,i| + this.performList(prop,rest[i]); + }; + } + + // kr{|trig, inputBuffer,outputBuffer| + // + // var params = [this.prEncodeBuffer(inputBuffer), + // this.prEncodeBuffer(outputBuffer)]; + // + // ^FluidLSTMClassifierQuery.kr(trig,this, *params); + // } +} + +// FluidLSTMForecasterQuery : FluidRTMultiOutUGen { +// *kr{ |trig, model, inputBuffer,outputBuffer| +// ^this.multiNew('control',trig, model.asUGenInput, +// inputBuffer.asUGenInput, outputBuffer.asUGenInput) +// } +// +// init { arg ... theInputs; +// inputs = theInputs; +// ^this.initOutputs(1, rate); +// } +// } \ No newline at end of file