ShortRealFeatures.cpp

Go to the documentation of this file.
00001 /*
00002  * This program is free software; you can redistribute it and/or modify
00003  * it under the terms of the GNU General Public License as published by
00004  * the Free Software Foundation; either version 3 of the License, or
00005  * (at your option) any later version.
00006  *
00007  * Written (W) 2008 Soeren Sonnenburg
00008  * Copyright (C) 2008 Fraunhofer Institute FIRST and Max-Planck-Society
00009  */
00010 
00011 #include "features/ShortRealFeatures.h"
00012 #include "lib/File.h"
00013 
00014 bool CShortRealFeatures::load(CHAR* fname)
00015 {
00016     bool status=false;
00017     num_vectors=1;
00018     num_features=0;
00019     CFile f(fname, 'r', F_SHORTREAL);
00020     LONG numf=0 ;
00021     free_feature_matrix();
00022     feature_matrix=f.load_shortreal_data(NULL, numf);
00023     num_features=numf;
00024 
00025 
00026     if (!f.is_ok()) {
00027       SG_ERROR( "loading file \"%s\" failed", fname);
00028     }
00029     else
00030         status=true;
00031 
00032     return status;
00033 }
00034 
00035 bool CShortRealFeatures::save(CHAR* fname)
00036 {
00037     INT len;
00038     bool free;
00039     SHORTREAL* fv;
00040 
00041     CFile f(fname, 'w', F_SHORTREAL);
00042 
00043     for (INT i=0; i< (INT) num_vectors && f.is_ok(); i++)
00044     {
00045         if (!(i % (num_vectors/10+1)))
00046             SG_PRINT( "%02d%%.", (int) (100.0*i/num_vectors));
00047         else if (!(i % (num_vectors/200+1)))
00048             SG_PRINT( ".");
00049 
00050         fv=get_feature_vector(i, len, free);
00051         f.save_shortreal_data(fv, len);
00052         free_feature_vector(fv, i, free) ;
00053     }
00054 
00055     if (f.is_ok())
00056         SG_INFO( "%d vectors with %d features each successfully written (filesize: %ld)\n", num_vectors, num_features, num_vectors*num_features*sizeof(SHORTREAL));
00057 
00058     return true;
00059 }

SHOGUN Machine Learning Toolbox - Documentation