updated super simple examples with comments and new interface
parent
1225b37714
commit
fc0f762a3d
@ -1,46 +1,63 @@
|
|||||||
s.reboot
|
s.reboot
|
||||||
|
|
||||||
|
|
||||||
~urn = { |n=31416, min=0,max=31415| (min..max).scramble.keep(n) };
|
~urn = { |n=31416, min=0,max=31415| (min..max).scramble.keep(n) };
|
||||||
|
|
||||||
|
// creates 200 indices, then values of the output of a fundion with a predictable shape of a sinewave
|
||||||
n = 200
|
n = 200
|
||||||
~idx = ~urn.value(n)
|
~idx = ~urn.value(n)
|
||||||
~data = n.collect{|i|sin(~idx[i]/5000)}
|
~data = n.collect{|i|sin(~idx[i]/5000)}
|
||||||
|
|
||||||
|
// creates the dataset with these associated indices and values
|
||||||
(
|
(
|
||||||
~simpleInput = FluidDataSet(s,\simpleInput,1);
|
~simpleInput = FluidDataSet(s,\simpleInput,1);
|
||||||
~simpleOutput = FluidDataSet(s,\simpleOutput,1);
|
~simpleOutput = FluidDataSet(s,\simpleOutput,1);
|
||||||
b = Buffer.alloc(s,1,1);
|
b = Buffer.alloc(s,1,1);
|
||||||
~mappingviz = Buffer.alloc(s,31416,1);
|
~mappingviz = Buffer.alloc(s,512);
|
||||||
)
|
)
|
||||||
|
|
||||||
(
|
(
|
||||||
Routine{
|
Routine{
|
||||||
n.do{|i|
|
n.do{|i|
|
||||||
b.set(0,~idx[i]);
|
b.set(0,~idx[i]);
|
||||||
s.sync;
|
s.sync;
|
||||||
~simpleInput.addPoint(i.asString,b,{("Added Input" + i).postln});
|
~simpleInput.addPoint(i.asString,b,{("Added Input" + i).postln});
|
||||||
b.set(0,~data[i]);
|
b.set(0,~data[i]);
|
||||||
s.sync;
|
s.sync;
|
||||||
~simpleOutput.addPoint(i.asString,b,{("Added Output" + i).postln});
|
~simpleOutput.addPoint(i.asString,b,{("Added Output" + i).postln});
|
||||||
~mappingviz.set(~idx[i].asInt,~data[i])
|
~mappingviz.set((~idx[i]/61).asInt,~data[i])
|
||||||
}
|
}
|
||||||
}.play
|
}.play
|
||||||
)
|
)
|
||||||
(
|
|
||||||
~simpleInput.clear;
|
//look at the seeing material
|
||||||
~simpleOutput.clear;
|
|
||||||
)
|
|
||||||
3%2
|
|
||||||
~mappingviz.plot(minval:-1,maxval:1)
|
~mappingviz.plot(minval:-1,maxval:1)
|
||||||
|
|
||||||
~mappingresult = Buffer.alloc(s,31416,1);
|
//create a buffer to query
|
||||||
|
~mappingresult = Buffer.alloc(s,512);
|
||||||
|
|
||||||
|
//make the process then fit the data
|
||||||
~knn = FluidKNN(s)
|
~knn = FluidKNN(s)
|
||||||
~knn.index(~simpleInput,action:{"index done".postln})
|
~knn.fit(~simpleInput,action:{"fitting done".postln})
|
||||||
|
|
||||||
|
// query 512 points along the line (slow because of all that sync'ing)
|
||||||
(
|
(
|
||||||
|
k = 1; // change to see how many points the system uses to regress
|
||||||
|
Routine{
|
||||||
|
512.do{|i|
|
||||||
|
b.set(0,i*61);
|
||||||
|
s.sync;
|
||||||
|
~knn.regressPoint(b,~simpleOutput,k,action:{|d|~mappingresult.set(i,d);});
|
||||||
|
s.sync;
|
||||||
|
i.postln;
|
||||||
|
}
|
||||||
|
}.play
|
||||||
|
)
|
||||||
|
|
||||||
|
// look at the interpolated values
|
||||||
|
~mappingresult.plot
|
||||||
|
|
||||||
512.do{|i|
|
// clears both datasets
|
||||||
b.set(0,i);
|
(
|
||||||
~knn.regress(b,~simpleOutput,1,action:{|d|~mappingresult.set(i,d)});
|
~simpleInput.clear;
|
||||||
// if(i%512 == 0, {i.postln; s.sync},{});
|
~simpleOutput.clear;
|
||||||
}
|
)
|
||||||
)
|
|
||||||
|
|||||||
Loading…
Reference in New Issue