Skip to content

Commit

Permalink
Fix doxygen warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
breyerml committed Dec 20, 2024
1 parent 3d66e91 commit 6ac8827
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 53 deletions.
7 changes: 7 additions & 0 deletions include/plssvm/data_set/classification_data_set.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ namespace plssvm {
// forward declare C-SVC class
class csvc;

/**
* @brief Encapsulate all necessary data that is needed for training or predicting using an C-SVC.
* @details May or may not contain labels!
* Internally, saves all data using [`std::shared_ptr`](https://en.cppreference.com/w/cpp/memory/shared_ptr) to make a plssvm::classification_data_set relatively cheap to copy!
* @tparam U the label type of the data (must be an arithmetic type or `std::string`; default: `int`)
*/
template <typename U = int>
class classification_data_set : public data_set<U> {
// make sure only valid template types are used
Expand All @@ -53,6 +59,7 @@ class classification_data_set : public data_set<U> {
template <typename>
friend class classification_model;

/// The base data set class.
using base_data_set = data_set<U>;

using base_data_set::data_ptr_;
Expand Down
5 changes: 3 additions & 2 deletions include/plssvm/data_set/data_set.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,12 @@ class data_set {
data_set(data_set &&) noexcept = default;
/**
* @brief Default copy assignment operator.
* @return `*this`
*/
data_set &operator=(const data_set &) = default;
/**
* @brief Default move assignment operator.
* @return `*this`
*/
data_set &operator=(data_set &&) noexcept = default;

Expand Down Expand Up @@ -300,8 +302,7 @@ class data_set {
data_ptr_{ std::make_shared<soa_matrix<real_type>>() } { }

/**
* @brief Create the mapping between the provided labels and the internally used indices.
* @param[in] classes the list of different labels used to create the index mapping
* @brief Create the mapping between the provided labels and the internally used values.
* @throws plssvm::data_set_exception any exception of the plssvm::data_set::label_mapper class
*/
virtual void map_label() = 0;
Expand Down
9 changes: 8 additions & 1 deletion include/plssvm/data_set/regression_data_set.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@ namespace plssvm {
// forward declare C-SVR class
class csvr;

template <typename U = int>
/**
* @brief Encapsulate all necessary data that is needed for training or predicting using an C-SVR.
* @details May or may not contain labels!
* Internally, saves all data using [`std::shared_ptr`](https://en.cppreference.com/w/cpp/memory/shared_ptr) to make a plssvm::regression_data_set relatively cheap to copy!
* @tparam U the label type of the data (must be an arithmetic type, except boolean or character types; default: `real_type`)
*/
template <typename U = real_type>
class regression_data_set : public data_set<U> {
// make sure only valid template types are used
static_assert(detail::tuple_contains_v<U, detail::supported_label_types_regression>,
Expand All @@ -49,6 +55,7 @@ class regression_data_set : public data_set<U> {
template <typename>
friend class regression_model;

/// The base data set class.
using base_data_set = data_set<U>;

using base_data_set::data_ptr_;
Expand Down
2 changes: 0 additions & 2 deletions include/plssvm/detail/io/regression_libsvm_model_parsing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,10 +422,8 @@ inline void write_libsvm_model_header_regression(fmt::ostream &out, const plssvm
* @tparam label_type the type of the labels (any arithmetic type, except bool, or std::string)
* @param[in] filename the file to write the LIBSVM model to
* @param[in] params the SVM parameters
* @param[in] classification the used multi-class classification strategy
* @param[in] rho the rho value resulting from the hyperplane learning
* @param[in] alpha the weights learned by the SVM
* @param[in] index_sets index sets containing the SV indices per class
* @param[in] data the data used to create the model
* @attention The PLSSVM model file is only compatible with LIBSVM for the one vs. one classification type.
*/
Expand Down
1 change: 1 addition & 0 deletions include/plssvm/detail/type_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ constexpr bool is_container_v = is_sequence_container_v<T> || is_associative_con
*/
template <typename T, typename... Types>
struct is_one_type_of {
/// Set to `true` if @p T is in the type set @p Types.
constexpr static bool value = (std::is_same_v<T, Types> || ...);
};

Expand Down
9 changes: 2 additions & 7 deletions include/plssvm/model/classification_model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#include <cstddef> // std::size_t
#include <memory> // std::shared_ptr, std::make_shared
#include <numeric> // std::iota
#include <optional> // std::optional
#include <string> // std::string
#include <tuple> // std::tie
#include <utility> // std::move
Expand All @@ -41,12 +40,7 @@
namespace plssvm {

/**
* @example model_examples.cpp
* @brief A few examples regarding the plssvm::model class.
*/

/**
* @brief Implements a class encapsulating the result of a call to the SVM fit function. A model is used to predict the labels of a new data set.
* @brief Implements a class encapsulating the result of a call to the C-SVC fit function. A model is used to predict the labels of a new data set.
* @tparam U the type of the used labels (must be an arithmetic type or `std:string`; default: `int`)
*/
template <typename U = int>
Expand All @@ -59,6 +53,7 @@ class classification_model : public model<U> {
friend class csvm;
friend class csvc;

/// The base model class.
using base_model = model<U>;

// TODO: better?
Expand Down
63 changes: 30 additions & 33 deletions include/plssvm/model/regression_model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,44 +13,33 @@
#define PLSSVM_MODEL_REGRESSION_MODEL_HPP_
#pragma once

#include "plssvm/classification_types.hpp" // plssvm::classification_type
#include "plssvm/constants.hpp" // plssvm::real_type
#include "plssvm/data_set/data_set.hpp" // plssvm::data_set
#include "plssvm/data_set/regression_data_set.hpp" // plssvm::regression_data_set
#include "plssvm/detail/assert.hpp" // PLSSVM_ASSERT
#include "plssvm/detail/io/classification_libsvm_model_parsing.hpp" // plssvm::detail::io::{parse_libsvm_model_header, parse_libsvm_model_data, write_libsvm_model_data}
#include "plssvm/detail/io/file_reader.hpp" // plssvm::detail::io::file_reader
#include "plssvm/detail/io/regression_libsvm_model_parsing.hpp" //
#include "plssvm/detail/logging.hpp" // plssvm::detail::log
#include "plssvm/detail/tracking/performance_tracker.hpp" // PLSSVM_DETAIL_TRACKING_PERFORMANCE_TRACKER_ADD_TRACKING_ENTRY, plssvm::detail::tracking::tracking_entry
#include "plssvm/detail/type_list.hpp" // plssvm::detail::{supported_label_types, tuple_contains_v}
#include "plssvm/matrix.hpp" // plssvm::soa_matrix, plssvm::aos_matrix
#include "plssvm/model/model.hpp" // plssvm::model
#include "plssvm/parameter.hpp" // plssvm::parameter
#include "plssvm/verbosity_levels.hpp" // plssvm::verbosity_level

#include <chrono> // std::chrono::{time_point, steady_clock, duration_cast, milliseconds}
#include <cstddef> // std::size_t
#include <memory> // std::shared_ptr, std::make_shared
#include <numeric> // std::iota
#include <optional> // std::optional
#include <string> // std::string
#include <tuple> // std::tie
#include <utility> // std::move
#include <vector> // std::vector
#include "plssvm/constants.hpp" // plssvm::real_type
#include "plssvm/data_set/data_set.hpp" // plssvm::data_set
#include "plssvm/data_set/regression_data_set.hpp" // plssvm::regression_data_set
#include "plssvm/detail/io/file_reader.hpp" // plssvm::detail::io::file_reader
#include "plssvm/detail/io/regression_libsvm_model_parsing.hpp" // plssvm::detail::io::{parse_libsvm_model_header_regression, parse_libsvm_model_data_regression, write_libsvm_model_data_regression}
#include "plssvm/detail/logging.hpp" // plssvm::detail::log
#include "plssvm/detail/tracking/performance_tracker.hpp" // PLSSVM_DETAIL_TRACKING_PERFORMANCE_TRACKER_ADD_TRACKING_ENTRY, plssvm::detail::tracking::tracking_entry
#include "plssvm/detail/type_list.hpp" // plssvm::detail::{supported_label_types, tuple_contains_v}
#include "plssvm/matrix.hpp" // plssvm::soa_matrix, plssvm::aos_matrix
#include "plssvm/model/model.hpp" // plssvm::model
#include "plssvm/parameter.hpp" // plssvm::parameter
#include "plssvm/verbosity_levels.hpp" // plssvm::verbosity_level

#include <chrono> // std::chrono::{time_point, steady_clock, duration_cast, milliseconds}
#include <cstddef> // std::size_t
#include <memory> // std::shared_ptr, std::make_shared
#include <string> // std::string
#include <tuple> // std::tie
#include <utility> // std::move

namespace plssvm {

/**
* @example model_examples.cpp
* @brief A few examples regarding the plssvm::model class.
* @brief Implements a class encapsulating the result of a call to the C-SVR fit function. A model is used to predict the labels of a new data set.
* @tparam U the type of the used labels (must be an arithmetic type, except boolean or character types; default: `real_type`)
*/

/**
* @brief Implements a class encapsulating the result of a call to the SVM fit function. A model is used to predict the labels of a new data set.
* @tparam U the type of the used labels (must be an arithmetic type or `std:string`; default: `int`)
*/
template <typename U = int>
template <typename U = real_type>
class regression_model : public model<U> {
// make sure only valid template types are used
static_assert(detail::tuple_contains_v<U, detail::supported_label_types_regression>,
Expand All @@ -60,6 +49,7 @@ class regression_model : public model<U> {
friend class csvm;
friend class csvr;

/// The base model class.
using base_model = model<U>;

// TODO: better?
Expand Down Expand Up @@ -92,6 +82,13 @@ class regression_model : public model<U> {
void save(const std::string &filename) const override;

private:
/**
* @brief Create a new model using the SVM parameter @p params and the @p data.
* @details Default initializes the weights, i.e., no weights have currently been learned.
* @note This constructor may only be used in the befriended base C-SVM class!
* @param[in] params the SVM parameters used to learn this model
* @param[in] data the data used to learn this model
*/
regression_model(parameter params, regression_data_set<label_type> data);
};

Expand Down
2 changes: 1 addition & 1 deletion include/plssvm/regression_report.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ std::ostream &operator<<(std::ostream &out, const regression_report &report);
* @param[in] metric the metric
* @return the output-stream
*/
std::ostream &operator<<(std::ostream &out, const regression_report::metric &m);
std::ostream &operator<<(std::ostream &out, const regression_report::metric &metric);

} // namespace plssvm

Expand Down
12 changes: 12 additions & 0 deletions include/plssvm/svm/csvc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@

namespace plssvm {

/**
* @brief Base class for all C-SVC backends.
* @details This class implements all features shared between all C-SVC backends. It defines the whole public API of a C-SVC.
*/
class csvc : virtual public csvm {
public:
/// The type of the model returned by a call to the `fit` function and used in the `predict` and `score` functions.
Expand Down Expand Up @@ -422,6 +426,14 @@ class csvc : virtual public csvm {
return predicted_labels;
}

/**
* @brief Calculate the accuracy of the @p model.
* @details Uses the one vs. all (OAA) for the multi-class classification task.
* @tparam label_type the type of the label (an arithmetic type or `std::string`)
* @param[in] model a previously learned model
* @throws plssvm::exception any exception thrown in the respective backend's implementation of `plssvm::csvm::predict_values`
* @return the accuracy of the model (`[[nodiscard]]`)
*/
template <typename label_type>
[[nodiscard]] real_type score(const classification_model<label_type> &model) const {
return this->score(model, model.data_);
Expand Down
2 changes: 1 addition & 1 deletion include/plssvm/svm/csvm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ namespace plssvm {

/**
* @brief Base class for all C-SVM backends.
* @details This class implements all features shared between all C-SVM backends. It defines the whole public API of a C-SVM.
* @details This class implements all features shared between all C-SVM backends.
*/
class csvm {
public:
Expand Down
21 changes: 15 additions & 6 deletions include/plssvm/svm/csvr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@

namespace plssvm {

/**
* @brief Base class for all C-SVR backends.
* @details This class implements all features shared between all C-SVR backends. It defines the whole public API of a C-SVR.
*/
class csvr : virtual public csvm {
public:
/// The type of the model returned by a call to the `fit` function and used in the `predict` and `score` functions.
Expand Down Expand Up @@ -128,8 +132,7 @@ class csvr : virtual public csvm {
//*************************************************************************************************************************************//
/**
* @brief Predict the labels for the @p data set using the @p model.
* @details Uses the one vs. all (OAA) for the multi-class classification task.
* @tparam label_type the type of the label (an arithmetic type or `std::string`)
* @tparam label_type the type of the label
* @param[in] model a previously learned model
* @param[in] data the data to predict the labels for
* @throws plssvm::invalid_parameter_exception if the number of features in the @p model's support vectors don't match the number of features in the @p data set
Expand Down Expand Up @@ -189,21 +192,27 @@ class csvr : virtual public csvm {
}

// TODO: not possible since the LIBSVM SVR model loses the original label values?!
// /**
// * @brief Calculate the regression loss of the @p model.
// * @tparam label_type the type of the label
// * @param[in] model a previously learned model
// * @throws plssvm::exception any exception thrown in the respective backend's implementation of `plssvm::csvm::predict_values`
// * @return the regression loss of the model (`[[nodiscard]]`)
// */
// template <typename label_type>
// [[nodiscard]] real_type score(const regression_model<label_type> &model) const {
// return this->score(model, model.data_);
// }

/**
* @brief Calculate the accuracy of the labeled @p data set using the @p model.
* @details Uses the one vs. all (OAA) for the multi-class classification task.
* @tparam label_type the type of the label (an arithmetic type or `std::string`)
* @brief Calculate the regression loss of the labeled @p data set using the @p model.
* @tparam label_type the type of the label
* @param[in] model a previously learned model
* @param[in] data the labeled data set to score
* @throws plssvm::invalid_parameter_exception if the @p data to score has no labels
* @throws plssvm::invalid_parameter_exception if the number of features in the @p model's support vectors don't match the number of features in the @p data set
* @throws plssvm::exception any exception thrown in the respective backend's implementation of `plssvm::csvm::predict_values`
* @return the accuracy of the labeled @p data (`[[nodiscard]]`)
* @return the regression loss of the labeled @p data (`[[nodiscard]]`)
*/
template <typename label_type>
[[nodiscard]] real_type score(const regression_model<label_type> &model, const regression_data_set<label_type> &data) const {
Expand Down

0 comments on commit 6ac8827

Please sign in to comment.