data_set.hpp (1821B)
1 #ifndef DATA_SET_HPP_INCLUDED 2 #define DATA_SET_HPP_INCLUDED 3 4 #include <cstddef> 5 #include <string> 6 #include <vector> 7 8 #include <boost/shared_ptr.hpp> 9 #include <nmlp/Matrix.h> 10 #include <nmlp/Tensor.h> 11 12 #include "nmlp_base_iostream.hpp" 13 14 /** 15 * @brief A set of data. 16 */ 17 class Data_set{ 18 public: 19 /** @brief Construct a data set from a given set of view and their kind. */ 20 Data_set(boost::shared_ptr<Tensor> views, std::vector<std::string> const &view_kinds); 21 22 /** @brief Returns the number of element in the set. */ 23 std::size_t size() const; 24 25 /** @brief Returns the number of different views. */ 26 std::size_t number_of_views() const; 27 28 /** @brief Returns the kind of a given data view. */ 29 std::string kind(std::size_t id) const; 30 31 /** 32 * @brief Returns the vector corresponding to an element index and a view index. 33 * 34 * The vector is copied in a CPUMatrix which is then returned. 35 */ 36 boost::shared_ptr<Matrix> get(std::size_t element, std::size_t view) const; 37 38 /** 39 * @brief Returns the matrix corresponding to a view index. 40 * 41 * @warning The returned matrix is @b not a copy from the data set, it must not be modified. 42 */ 43 boost::shared_ptr<Matrix> get(std::size_t view) const; 44 45 private: 46 47 /** @brief The data itself. */ 48 boost::shared_ptr<Tensor> views; 49 50 /** @brief The kind of each view. */ 51 std::vector<std::string> view_kinds; 52 }; 53 54 /** 55 * @brief Construct a Data_set from a libsvm file containing a classification task. 56 * 57 * The first view of the returned Data_set is the 'input', the second, the 'output'. 58 * @param filepath The path to the svm file. 59 * @param kinds The list of kinds, must be of size 2: kinds[0] being the kind of the input and kinds[1] the kind of the output. 60 */ 61 Data_set classification_svmfile_to_data_set(std::string const &filepath, std::vector<std::string> kinds); 62 63 #endif 64