From b066e6fcd7a7e46ad8493c327d247ebfff8174f8 Mon Sep 17 00:00:00 2001 From: Pierre Alexandre Tremblay Date: Thu, 17 Dec 2020 09:32:08 +0000 Subject: [PATCH] helpfile corrected and right default values --- release-packaging/Classes/FluidRobustScale.sc | 2 +- .../Classes/FluidRobustScale.schelp | 63 ++++++++++--------- 2 files changed, 34 insertions(+), 31 deletions(-) diff --git a/release-packaging/Classes/FluidRobustScale.sc b/release-packaging/Classes/FluidRobustScale.sc index 0b69c5e..db53de9 100644 --- a/release-packaging/Classes/FluidRobustScale.sc +++ b/release-packaging/Classes/FluidRobustScale.sc @@ -2,7 +2,7 @@ FluidRobustScale : FluidRealTimeModel { var <>low, <>high, <>invert; - *new {|server, low = 0, high = 100, invert = 0| + *new {|server, low = 25, high = 75, invert = 0| ^super.new(server,[low,high,invert]) .low_(low).high_(high).invert_(invert); } diff --git a/release-packaging/HelpSource/Classes/FluidRobustScale.schelp b/release-packaging/HelpSource/Classes/FluidRobustScale.schelp index 137c929..b00aec6 100644 --- a/release-packaging/HelpSource/Classes/FluidRobustScale.schelp +++ b/release-packaging/HelpSource/Classes/FluidRobustScale.schelp @@ -1,12 +1,12 @@ TITLE:: FluidRobustScale summary:: Apply Robust Scaling to FluidDataSet categories:: FluidManipulation -related:: Classes/FluidStandardize, Classes/FluidDataSet +related:: Classes/FluidStandardize, Classes/FluidNormalize, Classes/FluidDataSet DESCRIPTION:: -Normalize the entries of a link::Classes/FluidDataSet::, or normalize a data point according to the learned bounds of a data set. On the server. +Scales the entries of a link::Classes/FluidDataSet::, or scales a data point according to the learned values of a data set. It will centre the median of each dimension to 0, and will scale the data to +/- the provided centiles, by default providing the first and third qartile (25 and 75).All happens on the server. -See http://www.faqs.org/faqs/ai-faq/neural-nets/part2/section-16.html +See https://scikit-learn.org/stable/auto_examples/preprocessing/plot_all_scaling.html#robustscaler CLASSMETHODS:: @@ -17,48 +17,48 @@ Create a new instance ARGUMENT:: server The link::Classes/Server:: on which to run ARGUMENT:: low -Maximum output value, default 1 +The low centile boundary, default 25. ARGUMENT:: high -Maximum output value, default 1 +The high centile boundary, default 75. ARGUMENT:: invert -The direction in which the normalization will occur for transform and transformpoint. The default 0 is taking in the range of the input used to fit and transforms it towards the normalised range. A value of 1 will expect an input of the normalized range to transform back to the original range. +The direction in which the scaling will occur for transform and transformpoint. The default 0 is taking in the range of the input used to fit and transforms it towards the robust scaling range. A value of 1 will expect an input of the scaling range to transform back to the original range. INSTANCEMETHODS:: METHOD:: fit -Compute the normalization factors from a link::Classes/FluidDataSet:: for later. +Compute the scaling factors from a link::Classes/FluidDataSet:: for later. ARGUMENT:: dataSet -The link::Classes/FluidDataSet:: to normalize +The link::Classes/FluidDataSet:: to scale ARGUMENT:: action A function to run when processing is complete METHOD:: transform -Normalize a link::Classes/FluidDataSet:: into another link::Classes/FluidDataSet::, using the learned extrema from a previous call to link::Classes/FluidRobustScale#fit:: +Scale a link::Classes/FluidDataSet:: into another link::Classes/FluidDataSet::, using the learned extrema from a previous call to link::Classes/FluidRobustScale#fit:: ARGUMENT:: sourceDataSet -The link::Classes/FluidDataSet:: to normalize +The link::Classes/FluidDataSet:: to scale ARGUMENT:: destDataSet -The link::Classes/FluidDataSet:: to populate with normalized data +The link::Classes/FluidDataSet:: to populate with scaled data ARGUMENT:: action A function to run when processing is complete METHOD:: fitTransform -Normalize a link::Classes/FluidDataSet:: +Scale a link::Classes/FluidDataSet:: ARGUMENT:: sourceDataSet -The link::Classes/FluidDataSet:: to normalize +The link::Classes/FluidDataSet:: to scale ARGUMENT:: destDataSet -The link::Classes/FluidDataSet:: to populate with normalized data +The link::Classes/FluidDataSet:: to populate with scaled data ARGUMENT:: action A function to run when processing is complete METHOD:: transformPoint -Normalize a new data point, using the learned extrema from a previous call to link::Classes/FluidRobustScale#fit:: +Scale a new data point, using the learned scaling from a previous call to link::Classes/FluidRobustScale#fit:: ARGUMENT:: sourceBuffer A link::Classes/Buffer:: with the new data point ARGUMENT:: destBuffer -A link::Classes/Buffer:: to contain the normalized value +A link::Classes/Buffer:: to contain the scaled value ARGUMENT:: action A function to run when processing is complete @@ -69,11 +69,11 @@ s.boot; // FluidRobustScale.dumpAllMethods ( ~audiofile = File.realpath(FluidBufPitch.class.filenameSymbol).dirname +/+ "../AudioFiles/Tremblay-ASWINE-ScratchySynth-M.wav"; -~raw = FluidDataSet(s,\norm_help_raw); -~norm = FluidDataSet(s,\norm_help_normd); +~raw = FluidDataSet(s); +~scaled = FluidDataSet(s); ~pitch_feature = Buffer.new(s); ~stats = Buffer.alloc(s, 7, 2); -~normalizer = FluidRobustScale(s); +~robust = FluidRobustScale(s); ) // Load audio and run a pitch analysis, which gives us pitch and pitch confidence (so a 2D datum) @@ -91,7 +91,7 @@ FluidBufPitch.process(s,~audio, features: ~pitch_feature); var count = PulseCount.kr(trig) - 1; var chunkLen = (~pitch_feature.numFrames / 10).asInteger; var stats = FluidBufStats.kr( - source: ~pitch_feature, startFrame: count * chunkLen, + source: ~pitch_feature, startFrame: count * chunkLen, numFrames: chunkLen, stats: ~stats, trig: (trig * (count <=9)), blocking:1 ); var rd = BufRd.kr(2, ~stats, DC.kr(0), 0, 1);// pick only mean pitch and confidence @@ -104,16 +104,19 @@ FluidBufPitch.process(s,~audio, features: ~pitch_feature); }.play; ) -// Normalize and load to language-side array +~raw.print; +~raw.clear; + +// Scale and load to language-side array ( ~rawarray = Array.new(10); -~normedarray= Array.new(10); -~normalizer.fitTransform(~raw,~norm, { +~scaledarray= Array.new(10); +~robust.fitTransform(~raw,~scaled, { ~raw.dump{|x| 10.do{|i| ~rawarray.add(x["data"][i.asString]) }}; - ~norm.dump{|x| 10.do{|i| - ~normedarray.add(x["data"][i.asString]) + ~scaled.dump{|x| 10.do{|i| + ~scaledarray.add(x["data"][i.asString]) }}; }); ) @@ -122,14 +125,14 @@ FluidBufPitch.process(s,~audio, features: ~pitch_feature); //which can be unhelpful in many cases ( -~rawarray.flatten(1).unlace.plot("Unnormalized",Rect(0,0,400,400),minval:0,maxval:[5000,1]).plotMode=\bars; -~plot2 = ~normedarray.flatten(1).unlace.plot("Normalized",Rect(410,0,400,400)).plotMode=\bars; +~rawarray.flatten(1).unlace.plot("Raw Data",Rect(0,0,400,400),minval:0,maxval:[5000,1]).plotMode=\bars; +~plot2 = ~scaledarray.flatten(1).unlace.plot("Scaled",Rect(410,0,400,400)).plotMode=\bars; ) // single point transform on arbitrary value ~inbuf = Buffer.loadCollection(s,0.5.dup); ~outbuf = Buffer.new(s); -~normalizer.transformPoint(~inbuf,~outbuf,{|x|x.postln;x.getn(0,2,{|y|y.postln;};)}); +~robust.transformPoint(~inbuf,~outbuf,{|x|x.postln;x.getn(0,2,{|y|y.postln;};)}); OSCFunc.trace(false,true) //Server side queries @@ -149,9 +152,9 @@ OSCFunc.trace(false,true) //assemble data point BufWr.kr(avg[0],inputPoint,0); BufWr.kr(avg[1],inputPoint,1); - ~normalizer.kr(trig,inputPoint,outputPoint); + ~robust.kr(trig,inputPoint,outputPoint); Poll.kr(trig,BufRd.kr(1,inputPoint,[0,1]),["pitch (raw)", "confidence (raw)"]); - Poll.kr(trig,BufRd.kr(1,outputPoint,[0,1]),["pitch (normalized)", "confidence (normalized)"]) + Poll.kr(trig,BufRd.kr(1,outputPoint,[0,1]),["pitch (scaled)", "confidence (scaled)"]) }.play; ) ::