Beispiel #1
0
void make_nn(char *path_pattern, char *saved_name)
{
    size_t desc_layers[] = { 400, 210, 52 };
    struct net nwk = net_init(3, desc_layers);
    struct training t = load_pattern(path_pattern);

    train_nn(nwk, t);
    net_save(nwk, saved_name);
    net_free(nwk);
}
Beispiel #2
0
/*
  corrected solution with dense format extension
*/
void read_problem(const char *filename)
{
	int elements, max_index, i, j;
	int type, dim;

	FILE *fp = fopen(filename,"r");
	if(fp == NULL)
	{
		fprintf(stderr,"can't open input file %s\n",filename);
		exit(1);
	}

    // Support multiple data files and label renaming map
    bool mfilemode = false;
	int ch1 = getc(fp);
	if (ch1 == '#')
	{
		int ch2 = getc(fp);
		if (ch2 == 'm')
            mfilemode = true;
		do { ch2 = getc(fp); } while (ch2 != '\n');
	}
    else 
        ungetc(ch1,fp);

    if (mfilemode == true)
    {
        int numFile;     
        int numMap;
        fscanf(fp,"%d %d\n", &numFile, &numMap); 
        printf("#files : %d",numFile);
        char** filenames = new char*[numFile];
        int*   numPats   = new int[numFile];
        int fidx;
        for (fidx = 0; fidx<numFile; fidx++)
        {
            filenames[fidx] = new char[FILENAME_LEN];
            fscanf(fp,"%s\n", filenames[fidx]);
            printf(", %s", filenames[fidx]);
        }
        printf("\n");
        double *orgLab = new double[numMap];
        double *newLab = new double[numMap];
        for (int midx = 0; midx<numMap; midx++)
        {            
            fscanf(fp,"%lf>%lf\n", orgLab+midx, newLab+midx);
            printf("%g>%g\n", orgLab[midx],newLab[midx]);
        }

   	    prob.l   = 0;
	    elements = 0;
	    type     = 0; // sparse format
	    dim      = 0;
        for (fidx = 0; fidx<numFile; fidx++)
        {
            FILE *fp2 = fopen(filenames[fidx],"r+t");
            if(fp2 == NULL)
		        fprintf(stderr,"can't open input file %s\n",filenames[fidx]);	
	        else
    	        count_pattern(fp2, prob, elements, type, dim);
            numPats[fidx] = prob.l;
            fclose(fp2);
        }

        prob.y  = Malloc(double,prob.l);
	    prob.x  = Malloc(struct svm_node *,prob.l);
	    x_space = Malloc(struct svm_node,elements + prob.l);

	    if (!prob.y || !prob.x || !x_space)
	    {
		    fprintf(stdout, "ERROR: not enough memory!\n");

		    prob.l = 0;
		    return;
	    }

	    max_index = 0;
	    j         = 0;
        for (fidx = 0; fidx<numFile; fidx++)
        {
            FILE *fp2 = fopen(filenames[fidx],"r+t");
            if(fp2 == NULL)
		        fprintf(stderr,"can't open input file %s\n",filenames[fidx]);	
	        else
                load_pattern(fp2, prob, type, dim, (fidx>0)?numPats[fidx-1]:0, numPats[fidx],  max_index, j, orgLab, newLab, numMap);            
            fclose(fp2);
        }
        for (fidx = 0; fidx<numFile; fidx++)
            delete [] filenames[fidx];
        delete [] filenames;
        delete [] numPats;
        delete [] orgLab;
        delete [] newLab;
    }