corrected somethings in algo
This commit is contained in:
parent
4a2050f8c0
commit
0a45563c3f
|
@ -34,6 +34,7 @@ gboolean attack_detect_freq(struct data_frame *df)
|
|||
head = (struct freqlist *)malloc(sizeof(struct freqlist));
|
||||
head->AVERAGE_OF_FREQUENCY = 50;
|
||||
head->COUNT = 500;
|
||||
head->idcode=to_intconvertor(df->idcode);
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
|
@ -83,6 +84,7 @@ gboolean attack_detect_freq(struct data_frame *df)
|
|||
bring = (struct freqlist *)malloc(sizeof(struct freqlist));
|
||||
bring->AVERAGE_OF_FREQUENCY = 50;
|
||||
bring->COUNT = 500;
|
||||
bring->idcode = to_intconvertor(df->idcode);
|
||||
previous->next=bring;
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -117,6 +119,7 @@ gboolean attack_detect_vol(struct data_frame *df)
|
|||
headvol = (struct vollist *)malloc(sizeof(struct vollist));
|
||||
headvol->AVERAGE_OF_VOLTAGE = CURR_vol;
|
||||
headvol->COUNT = 500;
|
||||
headvol->idcode=to_intconvertor(df->idcode);
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
|
@ -160,6 +163,7 @@ gboolean attack_detect_vol(struct data_frame *df)
|
|||
bring->AVERAGE_OF_VOLTAGE = CURR_vol;
|
||||
bring->COUNT = 500;
|
||||
previous->next = bring;
|
||||
bring->idcode = to_intconvertor(df->idcode);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,54 +6,97 @@
|
|||
#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;
|
||||
// FILE *fp;
|
||||
|
||||
/*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;
|
||||
struct kmeans1
|
||||
{
|
||||
int idcode;
|
||||
unsigned long long int count_A = 1000;
|
||||
unsigned long long int count_B = 1000;
|
||||
unsigned long long int count_C = 1000;
|
||||
long double A = 50;
|
||||
long double B = 49;
|
||||
long double C = 51;
|
||||
struct kmeans1 *next;
|
||||
}
|
||||
|
||||
struct kmeans1 *headk = NULL;
|
||||
|
||||
gboolean kmeans(struct data_frame *df)
|
||||
{
|
||||
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);
|
||||
if (headk == NULL)
|
||||
{
|
||||
headk->A = 50;
|
||||
headk->B = 49;
|
||||
headk->C = 51;
|
||||
headk->count_A = 1000;
|
||||
headk->count_B = 1000;
|
||||
headk->count_C = 1000;
|
||||
headk->next = NULL;
|
||||
headk->idcode = to_intconvertor(df->idcode);
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
struct kmeans1 *temp == headk;
|
||||
struct kmeans1 *previous == NULL;
|
||||
while (temp != NULL)
|
||||
{
|
||||
if (temp->idcode == to_intconvertor(df->idcode))
|
||||
{
|
||||
float CURR_FREQ;
|
||||
if (df->dpmu[0]->fmt->freq == '0')
|
||||
{
|
||||
CURR_FREQ = 50 + to_intconvertor(df->dpmu[0]->freq) * 1e-3;
|
||||
}
|
||||
else
|
||||
{
|
||||
CURR_FREQ = decode_ieee_single(df->dpmu[0]->freq);
|
||||
}
|
||||
|
||||
long double diff_A = fabs(temp->A - CURR_FREQ);
|
||||
long double diff_B = fabs(temp->B - CURR_FREQ);
|
||||
long double diff_C = fabs(temp->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);
|
||||
temp->A = ((temp->count_A * (temp->A)) + CURR_FREQ) / (++temp->count_A);
|
||||
return TRUE;
|
||||
}
|
||||
else if (diff_B < diff_C)
|
||||
{
|
||||
B = ((count_B * (B)) + CURR_FREQ) / (++count_B);
|
||||
temp->B = ((temp->count_B * (temp->B)) + CURR_FREQ) / (++temp->count_B);
|
||||
return FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
C = ((count_C * (C)) + CURR_FREQ) / (++count_C);
|
||||
temp->C = ((temp->count_C * (temp->C)) + CURR_FREQ) / (++temp->count_C);
|
||||
return FALSE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
previous=temp;
|
||||
temp = temp->next;
|
||||
}
|
||||
if(temp==NULL)
|
||||
{
|
||||
struct kmeans1 *bring = (struct kmeans1 *)malloc(sizeof(struct kmeans1));
|
||||
bring->A = 50;
|
||||
bring->B = 49;
|
||||
bring->C = 51;
|
||||
bring->count_A = 1000;
|
||||
bring->count_B = 1000;
|
||||
bring->count_C = 1000;
|
||||
bring->next = NULL;
|
||||
bring->idcode = to_intconvertor(df->idcode);
|
||||
previous->next=bring;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*Pavan Changes*/
|
Loading…
Reference in New Issue