GenSVM
Functions
gensvm_io.h File Reference

Header file for gensvm_io.c. More...

#include "gensvm_base.h"
#include "gensvm_print.h"
#include "gensvm_strutil.h"
Include dependency graph for gensvm_io.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void gensvm_read_data (struct GenData *dataset, char *data_file)
 Read data from file. More...
 
void gensvm_read_data_libsvm (struct GenData *dataset, char *data_file)
 Read data from a file in LibSVM/SVMlight format. More...
 
void gensvm_read_model (struct GenModel *model, char *model_filename)
 Read model from file. More...
 
void gensvm_write_model (struct GenModel *model, char *output_filename)
 Write model to file. More...
 
void gensvm_write_predictions (struct GenData *data, long *predy, char *output_filename)
 Write predictions to file. More...
 
void gensvm_time_string (char *buffer)
 Get time string with UTC offset. More...
 

Detailed Description

Header file for gensvm_io.c.

Author
G.J.J. van den Burg
Date
2014-01-07

Function declarations for input/output functions.

This file is part of GenSVM.

GenSVM is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

GenSVM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with GenSVM. If not, see http://www.gnu.org/licenses/.

Definition in file gensvm_io.h.

Function Documentation

◆ gensvm_read_data()

void gensvm_read_data ( struct GenData dataset,
char *  data_file 
)

Read data from file.

Read the data from the data_file. The data matrix X is augmented with a column of ones, to get the matrix Z. The data is expected to follow a specific format, which is specified in the Default Data File Specification. The class labels are assumed to be in the interval [1 .. K], which can be checked using the function gensvm_check_outcome_contiguous().

Parameters
[in,out]datasetinitialized GenData struct
[in]data_filefilename of the data file.

Definition at line 47 of file gensvm_io.c.

Here is the call graph for this function:

◆ gensvm_read_data_libsvm()

void gensvm_read_data_libsvm ( struct GenData data,
char *  data_file 
)

Read data from a file in LibSVM/SVMlight format.

This function reads data from a file where the data is stored in LibSVM/SVMlight format. The file format is described in LibSVM/SVMlight Data File Specification. This is a sparse data format, which can be beneficial for certain applications. The advantage of having this function here is twofold: 1) existing datasets where data is stored in LibSVM/SVMlight format can be easily used in GenSVM, and 2) sparse datasets which are too large for memory when kept in dense format can be loaded efficiently into GenSVM.

Note
This code is based on the read_problem() function in the svm-train.c file of LibSVM. It has however been expanded to be able to handle data files without labels.
This file tries to detect whether 1-based or 0-based indexing is used in the data file. By default 1-based indexing is used, but if an index is found with value 0, 0-based indexing is assumed.
See also
gensvm_read_problem()
Parameters
[in]dataGenData structure
[in]data_filefilename of the datafile

Definition at line 178 of file gensvm_io.c.

Here is the call graph for this function:

◆ gensvm_read_model()

void gensvm_read_model ( struct GenModel model,
char *  model_filename 
)

Read model from file.

Read a GenModel from a model file. The GenModel struct must have been initalized elswhere. The model file is expected to follow the Model File Specification. The easiest way to generate a model file is through gensvm_write_model(), which can for instance be used in trainGenSVM.c.

Parameters
[in,out]modelinitialized GenModel
[in]model_filenamefilename of the model file

Definition at line 410 of file gensvm_io.c.

Here is the call graph for this function:

◆ gensvm_time_string()

void gensvm_time_string ( char *  buffer)

Get time string with UTC offset.

Create a string for the current system time. Include an offset of UTC for consistency. The format of the generated string is "DDD MMM D HH:MM:SS YYYY (UTC +HH:MM)", e.g. "Fri Aug 9, 12:34:56 2013 (UTC +02:00)".

Parameters
[in,out]bufferallocated string buffer, on exit contains formatted string

Definition at line 596 of file gensvm_io.c.

Here is the call graph for this function:

◆ gensvm_write_model()

void gensvm_write_model ( struct GenModel model,
char *  output_filename 
)

Write model to file.

Write a GenModel to a file. The current time is specified in the file in UTC + offset. The model file further corresponds to the Model File Specification.

Parameters
[in]modelGenModel which contains an estimate for GenModel::V
[in]output_filenamethe output file to write the model to

Definition at line 494 of file gensvm_io.c.

Here is the call graph for this function:

◆ gensvm_write_predictions()

void gensvm_write_predictions ( struct GenData data,
long *  predy,
char *  output_filename 
)

Write predictions to file.

Write the given predictions to an output file, such that the resulting file corresponds to the Default Data File Specification.

Parameters
[in]dataGenData with the original instances
[in]predypredictions of the class labels of the instances in the given GenData. Note that the order of the instances is assumed to be the same.
[in]output_filenamethe file to which the predictions are written

Definition at line 556 of file gensvm_io.c.

Here is the call graph for this function: