22 #include <ml/MAClassifierSamples.hpp> 24 #include <MCBinaryData.hpp> 25 #include <MCDataContainer.hpp> 26 #include <MCDataStorage.hpp> 48 if (feature_vector.empty())
55 MC_WARNING(
"Feature count does not match with the stored vectors (%d != %d).",
66 if (feature_vectors.empty())
73 MC_WARNING(
"Feature vectors are not consistent.");
76 if (feature_vectors.size() != labels.size())
78 MC_WARNING(
"Feature vector count does not match with the label count (%d != %d).",
79 feature_vectors.size(), labels.size());
82 for (
unsigned int i = 0; i < feature_vectors.size(); ++i)
101 MC::DataStorageSPtr DataStorage(
new MCDataStorage(
"FeatureVectors",
true));
102 MC::DataContainerSPtr DataContainer(DataStorage->CreateContainer(
"FeatureVectors"));
109 if (!FeatureVectorsItem)
112 DataContainer->AddData(*FeatureVectorsItem);
114 reinterpret_cast<MC::FloatTable*
>(FeatureVectorsItem->DataPtr)->push_back(
FeatureVectors[i]);
116 return DataStorage->Encode();
123 MC::DataContainerSPtr DataContainer;
125 if (!DataStorage.get())
128 DataContainer = DataStorage->GetContainer(
"FeatureVectors");
129 if (!DataContainer.get())
132 const MC::DataItemBasePtrList& Items = DataContainer->GetAllData();
135 for (
auto& item : Items)
137 MC::FloatTable*
FeatureVectors =
reinterpret_cast<MC::FloatTable*
>(item->DataPtr);
140 for (
unsigned int i = 0; i < FeatureVectors->size(); ++i)
141 ClassifierSamples->
Labels.push_back(MCStrConvert<float>(item->DataName));
143 return ClassifierSamples;
151 if (BinaryData->LoadFromFile(file_name))
153 return Decode(*BinaryData);
161 MC::BinaryDataSPtr BinaryData(
Encode());
163 if (BinaryData->SaveToFile(file_name))
bool SaveToFile(const std::string &file_name) const
Save data to a file.
A helper class to fill the type info to the base structure.
void RemoveSample(unsigned int index)
Remove a sample.
MAClassifierSamples()
Class constructor.
static MAClassifierSamples * Decode(const MCBinaryData &data)
Decode from binary data.
const MC::FloatTable & GetFeatureVectors() const
Get all feature vectors.
#define MC_WARNING(...)
Warning macro.
Data container item base structure to store basic type info.
std::string MCToStr(const T value, bool hex_manipulator=false)
Convert an other type to string with std::stringstream.
Indexer< T > index(T &t)
Iterator magic for for loops to get the index while iterating through.
static MCDataStorage * Decode(const MCBinaryData &data, bool portable=false)
Load the data storage from binary form.
static MAClassifierSamples * LoadFromFile(const std::string &file_name)
Load data from a file.
Collected data with portable storage functions.
Data storage with file support.
bool MCIsConsistentTable(V &table)
Check the consistency of a table.
void AddSample(const MC::FloatList &feature_vector, float label)
Add a sample.
void AddSamples(const MC::FloatTable &feature_vectors, const MC::FloatList &labels)
Add more samples.
void MCMergeContainers(U &target, const U &other)
Merge two containers.
MC::FloatList Labels
Labels.
MC::FloatTable FeatureVectors
Feature vectors.
const MC::FloatList & GetLabels() const
Get all labels.
MCBinaryData * Encode() const
Encode into binary data.