Commit 6b72baff authored by Harshith Goka's avatar Harshith Goka

copy dynamic java code

parent deaca6ea
package com.example.harshith.ddc;
import java.util.Scanner;
class DTW{
public int m; public int n;
public int [][]distance; public int [][]minAccDist;
public void arrayInput(int []arr1, int []arr2){
System.out.println("Inherited.");
}
public void arrayInput(int [][]arr1, int [][]arr2){
System.out.println("Inherited.");
}
public void consoleInput(){
System.out.println("Inherited.");
}
public double distance(int p, int q){
System.out.println("Inherited.");
return 0;
}
public void distanceProcess(){
distance = new int[m][n];
for (int i=0; i<m; i++) {
for (int j=0; j<n; j++) {
distance[i][j] = (int) distance(i,j);
}
}
}
public void minAccDistProcess(){
distanceProcess();
minAccDist = new int[m][n];
minAccDist[0][0] = distance[0][0];
int w = 65536; // set window here
w=Math.max(w,Math.abs(m-n));
for (int i=1; i<Math.min(m,w); i++) {
minAccDist[i][0] = distance[i][0] + minAccDist[i-1][0];
}
for (int j=1; j<Math.min(n,w); j++) {
minAccDist[0][j] = distance[0][j] + minAccDist[0][j-1];
}
for (int i=1; i<m; i++) {
for (int j=Math.max(1,i-w); j<Math.min(n,i+w); j++) {
minAccDist[i][j] = distance[i][j] + Math.min( minAccDist[i-1][j-1], Math.min( minAccDist[i-1][j], minAccDist[i][j-1] ) );
}
}
}
public int dtwDistance(){
minAccDistProcess();
return minAccDist[m][n];
}
public int sdtwDistance(){
return 0;
}
public void arrayPrint(int [][]array){
System.out.print('\n');
for (int i=0; i<m; i++) {
for (int j=0; j<n; j++) {
String text = String.format("%03d", array[i][j]);
boolean done = false;
if(array[i][j]!=0){
for (int k=0; k<text.length(); k++) {
if(text.charAt(k)=='0' && !done) System.out.print(" ");
else { System.out.print(text.charAt(k)); done = true; }
}
}
else{
for (int k=0; k<text.length()-1; k++) {
System.out.print(" ");
}
System.out.print(0);
}
System.out.print(" ");
}
System.out.print("\n");
}
}
}
package com.example.harshith.ddc;
import java.util.Scanner;
/**
* Created by harshith on 28/6/16.
*/
class DTWoneD extends DTW {
public int []a; public int []b;
public void arrayInput(int []arr1, int []arr2){
a = arr1.clone(); b = arr2.clone();
m = a.length; n = b.length;
}
public void consoleInput(){
Scanner scan = new Scanner(System.in);
m = scan.nextInt();
n = scan.nextInt();
scan = new Scanner(System.in);
a = new int[m];
for (int i=0; i<m; i++) {
a[i] = scan.nextInt();
}
scan = new Scanner(System.in);
b = new int[n];
for (int i=0; i<n; i++) {
b[i] = scan.nextInt();
}
//minAccDistProcess();
}
public double distance(int p, int q){
return Math.abs(a[p] - b[q]);
}
}
package com.example.harshith.ddc;
/**
* Created by harshith on 28/6/16.
*/
class DTWtwoD extends DTW {
public int [][]a; public int [][]b;
public int dimSize = 0;
public void arrayInput(int [][]arr1, int [][]arr2){
a = arr1.clone(); b = arr2.clone();
m = a.length; n = b.length;
dimSize = a[0].length;
}
public double distance(int p, int q){
double totalSquared = 0;
for (int i=0; i<dimSize; i++) {
totalSquared += Math.pow(a[p][i] - b[q][i],2);
}
return Math.sqrt(totalSquared);
}
public int sdtwDistance(){
minAccDistProcess();
int mini = 65536;
for (int i=0; i<a.length; i++) {
mini = Math.min(mini,minAccDist[i][n-1]);
}
//arrayPrint(minAccDist);
return mini;
}
}
package com.example.harshith.ddc;
class DynamicGesture extends Gesture {
public int dataPoints = 5;
public int [][] point;
public DynamicGesture(){
point = new int [dataPoints][sensors];
}
public int[][] getPoint(){
return point;
}
public void printData(){
System.out.print('\n');
for (int i=0; i<dataPoints; i++) {
for (int j=0; j<sensors; j++) {
System.out.print(point[i][j] + " ");
}
System.out.print('\n');
}
}
public void updateFrame(int [][] sensorPoint){
for (int i=0; i<dataPoints; i++) {
for (int j=0; j<sensors; j++) {
point[i][j] = sensorPoint[i][j];
}
}
}
}
\ No newline at end of file
package com.example.harshith.ddc;
class DynamicPrime{
public static void main(String [] args){
int noOfGestures = 2;
Gesture []a = new Gesture[noOfGestures];
for (int i = 0; i<noOfGestures; i++) {
a[i] = new DynamicGesture();
}
int [][]array = new int[5][11];
for (int i=0; i<5; i++) {
for (int j=0; j<11; j++) {
array[i][j] = i*2;
}
}
a[0].updateFrame(array);
a[0].printData();
int [][]array2 = new int[5][11];
for (int i=0; i<5; i++) {
for (int j=0; j<11; j=j+2) {
array2[i][j] = i*2;
}
for (int j=1; j<11; j=j+2) {
array2[i][j] = 0;
}
}
a[1].updateFrame(array2);
a[1].printData();
// initialising the 10 gestures
DynamicQueue q = new DynamicQueue(a);
Live dynamiclive = new Live();
//dynamiclive.update(100);
q.foremostElement = 0;
for (int i=0; i<5; i++) {
dynamiclive.update(i*2);
q.updateQueue(dynamiclive);
q.processQueue();
q.proceedExecution();
q.print();
}
}
}
\ No newline at end of file
package com.example.harshith.ddc;
class DynamicQueue{
public int noOfSlots = 7;
public int noOfGestures;
public Gesture [] gesture;
public int [][] dtwGap;
public Live []liveElement;
public boolean [][]shortlist;
public int latestElement = 0;
public int foremostElement = 0;
public DynamicQueue(Gesture []gest){
gesture = gest.clone();
noOfGestures = gesture.length;
liveElement = new Live[noOfSlots];
for (int i=0; i<noOfSlots; i++) {
liveElement[i] = new Live();
}
shortlist = new boolean[noOfSlots][noOfGestures];
for (int i=0; i<noOfSlots; i++) {
for (int j=0; j<noOfGestures; j++) {
shortlist[i][j] = true;
}
}
dtwGap = new int[noOfSlots][noOfGestures];
}
public void overflowCheck(){
/* if(latestElement == foremostElement){
System.out.print("\n");
System.out.println("#########################");
System.out.println("#### Queue Overflow! ####");
System.out.println("##### Bogus follows #####");
System.out.println("#########################");
}*/
}
public void updateQueue(Live live){
liveElement[latestElement] = new Live(live);
for (int i=0; i<noOfGestures; i++) {
shortlist[latestElement][i] = true;
}
latestElement = (latestElement+1)%noOfSlots;
overflowCheck();
}
public int getShortlistCount(int slotNo){
int count = 0;
for (int i=0; i<noOfGestures; i++) {
if(shortlist[slotNo][i]) count++;
}
return count;
}
public int firstShortlistGestureIndex(int slotNo){
int i;
for (i=0; i<noOfGestures; i++) {
if(shortlist[slotNo][i]) break;
}
return i;
}
public boolean warpFit(int gestIndex, int slot, int tail){
// thresholdupdate();
return true;
}
public int[][] liveTempArrayComp(int slotNo, int livesTailNo){
int count = 0;
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++){
// for (int i=slotNo; i!=livesTailNo; i=(i+1)%noOfSlots){
x[i] = liveElement[(i+slotNo)%noOfSlots].reading;
}
return x;
}
public void processLive(int slotNo, int livesTailNo){
int threshold = 5;
DTW x;
int[][] arraytemp = liveTempArrayComp(slotNo,livesTailNo);
for (int i=0; i<noOfGestures; i++) {
x = new DTWtwoD();
x.arrayInput(gesture[i].getPoint(), arraytemp);
dtwGap[slotNo][i] = x.sdtwDistance();
}
for (int i=0; i<noOfGestures; i++) {
if(dtwGap[slotNo][i]>=threshold) shortlist[slotNo][i] = false;
}
}
public void processQueue(){
for (int i=foremostElement; i!=latestElement; i=(i+1)%noOfSlots) {
processLive(i,latestElement);
}
}
public void proceedExecution(){
for (int i=foremostElement; i!=latestElement; i=(i+1)%noOfSlots) {
if(getShortlistCount(i)==0) foremostElement = (foremostElement+1)%noOfSlots;
else if(getShortlistCount(i)==1) {
//gesture execute
gesture[firstShortlistGestureIndex(foremostElement)].execute(firstShortlistGestureIndex(foremostElement));
foremostElement = (foremostElement+1)%noOfSlots;
}
else break;
}
overflowCheck();
}
public void print(){
System.out.print('\n');
System.out.println("Live Elements:");
for (int i=0; i<liveElement[0].sensors; i++) {
for (int j=0; j<noOfSlots; j++) {
System.out.print(liveElement[j].reading[i] + " ");
}
System.out.print('\n');
}
gestureStatusPrint();
}
public void gestureStatusPrint(){
System.out.print('\n');
System.out.println("DTW Status:");
for (int i=0; i<noOfGestures; i++) {
for (int j=0; j<noOfSlots; j++) {
System.out.print(dtwGap[j][i] + " ");
}
System.out.print('\n');
}
System.out.println("Gesture Status:");
for (int i=0; i<noOfGestures; i++) {
for (int j=0; j<noOfSlots; j++) {
int d=0;
if(shortlist[j][i]) d=1;
System.out.print(d + " ");
}
System.out.print('\n');
}
System.out.println(foremostElement + " " + latestElement);
}
}
\ No newline at end of file
package com.example.harshith.ddc;
class Frame{
boolean mpu;
public int upperBound;
public int lowerBound;
public Frame(int index, boolean isMpu, int upBound, int lrBound, int levels){
if(!isMpu){
upperBound = upBound + index*((lrBound-upBound)/levels);
lowerBound = upBound + (index+1)*((lrBound-upBound)/levels);
}
else{
lowerBound = lrBound - (index+2)*((lrBound-upBound)/levels);
upperBound = lrBound - (index+1)*((lrBound-upBound)/levels);
}
if(index == 8){
if(isMpu){
lowerBound = upBound;
upperBound = lrBound;
}
else{
upperBound = upBound;
lowerBound = lrBound;
}
}
}
public void pushLimits(int []d){
d[0] = upperBound;
d[1] = lowerBound;
}
public void print(){
System.out.print(upperBound);
System.out.print(' ');
System.out.println(lowerBound);
}
}
\ No newline at end of file
package com.example.harshith.ddc;
class Gesture{
public int sensors = 11;
public int adcLevels = 2;
public int adcUpper = 0;
public int adcLower = 100;
public int mpuLevels = 3;
public int mpuUpper = 18000;
public int mpuLower = -18000;
public Gesture(){}
public int[][] getPoint(){
int [][] dummy = new int[100][sensors];
return dummy;
}
public void printData(){
System.out.println("Printing data...");
}
public void updateFrame(int [][] sensorLimits){
System.out.println("Updating static frame...");
}
public void updateFrame(int [][][] sensorLimits){
System.out.println("Updating dynamic frame...");
}
public void updateFrame(int []fing){
System.out.println("Updating frame for real...");
}
public boolean isInFrame(Live live){
System.out.println("Checking if the value is in the static frame...");
return true;
}
public boolean isInFrame(Live live, int index){
System.out.println("Checking if the value is in the dynamic frame...");
return true;
}
public void execute(int gest){
// perform system function
System.out.println(gest);
}
}
\ No newline at end of file
package com.example.harshith.ddc;
import java.util.Scanner;
class Live{
public int reading[];
public int sensors = 11 ;
public Live(){
reading = new int [sensors];
}
public Live(Live staticLive){
reading = new int [staticLive.sensors];
for (int i=0; i<sensors; i++) {
reading[i] = staticLive.reading[i];
}
}
public void update(int p){
for (int i=0; i<sensors; i++) {
reading[i] = p;
}
}
public void updateConsole(){
Scanner scan = new Scanner(System.in).useDelimiter("\\s");
for (int i=0; i<sensors; i++) {
reading[i] = scan.nextInt();
}
}
public void print(){
for (int i=0; i<sensors; i++) {
System.out.print(reading[i] + " ");
}
System.out.print('\n');
}
}
\ No newline at end of file
package com.example.harshith.ddc;
import java.util.Scanner;
class Prime{
public static void main(String [] args){
Gesture []a = new Gesture[8];
for (int i = 0; i<8; i++) {
a[i] = new StaticGesture();
}
int []hand = {0,0,0,0,0,0,0,0,0,0,0}; int q=0;
q=0; hand = new int [] {0,0,0,0,0,8,8,8,8,8,8};
// neutral
a[q].updateFrame(hand);
q=1; hand = new int [] {1,1,0,0,0,8,8,8,8,1,8};
// voice search
a[q].updateFrame(hand);
q=2; hand = new int [] {1,0,1,1,1,8,8,8,8,1,8};
// tap
a[q].updateFrame(hand);
q=3; hand = new int [] {0,1,1,1,0,8,8,8,8,1,8};
// call
a[q].updateFrame(hand);
q=4; hand = new int [] {0,0,1,1,1,8,8,8,-1,8,8};
// cam open
a[q].updateFrame(hand);
q=5; hand = new int [] {0,0,0,1,1,8,8,8,-1,8,8};
// cam click
a[q].updateFrame(hand);
q=6; hand = new int [] {1,0,1,1,0,8,8,8,8,1,8};
// music open
a[q].updateFrame(hand);
q=7; hand = new int [] {0,0,1,1,0,8,8,8,8,1,8};
// music play
a[q].updateFrame(hand);
for (int i=0; i<2; i++) {
System.out.println(i);
a[i].printData();
}
Live staticLive = new Live();
int no = 2;
//StaticLive.print();
int count = 0;
int gestActive = -1; boolean stay = true;
while(stay){
if(count == no){
a[gestActive].execute(gestActive);
count = 0;
gestActive = -1;
System.out.print("Continue? ");
Scanner contd = new Scanner(System.in);
String str = contd.next();
//if( str.equals("n") ) { stay = false; break; }
}
if(count<no){
staticLive.updateConsole();
}
for (int i=0; i<8; i++) {
if(a[i].isInFrame(staticLive)){
if(gestActive == i){
count++; continue;
}
else{
gestActive = i; count = 1; continue;
}
}
}
}
}
}
\ No newline at end of file
......@@ -70,7 +70,6 @@ public class ReceiveDataThread extends Thread {
startOfLineIndex = 1;
}
String dataIn = stringBuilder.substring(startOfLineIndex, endOfLineIndex);
String[] readingStrings = dataIn.split("\\+");
readings = new int[readingStrings.length];
for (int i = 0; i != readingStrings.length; i++) {
......
package com.example.harshith.ddc;
class StaticGesture extends Gesture {
public int [][] eFrame;
public StaticGesture(){
eFrame = new int [sensors] [];
for (int i=0; i<sensors; i++) {
eFrame[i] = new int [2];
}
}
public void printData(){
for (int i=0; i<5; i++) {
String text = String.format("%03d", eFrame[i][0]);