当前位置: 首页>>代码示例>>C++>>正文


C++ Corpus::shuffle方法代码示例

本文整理汇总了C++中Corpus::shuffle方法的典型用法代码示例。如果您正苦于以下问题:C++ Corpus::shuffle方法的具体用法?C++ Corpus::shuffle怎么用?C++ Corpus::shuffle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Corpus的用法示例。


在下文中一共展示了Corpus::shuffle方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

/*
* main
*/
int main(int argc, char* argv[])
{
	seedMT( time(NULL) );
	// seedMT(4357U);

	if (argc > 1)
	{
		Corpus* c = new Corpus();
		Params param;
		param.INNER_CV = true;
		if ( strcmp(argv[1], "estinf") == 0 ) {
			param.read_settings("settings.txt");
			param.NTOPICS = atoi(argv[2]);
			param.NLABELS = atoi(argv[3]);
			param.NFOLDS = atoi(argv[4]);
			param.INITIAL_C = atof(argv[5]);
			param.DELTA_ELL = atof(argv[6]);

			printf("K: %d, C: %.3f, Alpha: %d, svm: %d\n", param.NTOPICS, 
				param.INITIAL_C, param.ESTIMATE_ALPHA, param.SVM_ALGTYPE);

			c->read_data(param.train_filename, param.NLABELS);
			char dir[512];
			sprintf(dir, "20ng%d_c%d_f%d", param.NTOPICS, (int)param.INITIAL_C, param.NFOLDS);
			make_directory(dir);

			if ( param.INNER_CV ) {
				c->shuffle();

				char modelDir[512];
				sprintf(modelDir, "%s/innercv", dir);
				make_directory(modelDir);

				param.INITIAL_C = innerCV(modelDir, c, &param);
				printf("\n\nBest C: %f\n", param.INITIAL_C);
			}
			MedLDA model;
			model.run_em(argv[7], dir, c, &param);

			// testing.
			Corpus *tstC = new Corpus();
			tstC->read_data(param.test_filename, param.NLABELS);
			MedLDA evlModel;
			double dAcc = evlModel.infer(dir, tstC, &param);
			printf("Accuracy: %.3f\n", dAcc);
			delete tstC;
		}
		if ( strcmp(argv[1], "est") == 0 ) {
			param.read_settings("settings.txt");
			param.NTOPICS = atoi(argv[2]);
			param.NLABELS = atoi(argv[3]);
			param.NFOLDS = atoi(argv[4]);
			param.INITIAL_C = atof(argv[5]);
			param.DELTA_ELL = atof(argv[6]);

			c->read_data(param.train_filename, param.NLABELS);
			char dir[512];
			sprintf(dir, "%s%d_c%d_f%d", argv[7], param.NTOPICS, param.INITIAL_C, param.NFOLDS);
			make_directory(dir);

			if ( param.INNER_CV ) {
				c->shuffle();

				char modelDir[512];
				sprintf(modelDir, "%s/innercv", dir);
				make_directory(modelDir);

				param.INITIAL_C = innerCV(modelDir, c, &param);
				printf("\n\nBest C: %f\n", param.INITIAL_C);
			}
			MedLDA model;
			model.run_em(argv[8], dir, c, &param);
		}
		if (strcmp(argv[1], "inf")==0)
		{
			param.read_settings("settings.txt");
			param.NLABELS = atoi(argv[2]);
			c->read_data(param.test_filename, param.NLABELS);
			MedLDA model;
			double dAcc = model.infer(argv[3], c, &param);
			printf("Accuracy: %.3f\n", dAcc);
		}

		delete c;
	} else {
		printf("usage : MEDsLDAc estinf [k] [labels] [fold] [initial C] [l] [random/seeded/*]\n");
		printf("        MEDsLDAc est [k] [labels] [fold] [initial C] [l] [dir root] [random/seeded/*]\n");
		printf("        MEDsLDAc inf [labels] [model]\n");
	}
	return(0);
}
开发者ID:aacharya,项目名称:DSLDA2,代码行数:94,代码来源:main.cpp


注:本文中的Corpus::shuffle方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。