C++ API Reference for Intel® Data Analytics Acceleration Library 2020 Update 1

decision_forest_classification_model_builder.h
1 /* file: decision_forest_classification_model_builder.h */
2 /*******************************************************************************
3 * Copyright 2014-2020 Intel Corporation
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *******************************************************************************/
17 
18 /*
19 //++
20 // Implementation of class defining decision_forest classification model builder.
21 //--
22 */
23 #ifndef __DECISION_FOREST_CLASSIFICATION_MODEL_BUILDER_H__
24 #define __DECISION_FOREST_CLASSIFICATION_MODEL_BUILDER_H__
25 
26 #include "algorithms/decision_forest/decision_forest_classification_model.h"
27 
28 namespace daal
29 {
30 namespace algorithms
31 {
32 namespace decision_forest
33 {
42 namespace classification
43 {
44 
48 namespace interface1
49 {
50 
62 class DAAL_EXPORT ModelBuilder
63 {
64 public:
68  typedef size_t NodeId;
69 
73  typedef size_t TreeId;
74 
75  static const NodeId noParent = static_cast<size_t>(-1);
82  ModelBuilder(size_t nClasses, size_t nTrees)
83  {
84  _status |= initialize(nClasses, nTrees);
85  services::throwIfPossible(_status);
86  }
87 
93  TreeId createTree(size_t nNodes)
94  {
95  TreeId resId;
96  _status |= createTreeInternal(nNodes, resId);
97  services::throwIfPossible(_status);
98  return resId;
99  }
100 
109  NodeId addLeafNode(TreeId treeId, NodeId parentId, size_t position, size_t classLabel)
110  {
111  NodeId resId;
112  _status |= addLeafNodeInternal(treeId, parentId, position, classLabel, resId);
113  services::throwIfPossible(_status);
114  return resId;
115  }
116 
126  NodeId addSplitNode(TreeId treeId, NodeId parentId, size_t position, size_t featureIndex, double featureValue)
127  {
128  NodeId resId;
129  _status |= addSplitNodeInternal(treeId, parentId, position, featureIndex, featureValue, resId);
130  services::throwIfPossible(_status);
131  return resId;
132  }
133 
134  void setNFeatures(size_t nFeatures)
135  {
136  if(!_model.get())
137  {
138  _status |= services::ErrorNullModel;
139  services::throwIfPossible(_status);
140  }
141  else
142  {
143  _model->setNFeatures(nFeatures);
144  }
145  }
146 
151  ModelPtr getModel()
152  {
153  services::throwIfPossible(_status);
154  return _model;
155  }
156 
161  services::Status getStatus()
162  {
163  return _status;
164  }
165 
166 protected:
167  ModelPtr _model;
168  services::Status _status;
169  services::Status initialize(size_t nClasses, size_t nTrees);
170  services::Status createTreeInternal(size_t nNodes, TreeId& resId);
171  services::Status addLeafNodeInternal(TreeId treeId, NodeId parentId, size_t position, size_t classLabel, NodeId& res);
172  services::Status addSplitNodeInternal(TreeId treeId, NodeId parentId, size_t position, size_t featureIndex, double featureValue, NodeId& res);
173 };
175 } // namespace interface1
176 
180 namespace interface2
181 {
193 class DAAL_EXPORT ModelBuilder
194 {
195 public:
199  typedef size_t NodeId;
200 
204  typedef size_t TreeId;
205 
206  static const NodeId noParent = static_cast<size_t>(-1);
213  ModelBuilder(const size_t nClasses, const size_t nTrees) : _nClasses(nClasses)
214  {
215  _status |= initialize(nClasses, nTrees);
216  services::throwIfPossible(_status);
217  }
218 
224  TreeId createTree(const size_t nNodes)
225  {
226  TreeId resId;
227  _status |= createTreeInternal(nNodes, resId);
228  services::throwIfPossible(_status);
229  return resId;
230  }
231 
240  NodeId addLeafNode(const TreeId treeId, const NodeId parentId, const size_t position, const size_t classLabel)
241  {
242  NodeId resId;
243  _status |= addLeafNodeInternal(treeId, parentId, position, classLabel, resId);
244  services::throwIfPossible(_status);
245  return resId;
246  }
247 
256  NodeId addLeafNodeByProba(const TreeId treeId, const NodeId parentId, const size_t position, const double * const proba)
257  {
258  NodeId resId;
259  _status |= addLeafNodeByProbaInternal(treeId, parentId, position, proba, resId);
260  services::throwIfPossible(_status);
261  return resId;
262  }
263 
273  NodeId addSplitNode(const TreeId treeId, const NodeId parentId, const size_t position,
274  const size_t featureIndex, const double featureValue)
275  {
276  NodeId resId;
277  _status |= addSplitNodeInternal(treeId, parentId, position, featureIndex, featureValue, resId);
278  services::throwIfPossible(_status);
279  return resId;
280  }
281 
282  void setNFeatures(size_t nFeatures)
283  {
284  if(!_model.get())
285  {
286  _status |= services::ErrorNullModel;
287  services::throwIfPossible(_status);
288  }
289  else
290  {
291  _model->setNFeatures(nFeatures);
292  }
293  }
294 
299  ModelPtr getModel()
300  {
301  services::throwIfPossible(_status);
302  return _model;
303  }
304 
309  services::Status getStatus() const { return _status; }
310 
311 protected:
312  ModelPtr _model;
313  services::Status _status;
314  services::Status initialize(const size_t nClasses, const size_t nTrees);
315  services::Status createTreeInternal(const size_t nNodes, TreeId & resId);
316  services::Status addLeafNodeInternal(const TreeId treeId, const NodeId parentId, const size_t position,
317  const size_t classLabel, NodeId & res);
318  services::Status addLeafNodeByProbaInternal(const TreeId treeId, const NodeId parentId, const size_t position,
319  const double * const proba, NodeId & res);
320  services::Status addSplitNodeInternal(const TreeId treeId, const NodeId parentId, const size_t position,
321  const size_t featureIndex, const double featureValue, NodeId & res);
322 
323 private:
324  size_t _nClasses;
325 };
327 } // namespace interface2
328 using interface2::ModelBuilder;
329 
330 } // namespace classification
331 } // namespace decision_forest
332 } // namespace algorithms
333 } // namespace daal
334 #endif
daal::algorithms::decision_forest::classification::interface1::ModelBuilder
Model Builder class for Decision Forest Classification Model algorithm
Definition: decision_forest_classification_model_builder.h:62
daal::algorithms::decision_forest::classification::interface2::ModelBuilder::NodeId
size_t NodeId
Node identifier type is size_t
Definition: decision_forest_classification_model_builder.h:199
daal::algorithms::decision_forest::classification::interface1::ModelBuilder::NodeId
size_t NodeId
Node identifier type is size_t
Definition: decision_forest_classification_model_builder.h:68
daal::algorithms::decision_forest::classification::interface2::ModelBuilder::TreeId
size_t TreeId
Tree identifier type is size_t
Definition: decision_forest_classification_model_builder.h:204
daal::algorithms::decision_forest::classification::interface2::ModelBuilder::addLeafNodeByProba
NodeId addLeafNodeByProba(const TreeId treeId, const NodeId parentId, const size_t position, const double *const proba)
Definition: decision_forest_classification_model_builder.h:256
daal::algorithms::decision_forest::classification::interface1::ModelBuilder::addLeafNode
NodeId addLeafNode(TreeId treeId, NodeId parentId, size_t position, size_t classLabel)
Definition: decision_forest_classification_model_builder.h:109
daal::algorithms::decision_forest::classification::interface1::ModelBuilder::TreeId
size_t TreeId
Tree identifier type is size_t
Definition: decision_forest_classification_model_builder.h:73
daal::algorithms::decision_forest::classification::interface2::ModelBuilder::getModel
ModelPtr getModel()
Definition: decision_forest_classification_model_builder.h:299
daal::algorithms::decision_forest::classification::interface2::ModelBuilder::ModelBuilder
ModelBuilder(const size_t nClasses, const size_t nTrees)
Definition: decision_forest_classification_model_builder.h:213
daal::algorithms::decision_forest::classification::interface2::ModelBuilder
Model Builder class for Decision Forest Classification Model algorithm
Definition: decision_forest_classification_model_builder.h:193
daal::algorithms::decision_forest::classification::interface1::ModelBuilder::getModel
ModelPtr getModel()
Definition: decision_forest_classification_model_builder.h:151
daal::algorithms::decision_forest::classification::interface2::ModelBuilder::getStatus
services::Status getStatus() const
Definition: decision_forest_classification_model_builder.h:309
daal::services::ErrorNullModel
Definition: error_indexes.h:85
daal::algorithms::decision_forest::classification::interface1::ModelBuilder::createTree
TreeId createTree(size_t nNodes)
Definition: decision_forest_classification_model_builder.h:93
daal::algorithms::decision_forest::classification::interface2::ModelBuilder::createTree
TreeId createTree(const size_t nNodes)
Definition: decision_forest_classification_model_builder.h:224
daal::algorithms::decision_forest::classification::interface1::ModelBuilder::ModelBuilder
ModelBuilder(size_t nClasses, size_t nTrees)
Definition: decision_forest_classification_model_builder.h:82
daal::algorithms::decision_forest::classification::interface2::ModelBuilder::addSplitNode
NodeId addSplitNode(const TreeId treeId, const NodeId parentId, const size_t position, const size_t featureIndex, const double featureValue)
Definition: decision_forest_classification_model_builder.h:273
daal::algorithms::decision_forest::classification::interface2::ModelBuilder::addLeafNode
NodeId addLeafNode(const TreeId treeId, const NodeId parentId, const size_t position, const size_t classLabel)
Definition: decision_forest_classification_model_builder.h:240
daal::algorithms::decision_forest::classification::interface1::ModelBuilder::getStatus
services::Status getStatus()
Definition: decision_forest_classification_model_builder.h:161
daal::algorithms::decision_forest::classification::interface1::ModelBuilder::addSplitNode
NodeId addSplitNode(TreeId treeId, NodeId parentId, size_t position, size_t featureIndex, double featureValue)
Definition: decision_forest_classification_model_builder.h:126

For more complete information about compiler optimizations, see our Optimization Notice.