Machine Learning Weekly Class Note 2

This week I made a simple Machine Learning experiment to determine if a cube is closer to two predetermined locations on a canvas:

1. send x and y position to OSC on address localhost:6448
2. in Wekinator, set up the incoming port as 6448, set input data number to 2 ( x and y), set output data number to 1.
3. start Processing program, put cube to a place, goto Wekinator, drag the slider under outputs-1 to 0, then start recording in Wekinator. wait for a few seconds, then stop recording.
4. go to Processing sketch, drag the cube to another place. Goto Wekinator, drag the slider under outputs-1 to 1, then start recording data. Wait for a few seconds then stop recording.
5. click “Train” in Wekinator.
6. now data is trained. Goto Processing Sketch, drag the cube around, you will see the slider in Wekinator goes to 1 when the cube is in the 1st place we placed it, the slide goes to 2 when we drag the cube to the 2nd place we placed it in.

 

Below is the code in JAVA

import oscP5.*;
import netP5.*;

OscP5 oscP5;
NetAddress dest;
PFont f;

float bx;
float by;
int boxSize = 30;
boolean overBox = false;
boolean locked = false;
float xOffset = 0.0;
float yOffset = 0.0;

void setup() {
f = createFont(“Courier”, 15);
textFont(f);

size(640, 480, P2D);
noStroke();
smooth();

bx = width/2.0;
by = height/2.0;
rectMode(RADIUS);

/* start oscP5, listening for incoming messages at port 12000 */
oscP5 = new OscP5(this,9000);
dest = new NetAddress(“127.0.0.1″,6448);

}

void draw() {
background(0);
fill(255);
/*ellipse(mouseX, mouseY, 10, 10);
if(frameCount % 2 == 0) {
sendOsc();
} */
text(“Continuously sends box x and y position (2 inputs) to Wekinator\nUsing message /wek/inputs, to port 6448”, 10, 30);
text(“x=” + bx + “, y=” + by, 10, 80);

fill(0, 200, 0);

// Test if the cursor is over the box
if (mouseX > bx-boxSize && mouseX < bx+boxSize &&
mouseY > by-boxSize && mouseY < by+boxSize) {
overBox = true;
if(!locked) {
stroke(0, 255, 0);
fill(0, 255, 0);
}
} else {
stroke(0, 255, 0);
fill(0, 255, 0);
overBox = false;
}

// Draw the box
rect(bx, by, boxSize, boxSize);

//Send the OSC message with box current position
sendOsc();
}

void mousePressed() {
if(overBox) {
locked = true;
fill(0, 255, 0);
} else {
locked = false;
}
xOffset = mouseX-bx;
yOffset = mouseY-by;

}

void mouseDragged() {
if(locked) {
bx = mouseX-xOffset;
by = mouseY-yOffset;
}
}

void mouseReleased() {
locked = false;
}

 

void sendOsc() {
OscMessage msg = new OscMessage(“/wek/inputs”);
msg.add((float)bx);
msg.add((float)by);
oscP5.send(msg, dest);
}

Screen Shot 2017-12-02 at 12.52.36 AM

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s