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

multinomial_naive_bayes_training_distributed.h
1 /* file: multinomial_naive_bayes_training_distributed.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 the interface for multinomial naive Bayes model-based training
45 // in the distributed processing mode
46 //--
47 */
48 
49 #ifndef __NAIVE_BAYES_TRAINING_DISTRIBUTED_H__
50 #define __NAIVE_BAYES_TRAINING_DISTRIBUTED_H__
51 
52 #include "algorithms/algorithm.h"
53 #include "multinomial_naive_bayes_training_types.h"
54 
55 namespace daal
56 {
57 namespace algorithms
58 {
59 namespace multinomial_naive_bayes
60 {
61 namespace training
62 {
63 
64 namespace interface1
65 {
79 template<ComputeStep step, typename algorithmFPType, Method method, CpuType cpu>
80 class DAAL_EXPORT DistributedContainer;
81 
86 template<typename algorithmFPType, Method method, CpuType cpu>
87 class DAAL_EXPORT DistributedContainer<step2Master, algorithmFPType, method, cpu> : public TrainingContainerIface<distributed>
88 {
89 public:
95  DistributedContainer(daal::services::Environment::env *daalEnv);
97  ~DistributedContainer();
98 
105  services::Status compute() DAAL_C11_OVERRIDE;
112  services::Status finalizeCompute() DAAL_C11_OVERRIDE;
113 };
114 
127 template<ComputeStep step, typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = defaultDense>
128 class DAAL_EXPORT Distributed {};
129 
143 template<typename algorithmFPType, Method method>
144 class DAAL_EXPORT Distributed<step1Local, algorithmFPType, method> : public Online<algorithmFPType, method>
145 {
146 public:
147  typedef Online<algorithmFPType, method> super;
148 
149  typedef typename super::InputType InputType;
150  typedef typename super::ParameterType ParameterType;
151  typedef typename super::ResultType ResultType;
152  typedef typename super::PartialResultType PartialResultType;
153 
158  Distributed(size_t nClasses) : Online<algorithmFPType, method>::Online(nClasses) {}
159 
166  Distributed(const Distributed<step1Local, algorithmFPType, method> &other) :
167  Online<algorithmFPType, method>(other)
168  {}
169 
175  services::SharedPtr<Distributed<step1Local, algorithmFPType, method> > clone() const
176  {
177  return services::SharedPtr<Distributed<step1Local, algorithmFPType, method> >(cloneImpl());
178  }
179 
180 protected:
181  virtual Distributed<step1Local, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
182  {
183  return new Distributed<step1Local, algorithmFPType, method>(*this);
184  }
185 };
186 
200 template<typename algorithmFPType, Method method>
201 class DAAL_EXPORT Distributed<step2Master, algorithmFPType, method> : public Training<distributed>
202 {
203 public:
204  typedef algorithms::multinomial_naive_bayes::training::DistributedInput InputType;
205  typedef algorithms::multinomial_naive_bayes::Parameter ParameterType;
206  typedef algorithms::multinomial_naive_bayes::training::Result ResultType;
207  typedef algorithms::multinomial_naive_bayes::training::PartialResult PartialResultType;
208 
209  ParameterType parameter;
210  InputType input;
216  Distributed(size_t nClasses) : parameter(nClasses)
217  {
218  initialize();
219  }
220 
227  Distributed(const Distributed<step2Master, algorithmFPType, method> &other) :
228  Training<distributed>(other), input(other.input), parameter(other.parameter)
229  {
230  initialize();
231  }
232 
233  virtual ~Distributed() {}
234 
239  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)method; }
240 
245  services::Status setPartialResult(const PartialResultPtr& partialResult)
246  {
247  DAAL_CHECK(partialResult, services::ErrorNullPartialResult);
248  _partialResult = partialResult;
249  _pres = _partialResult.get();
250  return services::Status();
251  }
252 
257  PartialResultPtr getPartialResult() { return _partialResult; }
258 
265  services::Status setResult(const ResultPtr& result)
266  {
267  DAAL_CHECK(result, services::ErrorNullResult)
268  _result = result;
269  _res = _result.get();
270  return services::Status();
271  }
272 
277  ResultPtr getResult()
278  {
279  return ResultType::cast(_result);
280  }
281 
287  services::Status checkFinalizeComputeParams() DAAL_C11_OVERRIDE
288  {
289  PartialResultPtr partialResult = getPartialResult();
290  DAAL_CHECK(partialResult, services::ErrorNullResult);
291  services::Status s;
292  DAAL_CHECK_STATUS(s, partialResult->check(_par, method));
293  ResultPtr result = getResult();
294  DAAL_CHECK(result, services::ErrorNullResult);
295  DAAL_CHECK_STATUS(s, result->check(_pres, _par, method));
296  return s;
297  }
298 
304  services::SharedPtr<Distributed<step2Master, algorithmFPType, method> > clone() const
305  {
306  return services::SharedPtr<Distributed<step2Master, algorithmFPType, method> >(cloneImpl());
307  }
308 
309 protected:
310  PartialResultPtr _partialResult;
311  ResultPtr _result;
312 
313  virtual Distributed<step2Master, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
314  {
315  return new Distributed<step2Master, algorithmFPType, method>(*this);
316  }
317 
318  services::Status allocateResult() DAAL_C11_OVERRIDE
319  {
320  PartialResultPtr pres = getPartialResult();
321  ResultPtr res = getResult();
322  services::Status s = res->template allocate<algorithmFPType>(pres.get(), &parameter, (int)method);
323  _res = _result.get();
324  return s;
325  }
326 
327  services::Status allocatePartialResult() DAAL_C11_OVERRIDE
328  {
329  PartialResultPtr pres = getPartialResult();
330  services::Status s = pres->template allocate<algorithmFPType>((classifier::training::InputIface *)(&input), &parameter, (int)method);
331  _pres = _partialResult.get();
332  return s;
333  }
334 
335  services::Status initializePartialResult() DAAL_C11_OVERRIDE
336  {
337  return services::Status();
338  }
339 
340  void initialize()
341  {
342  _ac = new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step2Master, algorithmFPType, method)(&_env);
343  _in = &input;
344  _par = &parameter;
345  _result.reset(new ResultType());
346  _partialResult.reset(new PartialResultType());
347  }
348 };
350 } // namespace interface1
351 using interface1::DistributedContainer;
352 using interface1::Distributed;
353 
354 } // namespace training
355 } // namespace multinomial_naive_bayes
356 } // namespace algorithms
357 } //namespace daal
358 #endif
daal::algorithms::classifier::training::interface1::Input
Base class for the input objects in the training stage of the classification algorithms.
Definition: classifier_training_types.h:134
daal::algorithms::multinomial_naive_bayes::training::interface1::Distributed< step2Master, algorithmFPType, method >::setResult
services::Status setResult(const ResultPtr &result)
Definition: multinomial_naive_bayes_training_distributed.h:265
daal::services::interface1::Environment::_envStruct
The environment structure.
Definition: env_detect.h:95
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::multinomial_naive_bayes::training::interface1::Distributed< step2Master, algorithmFPType, method >::getPartialResult
PartialResultPtr getPartialResult()
Definition: multinomial_naive_bayes_training_distributed.h:257
daal::algorithms::classifier::interface1::Parameter
Base class for the parameters of the classification algorithm.
Definition: classifier_model.h:81
daal::algorithms::classifier::training::interface1::InputIface
Abstract class that specifies the interface of the classes of the classification algorithm input obje...
Definition: classifier_training_types.h:121
daal::algorithms::multinomial_naive_bayes::training::interface1::Distributed< step1Local, algorithmFPType, method >
Algorithm class for training Naive Bayes partial model in the distributed processing mode...
Definition: multinomial_naive_bayes_training_distributed.h:144
daal::services::ErrorNullPartialResult
Definition: error_indexes.h:131
daal::algorithms::multinomial_naive_bayes::training::interface1::Distributed< step2Master, algorithmFPType, method >::setPartialResult
services::Status setPartialResult(const PartialResultPtr &partialResult)
Definition: multinomial_naive_bayes_training_distributed.h:245
daal::algorithms::multinomial_naive_bayes::training::interface1::Distributed< step2Master, algorithmFPType, method >::getResult
ResultPtr getResult()
Definition: multinomial_naive_bayes_training_distributed.h:277
daal::algorithms::multinomial_naive_bayes::training::interface1::Distributed< step1Local, algorithmFPType, method >::Distributed
Distributed(size_t nClasses)
Definition: multinomial_naive_bayes_training_distributed.h:158
daal::algorithms::multinomial_naive_bayes::training::interface1::Distributed< step2Master, algorithmFPType, method >::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: multinomial_naive_bayes_training_distributed.h:239
daal::algorithms::multinomial_naive_bayes::training::interface1::Distributed< step2Master, algorithmFPType, method >::clone
services::SharedPtr< Distributed< step2Master, algorithmFPType, method > > clone() const
Definition: multinomial_naive_bayes_training_distributed.h:304
daal::algorithms::multinomial_naive_bayes::training::interface1::DistributedInput
Input objects of the naive Bayes training algorithm in the distributed processing mode...
Definition: multinomial_naive_bayes_training_types.h:257
daal::algorithms::kmeans::init::interface1::Distributed
class DAAL_EXPORT Distributed
Computes initial clusters for the K-Means algorithm in the distributed processing mode...
Definition: kmeans_init_distributed.h:281
daal::distributed
Definition: daal_defines.h:133
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::multinomial_naive_bayes::training::interface1::PartialResult
Provides methods to access partial results obtained with the compute() method of the naive Bayes trai...
Definition: multinomial_naive_bayes_training_types.h:104
daal::algorithms::multinomial_naive_bayes::training::interface1::Distributed< step2Master, algorithmFPType, method >::Distributed
Distributed(size_t nClasses)
Definition: multinomial_naive_bayes_training_distributed.h:216
daal::services::interface1::SharedPtr::get
T * get() const
Definition: daal_shared_ptr.h:332
daal::algorithms::multinomial_naive_bayes::training::interface1::Distributed< step2Master, algorithmFPType, method >
Algorithm class for training naive Bayes final model on the second step in the distributed processing...
Definition: multinomial_naive_bayes_training_distributed.h:201
daal::services::interface1::SharedPtr::reset
void reset()
Definition: daal_shared_ptr.h:265
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::Distributed< step2Master, algorithmFPType, method >::Distributed
Distributed(const Distributed< step2Master, algorithmFPType, method > &other)
Definition: multinomial_naive_bayes_training_distributed.h:227
daal::algorithms::multinomial_naive_bayes::training::interface1::DistributedContainer
class DAAL_EXPORT DistributedContainer
Class containing methods to compute naive Bayes training results in the distributed processing mode...
Definition: multinomial_naive_bayes_training_distributed.h:80
daal::algorithms::multinomial_naive_bayes::training::interface1::Distributed< step1Local, algorithmFPType, method >::clone
services::SharedPtr< Distributed< step1Local, algorithmFPType, method > > clone() const
Definition: multinomial_naive_bayes_training_distributed.h:175
daal::algorithms::classifier::training::interface1::PartialResult
Provides methods to access partial results obtained with the compute() method of the classifier train...
Definition: classifier_training_types.h:175
daal::algorithms::multinomial_naive_bayes::training::interface1::Distributed< step1Local, algorithmFPType, method >::Distributed
Distributed(const Distributed< step1Local, algorithmFPType, method > &other)
Definition: multinomial_naive_bayes_training_distributed.h:166
daal::algorithms::multinomial_naive_bayes::interface1::Parameter
Naive Bayes algorithm parameters.
Definition: multinomial_naive_bayes_model.h:84
daal::algorithms::classifier::training::interface1::Result
Provides methods to access final results obtained with the compute() method in the batch processing m...
Definition: classifier_training_types.h:222
daal::algorithms::multinomial_naive_bayes::training::interface1::Distributed< step2Master, algorithmFPType, method >::parameter
ParameterType parameter
Definition: multinomial_naive_bayes_training_distributed.h:209
daal::step1Local
Definition: daal_defines.h:143
daal::step2Master
Definition: daal_defines.h:144
daal::algorithms::multinomial_naive_bayes::training::interface1::Distributed
Algorithm class for training naive Bayes model in the distributed processing mode.
Definition: multinomial_naive_bayes_training_distributed.h:128
daal::services::ErrorNullResult
Definition: error_indexes.h:122
daal::algorithms::multinomial_naive_bayes::training::interface1::Distributed< step2Master, algorithmFPType, method >::input
InputType input
Definition: multinomial_naive_bayes_training_distributed.h:210
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::Training
Provides methods to train models that depend on the data provided. For example, these methods enable ...
Definition: training.h:86
daal::algorithms::multinomial_naive_bayes::training::interface1::Distributed< step2Master, algorithmFPType, method >::checkFinalizeComputeParams
services::Status checkFinalizeComputeParams() DAAL_C11_OVERRIDE
Definition: multinomial_naive_bayes_training_distributed.h:287

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