亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? em.c

?? k means algorithms for clustering purpose
?? C
字號:
/**
 *
 *	Data Mining 4TF3
 *	em implementation
 *	George A. Papayiannis
 *
 *	Inputs: <infile> <#observations> <#clusters>
 *	Output: To screen the clusters
 *
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>


/**
 *	Mean structure
 */

typedef struct mu_values {
	double mu_x;
	double mu_y;
} mu_stats;

/**
 *	Standard deviation structure
 */

typedef struct sd_values {
	double sd_x;
	double sd_y;
} sd_stats;

/**
 *	Probability structure
 */

typedef struct p_values {
	float p_x;
	float p_y;
} p_stats;

/**
 *	Cluster structure
 */

typedef struct cluster_values {
	mu_stats mu;
	sd_stats sd;
	p_stats p;
	p_stats e;
} cluster_stat;

/**
 *	Structure used to hold the points in the dataset
 *	x,y are the 2D values
 *	c is the cluster the point is currently part of
 *	p is the probability the given point is part of c
 */

typedef struct values {
	int x, y;
	int c;
	p_stats p;
} point;


/**
 *	Function definitions
 */

double normdist(int pt, double mu, double sd);
mu_stats calc_mu(point ds[], int num_points, int cluster);
sd_stats calc_sd(point ds[], int num_points, int cluster, mu_stats mu);
p_stats calc_p(point ds[], int num_points, int cluster);
p_stats calc_error(point ds[], int num_points, int cluster);

/**
 *	Main function
 */

int main(int argc, char *argv[]) {
	// check to ensure proper number of inputs provided
	if(argc < 3) {
		printf("USAGE: kmeans <infile> <#observations> <#clusters>\n");
		return -1;
	}
	//
	int num_points = atoi(argv[2]);
	int lcount = 0;
	int i, j, rand_x, rand_y, done;
	int max_x = 0; 
	int max_y = 0;
	int num_clusters = atoi(argv[3]);
	//
	FILE *infile;
	//
	point dataset[num_points];
	cluster_stat cluster_arr[num_clusters];
	cluster_stat old_cluster_arr[num_clusters];
	//
    char *str1;
	char line[100];
	//
	printf("\n---------------------------------------------\n");
	printf("em: processing input\n");
	printf("---------------------------------------------\n");
	printf("\nem: number of clusters %i\n",num_clusters);
	printf("em: number of points %i\n\n",num_points);
	//
	// initialize the dataset to -1
	//
	for (i=0; i<num_points; i++) {
		point value;
		value.x = -1;
		value.y = -1;
		value.c = -1;
		value.p.p_x = 0.01;
		value.p.p_y = 0.01;
		dataset[i] = value;
	}
	//	
	// open the file - if NULL is returned there was an error
	//
	if((infile = fopen(argv[1], "r")) == NULL) {
		printf("em: error opening file\n");
		exit(1);
	}
	//
	// read the file - set the dataset with the actual values
	//
	while( fgets(line, sizeof(line), infile) != NULL ) {
		point temp;
		temp = dataset[lcount];
		//
        str1 = strtok(line, " ");
		temp.x = atoi(str1);
		//	
		str1 = strtok(NULL, " ");
		temp.y = atoi(str1);
		//
		// find the maximums
		if (temp.x > max_x) {
			max_x = temp.x;
		}
		if (temp.y > max_y)	{
			max_y = temp.y;
		}
		//
		dataset[lcount] = temp;
		lcount++;
		printf("em: line %d - %i %i\n", lcount, temp.x, temp.y);	
	}
	// close the handle on the infile
	fclose(infile);
	//
	// seed the random generator with the time
	//
	srand(time(0));
	printf("\n---------------------------------------------\n");
	printf("em: randomly divide the dataset into %i clusters\n", num_clusters);
	printf("---------------------------------------------\n\n");
	//
	// randomly create the centers
	//
	int partition = num_points / num_clusters;
	int temp_count = 0;
	
	point temp_point;
	point temp_ds[partition];
	mu_stats mu_result;

	for (i=0; i<num_clusters; i++ ) {
		temp_count = 0;
		for (j=(partition*i); j<partition*(i+1); j++) {
			temp_point = dataset[j];
			temp_point.c = i;
			//temp_ds[temp_count] = temp_point;
			dataset[j] = temp_point;
			temp_count++;
		}	
		mu_result = calc_mu(dataset, num_points, i);
		sd_stats sd_result = calc_sd(dataset, num_points, i, mu_result);
		cluster_stat cluster;
		cluster.mu = mu_result;
		cluster.sd = sd_result;
		cluster.p = calc_p(dataset,num_points,i);
		cluster.e = calc_error(dataset,num_points,i);
		cluster_arr[i] = cluster;
		printf("em: cluster %i mu %f %f sd %f %f p %f %f e %f %f\n", i, cluster.mu.mu_x, cluster.mu.mu_y, cluster.sd.sd_x, cluster.sd.sd_y, cluster.p.p_x, cluster.p.p_y, cluster.e.p_x, cluster.e.p_y);
	}
	//
	// cluster the dataset - loop until done
	//
	printf("\n---------------------------------------------\n");
	printf("em: iterating till mu and sd close enough..\n");
	printf("---------------------------------------------\n\n");

	int iteration = 0;
	while(1) {
		// check which cluster a point should be a part of
		printf("em: iteration %i\n", iteration);
		for (i=0; i<num_clusters; i++ ) {
			for (j=0; j<num_points; j++ ) {
				point rt;
				cluster_stat ct;
				p_stats pr;
				ct = cluster_arr[i];
				rt = dataset[j];
				pr.p_x = ct.p.p_x * normdist(rt.x, ct.mu.mu_x, ct.sd.sd_x);
				pr.p_y = ct.p.p_y * normdist(rt.y, ct.mu.mu_y, ct.sd.sd_y);
				rt.p = pr;
				if (pr.p_x > ct.p.p_x && pr.p_y > ct.p.p_y){
					//printf("%i\n",i);
					rt.c = i;
				}
				dataset[j] = rt;
				// printf("%f\n",temp_result_x * temp_result_y);
			}				
		}
		//
		// detemine the new mixture, calculate the error
		//
		done = 1;
		for (i=0; i<num_clusters; i++ ) {
			cluster_stat cluster;
			cluster = cluster_arr[i];
			cluster.p = calc_p(dataset,num_points,i);
			cluster.mu = calc_mu(dataset, num_points, i);
			cluster.sd = calc_sd(dataset, num_points, i, mu_result);
			p_stats ce = calc_error(dataset,num_points,i);
			//printf("%f, %f, %f \n", ce.p_x, cluster.e.p_x, abs(ce.p_x) - abs(cluster.e.p_x));
			cluster.e = ce;
			cluster_arr[i] = cluster;
			printf("em: cluster %i mu %f %f sd %f %f p %f %f e %f %f\n", i, cluster.mu.mu_x, cluster.mu.mu_y, cluster.sd.sd_x, cluster.sd.sd_y, cluster.p.p_x, cluster.p.p_y, cluster.e.p_x, cluster.e.p_y);
			if ( (abs(ce.p_x) - abs(cluster.e.p_x)) < 1.0) {
				done = 0;
			}
			//	printf("error: %f\n",abs(ce.p_x - cluster.e.p_x));
				
		}
		if (done == 0){
			break;
		}		
		iteration++;
	}
	//
	// output clusters
	//
	printf("\n---------------------------------------------\n");
	printf("em: clustering complete\n");
	printf("---------------------------------------------\n");
	for (i=0; i<num_clusters; i++ ) {
		cluster_stat cluster = cluster_arr[i];
		printf("em: final cluster %i mu %f %f sd %f %f p %f %f e %f %f\n", i, cluster.mu.mu_x, cluster.mu.mu_y, cluster.sd.sd_x, cluster.sd.sd_y, cluster.p.p_x, cluster.p.p_y, cluster.e.p_x, cluster.e.p_y);
		for (j=0; j<num_points; j++ ) {
			point rt;
			rt = dataset[j];
			// output based on cluster
			if (rt.c == i) {
				printf("em: cluster %i point (%i,%i)\n",rt.c,rt.x,rt.y);
			}
		}						
	}
}

/**
 *	Density function for normal distribution
 */

double normdist(int pt, double mu, double sd) {
	double result = 0.0;
	result = 1/(sqrt(2*M_PI)*sd);
	result = result * exp( (pow((double)pt - mu, 2.0)) / (2.0 * pow(sd,2.0)));
	return result;
}

/**
 *	Calculate mu of the given cluster.  The probability of each point
 *	being part of that given cluster will be used as a weight for that point.
 *	This is following what was said in DM: PMLTaT - WF
 */

mu_stats calc_mu(point ds[], int num_points, int cluster) {
	//
	int i = 0;
	p_stats prob;
	//
	point temp;
	mu_stats result;
	//
	result.mu_x = 0.0;
	result.mu_y = 0.0;
	prob.p_x = 0.0;
	prob.p_y = 0.0;
	//
	for (i=0; i<num_points; i++) {
		temp = ds[i];
		//printf("\n%i %i %i %i",start_index, end_index, temp.c, i);
		if (temp.c == cluster) {
			
			//printf("\nsanity: %i %i %i %i",temp.x,temp.y,temp.c, i);

			result.mu_x = result.mu_x + (temp.x*temp.p.p_x);
			result.mu_y = result.mu_y + (temp.y*temp.p.p_y);
			prob.p_x = prob.p_x + temp.p.p_x;
			prob.p_y = prob.p_y + temp.p.p_y;

		}
	}
	//
	result.mu_x = result.mu_x/prob.p_x;
	result.mu_y = result.mu_y/prob.p_y;
	//
	return result;
}

/**
 *	Calculate sd of the given cluster, based on the mu.  The probability of each point
 *	being part of that given cluster will be used as a weight for that point.
 *	This is following what was said in DM: PMLTaT - WF
 */

sd_stats calc_sd(point ds[], int num_points, int cluster, mu_stats mu) {
	int i = 0;
	p_stats prob;
	//
	point temp;
	sd_stats result;
	//
	result.sd_x = 0.0;
	result.sd_y = 0.0;
	prob.p_x = 0.0;
	prob.p_y = 0.0;

	//
	for (i=0; i<num_points; i++) {
		temp = ds[i];
		if (temp.c == cluster) {
			result.sd_x = result.sd_x + (temp.p.p_x * pow((temp.x - mu.mu_x),2));
			result.sd_y = result.sd_y + (temp.p.p_y * pow((temp.y - mu.mu_y),2));
			prob.p_x = prob.p_x + temp.p.p_x;
			prob.p_y = prob.p_y + temp.p.p_y;
		}
	}
	//
	result.sd_x = result.sd_x/prob.p_x;
	result.sd_y = result.sd_y/prob.p_y;
	//
	return result;
}

/**
 *	Calculates the probability of a given cluster
 */

p_stats calc_p(point ds[], int num_points, int cluster) {
	int i=0;
	int count = 0;
	p_stats result;
	result.p_x = 0.0;
	result.p_y = 0.0;
	
	point temp;

	for (i=0; i<num_points; i++) {
		temp = ds[i];
		if (temp.c == cluster) {
			result.p_x = result.p_x + temp.p.p_x;
			result.p_y = result.p_y + temp.p.p_y;
			count++;
		}
	}
	//
	result.p_x = result.p_x / count;
	result.p_y = result.p_y / count;
	//
	return result;

}

/**
 *	Calculates the error of a given cluster
 */

p_stats calc_error(point ds[], int num_points, int cluster) {
	int i=0;
	p_stats result;
	result.p_x = 0.0;
	result.p_y = 0.0;
	
	point temp;

	for (i=0; i<num_points; i++) {
		temp = ds[i];
		if (temp.c == cluster) {
			result.p_x = result.p_x + log(temp.p.p_x);
			result.p_y = result.p_y + log(temp.p.p_y);
		}
	}
	//
	return result;
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
久久噜噜亚洲综合| 亚洲夂夂婷婷色拍ww47| 精品久久久久久久久久久久包黑料 | 久久精品人人做| 日韩一二在线观看| 日韩网站在线看片你懂的| 日韩一区二区三免费高清| 欧美一区二区免费视频| 欧美一级黄色大片| 久久久蜜桃精品| 国产女主播一区| 国产精品剧情在线亚洲| 成人免费在线视频观看| 日韩理论电影院| 亚洲一区在线观看视频| 亚洲a一区二区| 青青草97国产精品免费观看| 日精品一区二区三区| 日本午夜一本久久久综合| 久久99精品一区二区三区三区| 久久99国产精品尤物| 国产一区二区电影| av一二三不卡影片| 不卡av在线网| 日本韩国一区二区三区| 欧美视频一区二区在线观看| 7777精品伊人久久久大香线蕉| 日韩三级视频中文字幕| 亚洲精品在线免费观看视频| 亚洲国产aⅴ天堂久久| 色综合久久中文字幕综合网| 欧美这里有精品| 3d动漫精品啪啪一区二区竹菊| 8x8x8国产精品| 日韩欧美国产系列| 国产精品午夜电影| 亚洲一卡二卡三卡四卡无卡久久| 免费看日韩a级影片| 国产一区二区三区日韩| 91丝袜美女网| 93久久精品日日躁夜夜躁欧美| 91视频.com| 日韩三级在线观看| 自拍偷拍国产精品| 日韩精品色哟哟| 国产福利一区二区三区视频在线| 91在线视频官网| 欧美一区二区久久| 国产精品成人网| 日韩 欧美一区二区三区| 东方欧美亚洲色图在线| 欧美视频你懂的| 久久久久久麻豆| 亚洲电影第三页| 国产成人欧美日韩在线电影 | 国产亚洲一本大道中文在线| 一区二区三区四区中文字幕| 韩国v欧美v亚洲v日本v| 色94色欧美sute亚洲13| 精品精品欲导航| 一区二区三区精密机械公司| 国产一区二区三区免费播放 | 久久久久9999亚洲精品| 亚洲自拍偷拍图区| 成人污视频在线观看| 欧美一区二区精美| 亚洲免费av网站| 国产精品资源站在线| 7799精品视频| 亚洲资源中文字幕| 丁香另类激情小说| 欧美不卡激情三级在线观看| 亚洲一区二区三区不卡国产欧美| 国产一区二区三区在线观看免费| 欧美日韩一区二区欧美激情| 国产精品国产三级国产aⅴ中文| 美女尤物国产一区| 欧美日韩情趣电影| 亚洲乱码日产精品bd| 高清日韩电视剧大全免费| 欧美成人精精品一区二区频| 亚洲.国产.中文慕字在线| 91亚洲午夜精品久久久久久| 国产日韩av一区二区| 久久99国产精品久久99| 欧美二区乱c少妇| 亚洲一区在线电影| 91成人免费在线视频| 成人免费视频在线观看| 国产成人精品网址| 亚洲精品一区二区三区影院| 美国精品在线观看| 在线播放中文一区| 午夜精品久久久久| 欧美猛男gaygay网站| 亚洲精品日产精品乱码不卡| av亚洲产国偷v产偷v自拍| 国产免费成人在线视频| 亚洲人妖av一区二区| 欧美成人午夜电影| 国产精品视频一二| 丰满少妇在线播放bd日韩电影| 精品久久久网站| 久久69国产一区二区蜜臀| 日韩视频免费直播| 免费国产亚洲视频| 精品对白一区国产伦| 久久精品国产99国产精品| 欧美一区二区女人| 蜜乳av一区二区| 久久亚洲精品国产精品紫薇| 国产美女精品人人做人人爽| 久久日韩粉嫩一区二区三区| 国产精品1区二区.| 久久精品欧美日韩| 成人午夜精品在线| 亚洲天堂久久久久久久| 在线视频国内一区二区| 亚洲国产aⅴ天堂久久| 91精品国产综合久久精品app| 奇米一区二区三区| 国产网站一区二区| 色婷婷综合激情| 亚洲超碰精品一区二区| 欧美一级日韩一级| 国产精选一区二区三区| 国产精品久久毛片a| 91免费版pro下载短视频| 亚洲国产另类精品专区| 欧美一区二区视频免费观看| 精品一区二区国语对白| 国产精品久久久久婷婷| 在线观看视频欧美| 视频一区欧美日韩| 久久影院午夜论| 91麻豆视频网站| 丝袜国产日韩另类美女| 精品国产免费一区二区三区四区 | 午夜久久久影院| 欧美va天堂va视频va在线| 夫妻av一区二区| 一区二区三区四区av| 91精品国产综合久久福利软件| 国产一区二区三区免费播放 | 国产精品白丝jk白祙喷水网站| 亚洲欧美在线观看| 欧美精品乱人伦久久久久久| 国产伦精品一区二区三区免费迷 | 精品国一区二区三区| 99精品偷自拍| 免费不卡在线观看| 亚洲欧洲色图综合| 日韩精品一区二区三区中文不卡| av不卡一区二区三区| 日本不卡123| 国产精品久久免费看| 91精品国产日韩91久久久久久| 国产不卡在线视频| 日韩精品五月天| 亚洲另类中文字| 久久综合九色综合欧美亚洲| 在线观看av一区| 大桥未久av一区二区三区中文| 午夜精彩视频在线观看不卡| 欧美国产精品一区| 欧美大片顶级少妇| 欧美午夜一区二区| 成人午夜免费av| 久久99精品国产麻豆不卡| 亚洲一区影音先锋| 亚洲欧美综合另类在线卡通| 日韩精品一区在线| 欧美日韩在线综合| jlzzjlzz亚洲日本少妇| 狠狠色综合色综合网络| 一区二区久久久久| 中文一区二区在线观看| 日韩精品一区国产麻豆| 欧美性色黄大片| 日本精品免费观看高清观看| 成人白浆超碰人人人人| 国产在线视频一区二区三区| 日韩高清中文字幕一区| 亚洲精品国产第一综合99久久 | 亚洲欧洲韩国日本视频| 久久亚洲一级片| 日韩一二在线观看| 欧美日韩国产影片| 欧美视频在线一区| 色综合视频在线观看| 成人黄色777网| 成人午夜在线播放| 国产一区在线精品| 紧缚奴在线一区二区三区| 日产精品久久久久久久性色| 亚洲sss视频在线视频| 亚洲午夜久久久久久久久电影网| 最新不卡av在线| 中文字幕一区二区三区乱码在线| 欧美激情一区不卡|