normalised added DTW algo
This commit is contained in:
parent
658e423553
commit
1ee60c80b2
|
@ -1,4 +1,3 @@
|
|||
|
||||
/*pavan changes*/
|
||||
|
||||
void DTWdistance(struct data_frame *df,gboolean *result);
|
|
@ -2,15 +2,9 @@
|
|||
#include <gtk/gtk.h>
|
||||
// intial variables
|
||||
|
||||
unsigned long long int count_A=500;
|
||||
unsigned long long int count_B=500;
|
||||
unsigned long long int count_C=500;
|
||||
long double A=50;
|
||||
long double B=49.5;
|
||||
long double C=50.5;
|
||||
|
||||
|
||||
//function declaration
|
||||
gboolean kmeans(struct data_frame *df,unsigned long long int *count_A,unsigned long long int *count_B,
|
||||
unsigned long long int *count_C,long double *A,long double *B,long double *C);
|
||||
gboolean kmeans(struct data_frame *df);
|
||||
|
||||
/*Pavan Changes*/
|
60596
iPDC/points.csv
60596
iPDC/points.csv
File diff suppressed because it is too large
Load Diff
|
@ -1,4 +1,3 @@
|
|||
|
||||
#include "parser.h"
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
@ -11,7 +10,7 @@ int count_track1=0;
|
|||
int count_track2=0;
|
||||
int flag=0;
|
||||
|
||||
void DTWdistance(struct data_frame *df,gboolean *result)
|
||||
void DTWdistance(struct data_frame *df,int *result)
|
||||
{
|
||||
float CURR_FREQ = 50 + to_intconvertor(df->dpmu[0]->freq)*1e-3;
|
||||
// printf("count1: %d\ncount2: %d\n",count_track1,count_track2);
|
||||
|
@ -73,11 +72,19 @@ void DTWdistance(struct data_frame *df,gboolean *result)
|
|||
}
|
||||
|
||||
printf("DTWdistance: %f\n",DTW[500][500]);
|
||||
if(DTW[500][500]>=35) *result=false;
|
||||
else *result=true;
|
||||
free(freq1);
|
||||
if(DTW[500][500]>=35)
|
||||
{
|
||||
free(freq2);
|
||||
*result=0;
|
||||
}
|
||||
else
|
||||
{
|
||||
long double *temp=freq1;
|
||||
freq1=freq2;
|
||||
free(temp);
|
||||
*result=1;
|
||||
}
|
||||
free(DTW);
|
||||
count_track1=0;
|
||||
count_track1=1;
|
||||
}
|
||||
}
|
|
@ -2,32 +2,56 @@
|
|||
|
||||
#include "parser.h"
|
||||
#include <stdlib.h>
|
||||
c
|
||||
#include <stdio.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include <math.h>
|
||||
|
||||
FILE *fp;
|
||||
/*intial weights weights for each points */
|
||||
unsigned long long int count_A = 1000;
|
||||
unsigned long long int count_B = 1000;
|
||||
unsigned long long int count_C = 1000;
|
||||
|
||||
gboolean kmeans(struct data_frame *df,unsigned long long int *count_A,unsigned long long int *count_B,
|
||||
unsigned long long int *count_C,long double *A,long double *B,long double *C)
|
||||
/*In India frequency ranges from 49.5 to 50.2 Hz*/
|
||||
long double std_dev = 0.6454972244;
|
||||
long double A = 0; // for point A=50
|
||||
long double B = -1.5491933394; // for point B=49
|
||||
long double C = 0.7745966692; // for point C=50.5
|
||||
long double mean = 50;
|
||||
unsigned long long int count = 3000;
|
||||
|
||||
gboolean kmeans(struct data_frame *df)
|
||||
{
|
||||
float CURR_FREQ = 50 + to_intconvertor(df->dpmu[0]->freq)*1e-3;
|
||||
long double diff_A = fabs(*A-CURR_FREQ);
|
||||
long double diff_B = fabs(*B-CURR_FREQ);
|
||||
long double diff_C = fabs(*C-CURR_FREQ);
|
||||
//fp = fopen("points.csv","a");
|
||||
//printf("A: %Lf, B: %Lf, C: %Lf\n",*A,*B,*C);
|
||||
//fprintf(fp,"%Lf, %Lf, %Lf\n",*A,*B,*C);
|
||||
//fclose(fp);
|
||||
if(diff_A <= diff_B && diff_A <= diff_C){
|
||||
*A = ((*count_A*(*A))+CURR_FREQ)/(++*count_A);
|
||||
long double CURR_FREQ = 50 + to_intconvertor(df->dpmu[0]->freq) * 1e-3;
|
||||
long double CURR_FREQ_temp=CURR_FREQ;
|
||||
CURR_FREQ = (CURR_FREQ - mean) / std_dev;
|
||||
long double diff_A = fabs(A - CURR_FREQ);
|
||||
long double diff_B = fabs(B - CURR_FREQ);
|
||||
long double diff_C = fabs(C - CURR_FREQ);
|
||||
fp = fopen("points.csv","a");
|
||||
printf("A: %Lf, B: %Lf, C: %Lf\n",A,B,C);
|
||||
fprintf(fp,"%Lf, %Lf, %Lf\n",A,B,C);
|
||||
fclose(fp);
|
||||
|
||||
/*Updating std_dev and mean*/
|
||||
printf("std_dev: %Lf, mean: %Lf\n",std_dev,mean);
|
||||
mean= ((mean*count)+CURR_FREQ_temp)/(++count);
|
||||
std_dev=(((std_dev*std_dev)*(count-1))+(CURR_FREQ*std_dev*CURR_FREQ*std_dev))/count;
|
||||
std_dev=sqrt(std_dev);
|
||||
|
||||
if (diff_A <= diff_B && diff_A <= diff_C)
|
||||
{
|
||||
A = ((count_A * (A)) + CURR_FREQ) / (++count_A);
|
||||
return TRUE;
|
||||
}
|
||||
else if(diff_B < diff_C){
|
||||
*B = ((*count_B*(*B))+CURR_FREQ)/(++*count_B);
|
||||
else if (diff_B < diff_C)
|
||||
{
|
||||
B = ((count_B * (B)) + CURR_FREQ) / (++count_B);
|
||||
return FALSE;
|
||||
}
|
||||
else{
|
||||
*C = ((*count_C*(*C))+CURR_FREQ)/(++*count_C);
|
||||
else
|
||||
{
|
||||
C = ((count_C * (C)) + CURR_FREQ) / (++count_C);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include "align_sort.h"
|
||||
#include "map_vis.h"
|
||||
#include "parser.h"
|
||||
|
@ -8,7 +9,9 @@
|
|||
#include "Kmeans.h"
|
||||
#include "Dynamic_time_warping.h"
|
||||
|
||||
gboolean value = true;
|
||||
/*used for DTW*/
|
||||
int result=1;
|
||||
/*used for DTW*/
|
||||
|
||||
gboolean update_images(gpointer* pars){
|
||||
myParameters* parameters = (myParameters*) pars;
|
||||
|
@ -19,9 +22,8 @@ gboolean update_images(gpointer* pars){
|
|||
int freq = to_intconvertor(df->dpmu[0]->freq);
|
||||
//gboolean green =attack_detect(df,&START,&COUNT,&SUM_OF_FREQUENCY);
|
||||
//printf("map_vis A: %Lf, B: %Lf,C: %Lf\n",A,B,C);
|
||||
//gboolean green = kmeans(df,&count_A,&count_B,&count_C,&A,&B,&C);
|
||||
DTWdistance(df,&value);
|
||||
gboolean green=value;
|
||||
gboolean green = kmeans(df);
|
||||
//DTWdistance(df,&result);
|
||||
if(parameters->g_last_image != 0){
|
||||
osm_gps_map_image_remove(parameters->util_map, parameters->g_last_image);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue