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 { ...@@ -4,9 +4,14 @@ class DynamicGesture extends Gesture {
public int dataPoints = 5; public int dataPoints = 5;
public int [][] point; public int [][] point;
public boolean [] consider;
public DynamicGesture(){ public DynamicGesture(){
point = new int [dataPoints][sensors]; point = new int [dataPoints][sensors];
consider = new boolean[sensors];
/*for (int i=0; i<sensors; i++) {
consider[i] = true;
}*/
} }
public int[][] getPoint(){ public int[][] getPoint(){
...@@ -14,6 +19,12 @@ class DynamicGesture extends Gesture { ...@@ -14,6 +19,12 @@ class DynamicGesture extends Gesture {
} }
public void printData(){ 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'); System.out.print('\n');
for (int i=0; i<dataPoints; i++) { for (int i=0; i<dataPoints; i++) {
for (int j=0; j<sensors; j++) { for (int j=0; j<sensors; j++) {
...@@ -23,12 +34,32 @@ class DynamicGesture extends Gesture { ...@@ -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 i=0; i<dataPoints; i++) {
for (int j=0; j<sensors; j++) { for (int j=0; j<sensors; j++) {
point[i][j] = sensorPoint[i][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{ ...@@ -5,22 +5,25 @@ class DynamicPrime{
int noOfGestures = 2; int noOfGestures = 2;
Gesture []a = new Gesture[noOfGestures]; DynamicGesture []a = new DynamicGesture[noOfGestures];
for (int i = 0; i<noOfGestures; i++) { for (int i = 0; i<noOfGestures; i++) {
a[i] = new DynamicGesture(); a[i] = new DynamicGesture();
} }
int [][]array = new int[5][11]; int [][]array = new int[5][11];
int []cons = new int[11];
for (int i=0; i<5; i++) { 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; array[i][j] = i*2;
} }
} }
//cons = new int[] {1,1,1,1,1,0,0,0,0,0,0};
a[0].updateFrame(array); cons = new int[] {1,1,1,1,1,1,1,1,1,1,1};
a[0].updateFrame(array,cons);
a[0].printData(); a[0].printData();
int [][]array2 = new int[5][11]; int [][]array2 = new int[5][11];
int []cons2 = new int[11];
for (int i=0; i<5; i++) { for (int i=0; i<5; i++) {
for (int j=0; j<11; j=j+2) { for (int j=0; j<11; j=j+2) {
array2[i][j] = i*2; array2[i][j] = i*2;
...@@ -29,8 +32,8 @@ class DynamicPrime{ ...@@ -29,8 +32,8 @@ class DynamicPrime{
array2[i][j] = 0; array2[i][j] = 0;
} }
} }
cons2 = new int[] {1,1,1,1,1,0,0,0,1,0,0};
a[1].updateFrame(array2); a[1].updateFrame(array2,cons2);
a[1].printData(); a[1].printData();
// initialising the 10 gestures // initialising the 10 gestures
......
...@@ -3,7 +3,7 @@ package com.example.harshith.ddc; ...@@ -3,7 +3,7 @@ package com.example.harshith.ddc;
class DynamicQueue{ class DynamicQueue{
public int noOfSlots = 5000; public int noOfSlots = 5000;
public int noOfGestures; public int noOfGestures;
public Gesture [] gesture; public DynamicGesture [] gesture;
public int [][] dtwGap; public int [][] dtwGap;
public Live []liveElement; public Live []liveElement;
public boolean [][]shortlist; public boolean [][]shortlist;
...@@ -11,7 +11,7 @@ class DynamicQueue{ ...@@ -11,7 +11,7 @@ class DynamicQueue{
public int latestElement = 0; public int latestElement = 0;
public int foremostElement = 0; public int foremostElement = 0;
public DynamicQueue(Gesture []gest){ public DynamicQueue(DynamicGesture []gest){
gesture = gest.clone(); gesture = gest.clone();
noOfGestures = gesture.length; noOfGestures = gesture.length;
...@@ -73,14 +73,37 @@ class DynamicQueue{ ...@@ -73,14 +73,37 @@ class DynamicQueue{
} }
public int[][] liveTempArrayComp(int slotNo, int livesTailNo){ public int[][] liveTempArrayComp(int slotNo, int livesTailNo, int gestNo){
int count = 0; int count = 0;
for (int i=slotNo; i!=livesTailNo; i=(i+1)%noOfSlots){count++;} for (int i=slotNo; i!=livesTailNo; i=(i+1)%noOfSlots){count++;}
int[][] x = new int[count][liveElement[0].sensors];
for (int i=0; i<count; i++){ int[][] x = new int[count][gesture[gestNo].getConsiderCount()];
// for (int i=slotNo; i!=livesTailNo; i=(i+1)%noOfSlots){
x[i] = liveElement[(i+slotNo)%noOfSlots].reading; 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;
}
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; return x;
...@@ -90,11 +113,14 @@ class DynamicQueue{ ...@@ -90,11 +113,14 @@ class DynamicQueue{
int threshold = 5; int threshold = 5;
DTW x; DTW x;
int[][] arraytemp = liveTempArrayComp(slotNo,livesTailNo);
for (int i=0; i<noOfGestures; i++) { for (int i=0; i<noOfGestures; i++) {
x = new DTWtwoD(); 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(); dtwGap[slotNo][i] = x.sdtwDistance();
} }
for (int i=0; i<noOfGestures; i++) { for (int i=0; i<noOfGestures; i++) {
......
...@@ -21,7 +21,7 @@ class Gesture{ ...@@ -21,7 +21,7 @@ class Gesture{
System.out.println("Printing data..."); System.out.println("Printing data...");
} }
public void updateFrame(int [][] sensorLimits){ public void updateFrame(int [][] sensorPoint, int[] considerPoints){
System.out.println("Updating static frame..."); System.out.println("Updating static frame...");
} }
...@@ -33,6 +33,14 @@ class Gesture{ ...@@ -33,6 +33,14 @@ class Gesture{
System.out.println("Updating frame for real..."); System.out.println("Updating frame for real...");
} }
public void updateConsider(int [] array){
}
public int getConsiderCount(){
return 0;
}
public boolean isInFrame(Live live){ public boolean isInFrame(Live live){
System.out.println("Checking if the value is in the static frame..."); System.out.println("Checking if the value is in the static frame...");
return true; return true;
......
...@@ -4,7 +4,7 @@ import java.util.Scanner; ...@@ -4,7 +4,7 @@ import java.util.Scanner;
class Live{ class Live{
public int reading[]; public int reading[];
public int sensors = 11 ; public int sensors = 11;
public Live(){ public Live(){
reading = new int [sensors]; reading = new int [sensors];
...@@ -17,14 +17,14 @@ class Live{ ...@@ -17,14 +17,14 @@ class Live{
} }
} }
public void update(int p){ public void update(int reading){
for (int i=0; i<sensors; i++) { for (int i=0; i<sensors; i++) {
reading[i] = p; this.reading[i] = reading;
} }
} }
public void update(int[] p){ public void update(int[] readings){
reading = p.clone(); reading = readings.clone();
} }
public void updateConsole(){ public void updateConsole(){
......
...@@ -37,21 +37,25 @@ public class ReceiveDataThread extends Thread { ...@@ -37,21 +37,25 @@ public class ReceiveDataThread extends Thread {
int noOfGestures = 2; int noOfGestures = 2;
Gesture []a = new Gesture[noOfGestures]; DynamicGesture []a = new DynamicGesture[noOfGestures];
for (int i = 0; i<noOfGestures; i++) { for (int i = 0; i<noOfGestures; i++) {
a[i] = new DynamicGesture(); a[i] = new DynamicGesture();
} }
int [][]array = new int[5][11]; int [][]array = new int[5][11];
int []cons = new int[11];
for (int i=0; i<5; i++) { 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; array[i][j] = i*2;
} }
} }
//cons = new int[] {1,1,1,1,1,0,0,0,0,0,0};
a[0].updateFrame(array); 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 [][]array2 = new int[5][11];
int []cons2 = new int[11];
for (int i=0; i<5; i++) { for (int i=0; i<5; i++) {
for (int j=0; j<11; j=j+2) { for (int j=0; j<11; j=j+2) {
array2[i][j] = i*2; array2[i][j] = i*2;
...@@ -60,14 +64,16 @@ public class ReceiveDataThread extends Thread { ...@@ -60,14 +64,16 @@ public class ReceiveDataThread extends Thread {
array2[i][j] = 0; array2[i][j] = 0;
} }
} }
cons2 = new int[] {1,1,1,1,1,0,0,0,1,0,0};
a[1].updateFrame(array2); a[1].updateFrame(array2,cons2);
a[1].printData();
// initialising the 10 gestures // initialising the 10 gestures
DynamicQueue q = new DynamicQueue(a); DynamicQueue q = new DynamicQueue(a);
Live dynamiclive = new Live(); Live dynamiclive = new Live();
byte[] buffer = new byte[64]; byte[] buffer = new byte[64];
int bytes = -1; int bytes = -1;
String readMessage; String readMessage;
...@@ -79,13 +85,14 @@ public class ReceiveDataThread extends Thread { ...@@ -79,13 +85,14 @@ public class ReceiveDataThread extends Thread {
readMessage = new String(buffer,0,bytes); readMessage = new String(buffer,0,bytes);
stringBuilder.append(readMessage); stringBuilder.append(readMessage);
convert(); convert();
if(readings.length == 11) { if(readings != null && readings.length == 11) {
dynamiclive.update(readings); dynamiclive.update(readings);
q.updateQueue(dynamiclive); q.updateQueue(dynamiclive);
q.processQueue(); q.processQueue();
i = q.proceedExecution(); i = q.proceedExecution();
if(i != -1){ 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(); // q.print();
} }
......
...@@ -16,6 +16,7 @@ import java.util.UUID; ...@@ -16,6 +16,7 @@ import java.util.UUID;
*/ */
public class ReceiveService extends Service { public class ReceiveService extends Service {
int mode = 0;
ConnectThread connectThread; ConnectThread connectThread;
ReceiveDataThread receiveDataThread; ReceiveDataThread receiveDataThread;
private static final UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"); 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