kmeans algo

This commit is contained in:
pavanvpatil 2022-10-12 02:01:31 +05:30
parent 5d8acb43cf
commit 09d33644c9
3 changed files with 56 additions and 18 deletions

16
iPDC/inc/Kmeans.h Normal file
View File

@ -0,0 +1,16 @@
/*Pavan Changes*/
#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);
/*Pavan Changes*/

29
iPDC/src/Kmeans.c Normal file
View File

@ -0,0 +1,29 @@
/*Pavan Changes*/
#include "parser.h"
#include <stdlib.h>
#include <gtk/gtk.h>
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)
{
float CURR_FREQ = to_intconvertor(df->dpmu[0]->freq);
long double diff_A = abs(*A-CURR_FREQ);
long double diff_B = abs(*B-CURR_FREQ);
long double diff_C = abs(*C-CURR_FREQ);
printf("A: %Lf, B: %Lf, C: %Lf\n",*A,*B,*C);
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);
return FALSE;
}
else{
*C = ((*count_C*(*C))+CURR_FREQ)/(++*count_C);
return FALSE;
}
}
/*Pavan Changes*/

View File

@ -4,6 +4,7 @@
#include "parser.h" #include "parser.h"
#include "osm-gps-map.h" #include "osm-gps-map.h"
#include "Attack_detect.h" #include "Attack_detect.h"
#include "Kmeans.h"
gboolean update_images(gpointer* pars){ gboolean update_images(gpointer* pars){
@ -13,16 +14,8 @@ gboolean update_images(gpointer* pars){
return TRUE; return TRUE;
} }
int freq = to_intconvertor(df->dpmu[0]->freq); int freq = to_intconvertor(df->dpmu[0]->freq);
gboolean green =attack_detect(df,&START,&COUNT,&SUM_OF_FREQUENCY); //gboolean green =attack_detect(df,&START,&COUNT,&SUM_OF_FREQUENCY);
gboolean green = kmeans(df,&count_A,&count_B,&count_C,&A,&B,&C);
// if(parameters->g_last_image != 0){
// osm_gps_map_image_remove(parameters->util_map, parameters->g_last_image);
// }
// if (freq > 300){
// parameters->g_last_image = osm_gps_map_image_add(parameters->util_map,15.518597, 74.925584, parameters->g_green_image);
// }else{
// parameters->g_last_image = osm_gps_map_image_add(parameters->util_map,15.518597, 74.925584, parameters->g_red_image);
// }
if(parameters->g_last_image != 0){ if(parameters->g_last_image != 0){
osm_gps_map_image_remove(parameters->util_map, parameters->g_last_image); osm_gps_map_image_remove(parameters->util_map, parameters->g_last_image);
} }