int main( int argc, char *argv[] ){
    if( argc < 5 ){
        printf( "usage:<input> <taxomonyfile> <suffix> [infofiles...]\n"\
                "make item knn feature, infofile must be in the order of input so merge-sort style algorithm can be used\n" );
        return -1;
    }
    char fout[ 256 ];
    sprintf( fout, "features/%s.%s", argv[1], argv[3] );
    FILE *fi = fopen_check( argv[1], "r" );
    FILE *fo = fopen_check( fout, "w" );
    load_taxonomy( argv[2] );

    UserRecord urecord( argc - 4, argv + 4 );    
    // use iid as feature id, one for implicit and another for explicit
    fprintf( fo, "%d\n", NUM_ITEM );
    int uid, iid, rate;
    while( fscanf( fi, "%d%d%d", &uid, &iid, &rate ) == 3 ){
        urecord.init_record( uid );
        if( parent[iid] >= 0 && urecord.rec[ parent[iid] ] >= 0 ){            
            // output both explicit feedback and implicit feedback
            fprintf( fo, "1 %d:%f\n", iid, (urecord.rec[parent[iid]]-urecord.mean_score)/100.0f );
        }else{
            fprintf( fo, "0\n" ); 
        }
    }    
    fclose( fo );
    fclose( fi );
    return 0;
}
int main( int argc, char *argv[] ){
    if( argc < 3 ){
        printf( "usage:<input> <input.day>\n" );
        return -1;
    }
    load_stats();
    char fout[ 256 ];
    sprintf( fout, "features/%s.UserDayInterpolation", argv[1] );
    FILE *fi = fopen_check( argv[1], "r" );
    FILE *fd = fopen_check( argv[2], "r" );
    FILE *fo = fopen_check( fout, "w" );

    fprintf( fo, "%d\n", num_index );
    int uid, iid, rate, day;
    while( fscanf( fi, "%d%d%d", &uid, &iid, &rate ) == 3 ){
        assert_true( fscanf( fd, "%d", &day ) == 1 );
        const int base = pustart[ uid ];
        if( day == first[ uid ] ){ 
            fprintf( fo, "1 %d:1\n", base ); continue;
        }
        if( day == last[ uid ] ){ 
            fprintf( fo, "1 %d:1\n", base+1 ); continue;
        }
        fprintf( fo, "2 %d:%f %d:%f\n", 
                 base  , static_cast<float>( last[uid] - day  )/(last[uid]-first[uid]),  
                 base+1, static_cast<float>( day - first[uid] )/(last[uid]-first[uid]) );        
    }
    fclose( fo );
    fclose( fd );
    fclose( fi );
    return 0;
}
inline void load_taxonomy(  const char *fname ){
    FILE *fi = fopen_check( fname, "r" );
    for( int i = 0; i < NUM_ITEM; i ++ ){
        assert_true( fscanf( fi, "%d", &parent[i] ) == 1 );
    }
    fclose( fi );
}
inline void load_stats( void ){
    FILE *fi = fopen_check( "user_daystats.txt", "r" );
    num_index = 0;
    int uid, nday;
    while( fscanf( fi, "%d%*d%*d%d", &uid, &nday ) == 2 ){
        start[ uid ] = num_index;
        num_index += nday;
    }
    fclose( fi );
}
inline void load_stats( void ){
    num_index = 0;
    FILE *fi = fopen_check( "user_daystats.txt", "r" );
    int uid, st, ed;
    while( fscanf( fi, "%d%d%d%*d", &uid, &st, &ed ) == 3 ){
        first[ uid ] = st;
        last [ uid ] = ed;
        pustart[ uid ] = num_index;
        num_index ++;
        if( ed != st ) num_index ++;
    }
    fclose( fi );
}
int main( int argc, char *argv[] ){
    if( argc < 3 ){
        printf( "usage:<input> <input.userdayidx>\n" );
        return -1;
    }
    load_stats();
    char fout[ 256 ];
    sprintf( fout, "features/%s.UserDayBias", argv[1] );
    FILE *fi = fopen_check( argv[1], "r" );
    FILE *fd = fopen_check( argv[2], "r" );
    FILE *fo = fopen_check( fout, "w" );

    fprintf( fo, "%d\n", num_index );
    int uid, iid, rate, dayidx;
    while( fscanf( fi, "%d%d%d", &uid, &iid, &rate ) == 3 ){
        assert_true( fscanf( fd, "%d", &dayidx ) == 1 );
        fprintf( fo, "1 %d:1\n", start[ uid ] + dayidx );
    }
    fclose( fo );
    fclose( fd );
    fclose( fi );
    return 0;
}
예제 #7
0
long file_reader(char *file_name, uint8_t *memory)
{
    /* PRE:  The file with given name contains valid binary data only. The 
             memory pointer points to valid processor-emulating memory. */
    /* POST: Loads the contents of the file with given name into memory 
             starting at location pointed to by given pointer, in the same 
             endian as the file. Returns the length of the file if 
             successful. */

    assert (file_name != NULL && memory != NULL);

    FILE *file = fopen(file_name, "rb");
   	fopen_check(file); 
    
    /* Set current position to the end of the file */
    fseek(file, 0, SEEK_END);
    
    /* Calculate file size using the current position (end of file) */
    const long size = ftell(file);
    
    if(size == -1) {
        perror("Error with file size");
        fclose(file);
        exit(EXIT_FAILURE);
    }
    
    /* Set current position to the start of the file */
    fseek(file, 0, SEEK_SET);
    
    /* Read the content of the file (from position 1 to the end) into the 
       memory */
    fread(memory, 1, size, file);
    
    fclose(file);
    
    return size;
}
 Entry( const char *fname ){
     this->uid = -1; 
     fi = fopen_check( fname, "r" );
 }