| 1 |
//--------------------------------------------------------------------- |
| 2 |
// name: wekinator-import.ck |
| 3 |
// desc: this examples imports training data from an .arff file, |
| 4 |
// (which can be saved either from the Wekinator app or |
| 5 |
// using Wekinator.exportObs()) |
| 6 |
// |
| 7 |
// version: need chuck version 1.5.0.0 or higher |
| 8 |
// sorting: part of ChAI (ChucK for AI) |
| 9 |
// |
| 10 |
// uncomment for Wekinator API: |
| 11 |
// Wekinator.help(); |
| 12 |
// |
| 13 |
// authors: Yikai Li |
| 14 |
// Ge Wang (https://ccrma.stanford.edu/~ge/) |
| 15 |
// Rebecca Fiebrink (original Wekinator framework) |
| 16 |
// date: Winter 2023 |
| 17 |
//--------------------------------------------------------------------- |
| 18 |
|
| 19 |
// instantiate a global Wekinator, so other files can easily use |
| 20 |
global Wekinator wek; |
| 21 |
|
| 22 |
// print |
| 23 |
cherr <= "loading observations from file..." <= IO.newline(); |
| 24 |
// load an ARFF data file containing input-output observations |
| 25 |
// (generated either from Wekinator.exportObs() or Wekinator app) |
| 26 |
// NOTE: Wekinator.importObs() clears existing training data, |
| 27 |
// and uses the inputDims and outputDims inferred from file |
| 28 |
// NOTE: it is possible to add additional observations after |
| 29 |
wek.importObs( me.dir() + "currentData.arff" ); |
| 30 |
|
| 31 |
// print what we loaded |
| 32 |
cherr <= "inputDims: " <= wek.inputDims() <= " " |
| 33 |
<= "outputDims: " <= wek.outputDims() <= " " |
| 34 |
<= "numObs: " <= wek.numObs() <= IO.newline(); |
| 35 |
|
| 36 |
// train using current observations |
| 37 |
wek.train(); |
| 38 |
|
| 39 |
// input (dimensions should match inputDims) |
| 40 |
[0.3, 0.25, 0.4] @=> float x[]; |
| 41 |
// output (dimensions should match outputDims) |
| 42 |
float y[wek.outputDims()]; |
| 43 |
// predict output based on input |
| 44 |
wek.predict( x, y ); |
| 45 |
|
| 46 |
// print |
| 47 |
for( int i; i < y.size(); i++ ) { cherr <= y[i] <= " "; } |
| 48 |
cherr <= IO.newline(); |