PLSSVM - Parallel Least Squares Support Vector Machine  2.0.0
A Least Squares Support Vector Machine implementation using different backends.
Classes | Functions
plssvm::detail::io Namespace Reference

Namespace containing implementation details for the IO related functions. Should not directly be used by users. More...

Classes

class  file_reader
 The plssvm::detail::file_reader class is responsible for reading a file and splitting it into its lines. More...
 

Functions

template<typename label_type >
std::tuple< std::size_t, std::size_t, std::set< label_type >, std::size_t > parse_arff_header (const std::vector< std::string_view > &lines)
 Parse the ARFF file header, i.e., determine the number of features, the length of the ARRF header, whether the data set is annotated with labels and at which position the label is written in the data set. More...
 
template<typename real_type , typename label_type >
std::tuple< std::size_t, std::size_t, std::vector< std::vector< real_type > >, std::vector< label_type > > parse_arff_data (const file_reader &reader)
 Parse all data points and potential label using the file reader, ignoring all empty lines and lines starting with an %. If no labels are found, returns an empty vector. More...
 
template<typename real_type , typename label_type , bool has_label>
void write_arff_data_impl (const std::string &filename, const std::vector< std::vector< real_type >> &data, const std::vector< label_type > &label)
 Write the provided data and labels to the ARFF file filename. More...
 
template<typename real_type , typename label_type >
void write_arff_data (const std::string &filename, const std::vector< std::vector< real_type >> &data, const std::vector< label_type > &label)
 Write the provided data and labels to the ARFF file filename. More...
 
template<typename real_type >
void write_arff_data (const std::string &filename, const std::vector< std::vector< real_type >> &data)
 Write the provided data to the ARFF file filename. More...
 
void swap (file_reader &lhs, file_reader &rhs)
 Elementwise swap the contents of lhs and rhs. More...
 
template<typename real_type , typename label_type , typename size_type >
std::tuple< plssvm::parameter, real_type, std::vector< label_type >, std::size_t > parse_libsvm_model_header (const std::vector< std::string_view > &lines)
 Parse the LIBSVM model file header. More...
 
template<typename real_type , typename label_type >
std::vector< label_type > write_libsvm_model_header (fmt::ostream &out, const plssvm::parameter &params, const real_type rho, const data_set< real_type, label_type > &data)
 Write the LIBSVM model file header to out. More...
 
template<typename real_type , typename label_type >
void write_libsvm_model_data (const std::string &filename, const plssvm::parameter &params, const real_type rho, const std::vector< real_type > &alpha, const data_set< real_type, label_type > &data)
 Write the LIBSVM model to the file filename. More...
 
std::size_t parse_libsvm_num_features (const std::vector< std::string_view > &lines, const std::size_t skipped_lines=0)
 Parse the maximum number of features per data point given in lines, where the first skipped_lines are skipped. More...
 
template<typename real_type , typename label_type >
std::tuple< std::size_t, std::size_t, std::vector< std::vector< real_type > >, std::vector< label_type > > parse_libsvm_data (const file_reader &reader, const std::size_t skipped_lines=0)
 Parse all data points and potential label using the file reader, ignoring all empty lines and lines starting with an #. If no labels are found, returns an empty vector. More...
 
template<typename real_type , typename label_type , bool has_label>
void write_libsvm_data_impl (const std::string &filename, const std::vector< std::vector< real_type >> &data, const std::vector< label_type > &label)
 Write the provided data and labels to the LIBSVM file filename. More...
 
template<typename real_type , typename label_type >
void write_libsvm_data (const std::string &filename, const std::vector< std::vector< real_type >> &data, const std::vector< label_type > &label)
 Write the provided data and labels to the LIBSVM file filename. More...
 
template<typename real_type >
void write_libsvm_data (const std::string &filename, const std::vector< std::vector< real_type >> &data)
 Write the provided data to the LIBSVM file filename. More...
 
template<typename real_type , typename factors_type >
std::tuple< std::pair< real_type, real_type >, std::vector< factors_type > > parse_scaling_factors (const file_reader &reader)
 Read the scaling interval and factors stored using LIBSVM's file format from the file filename. More...
 
template<typename real_type , typename factors_type >
void write_scaling_factors (const std::string &filename, const std::pair< real_type, real_type > &scaling_interval, const std::vector< factors_type > &scaling_factors)
 Write the scaling_interval and scaling_factors to a file for later usage in scaling another data set using LIBSVM's file format. More...
 

Detailed Description

Namespace containing implementation details for the IO related functions. Should not directly be used by users.

Function Documentation

◆ parse_arff_header()

template<typename label_type >
std::tuple<std::size_t, std::size_t, std::set<label_type>, std::size_t> plssvm::detail::io::parse_arff_header ( const std::vector< std::string_view > &  lines)
inline

Parse the ARFF file header, i.e., determine the number of features, the length of the ARRF header, whether the data set is annotated with labels and at which position the label is written in the data set.

Template Parameters
label_typethe type of the labels (any arithmetic type or std::string)
Parameters
[in]linesthe ARFF header to parse
Exceptions
plssvm::invalid_file_format_exceptionif the @RELATION field does not come before any other @ATTRIBUTE
plssvm::invalid_file_format_exceptionif the @RELATION field does not have a name
plssvm::invalid_file_format_exceptionif the @RELATION field does have a name with whitespaces but is not quoted
plssvm::invalid_file_format_exceptionif an @ATTRIBUTE field has the type NUMERIC and the name CLASS
plssvm::invalid_file_format_exceptionif an @ATTRIBUTE field does not have a name
plssvm::invalid_file_format_exceptionif an @ATTRIBUTE field does have a name with whitespaces but is not quoted
plssvm::invalid_file_format_exceptionif multiple @ATTRIBUTES with the name CLASS are provided
plssvm::invalid_file_format_exceptionif the class field does not provide any labels
plssvm::invalid_file_format_exceptionif the class field provides labels that are no enclosed in {} (ARFF nominal attributes)
plssvm::invalid_file_format_exceptionif only a single label has been provided
plssvm::invalid_file_format_exceptionif a label has been provided multiple times
plssvm::invalid_file_format_exceptionif a string label contains a whitespace
plssvm::invalid_file_format_exceptionif a header entry starts with an @ but is none of @RELATION, @ATTRIBUTE, or @DATA
plssvm::invalid_file_format_exceptionif no feature attributes are provided
plssvm::invalid_file_format_exceptionif the @DATA attribute is missing
Returns
the necessary header information: [num_features, num_header_lines, unique_labels, label_idx] ([[nodiscard]])

◆ parse_arff_data()

template<typename real_type , typename label_type >
std::tuple<std::size_t, std::size_t, std::vector<std::vector<real_type> >, std::vector<label_type> > plssvm::detail::io::parse_arff_data ( const file_reader reader)
inline

Parse all data points and potential label using the file reader, ignoring all empty lines and lines starting with an %. If no labels are found, returns an empty vector.

An example file can look like

@RELATION name
@ATTRIBUTE feature_0 numeric
@ATTRIBUTE feature_1 numeric
@ATTRIBUTE feature_2 numeric
@ATTRIBUTE feature_3 numeric
@ATTRIBUTE class {-1,1}
@DATA
-1.117827500607882,-2.9087188881250993,0.66638344270039144,1.0978832703949288,1
-0.5282118298909262,-0.335880984968183973,0.51687296029754564,0.54604461446026,1
0.0,0.60276937379453293,-0.13086851759108944,0.0,-1
0.57650218263054642,1.01405596624706053,0.13009428079760464,0.7261913886869387,-1
1.88494043717792,1.00518564317278263,0.298499933047586044,1.6464627048813514,-1
constexpr std::string_view name
The name of the library.
Definition: version.hpp:26
Template Parameters
real_typethe floating point type
label_typethe type of the labels (any arithmetic type or std::string)
Parameters
[in]readerthe file_reader used to read the ARFF data
Note
The features must be provided with zero-based indices!
Exceptions
plssvm::invalid_file_format_exceptionif no features could be found (may indicate an empty file)
plssvm::invalid_file_format_exceptionif a label couldn't be converted to the provided label_type
plssvm::invalid_file_format_exceptionif a feature index couldn't be converted to unsigned long
plssvm::invalid_file_format_exceptionif a feature value couldn't be converted to the provided real_type
plssvm::invalid_file_format_exceptionif an '@' is read inside the @DATA section
plssvm::invalid_file_format_exceptionif a closing curly brace '}' is missing in the sparse data point description
plssvm::invalid_file_format_exceptionif an closing curly brace '{' is missing in the sparse data point description
plssvm::invalid_file_format_exceptionif a index is out-of-bounce with respect to the provided ARFF header information
plssvm::invalid_file_format_exceptionif the ARFF header specifies labels but any data point misses a label
plssvm::invalid_file_format_exceptionif the number of found features and labels mismatches the numbers provided in the ARFF header
plssvm::invalid_file_format_exceptionif a label in the data section has been found, that did not appear in the header
Returns
a std::tuple containing: [num_data_points, num_features, data_points, labels] ([[nodiscard]])

◆ write_arff_data_impl()

template<typename real_type , typename label_type , bool has_label>
void plssvm::detail::io::write_arff_data_impl ( const std::string &  filename,
const std::vector< std::vector< real_type >> &  data,
const std::vector< label_type > &  label 
)
inline

Write the provided data and labels to the ARFF file filename.

An example file can look like

@RELATION name
@ATTRIBUTE feature_0 numeric
@ATTRIBUTE feature_1 numeric
@ATTRIBUTE feature_2 numeric
@ATTRIBUTE feature_3 numeric
@ATTRIBUTE class {-1,1}
@DATA
-1.117827500607882,-2.9087188881250993,0.66638344270039144,1.0978832703949288,1
-0.5282118298909262,-0.335880984968183973,0.51687296029754564,0.54604461446026,1
0.0,0.60276937379453293,-0.13086851759108944,0.0,-1
0.57650218263054642,1.01405596624706053,0.13009428079760464,0.7261913886869387,-1
1.88494043717792,1.00518564317278263,0.298499933047586044,1.6464627048813514,-1

Note that the output will always be dense, i.e., all features with a value of 0.0 are explicitly written in the resulting file.

Template Parameters
real_typethe floating point type
label_typethe type of the labels (any arithmetic type or std::string)
has_labelif true the provided labels are also written to the file, if false no labels are outputted
Parameters
[in]filenamethe filename to write the data to
[in]datathe data points to write to the file
[in]labelthe labels to write to the file
Note
The resulting order of the data points in the ARFF file is unspecified!
The features are written using zero-based indices!

◆ write_arff_data() [1/2]

template<typename real_type , typename label_type >
void plssvm::detail::io::write_arff_data ( const std::string &  filename,
const std::vector< std::vector< real_type >> &  data,
const std::vector< label_type > &  label 
)
inline

Write the provided data and labels to the ARFF file filename.

An example file can look like

@RELATION name
@ATTRIBUTE feature_0 numeric
@ATTRIBUTE feature_1 numeric
@ATTRIBUTE feature_2 numeric
@ATTRIBUTE feature_3 numeric
@ATTRIBUTE class {-1,1}
@DATA
-1.117827500607882,-2.9087188881250993,0.66638344270039144,1.0978832703949288,1
-0.5282118298909262,-0.335880984968183973,0.51687296029754564,0.54604461446026,1
0.0,0.60276937379453293,-0.13086851759108944,0.0,-1
0.57650218263054642,1.01405596624706053,0.13009428079760464,0.7261913886869387,-1
1.88494043717792,1.00518564317278263,0.298499933047586044,1.6464627048813514,-1

Note that the output will always be dense, i.e., all features with a value of 0.0 are explicitly written in the resulting file.

Template Parameters
real_typethe floating point type
label_typethe type of the labels (any arithmetic type or std::string)
Parameters
[in]filenamethe filename to write the data to
[in]datathe data points to write to the file
[in]labelthe labels to write to the file
Note
The resulting order of the data points in the ARFF file is unspecified!
The features are written using zero-based indices!

◆ write_arff_data() [2/2]

template<typename real_type >
void plssvm::detail::io::write_arff_data ( const std::string &  filename,
const std::vector< std::vector< real_type >> &  data 
)
inline

Write the provided data to the ARFF file filename.

An example file can look like

@RELATION name
@ATTRIBUTE feature_0 numeric
@ATTRIBUTE feature_1 numeric
@ATTRIBUTE feature_2 numeric
@ATTRIBUTE feature_3 numeric
@DATA
-1.117827500607882,-2.9087188881250993,0.66638344270039144,1.0978832703949288
-0.5282118298909262,-0.335880984968183973,0.51687296029754564,0.54604461446026
0.0,0.60276937379453293,-0.13086851759108944,0.0
0.57650218263054642,1.01405596624706053,0.13009428079760464,0.7261913886869387
1.88494043717792,1.00518564317278263,0.298499933047586044,1.6464627048813514

Note that the output will always be dense, i.e., all features with a value of 0.0 are explicitly written in the resulting file.

Template Parameters
real_typethe floating point type
Parameters
[in]filenamethe filename to write the data to
[in]datathe data points to write to the file
Note
The resulting order of the data points in the ARFF file is unspecified!
The features are written using zero-based indices!

◆ swap()

void plssvm::detail::io::swap ( file_reader lhs,
file_reader rhs 
)

Elementwise swap the contents of lhs and rhs.

Parameters
[in,out]lhsthe first file_reader
[in,out]rhsthe second file_reader

◆ parse_libsvm_model_header()

template<typename real_type , typename label_type , typename size_type >
std::tuple<plssvm::parameter, real_type, std::vector<label_type>, std::size_t> plssvm::detail::io::parse_libsvm_model_header ( const std::vector< std::string_view > &  lines)
inline

Parse the LIBSVM model file header.

An example LIBSVM model file header for the linear kernel and two labels could look like

svm_type c_svc
kernel_type linear
nr_class 2
rho 0.37330625882191915
label 1 -1
total_sv 5
nr_sv 2 3
SV
Template Parameters
real_typethe floating point type
label_typethe type of the labels (any arithmetic type, except bool, or std::string)
size_typethe size type
Parameters
[in]linesthe LIBSVM model file header to parse>
Exceptions
plssvm::invalid_file_format_exceptionif an invalid 'svm_type' has been provided, i.e., 'svm_type' is not 'c_csc'
plssvm::invalid_file_format_exceptionif an invalid 'kernel_type has been provided
plssvm::invalid_file_format_exceptionif the number of support vectors ('total_sv') is zero
plssvm::invalid_file_format_exceptionif less than two labels have been provided
plssvm::invalid_file_format_exceptionif less than two number of support vectors per label have been provided
plssvm::invalid_file_format_exceptionif an invalid header entry has been read
plssvm::invalid_file_format_exceptionif the 'svm_type' is missing
plssvm::invalid_file_format_exceptionif the 'kernel_type' is missing
plssvm::invalid_file_format_exceptionif SVM parameter are explicitly provided that are not used in the give kernel (e.g., 'gamma' is provided for the 'linear' kernel)
plssvm::invalid_file_format_exceptionif the number of classes ('nr_class') is missing
plssvm::invalid_file_format_exceptionif the total number of support vectors ('total_sv') is missing
plssvm::invalid_file_format_exceptionif the value for rho is missing
plssvm::invalid_file_format_exceptionif the labels are missing
plssvm::invalid_file_format_exceptionif the number of provided labels is not the same as the value of 'nr_class'
plssvm::invalid_file_format_exceptionif the number of support vectors per class ('nr_sv') is missing
plssvm::invalid_file_format_exceptionif the number of provided number of support vectors per class is not the same as the value of 'nr_class'
plssvm::invalid_file_format_exceptionif the number of sum of all number of support vectors per class is not the same as the value of 'total_sv'
plssvm::invalid_file_format_exceptionif no support vectors have been provided in the data section
plssvm::invalid_file_format_exceptionif the number of labels is not two
Returns
the necessary header information: [the SVM parameter, the value of rho, the labels of the data points, num_header_lines] ([[nodiscard]])

◆ write_libsvm_model_header()

template<typename real_type , typename label_type >
std::vector<label_type> plssvm::detail::io::write_libsvm_model_header ( fmt::ostream &  out,
const plssvm::parameter params,
const real_type  rho,
const data_set< real_type, label_type > &  data 
)
inline

Write the LIBSVM model file header to out.

An example LIBSVM model file header for the linear kernel and two labels could look like

svm_type c_svc
kernel_type linear
nr_class 2
rho 0.37330625882191915
label 1 -1
total_sv 5
nr_sv 2 3
SV
Template Parameters
real_typethe floating point type
label_typethe type of the labels (any arithmetic type, except bool, or std::string)
Parameters
[in,out]outthe output-stream to write the header information to
[in]paramsthe SVM parameters
[in]rhothe rho value resulting from the hyperplane learning
[in]datathe data used to create the model
Returns
the order of the labels; necessary to write the data points in the correct order ([[nodiscard]])

◆ write_libsvm_model_data()

template<typename real_type , typename label_type >
void plssvm::detail::io::write_libsvm_model_data ( const std::string &  filename,
const plssvm::parameter params,
const real_type  rho,
const std::vector< real_type > &  alpha,
const data_set< real_type, label_type > &  data 
)
inline

Write the LIBSVM model to the file filename.

An example LIBSVM model file for the linear kernel and two labels could look like

svm_type c_svc
kernel_type linear
nr_class 2
rho 0.37330625882191915
label 1 -1
total_sv 5
nr_sv 2 3
SV
-0.17609610490769723 1:-1.117828e+00 2:-2.908719e+00 3:6.663834e-01 4:1.097883e+00
0.8838187731213127 1:-5.282118e-01 2:-3.358810e-01 3:5.168730e-01 4:5.460446e-01
-0.47971257671001616 1:-2.098121e-01 2:6.027694e-01 3:-1.308685e-01 4:1.080525e-01
0.0034556484621847128 1:1.884940e+00 2:1.005186e+00 3:2.984999e-01 4:1.646463e+00
-0.23146573996578407 1:5.765022e-01 2:1.014056e+00 3:1.300943e-01 4:7.261914e-01
Template Parameters
real_typethe floating point type
label_typethe type of the labels (any arithmetic type, except bool, or std::string)
Parameters
[in]filenamethe file to write the LIBSVM model to
[in]paramsthe SVM parameters
[in]rhothe rho value resulting from the hyperplane learning
[in]alphathe weights learned by the SVM
[in]datathe data used to create the model

◆ parse_libsvm_num_features()

std::size_t plssvm::detail::io::parse_libsvm_num_features ( const std::vector< std::string_view > &  lines,
const std::size_t  skipped_lines = 0 
)
inline

Parse the maximum number of features per data point given in lines, where the first skipped_lines are skipped.

The maximum number of features equals the biggest found feature index. Since LIBSVM mandates that the features are ordered strictly increasing, it is sufficient to only look at the last feature index of each data point.

Parameters
[in]linesthe LIBSVM data to parse for the number of features
[in]skipped_linesthe number of lines that should be skipped at the beginning
Note
The features must be provided with one-based indices!
Exceptions
plssvm::invalid_file_format_exceptionif a feature index couldn't be converted to unsigned long
Returns
the number of features ([[nodiscard]])

◆ parse_libsvm_data()

template<typename real_type , typename label_type >
std::tuple<std::size_t, std::size_t, std::vector<std::vector<real_type> >, std::vector<label_type> > plssvm::detail::io::parse_libsvm_data ( const file_reader reader,
const std::size_t  skipped_lines = 0 
)
inline

Parse all data points and potential label using the file reader, ignoring all empty lines and lines starting with an #. If no labels are found, returns an empty vector.

An example file can look like

1 1:-1.117827500607882 2:-2.9087188881250993 3:0.66638344270039144 4:1.0978832703949288
1 1:-0.5282118298909262 2:-0.335880984968183973 3:0.51687296029754564 4:0.54604461446026
-1 1:0.57650218263054642 2:1.01405596624706053 3:0.13009428079760464 4:0.7261913886869387
-1 1:-0.20981208921241892 2:0.60276937379453293 3:-0.13086851759108944 4:0.10805254527169827
-1 1:1.88494043717792 2:1.00518564317278263 3:0.298499933047586044 4:1.6464627048813514
Template Parameters
real_typethe floating point type
label_typethe type of the labels (any arithmetic type or std::string)
Parameters
[in]readerthe file_reader used to read the LIBSVM data
[in]skipped_linesthe number of lines that should be skipped at the beginning
Note
The features must be provided with one-based indices!
Exceptions
plssvm::invalid_file_format_exceptionif no features could be found (may indicate an empty file)
plssvm::invalid_file_format_exceptionif a label couldn't be converted to the provided label_type
plssvm::invalid_file_format_exceptionif a feature index couldn't be converted to unsigned long
plssvm::invalid_file_format_exceptionif a feature value couldn't be converted to the provided real_type
plssvm::invalid_file_format_exceptionif the provided LIBSVM file uses zero-based indexing (LIBSVM mandates one-based indices)
plssvm::invalid_file_format_exceptionif the feature (indices) are not given in a strictly increasing order
plssvm::invalid_file_format_exceptionif only some data points are annotated with labels
Returns
a std::tuple containing: [num_data_points, num_features, data_points, labels] ([[nodiscard]])

◆ write_libsvm_data_impl()

template<typename real_type , typename label_type , bool has_label>
void plssvm::detail::io::write_libsvm_data_impl ( const std::string &  filename,
const std::vector< std::vector< real_type >> &  data,
const std::vector< label_type > &  label 
)
inline

Write the provided data and labels to the LIBSVM file filename.

An example file can look like

1 1:-1.117827500607882 3:0.66638344270039144 4:1.0978832703949288
1 1:-0.5282118298909262 2:-0.335880984968183973 3:0.51687296029754564 4:0.54604461446026
-1 3:0.13009428079760464 4:0.7261913886869387
-1 1:-0.20981208921241892 2:0.60276937379453293
-1 4:1.6464627048813514

Note that the output may be sparse, i.e., all features with a value of 0.0 are omitted in the resulting file.

Template Parameters
real_typethe floating point type
label_typethe type of the labels (any arithmetic type or std::string)
has_labelif true the provided labels are also written to the file, if false no labels are outputted
Parameters
[in]filenamethe filename to write the data to
[in]datathe data points to write to the file
[in]labelthe labels to write to the file
Note
The resulting order of the data points in the LIBSVM file is unspecified!
The features are written using one-based indices!

◆ write_libsvm_data() [1/2]

template<typename real_type , typename label_type >
void plssvm::detail::io::write_libsvm_data ( const std::string &  filename,
const std::vector< std::vector< real_type >> &  data,
const std::vector< label_type > &  label 
)
inline

Write the provided data and labels to the LIBSVM file filename.

An example file can look like

1 1:-1.117827500607882 3:0.66638344270039144 4:1.0978832703949288
1 1:-0.5282118298909262 2:-0.335880984968183973 3:0.51687296029754564 4:0.54604461446026
-1 3:0.13009428079760464 4:0.7261913886869387
-1 1:-0.20981208921241892 2:0.60276937379453293
-1 4:1.6464627048813514

Note that the output may be sparse, i.e., all features with a value of 0.0 are omitted in the resulting file.

Template Parameters
real_typethe floating point type
label_typethe type of the labels (any arithmetic type or std::string)
Parameters
[in]filenamethe filename to write the data to
[in]datathe data points to write to the file
[in]labelthe labels to write to the file
Note
The resulting order of the data points in the LIBSVM file is unspecified!
The features are written using one-based indices!

◆ write_libsvm_data() [2/2]

template<typename real_type >
void plssvm::detail::io::write_libsvm_data ( const std::string &  filename,
const std::vector< std::vector< real_type >> &  data 
)
inline

Write the provided data to the LIBSVM file filename.

An example file can look like

1:-1.117827500607882 3:0.66638344270039144 4:1.0978832703949288
1:-0.5282118298909262 2:-0.335880984968183973 3:0.51687296029754564 4:0.54604461446026
3:0.13009428079760464 4:0.7261913886869387
1:-0.20981208921241892 2:0.60276937379453293
4:1.6464627048813514

Note that the output may be sparse, i.e., all features with a value of 0.0 are omitted in the resulting file.

Template Parameters
real_typethe floating point type
Parameters
[in]filenamethe filename to write the data to
[in]datathe data points to write to the file
Note
The resulting order of the data points in the LIBSVM file is unspecified!
The features are written using one-based indices!

◆ parse_scaling_factors()

template<typename real_type , typename factors_type >
std::tuple<std::pair<real_type, real_type>, std::vector<factors_type> > plssvm::detail::io::parse_scaling_factors ( const file_reader reader)
inline

Read the scaling interval and factors stored using LIBSVM's file format from the file filename.

An example file can look like

x
-1 1
1 -1.117827500607882 1.88494043717792
2 -2.908718888125099 1.0140559662470605
3 -0.13086851759108944 0.6663834427003914
4 0.10805254527169827 1.6464627048813514

Note that the scaling factors are given using an one-based indexing scheme, but are internally stored using zero-based indexing.

Template Parameters
real_typethe used floating point type
factors_typeplssvm::data_set<real_type>::scaling::factors (cannot be forward declared or included)
Parameters
[in]readerthe file_reader used to read the scaling factors
Exceptions
plssvm::invalid_file_format_exceptionif the header is omitted ('x' and the scaling interval)
plssvm::invalid_file_format_exceptionif the first line doesn't only contain x
plssvm::invalid_file_format_exceptionif the scaling interval is provided with more or less than two values
plssvm::invalid_file_format_exceptionif the scaling factors are provided with more or less than three values
plssvm::invalid_file_format_exceptionif the scaling factors feature index is zero-based instead of one-based
Returns
the read scaling interval and factors ([[nodiscard]])

◆ write_scaling_factors()

template<typename real_type , typename factors_type >
void plssvm::detail::io::write_scaling_factors ( const std::string &  filename,
const std::pair< real_type, real_type > &  scaling_interval,
const std::vector< factors_type > &  scaling_factors 
)
inline

Write the scaling_interval and scaling_factors to a file for later usage in scaling another data set using LIBSVM's file format.

An example file can look like

x
-1 1
1 -1.117827500607882 1.88494043717792
2 -2.908718888125099 1.0140559662470605
3 -0.13086851759108944 0.6663834427003914
4 0.10805254527169827 1.6464627048813514
Template Parameters
real_typethe used floating point type
factors_typeplssvm::data_set<real_type>::scaling::factors (cannot be forward declared or included)
Parameters
[in]filenamethe filename to write the data to
[in]scaling_intervalthe valid scaling interval, i.e., [first, second]
[in]scaling_factorsthe scaling factor for each feature; given zero based, but written to file one based!