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

multinomial_naive_bayes_training_online.h
1 /* file: multinomial_naive_bayes_training_online.h */
2 /*******************************************************************************
3 * Copyright 2014-2017 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 the interface for multinomial naive Bayes model-based training
45 // in the online processing mode
46 //--
47 */
48 
49 #ifndef __NAIVE_BAYES_TRAINING_ONLINE_H__
50 #define __NAIVE_BAYES_TRAINING_ONLINE_H__
51 
52 #include "algorithms/algorithm.h"
53 #include "multinomial_naive_bayes_training_types.h"
54 #include "algorithms/classifier/classifier_training_online.h"
55 
56 namespace daal
57 {
58 namespace algorithms
59 {
60 namespace multinomial_naive_bayes
61 {
62 namespace training
63 {
64 
65 namespace interface1
66 {
79 template<typename algorithmFPType, Method method, CpuType cpu>
80 class DAAL_EXPORT OnlineContainer : public TrainingContainerIface<online>
81 {
82 public:
88  OnlineContainer(daal::services::Environment::env *daalEnv);
90  ~OnlineContainer();
91 
98  services::Status compute() DAAL_C11_OVERRIDE;
105  services::Status finalizeCompute() DAAL_C11_OVERRIDE;
106 };
107 
121 template<typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = defaultDense>
122 class DAAL_EXPORT Online : public classifier::training::Online
123 {
124 public:
125 
130  Online(size_t nClasses) : parameter(nClasses)
131  {
132  initialize();
133  }
134 
141  Online(const Online<algorithmFPType, method> &other) :
142  classifier::training::Online(other), parameter(other.parameter)
143  {
144  initialize();
145  }
146 
147  virtual ~Online() {}
148 
153  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)method; }
154 
159  ResultPtr getResult()
160  {
161  return services::staticPointerCast<Result, classifier::training::Result>(_result);
162  }
163 
170  services::Status setResult(const ResultPtr& result)
171  {
172  DAAL_CHECK(result, services::ErrorNullResult)
173  _result = result;
174  _res = _result.get();
175  return services::Status();
176  }
177 
181  void resetResult()
182  {
183  _result.reset(new Result());
184  _res = NULL;
185  }
186 
191  PartialResultPtr getPartialResult() { return PartialResult::cast(_partialResult); }
192 
198  services::SharedPtr<Online<algorithmFPType, method> > clone() const
199  {
200  return services::SharedPtr<Online<algorithmFPType, method> >(cloneImpl());
201  }
202 
203  Parameter parameter;
205 protected:
206 
207  virtual Online<algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
208  {
209  return new Online<algorithmFPType, method>(*this);
210  }
211 
212  services::Status allocateResult() DAAL_C11_OVERRIDE
213  {
214  PartialResultPtr pres = getPartialResult();
215  ResultPtr res = services::staticPointerCast<Result, classifier::training::Result>(_result);
216  services::Status s = res->template allocate<algorithmFPType>(pres.get(), &parameter, (int)method);
217  _res = _result.get();
218  return s;
219  }
220 
221  services::Status allocatePartialResult() DAAL_C11_OVERRIDE
222  {
223  PartialResultPtr pres = getPartialResult();
224  services::Status s = pres->template allocate<algorithmFPType>((classifier::training::InputIface *)(&input), &parameter, (int)method);
225  _pres = _partialResult.get();
226  return s;
227  }
228 
229  services::Status initializePartialResult() DAAL_C11_OVERRIDE
230  {
231  PartialResultPtr pres = getPartialResult();
232  services::Status s = pres->template initialize<algorithmFPType>((classifier::training::InputIface *)(&input), &parameter, (int)method);
233  _pres = _partialResult.get();
234  return s;
235  }
236 
237  void initialize()
238  {
239  _ac = new __DAAL_ALGORITHM_CONTAINER(online, OnlineContainer, algorithmFPType, method)(&_env);
240  _par = &parameter;
241  _result.reset(new Result());
242  _partialResult.reset(new PartialResult());
243  }
244 };
246 } // namespace interface1
247 using interface1::OnlineContainer;
248 using interface1::Online;
249 
250 } // namespace training
251 } // namespace multinomial_naive_bayes
252 } // namespace algorithms
253 } // namespace daal
254 #endif
daal::algorithms::multinomial_naive_bayes::training::interface1::Online::parameter
Parameter parameter
Definition: multinomial_naive_bayes_training_online.h:203
daal
Definition: algorithm_base_common.h:57
daal::algorithms::multinomial_naive_bayes::training::interface1::OnlineContainer
Class containing computation methods for naive Bayes training in the online processing mode...
Definition: multinomial_naive_bayes_training_online.h:80
daal::algorithms::multinomial_naive_bayes::training::interface1::Online::Online
Online(const Online< algorithmFPType, method > &other)
Definition: multinomial_naive_bayes_training_online.h:141
daal::algorithms::multinomial_naive_bayes::training::interface1::Online::Online
Online(size_t nClasses)
Definition: multinomial_naive_bayes_training_online.h:130
daal::algorithms::multinomial_naive_bayes::training::interface1::Online::resetResult
void resetResult()
Definition: multinomial_naive_bayes_training_online.h:181
daal::algorithms::multinomial_naive_bayes::training::interface1::Online::getPartialResult
PartialResultPtr getPartialResult()
Definition: multinomial_naive_bayes_training_online.h:191
daal::algorithms::multinomial_naive_bayes::training::interface1::Result
Provides methods to access final results obtained with the compute() method of the naive Bayes traini...
Definition: multinomial_naive_bayes_training_types.h:185
daal::algorithms::multinomial_naive_bayes::training::interface1::Online::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: multinomial_naive_bayes_training_online.h:153
daal::online
Definition: daal_defines.h:133
daal::algorithms::multinomial_naive_bayes::training::interface1::Online::getResult
ResultPtr getResult()
Definition: multinomial_naive_bayes_training_online.h:159
daal::algorithms::multinomial_naive_bayes::training::interface1::Online::clone
services::SharedPtr< Online< algorithmFPType, method > > clone() const
Definition: multinomial_naive_bayes_training_online.h:198
daal::services::ErrorNullResult
Definition: error_indexes.h:122
daal::algorithms::TrainingContainerIface
Abstract interface class that provides virtual methods to access and run implementations of the model...
Definition: training.h:76
daal::algorithms::multinomial_naive_bayes::training::interface1::Online
Algorithm class for training naive Bayes model.
Definition: multinomial_naive_bayes_training_online.h:122
daal::algorithms::multinomial_naive_bayes::training::interface1::Online::setResult
services::Status setResult(const ResultPtr &result)
Definition: multinomial_naive_bayes_training_online.h:170

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