3D point sequence analysis with Encog

Akonkagva's picture

Hi,

I am pretty new to NN, but I have a problem which I intend to solve using neural networks:

Basicly, I have an example linked list that contains an objects with timestamp and a hand position in 3d(x,y,z), I need to compare it to another linked list that also contains and object with timestamp and hand position(x,y,z). The original and new one might vary in size. I could easily record multiple example gestures of the same type in order to improve accuracy.

I have implemented this with DTW and Hashmap, but to access the performance I was asked to develop a NN comparison aswell, I have chosen this amaizing library to help me build it.

What is the common way to solve this using the Encog ?

P.S this is how I tried to implement with Hopfield Associate

public void hopfieldNeuralNetworkAnalysis()
{
// result

//Algorhitm
/*
* create a normal int[] of x y z normalise();
*
*/

// Get userDefinedGestureLibrary

LinkedList userDefinedGestures = UserDefinedGestureLibrary
.getInstance().getGesturesData();

// Get recorded moves

LinkedList handGestures = RuntimeGesturesLibrary.getInstance()
.getGesturesList();

// Create x[] y[] z[] array of recorded data
double[] xRecorded = new double[handGestures.size()];
for (int count = 0; count < xRecorded.length; count++) {
xRecorded[count] = handGestures.get(count).getX();
}
double[] yRecorded = new double[handGestures.size()];
for (int count = 0; count < yRecorded.length; count++) {
yRecorded[count] = handGestures.get(count).getY();
}
double[] zRecorded = new double[handGestures.size()];
for (int count = 0; count < zRecorded.length; count++) {
zRecorded[count] = handGestures.get(count).getZ();
}
// System.out.println("Count openni:"+zRecorded.length);
xRecorded = normalise(xRecorded);
yRecorded = normalise(yRecorded);
zRecorded = normalise(zRecorded);

int normalisedBoolSize = 1000;

boolean[] xRecord = new boolean[normalisedBoolSize];
for(int i = 0; i < xRecorded.length; i++)
{
xRecord[(int)xRecorded[i]] = true;
}

boolean[] yRecord = new boolean[normalisedBoolSize];

for(int i = 0; i < yRecorded.length; i++)
{
yRecord[(int)yRecorded[i]] = true;
}
boolean[] zRecord = new boolean[normalisedBoolSize];

for(int i = 0; i < zRecorded.length; i++)
{
zRecord[(int)zRecorded[i]] = true;
}

BiPolarNeuralData currentNeuralDataX = new BiPolarNeuralData(xRecord);

BiPolarNeuralData currentNeuralDataY = new BiPolarNeuralData(yRecord);

BiPolarNeuralData currentNeuralDataZ = new BiPolarNeuralData(zRecord);

/* analyse current frame create 12 arrays of booleans
*

*
* associate current * trained
*
* try all 4 states
*
* if everythyng matches good -> show results
*/

boolean[][] idealUserGesturesX = new boolean[userDefinedGestures.size()][normalisedBoolSize];
boolean[][] idealUserGesturesY = new boolean[userDefinedGestures.size()][normalisedBoolSize];
boolean[][] idealUserGesturesZ = new boolean[userDefinedGestures.size()][normalisedBoolSize];

HopfieldNetwork hopfieldLogicX = new HopfieldNetwork(normalisedBoolSize);

HopfieldNetwork hopfieldLogicY = new HopfieldNetwork(normalisedBoolSize);

HopfieldNetwork hopfieldLogicZ = new HopfieldNetwork(normalisedBoolSize);

for (int i = 0; i < userDefinedGestures.size(); i++) {
double result = 0;
// check if data is Recorded

if (userDefinedGestures.get(i).getStatus().equals("Recorded")) {

LinkedList data = userDefinedGestures.get(i)
.getData();

// Create x[] y[] z[] array of user recorded data
double[] xUserRecorded = new double[data.size()];
for (int count = 0; count < data.size(); count++) {
xUserRecorded[count] = data.get(count).getX();
}
double[] yUserRecorded = new double[data.size()];
for (int count = 0; count < data.size(); count++) {
yUserRecorded[count] = data.get(count).getY();
}
double[] zUserRecorded = new double[data.size()];
for (int count = 0; count < data.size(); count++) {
zUserRecorded[count] = data.get(count).getZ();
}
xUserRecorded = normalise(xUserRecorded);
yUserRecorded = normalise(yUserRecorded);
zUserRecorded = normalise(zUserRecorded);

boolean[] userGesturesX = new boolean[normalisedBoolSize];
boolean[] userGesturesY = new boolean[normalisedBoolSize];
boolean[] userGesturesZ = new boolean[normalisedBoolSize];

for(int j = 0; j < xUserRecorded.length; j++)
{
idealUserGesturesX[i][(int)xUserRecorded[j]] = true;
userGesturesX[(int)xUserRecorded[j]] = true;
}

for(int j = 0; j < yUserRecorded.length; j++)
{
idealUserGesturesY[i][(int)yUserRecorded[j]] = true;
userGesturesY[(int)yUserRecorded[j]] = true;
}

for(int j = 0; j < zUserRecorded.length; j++)
{
idealUserGesturesZ[i][(int)zUserRecorded[j]] = true;
userGesturesZ[(int)zUserRecorded[j]] = true;
}

/* train on user gestures*/

hopfieldLogicX.addPattern(new BiPolarNeuralData(userGesturesX));

hopfieldLogicY.addPattern(new BiPolarNeuralData(userGesturesY));

hopfieldLogicZ.addPattern(new BiPolarNeuralData(userGesturesZ));

}

}

hopfieldLogicX.setCurrentState(currentNeuralDataX);
int cycles = hopfieldLogicX.runUntilStable(10000);
currentNeuralDataX = (BiPolarNeuralData)hopfieldLogicX.getCurrentState();

hopfieldLogicY.setCurrentState(currentNeuralDataY);
cycles = hopfieldLogicY.runUntilStable(10000);
currentNeuralDataX = (BiPolarNeuralData)hopfieldLogicY.getCurrentState();

hopfieldLogicY.setCurrentState(currentNeuralDataZ);
cycles = hopfieldLogicZ.runUntilStable(10000);
currentNeuralDataZ = (BiPolarNeuralData)hopfieldLogicZ.getCurrentState();

for(int i = 0; i < userDefinedGestures.size(); i++)
{
boolean correct = true;
int mismatch = 0;
System.out.println();
for(int j = 0; j < normalisedBoolSize; j++)
{

if(currentNeuralDataX.getBoolean(j) != idealUserGesturesX[i][j])
{
mismatch++;
correct = false;
}
}
if(correct)
{
System.out.println("Found :"+userDefinedGestures.get(i).getGestureName());
}
else
{
System.out.println("Not "+userDefinedGestures.get(i).getGestureName()+" mismatch:"+mismatch);
}
}

}

Looking forward to your answers,
Peter


Copyright 2005 - 2012 by Heaton Research, Inc.. Heaton Research™ and Encog™ are trademarks of Heaton Research. Click here for copyright, license and trademark information.