Skip to content

Instantly share code, notes, and snippets.

@frx
Created April 27, 2011 14:05
Show Gist options
  • Save frx/511ebb332a6f18d02c62 to your computer and use it in GitHub Desktop.
Save frx/511ebb332a6f18d02c62 to your computer and use it in GitHub Desktop.
Usage of StreamingFile and StreamingFeatures
#include <shogun/features/StreamingFeatures.h>
#include <shogun/lib/StreamingFile.h>
#include <shogun/lib/common.h>
#include <shogun/base/init.h>
#include <stdlib.h>
#include <stdio.h>
using namespace shogun;
int main()
{
init_shogun();
FILE* infile=fopen("sample.dat", "r");
CStreamingFile* f = new CStreamingFile(infile);
CStreamingFeatures* features = new CStreamingFeatures(f, false);
SG_REF(features);
float64_t* fv;
int32_t length, vector_number = 0;
float64_t label;
features->start_parser();
while (features->get_next_feature_vector(fv, length, label))
{
vector_number++;
printf("Vector %d\n--------------", vector_number);
for (int i=0; i<length; i++)
{
printf("Fv[%d] = %f\t", i, fv[i]);
}
printf("\n");
features->free_feature_vector();
}
printf("Done. Vectors parsed=%d.\n", vector_number);
SG_UNREF(features);
exit_shogun();
return 0;
}
/* sample.dat is something like this:
1 -1.991488249375454 -4.10515592045831
1 -4.638179746904141 -0.7680036306633036
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment