48 template <
class FeatureType,
class NodeType>
52 Fern() : num_of_decisions_(0), features_(0), thresholds_(0), nodes_(1) {}
61 num_of_decisions_ = num_of_decisions;
62 features_.resize(num_of_decisions_);
63 thresholds_.resize(num_of_decisions_, std::numeric_limits<float>::quiet_NaN());
64 nodes_.resize(0x1 << num_of_decisions_);
71 return 0x1U << num_of_decisions_;
78 return num_of_decisions_;
90 stream.write(
reinterpret_cast<const char*
>(&num_of_decisions_),
91 sizeof(num_of_decisions_));
93 for (
auto& feature : features_) {
94 feature.serialize(stream);
97 for (
const auto& threshold : thresholds_) {
98 stream.write(
reinterpret_cast<const char*
>(&threshold),
sizeof(threshold));
101 for (
auto& node : nodes_) {
102 node.serialize(stream);
113 stream.read(
reinterpret_cast<char*
>(&num_of_decisions_),
sizeof(num_of_decisions_));
115 features_.resize(num_of_decisions_);
116 thresholds_.resize(num_of_decisions_);
117 nodes_.resize(0x1 << num_of_decisions_);
119 for (
auto& feature : features_) {
120 feature.deserialize(stream);
123 for (
const auto& threshold : thresholds_) {
124 stream.read(
reinterpret_cast<char*
>(&(threshold)),
sizeof(threshold));
127 for (
auto& node : nodes_) {
128 node.deserialize(stream);
139 return nodes_[node_index];
146 inline const NodeType&
149 return nodes_[node_index];
159 return features_[feature_index];
166 inline const FeatureType&
169 return features_[feature_index];
179 return thresholds_[threshold_index];
189 return thresholds_[threshold_index];
194 std::size_t num_of_decisions_;
196 std::vector<FeatureType> features_;
198 std::vector<float> thresholds_;
200 std::vector<NodeType> nodes_;
Class representing a Fern.
const float & accessThreshold(const std::size_t threshold_index) const
Access operator for thresholds.
std::size_t getNumOfNodes()
Returns the number of nodes the Fern has.
NodeType & operator[](const std::size_t node_index)
Access operator for nodes.
const NodeType & operator[](const std::size_t node_index) const
Access operator for nodes.
void deserialize(::std::istream &stream)
Deserializes the fern.
const FeatureType & accessFeature(const std::size_t feature_index) const
Access operator for features.
std::size_t getNumOfFeatures()
Returns the number of features the Fern has.
float & accessThreshold(const std::size_t threshold_index)
Access operator for thresholds.
void serialize(::std::ostream &stream) const
Serializes the fern.
void initialize(const std::size_t num_of_decisions)
Initializes the fern.
FeatureType & accessFeature(const std::size_t feature_index)
Access operator for features.
Define standard C methods and C++ classes that are common to all methods.