now a proper recursive function!

nix
Pierre Alexandre Tremblay 5 years ago
parent e5223ef0e5
commit 25dce02ce8

@ -59,39 +59,31 @@ Routine{
~slices.dump{|x|~sliceDict = x;}; ~slices.dump{|x|~sliceDict = x;};
) )
//the windowed function
( (
Routine{ ~windowedFunct = {arg head, winSize;
~indices = [0]; var nbass = [], assignments = [], tempDict;
~head = 0; //check the size of everything to not overrun
winSize = (~originalslicesarray.size - head).min(winSize);
~tempDict = (); //copy the items to a subdataset from hear
winSize.do{|i|
while ( {~head <= (~originalslicesarray.size - ~winSize)}, ~tempDict.put((i.asString), ~sliceDict["data"][(i+head).asString]);//here one could curate which stats to take
{ "whichslices:%\n".postf(i+head);
var step = ~winSize - 1;
var nbass = [];
var cond = Condition.new;
~assignments = [];
//run a process on ~winSize items from ~head (with an overlap of 1)
//copy the items to a subdataset
~winSize.do{|i|
~tempDict.put((i.asString), ~sliceDict["data"][(i+~head).asString]);//here one could curate which stats to take
"whichslices:%\n".postf(i+~head);
}; };
~windowDS.load(Dictionary.newFrom([\cols, 133, \data, ~tempDict]), action: { ~windowDS.load(Dictionary.newFrom([\cols, 133, \data, ~tempDict]), action: {
"% - loaded\n".postf(~head); "% - loaded\n".postf(head);
//kmeans 2 and retrieve ordered array of class assignations //kmeans 2 and retrieve ordered array of class assignations
~kmeans.fitPredict(~windowDS, ~windowLS, action: {|x| ~kmeans.fitPredict(~windowDS, ~windowLS, action: {|x|
nbass = x; nbass = x;
"% - fitted1: ".postf(~head); nbass.postln; "% - fitted1: ".postf(head); nbass.postln;
if (nbass.includes(0.0), { if (nbass.includes(0.0), {
~kmeans.fitPredict(~windowDS, ~windowLS, {|x| ~kmeans.fitPredict(~windowDS, ~windowLS, {|x|
nbass = x; "% - fitted2: ".postf(~head); nbass.postln; nbass = x; "% - fitted2: ".postf(head); nbass.postln;
if (nbass.includes(0.0), { if (nbass.includes(0.0), {
~kmeans.fitPredict(~windowDS, ~windowLS, {|x| ~kmeans.fitPredict(~windowDS, ~windowLS, {|x|
nbass = x; "% - fitted3: ".postf(~head); nbass.postln; nbass = x; "% - fitted3: ".postf(head); nbass.postln;
}); });
}); });
}); });
@ -99,75 +91,35 @@ Routine{
~windowLS.dump{|x| ~windowLS.dump{|x|
~assignments = x.at("data").asSortedArray.flop[1].flatten; ~assignments = x.at("data").asSortedArray.flop[1].flatten;
"% - assigned ".postf(~head); "% - assigned ".postf(head);
~assignments.postln; ~assignments.postln;
step.do{|i| (winSize-1).do{|i|
if (~assignments[i+1] != ~assignments[i], {~indices= ~indices ++ (~originalslicesarray[~head+i+1])}); if (~assignments[i+1] != ~assignments[i], {~indices= ~indices ++ (~originalslicesarray[head+i+1])});
}; };
cond.unhang; //if we still have some frames to do, do them
}; if (((head+winSize) < ~originalslicesarray.size), {
});
});
cond.hang;
~head = ~head + step;
"-----------------".postln; "-----------------".postln;
}); ~windowedFunct.value(head + winSize, winSize);
//leftovers (half baked, needs to run it all properly but hey, let's fix it first }, {~indices = ~indices ++ (b.numFrames); "done".postln;});//if we're done close the books
if ( (~originalslicesarray.size - ~head) > 1, {
var nbass = [];
var cond = Condition.new;
~assignments = [];
//run a process on (a.size - ~head) items from ~head
//copy the items to a subdataset
(~originalslicesarray.size - ~head).do{|i|
~tempDict.put((i.asString), ~sliceDict["data"][(i+~head).asString]);//here one could curate which stats to take
"whichslices:%\n".postf(i+~head);
}; };
~windowDS.load(Dictionary.newFrom([\cols, 133, \data, ~tempDict]), action: {
"% - loaded\n".postf(~head);
//kmeans 2 and retrieve ordered array of class assignations
~kmeans.fitPredict(~windowDS, ~windowLS, action: {|x|
nbass = x;
"% - fitted1: ".postf(~head); nbass.postln;
if (nbass.includes(0.0), {
~kmeans.fitPredict(~windowDS, ~windowLS, {|x|
nbass = x; "% - fitted2: ".postf(~head); nbass.postln;
if (nbass.includes(0.0), {
~kmeans.fitPredict(~windowDS, ~windowLS, {|x|
nbass = x; "% - fitted3: ".postf(~head); nbass.postln;
});
});
}); });
}); });
}
)
~windowLS.dump{|x| //the function
~assignments = x.at("data").asSortedArray.flop[1].flatten;
"% - assigned ".postf(~head);
~assignments.postln; ~indices = [0];
~tempDict = ();
(~originalslicesarray.size - ~head - 1).do{|i| ~windowedFunct.value(0, 4);
if (~assignments[i+1] != ~assignments[i], {~indices= ~indices ++ (~originalslicesarray[~head+i+1])});
}; ~indices.postln;
cond.unhang;
};
});
});
cond.hang;
"done".postln;
});
//add the endoffile indice to the array
~indices = ~indices ++ (b.numFrames);
~indices.postln; ~windowDS.print
}.play;
)
{var i = 8;BufRd.ar(1,b,Line.ar(~originalslicesarray[i],~originalslicesarray[i+1],(~originalslicesarray[i+1] - ~originalslicesarray[i])/b.sampleRate, doneAction: 2))}.play; {var i = 8;BufRd.ar(1,b,Line.ar(~originalslicesarray[i],~originalslicesarray[i+1],(~originalslicesarray[i+1] - ~originalslicesarray[i])/b.sampleRate, doneAction: 2))}.play;
{var i = 4;BufRd.ar(1,b,Line.ar(~indices[i],~indices[i+1],(~indices[i+1] - ~indices[i])/b.sampleRate, doneAction: 2))}.play; {var i = 4;BufRd.ar(1,b,Line.ar(~indices[i],~indices[i+1],(~indices[i+1] - ~indices[i])/b.sampleRate, doneAction: 2))}.play;
@ -202,3 +154,4 @@ if (f.isOpen , {
f.close; f.close;
}); });
) )

Loading…
Cancel
Save