#ifndef MEDIA_LEARNING_COMMON_LABELLED_EXAMPLE_H_
#define MEDIA_LEARNING_COMMON_LABELLED_EXAMPLE_H_
#include <initializer_list>
#include <ostream>
#include <vector>
#include "base/check_op.h"
#include "base/component_export.h"
#include "media/learning/common/value.h"
namespace media {
namespace learning {
using FeatureVector = std::vector<FeatureValue>;
using WeightType = size_t;
struct COMPONENT_EXPORT(LEARNING_COMMON) LabelledExample {
LabelledExample();
LabelledExample(FeatureVector feature_vector, TargetValue target);
LabelledExample(std::initializer_list<FeatureValue> init_list,
TargetValue target);
LabelledExample(const LabelledExample& rhs);
LabelledExample(LabelledExample&& rhs) noexcept;
~LabelledExample();
bool operator==(const LabelledExample& rhs) const;
bool operator!=(const LabelledExample& rhs) const;
bool operator<(const LabelledExample& rhs) const;
LabelledExample& operator=(const LabelledExample& rhs);
LabelledExample& operator=(LabelledExample&& rhs) noexcept;
FeatureVector features;
TargetValue target_value;
WeightType weight = 1u;
};
class COMPONENT_EXPORT(LEARNING_COMMON) TrainingData {
public:
using ExampleVector = std::vector<LabelledExample>;
using const_iterator = ExampleVector::const_iterator;
TrainingData();
TrainingData(const TrainingData& rhs);
TrainingData(TrainingData&& rhs);
TrainingData& operator=(const TrainingData& rhs);
TrainingData& operator=(TrainingData&& rhs);
~TrainingData();
void push_back(const LabelledExample& example) {
DCHECK_GT(example.weight, 0u);
examples_.push_back(example);
total_weight_ += example.weight;
}
bool empty() const { return !total_weight_; }
size_t size() const { return examples_.size(); }
WeightType total_weight() const { return total_weight_; }
const_iterator begin() const { return examples_.begin(); }
const_iterator end() const { return examples_.end(); }
bool is_unweighted() const { return examples_.size() == total_weight_; }
const LabelledExample& operator[](size_t i) const { return examples_[i]; }
LabelledExample& operator[](size_t i) { return examples_[i]; }
TrainingData DeDuplicate() const;
private:
ExampleVector examples_;
WeightType total_weight_ = 0u;
};
COMPONENT_EXPORT(LEARNING_COMMON)
std::ostream& operator<<(std::ostream& out, const LabelledExample& example);
COMPONENT_EXPORT(LEARNING_COMMON)
std::ostream& operator<<(std::ostream& out, const FeatureVector& features);
}
}
#endif