Exemple #1
0
int main(int argc, char **argv)
{
	unsigned int size = DAT_SIZE;
	unsigned int i;
	featureset f;
	int fd;
	struct timeval start, end;
	unsigned char *mydata;
	glob_t gbuf;

	if (argc != 2) {
		fprintf(stderr, "usage: %s <dirname>\n", argv[0]);
		return 1;
	}

	if ((mydata = (unsigned char *)malloc(size)) == NULL) {
		fprintf(stderr, "mydata could not be accomodated!\n");
		return 1;
	}

	glob(argv[1], 0, NULL, &gbuf);
	init_featureset(mydata, size, &f);

	fprintf(stdout, "mean\tvariance\tentropy\tpower\tfmean\tfvariance\n");

	for (i = 0; (i < gbuf.gl_pathc); ++i) {

		fd = open(gbuf.gl_pathv[i], O_RDONLY);

		//fprintf(stdout, "%s\t", gbuf.gl_pathv[i]);
		read(fd, mydata, size);

		gettimeofday(&start, NULL);
		compute_features(mydata, size, &f);
		gettimeofday(&end, NULL);

		normalize_features(&f, size);
		fprintf(stdout, "%1.15e\t", f.mean);
		fprintf(stdout, "%1.15e\t", f.variance);
		fprintf(stdout, "%1.15e\t", f.entropy);
		fprintf(stdout, "%1.15e\t", f.power);
		fprintf(stdout, "%1.15e\t", f.fmean);
		fprintf(stdout, "%1.15e\n", f.fvariance);

		close(fd);
	}

	finit_featureset(&f);
	free(mydata);

	return 0;
}
Exemple #2
0
int main(int argc, char **argv)
{

	struct svm_model *model;
	struct svm_node *x;
	int fd;
	unsigned int i, j;
	double v;
	unsigned int size = DAT_SIZE;
	unsigned char *mydata;
	featureset f;
	glob_t gbuf;

	if (argc != 3) {
		fprintf(stderr, "usage: %s <modelfile> <inputdir>\n", argv[0]);
		return 1;
	}

	if ((model = svm_load_model(argv[1])) == 0) {
		fprintf(stderr, "could not open model file %s\n", argv[1]);
		return 1;
	}

	glob(argv[2], 0, NULL, &gbuf);

	if ((mydata = (unsigned char *)malloc(size)) == NULL) {
		fprintf(stderr, "mydata could not be accomodated!\n");
		return 1;
	}

	init_featureset(&f, size);
	x = (struct svm_node *)malloc(max_nr_attr * sizeof(struct svm_node));

	fprintf(stdout,
		"file\ttype\tmean\tvariance\tentropy\tpower\tfmean\tfvariance\n");

	for (i = 0; (i < gbuf.gl_pathc); ++i) {

		if ((fd = open(gbuf.gl_pathv[i], O_RDONLY)) == -1) {
			fprintf(stderr, "could not open input file %s\n",
				gbuf.gl_pathv[i]);
			return 1;
		}

		read(fd, mydata, size);
		compute_features(mydata, size, &f);
		normalize_features(&f, size);
		init_svmnode(&f, x);
		v = svm_predict(model, x);

		fprintf(stdout, "%s\t", gbuf.gl_pathv[i]);
		fprintf(stdout, "%g\t", v);
		for (j = 0; j < max_nr_attr; ++j)
			fprintf(stdout, "%g\t", x[j].value);
		fprintf(stdout, "\n");

		close(fd);
	}

	finit_featureset(&f);
	svm_destroy_model(model);
	free(mydata);
	free(x);
	return 0;
}