C++ API Reference for Intel® Data Analytics Acceleration Library 2018 Update 2

multinomial_naive_bayes_model.h
1 /* file: multinomial_naive_bayes_model.h */
2 /*******************************************************************************
3 * Copyright 2014-2018 Intel Corporation
4 * All Rights Reserved.
5 *
6 * If this software was obtained under the Intel Simplified Software License,
7 * the following terms apply:
8 *
9 * The source code, information and material ("Material") contained herein is
10 * owned by Intel Corporation or its suppliers or licensors, and title to such
11 * Material remains with Intel Corporation or its suppliers or licensors. The
12 * Material contains proprietary information of Intel or its suppliers and
13 * licensors. The Material is protected by worldwide copyright laws and treaty
14 * provisions. No part of the Material may be used, copied, reproduced,
15 * modified, published, uploaded, posted, transmitted, distributed or disclosed
16 * in any way without Intel's prior express written permission. No license under
17 * any patent, copyright or other intellectual property rights in the Material
18 * is granted to or conferred upon you, either expressly, by implication,
19 * inducement, estoppel or otherwise. Any license under such intellectual
20 * property rights must be express and approved by Intel in writing.
21 *
22 * Unless otherwise agreed by Intel in writing, you may not remove or alter this
23 * notice or any other notice embedded in Materials by Intel or Intel's
24 * suppliers or licensors in any way.
25 *
26 *
27 * If this software was obtained under the Apache License, Version 2.0 (the
28 * "License"), the following terms apply:
29 *
30 * You may not use this file except in compliance with the License. You may
31 * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
32 *
33 *
34 * Unless required by applicable law or agreed to in writing, software
35 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
36 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
37 *
38 * See the License for the specific language governing permissions and
39 * limitations under the License.
40 *******************************************************************************/
41 
42 /*
43 //++
44 // Implementation of class defining Naive Bayes model.
45 //--
46 */
47 
48 #ifndef __NAIVE_BAYES_MODEL_H__
49 #define __NAIVE_BAYES_MODEL_H__
50 
51 #include "algorithms/algorithm.h"
52 #include "data_management/data/numeric_table.h"
53 #include "data_management/data/homogen_numeric_table.h"
54 #include "algorithms/classifier/classifier_model.h"
55 
56 namespace daal
57 {
58 namespace algorithms
59 {
69 namespace multinomial_naive_bayes
70 {
71 
75 namespace interface1
76 {
83 /* [Parameter source code] */
84 struct DAAL_EXPORT Parameter : public classifier::Parameter
85 {
92  Parameter(size_t nClasses, const data_management::NumericTablePtr &priorClassEstimates_ = data_management::NumericTablePtr(),
93  const data_management::NumericTablePtr &alpha_ = data_management::NumericTablePtr()) :
94  classifier::Parameter(nClasses), priorClassEstimates(priorClassEstimates_), alpha(alpha_) {}
95 
96  data_management::NumericTablePtr priorClassEstimates;
97  data_management::NumericTablePtr alpha;
99  services::Status check() const DAAL_C11_OVERRIDE;
100 };
101 /* [Parameter source code] */
102 
103 
108 class DAAL_EXPORT Model : public classifier::Model
109 {
110 public:
111  DECLARE_MODEL(Model, classifier::Model);
112 
117  Model() {}
118 
126  template<typename modelFPType>
127  DAAL_EXPORT Model(size_t nFeatures, const Parameter &parameter, modelFPType dummy);
128 
135  template<typename modelFPType>
136  DAAL_EXPORT static services::SharedPtr<Model> create(size_t nFeatures, const Parameter &parameter,
137  services::Status *stat = NULL);
138 
140  virtual ~Model() {}
141 
146  data_management::NumericTablePtr getLogP() { return _logP; }
147 
152  data_management::NumericTablePtr getLogTheta() { return _logTheta; }
153 
158  data_management::NumericTablePtr getAuxTable() { return _auxTable; }
159 
164  size_t getNumberOfFeatures() const DAAL_C11_OVERRIDE { return (_logTheta ?_logTheta->getNumberOfColumns() : 0); }
165 
166 protected:
167  data_management::NumericTablePtr _logP;
168  data_management::NumericTablePtr _logTheta;
169  data_management::NumericTablePtr _auxTable;
170 
171  template<typename modelFPType>
172  DAAL_EXPORT Model(size_t nFeatures, const Parameter &parameter, modelFPType dummy, services::Status &st);
173 
174  template<typename Archive, bool onDeserialize>
175  services::Status serialImpl(Archive *arch)
176  {
177  services::Status st = classifier::Model::serialImpl<Archive, onDeserialize>(arch);
178  if (!st)
179  return st;
180  arch->setSharedPtrObj(_logP );
181  arch->setSharedPtrObj(_logTheta);
182  arch->setSharedPtrObj(_auxTable);
183 
184  return st;
185  }
186 };
187 
188 typedef services::SharedPtr<Model> ModelPtr;
189 
194 class DAAL_EXPORT PartialModel : public classifier::Model
195 {
196 public:
197  DECLARE_SERIALIZABLE_CAST(PartialModel);
202  PartialModel();
203 
211  template<typename modelFPType>
212  DAAL_EXPORT PartialModel(size_t nFeatures, const Parameter &parameter, modelFPType dummy);
213 
221  template<typename modelFPType>
222  DAAL_EXPORT static services::SharedPtr<PartialModel> create(size_t nFeatures, const Parameter &parameter,
223  services::Status *stat = NULL);
225  virtual ~PartialModel() {}
226 
227  size_t getNObservations()
228  {
229  return _nObservations;
230  }
231 
232  void setNObservations( size_t nObservations )
233  {
234  _nObservations = nObservations;
235  }
236 
241  size_t getNumberOfFeatures() const DAAL_C11_OVERRIDE { return (_classGroupSum ? _classGroupSum->getNumberOfColumns() : 0); }
242 
247  size_t getNFeatures() const DAAL_C11_OVERRIDE { return getNumberOfFeatures(); }
248 
253  void setNFeatures(size_t nFeatures) DAAL_C11_OVERRIDE {}
254 
255  template<typename modelFPType>
256  services::Status initialize()
257  {
258  _classSize->assign((int)0);
259  _classGroupSum->assign((int)0);
260  _nObservations = 0;
261  return services::Status();
262  }
263 
264  data_management::NumericTablePtr getClassSize() { return _classSize; }
265  data_management::NumericTablePtr getClassGroupSum() { return _classGroupSum; }
266 
267 protected:
268  data_management::NumericTablePtr _classSize;
269  data_management::NumericTablePtr _classGroupSum;
270  size_t _nObservations;
271 
272  template<typename modelFPType>
273  DAAL_EXPORT PartialModel(size_t nFeatures, const Parameter &parameter,
274  modelFPType dummy, services::Status &st);
275 
276  template<typename Archive, bool onDeserialize>
277  services::Status serialImpl(Archive *arch)
278  {
279  services::Status st = classifier::Model::serialImpl<Archive, onDeserialize>(arch);
280  if (!st)
281  return st;
282  arch->set(_nObservations);
283  arch->setSharedPtrObj(_classSize);
284  arch->setSharedPtrObj(_classGroupSum);
285 
286  return st;
287  }
288 };
289 typedef services::SharedPtr<PartialModel> PartialModelPtr;
290 } // namespace interface1
291 using interface1::Parameter;
292 using interface1::Model;
293 using interface1::ModelPtr;
294 using interface1::PartialModel;
295 using interface1::PartialModelPtr;
296 
297 } // namespace multinomial_naive_bayes
299 } // namespace algorithms
300 } // namespace daal
301 #endif
daal::services::interface1::Status
Class that holds the results of API calls. In case of API routine failure it contains the list of err...
Definition: error_handling.h:491
daal
Definition: algorithm_base_common.h:57
daal::algorithms::classifier::interface1::Parameter
Base class for the parameters of the classification algorithm.
Definition: classifier_model.h:81
daal::algorithms::multinomial_naive_bayes::interface1::Parameter::alpha
data_management::NumericTablePtr alpha
Definition: multinomial_naive_bayes_model.h:97
daal::algorithms::multinomial_naive_bayes::interface1::Model::Model
Model()
Definition: multinomial_naive_bayes_model.h:117
daal::algorithms::multinomial_naive_bayes::interface1::Parameter::Parameter
Parameter(size_t nClasses, const data_management::NumericTablePtr &priorClassEstimates_=data_management::NumericTablePtr(), const data_management::NumericTablePtr &alpha_=data_management::NumericTablePtr())
Definition: multinomial_naive_bayes_model.h:92
daal::algorithms::multinomial_naive_bayes::interface1::Model
Multinomial naive Bayes model.
Definition: multinomial_naive_bayes_model.h:108
daal::algorithms::multinomial_naive_bayes::interface1::PartialModel::getNumberOfFeatures
size_t getNumberOfFeatures() const DAAL_C11_OVERRIDE
Definition: multinomial_naive_bayes_model.h:241
daal::algorithms::multinomial_naive_bayes::interface1::PartialModel
PartialModel represents partial multinomial naive Bayes model.
Definition: multinomial_naive_bayes_model.h:194
daal::algorithms::multinomial_naive_bayes::interface1::Model::getLogP
data_management::NumericTablePtr getLogP()
Definition: multinomial_naive_bayes_model.h:146
daal::services::interface1::SharedPtr
Shared pointer that retains shared ownership of an object through a pointer. Several SharedPtr object...
Definition: daal_shared_ptr.h:187
daal::algorithms::classifier::interface1::Model
Base class for the model of the classification algorithm.
Definition: classifier_model.h:95
daal::algorithms::multinomial_naive_bayes::interface1::PartialModel::getNFeatures
size_t getNFeatures() const DAAL_C11_OVERRIDE
Definition: multinomial_naive_bayes_model.h:247
daal::algorithms::multinomial_naive_bayes::interface1::Model::getNumberOfFeatures
size_t getNumberOfFeatures() const DAAL_C11_OVERRIDE
Definition: multinomial_naive_bayes_model.h:164
daal::algorithms::multinomial_naive_bayes::interface1::Parameter
Naive Bayes algorithm parameters.
Definition: multinomial_naive_bayes_model.h:84
daal::algorithms::multinomial_naive_bayes::interface1::Model::getLogTheta
data_management::NumericTablePtr getLogTheta()
Definition: multinomial_naive_bayes_model.h:152
daal::algorithms::multinomial_naive_bayes::interface1::PartialModel::setNFeatures
void setNFeatures(size_t nFeatures) DAAL_C11_OVERRIDE
Definition: multinomial_naive_bayes_model.h:253
daal::algorithms::multinomial_naive_bayes::interface1::Parameter::priorClassEstimates
data_management::NumericTablePtr priorClassEstimates
Definition: multinomial_naive_bayes_model.h:96
daal::algorithms::multinomial_naive_bayes::interface1::Model::getAuxTable
data_management::NumericTablePtr getAuxTable()
Definition: multinomial_naive_bayes_model.h:158
daal::algorithms::covariance::nObservations
Definition: covariance_types.h:102

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