48 template <
class FeatureType,
class NodeType>
52 Fern() : num_of_decisions_(0), features_(0), thresholds_(0), nodes_(1) {}
64 num_of_decisions_ = num_of_decisions;
65 features_.resize(num_of_decisions_);
66 thresholds_.resize(num_of_decisions_, std::numeric_limits<float>::quiet_NaN());
67 nodes_.resize(0x1 << num_of_decisions_);
74 return 0x1U << num_of_decisions_;
81 return num_of_decisions_;
93 stream.write(
reinterpret_cast<const char*
>(&num_of_decisions_),
94 sizeof(num_of_decisions_));
96 for (std::size_t feature_index = 0; feature_index < features_.size();
98 features_[feature_index].serialize(stream);
101 for (std::size_t threshold_index = 0; threshold_index < thresholds_.size();
103 stream.write(
reinterpret_cast<const char*
>(&(thresholds_[threshold_index])),
104 sizeof(thresholds_[threshold_index]));
107 for (std::size_t node_index = 0; node_index < nodes_.size(); ++node_index) {
108 nodes_[node_index].serialize(stream);
119 stream.read(
reinterpret_cast<char*
>(&num_of_decisions_),
sizeof(num_of_decisions_));
121 features_.resize(num_of_decisions_);
122 thresholds_.resize(num_of_decisions_);
123 nodes_.resize(0x1 << num_of_decisions_);
125 for (std::size_t feature_index = 0; feature_index < features_.size();
127 features_[feature_index].deserialize(stream);
130 for (std::size_t threshold_index = 0; threshold_index < thresholds_.size();
132 stream.read(
reinterpret_cast<char*
>(&(thresholds_[threshold_index])),
133 sizeof(thresholds_[threshold_index]));
136 for (std::size_t node_index = 0; node_index < nodes_.size(); ++node_index) {
137 nodes_[node_index].deserialize(stream);
148 return nodes_[node_index];
155 inline const NodeType&
158 return nodes_[node_index];
168 return features_[feature_index];
175 inline const FeatureType&
178 return features_[feature_index];
188 return thresholds_[threshold_index];
198 return thresholds_[threshold_index];
203 std::size_t num_of_decisions_;
205 std::vector<FeatureType> features_;
207 std::vector<float> thresholds_;
209 std::vector<NodeType> nodes_;