⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 select_analysis.c

📁 使用具有增量学习的监控式学习方法。包括几个不同的分类算法。
💻 C
字号:
/* Copyright (C) 2002  Mikael Ylikoski * See the accompanying file "README" for the full copyright notice *//** * @file * Select database analysis. * Prints all vectors in a classifier database with terms sorted in * order of weight. Words are taken from a dictionary file. * * Maybe also calculate overall (total sum over all classes) vector. * * Maybe also show for each word the weight for all classes: * hello: 0=2 1=24 2=43 3=0 * * @author  Mikael Ylikoski * @date    2002 */#include <stdio.h>#include <stdlib.h>#include <string.h>#include "dictionary.h"#include "utility.h"#include "vector.h"/** * Add word from dictionary to array. * * @param w  word to add */static voidadd_word (gpointer key, gpointer value, gpointer data) {    char **words;    words = (char **)data;    words[*(int *)value] = (char *)key;}/** * Main program. */intmain (int argc, char *argv[]) {    FILE *f;    const char *str;    char **words;	/**< Array of words from dictionary */    int i, j, k, noc;    dict *dt;    vector *v;    vv *var;    if (argc != 3) {	fprintf (stderr, "Usage: %s <vectorizer file> <database file>\n",		 argv[0]);	return 1;    }    /* Load dictionary */    f = fopen (argv[1], "r");    if (!f) {	fprintf (stderr, "Error: Cannot open dictionary file\n");	return 1;    }    dt = NULL;    while ((str = get_next_key (f))) {	if (!strcmp (str, "dictionary")) {	    dt = dict_load (f);	    break;	}	flush_next_value (f);    }    fclose (f);    if (!dt) {	fprintf (stderr, "Error: Cannot load dictionary\n");	return 1;    }    /* Print sorted dictionary */    j = dict_get_size (dt);    words = my_malloc (sizeof(char *) * j);    dict_for_each (dt, add_word);    //for (i = 0; i < j; i++)    //	printf ("%d %s\n", i, words[i]);    /* Load classifier */    f = fopen (argv[2], "r");    if (!f) {	fprintf (stderr, "Error: Cannot open classifier file\n");	return 1;    }    /* Load global */    noc = -1;    while ((str = get_next_key (f))) {	if (!strcmp (str, "noc")) {	    str = get_next_value (f);	    noc = atoi (str);	    break;	} else if (str[0] == '[') {	    break;	}	flush_next_value (f);    }    if (noc < 1) {	fprintf (stderr, "Error: Cannot find any classes\n");	return 1;    }    while ((str = get_next_key (f))) {	if (!strcmp (str, "[global]")) {	    printf ("%s\n", str);	    break;	}	flush_next_value (f);    }    if (!str) {	fprintf (stderr, "Error: Cannot find global section\n");	return 1;    }    /* Load classes */    for (i = 0; i <= noc; i++) {	while ((str = get_next_key (f))) {	    if (!strcmp (str, "vec")) {		v = vector_load (f);		if (!v) {		    printf ("error\n");		}		var = vector_sort (v);		k = v->nel;		for (j = 0; j < k; j++) {		    //printf ("%d:", var[j].num);		    printf ("%s:", words[var[j].num]);		    printf ("%f ", var[j].val);		}		printf ("\n");		continue;	    } else if (str[0] == '[') {		printf ("%s\n", str);		break;	    }	    flush_next_value (f);	}    }    return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -