Compare commits

..

No commits in common. "c3f46cb6a8dd27fc1cfc40e1c233d5ade9aaa1b3" and "3213347dcb24340fd465ec0b336e2cbc8048c015" have entirely different histories.

4 changed files with 9600 additions and 26952 deletions

View File

@ -1,3 +1,3 @@
int *getRandoms(int lower, int upper, int count); int *getRandoms(int lower, int upper, int count);
long double distance(struct Point* A, struct Point* B); long double distance(struct Point* A, struct Point* B);
bool Kmeans2(struct data_frame *df); void Kmeans2(struct data_frame *df);

File diff suppressed because it is too large Load Diff

View File

@ -13,17 +13,10 @@ struct Point
long double minDist; // default infinite dist to nearest cluster long double minDist; // default infinite dist to nearest cluster
}; };
struct Kmeans2 int count = 0;
{ struct Point *P;
int idcode;
int count;
struct Point *P;
struct Kmeans2 *next;
};
struct Kmeans2 *head_of_kmeans2 = NULL; long double distance(struct Point* A, struct Point* B)
long double distance(struct Point *A, struct Point *B)
{ {
return (((A->x - B->x) * (A->x - B->x)) + ((A->y - B->y) * (A->y - B->y))); return (((A->x - B->x) * (A->x - B->x)) + ((A->y - B->y) * (A->y - B->y)));
} }
@ -63,31 +56,14 @@ int *getRandoms(int lower, int upper, int count)
} }
} }
bool Kmeans2(struct data_frame *df) void Kmeans2(struct data_frame *df)
{ {
if (head_of_kmeans2 == NULL) printf("count: %d\n",count);
if(count==0)
{ {
head_of_kmeans2 = (struct Kmeans2 *)malloc(sizeof(struct Kmeans2)); P = (struct Point *)malloc(sizeof(struct Point) * 500);
head_of_kmeans2->idcode = to_intconvertor(df->idcode);
head_of_kmeans2->count = 0;
head_of_kmeans2->next = NULL;
head_of_kmeans2->P = NULL;
return true;
} }
else if (count != 500)
{
struct Kmeans2 *temp = head_of_kmeans2;
struct Kmeans2 *previous = NULL;
while (temp != NULL)
{
if (temp->idcode == to_intconvertor(df->idcode))
{
printf("count: %d\n",temp->count);
if (temp->count == 0)
{
temp->P = (struct Point *)malloc(sizeof(struct Point) * 500);
}
if (temp->count != 500)
{ {
float CURR_FREQ; float CURR_FREQ;
if (df->dpmu[0]->fmt->freq == '0') if (df->dpmu[0]->fmt->freq == '0')
@ -137,11 +113,11 @@ bool Kmeans2(struct data_frame *df)
CURR_vol = decode_ieee_single(s1); CURR_vol = decode_ieee_single(s1);
} }
} }
temp->P[temp->count].x = CURR_FREQ; P[count].x = CURR_FREQ;
temp->P[temp->count].y = CURR_vol; P[count].y = CURR_vol;
temp->P[temp->count].cluster = -1; P[count].cluster = -1;
temp->P[temp->count].minDist = __DBL_MAX__; P[count].minDist = __DBL_MAX__;
temp->count++; count++;
} }
else else
{ {
@ -151,8 +127,8 @@ bool Kmeans2(struct data_frame *df)
struct Point *Centroids = (struct Point *)malloc(sizeof(struct Point) * no_of_clusters); struct Point *Centroids = (struct Point *)malloc(sizeof(struct Point) * no_of_clusters);
for (int i = 0; i < no_of_clusters; i++) for (int i = 0; i < no_of_clusters; i++)
{ {
Centroids[i].x = temp->P[c[i]].x; Centroids[i].x = P[c[i]].x;
Centroids[i].y = temp->P[c[i]].y; Centroids[i].y = P[c[i]].y;
Centroids[i].minDist = __DBL_MAX__; Centroids[i].minDist = __DBL_MAX__;
Centroids[i].cluster = -1; Centroids[i].cluster = -1;
} }
@ -165,11 +141,11 @@ bool Kmeans2(struct data_frame *df)
{ {
for (int j = 0; j < 500; j++) for (int j = 0; j < 500; j++)
{ {
long double dist = distance(&Centroids[i], &temp->P[j]); long double dist = distance(&Centroids[i], &P[j]);
if (temp->P[j].minDist > dist) if (P[j].minDist > dist)
{ {
temp->P[j].minDist = dist; P[j].minDist = dist;
temp->P[j].cluster = i; P[j].cluster = i;
} }
} }
} }
@ -187,10 +163,10 @@ bool Kmeans2(struct data_frame *df)
for (int i = 0; i < 500; i++) for (int i = 0; i < 500; i++)
{ {
nPoints[temp->P[i].cluster]++; nPoints[P[i].cluster]++;
Sumx[temp->P[i].cluster] += temp->P[i].x; Sumx[P[i].cluster] += P[i].x;
Sumy[temp->P[i].cluster] += temp->P[i].y; Sumy[P[i].cluster] += P[i].y;
temp->P[i].minDist = __DBL_MAX__; P[i].minDist = __DBL_MAX__;
} }
for (int i = 0; i < no_of_clusters; i++) for (int i = 0; i < no_of_clusters; i++)
@ -203,43 +179,26 @@ bool Kmeans2(struct data_frame *df)
free(Sumx); free(Sumx);
free(Sumy); free(Sumy);
} }
temp->count = 0; count = 0;
FILE *fp; FILE *fp;
fp = fopen("kmeans.txt", "a"); fp = fopen("kmeans.txt","a");
for (int i = 0; i < 500; i++) for(int i=0;i<500;i++)
{ {
fprintf(fp, "%Lf, %Lf, %d\n", temp->P[i].x, temp->P[i].y, temp->P[i].cluster); fprintf(fp,"%Lf, %Lf, %d\n",P[i].x,P[i].y,P[i].cluster);
} }
fprintf(fp, "\n\n"); fprintf(fp,"\n\n");
for (int i = 0; i < no_of_clusters; i++) for(int i=0;i<no_of_clusters;i++)
{ {
fprintf(fp, "%d : %Lf, %Lf\n", i, Centroids[i].x, Centroids[i].y); fprintf(fp,"%d : %Lf, %Lf\n",i,Centroids[i].x,Centroids[i].y);
} }
fprintf(fp, "\n\n"); fprintf(fp,"\n\n");
fclose(fp); fclose(fp);
free(Centroids); free(Centroids);
free(temp->P); free(P);
}
return true;
break;
}
previous = temp;
temp = temp->next;
}
if (temp == NULL)
{
struct Kmeans2 *bring = (struct Kmeans2 *)malloc(sizeof(struct Kmeans2));
bring->idcode = to_intconvertor(df->idcode);
bring->count = 0;
bring->next = NULL;
bring->P = NULL;
previous->next = bring;
return true;
}
} }
} }

View File

@ -1,6 +1,5 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <stdbool.h>
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <pthread.h> #include <pthread.h>
#include "global.h" #include "global.h"
@ -155,11 +154,7 @@ gboolean update_images(gpointer* pars){
}else if (algorithm==1 && dimmension == 1){ }else if (algorithm==1 && dimmension == 1){
}else if (algorithm==1 && dimmension == 2){ }else if (algorithm==1 && dimmension == 2){
if(!Kmeans2(df)){ Kmeans2(df);
vis_ptr->last_image = osm_gps_map_image_add(parameters->util_map,lat, lon, parameters->g_red_image);
}else{
vis_ptr->last_image = osm_gps_map_image_add(parameters->util_map,lat, lon, parameters->g_green_image);
}
}else if (algorithm==2 && dimmension == 0){ }else if (algorithm==2 && dimmension == 0){
if(!DTWvolDistance(df)){ if(!DTWvolDistance(df)){
vis_ptr->last_image = osm_gps_map_image_add(parameters->util_map,lat, lon, parameters->g_red_image); vis_ptr->last_image = osm_gps_map_image_add(parameters->util_map,lat, lon, parameters->g_red_image);