Commit 9908764b authored by Harshith Goka's avatar Harshith Goka

Selective sensor DTW, few changes to classes

parent e37a6d8c
......@@ -4,9 +4,14 @@ class DynamicGesture extends Gesture {
public int dataPoints = 5;
public int [][] point;
public boolean [] consider;
public DynamicGesture(){
point = new int [dataPoints][sensors];
consider = new boolean[sensors];
/*for (int i=0; i<sensors; i++) {
consider[i] = true;
}*/
}
public int[][] getPoint(){
......@@ -14,6 +19,12 @@ class DynamicGesture extends Gesture {
}
public void printData(){
System.out.print('\n');
for (int j=0; j<sensors; j++) {
int prnt = 0;
if(consider[j]) prnt = 1;
System.out.print(prnt + " ");
}
System.out.print('\n');
for (int i=0; i<dataPoints; i++) {
for (int j=0; j<sensors; j++) {
......@@ -23,12 +34,32 @@ class DynamicGesture extends Gesture {
}
}
public void updateFrame(int [][] sensorPoint){
public void updateFrame(int [][] sensorPoint, int[] considerPoints){
for (int i=0; i<dataPoints; i++) {
for (int j=0; j<sensors; j++) {
point[i][j] = sensorPoint[i][j];
}
}
updateConsider(considerPoints);
}
public void updateConsider(int [] array){
for (int i=0; i<array.length; i++) {
if(array[i]==1) consider[i] = true;
//else consider[i] = false;
}
}
public int getConsiderCount(){
int count = 0;
for (int i=0; i<consider.length; i++) {
if(consider[i]) count++;
}
return count;
}
}
\ No newline at end of file
......@@ -5,22 +5,25 @@ class DynamicPrime{
int noOfGestures = 2;
Gesture []a = new Gesture[noOfGestures];
DynamicGesture []a = new DynamicGesture[noOfGestures];
for (int i = 0; i<noOfGestures; i++) {
a[i] = new DynamicGesture();
}
int [][]array = new int[5][11];
int []cons = new int[11];
for (int i=0; i<5; i++) {
for (int j=0; j<11; j++) {
for (int j=0; j<5; j++) {
array[i][j] = i*2;
}
}
a[0].updateFrame(array);
//cons = new int[] {1,1,1,1,1,0,0,0,0,0,0};
cons = new int[] {1,1,1,1,1,1,1,1,1,1,1};
a[0].updateFrame(array,cons);
a[0].printData();
int [][]array2 = new int[5][11];
int []cons2 = new int[11];
for (int i=0; i<5; i++) {
for (int j=0; j<11; j=j+2) {
array2[i][j] = i*2;
......@@ -29,8 +32,8 @@ class DynamicPrime{
array2[i][j] = 0;
}
}
a[1].updateFrame(array2);
cons2 = new int[] {1,1,1,1,1,0,0,0,1,0,0};
a[1].updateFrame(array2,cons2);
a[1].printData();
// initialising the 10 gestures
......
......@@ -3,7 +3,7 @@ package com.example.harshith.ddc;
class DynamicQueue{
public int noOfSlots = 5000;
public int noOfGestures;
public Gesture [] gesture;
public DynamicGesture [] gesture;
public int [][] dtwGap;
public Live []liveElement;
public boolean [][]shortlist;
......@@ -11,7 +11,7 @@ class DynamicQueue{
public int latestElement = 0;
public int foremostElement = 0;
public DynamicQueue(Gesture []gest){
public DynamicQueue(DynamicGesture []gest){
gesture = gest.clone();
noOfGestures = gesture.length;
......@@ -73,28 +73,54 @@ class DynamicQueue{
}
public int[][] liveTempArrayComp(int slotNo, int livesTailNo){
public int[][] liveTempArrayComp(int slotNo, int livesTailNo, int gestNo){
int count = 0;
for (int i=slotNo; i!=livesTailNo; i=(i+1)%noOfSlots){count++;}
int[][] x = new int[count][liveElement[0].sensors];
int[][] x = new int[count][gesture[gestNo].getConsiderCount()];
int index = 0;
for (int i=0; i<liveElement[slotNo].sensors; i++){
if(gesture[gestNo].consider[i]){
for (int j=0; j<count; j++) {
x[j][index] = liveElement[(j+slotNo)%noOfSlots].reading[i]; //gesture[gestNo].point[j][i];
}
index++;
}
}
return x;
}
for (int i=0; i<count; i++){
// for (int i=slotNo; i!=livesTailNo; i=(i+1)%noOfSlots){
x[i] = liveElement[(i+slotNo)%noOfSlots].reading;
public int[][] validSensorArrayComp(int gestNo){
int[][] x = new int[gesture[gestNo].dataPoints][gesture[gestNo].getConsiderCount()];
int index = 0;
for (int i=0; i<gesture[gestNo].sensors; i++){
if(gesture[gestNo].consider[i]){
for (int j=0; j<gesture[gestNo].dataPoints; j++) {
x[j][index] = gesture[gestNo].point[j][i];
}
index++;
}
}
return x;
}
}
public void processLive(int slotNo, int livesTailNo){
int threshold = 5;
DTW x;
int[][] arraytemp = liveTempArrayComp(slotNo,livesTailNo);
DTW x;
for (int i=0; i<noOfGestures; i++) {
x = new DTWtwoD();
x.arrayInput(gesture[i].getPoint(), arraytemp);
int[][] arraytemp = liveTempArrayComp(slotNo, livesTailNo, i);
int[][] gestarraytemp = validSensorArrayComp(i);
x.arrayInput(gestarraytemp, arraytemp);
dtwGap[slotNo][i] = x.sdtwDistance();
}
for (int i=0; i<noOfGestures; i++) {
......
......@@ -21,7 +21,7 @@ class Gesture{
System.out.println("Printing data...");
}
public void updateFrame(int [][] sensorLimits){
public void updateFrame(int [][] sensorPoint, int[] considerPoints){
System.out.println("Updating static frame...");
}
......@@ -33,6 +33,14 @@ class Gesture{
System.out.println("Updating frame for real...");
}
public void updateConsider(int [] array){
}
public int getConsiderCount(){
return 0;
}
public boolean isInFrame(Live live){
System.out.println("Checking if the value is in the static frame...");
return true;
......
......@@ -4,7 +4,7 @@ import java.util.Scanner;
class Live{
public int reading[];
public int sensors = 11 ;
public int sensors = 11;
public Live(){
reading = new int [sensors];
......@@ -17,14 +17,14 @@ class Live{
}
}
public void update(int p){
public void update(int reading){
for (int i=0; i<sensors; i++) {
reading[i] = p;
this.reading[i] = reading;
}
}
public void update(int[] p){
reading = p.clone();
public void update(int[] readings){
reading = readings.clone();
}
public void updateConsole(){
......
......@@ -37,21 +37,25 @@ public class ReceiveDataThread extends Thread {
int noOfGestures = 2;
Gesture []a = new Gesture[noOfGestures];
DynamicGesture []a = new DynamicGesture[noOfGestures];
for (int i = 0; i<noOfGestures; i++) {
a[i] = new DynamicGesture();
}
int [][]array = new int[5][11];
int []cons = new int[11];
for (int i=0; i<5; i++) {
for (int j=0; j<11; j++) {
for (int j=0; j<5; j++) {
array[i][j] = i*2;
}
}
a[0].updateFrame(array);
//cons = new int[] {1,1,1,1,1,0,0,0,0,0,0};
cons = new int[] {1,1,1,1,1,1,1,1,1,1,1};
a[0].updateFrame(array,cons);
a[0].printData();
int [][]array2 = new int[5][11];
int []cons2 = new int[11];
for (int i=0; i<5; i++) {
for (int j=0; j<11; j=j+2) {
array2[i][j] = i*2;
......@@ -60,14 +64,16 @@ public class ReceiveDataThread extends Thread {
array2[i][j] = 0;
}
}
a[1].updateFrame(array2);
cons2 = new int[] {1,1,1,1,1,0,0,0,1,0,0};
a[1].updateFrame(array2,cons2);
a[1].printData();
// initialising the 10 gestures
DynamicQueue q = new DynamicQueue(a);
Live dynamiclive = new Live();
byte[] buffer = new byte[64];
int bytes = -1;
String readMessage;
......@@ -79,13 +85,14 @@ public class ReceiveDataThread extends Thread {
readMessage = new String(buffer,0,bytes);
stringBuilder.append(readMessage);
convert();
if(readings.length == 11) {
if(readings != null && readings.length == 11) {
dynamiclive.update(readings);
q.updateQueue(dynamiclive);
q.processQueue();
i = q.proceedExecution();
if(i != -1){
handler.obtainMessage(Constants.READ_STATUS,readStatus,i,null).sendToTarget();
// handler.obtainMessage(Constants.READ_STATUS,readStatus,i,null).sendToTarget();
L.m("Gesture " + i + " is executed");
}
// q.print();
}
......
......@@ -16,6 +16,7 @@ import java.util.UUID;
*/
public class ReceiveService extends Service {
int mode = 0;
ConnectThread connectThread;
ReceiveDataThread receiveDataThread;
private static final UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment