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

multinomial_naive_bayes_training_distributed.h
1 /* file: multinomial_naive_bayes_training_distributed.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 the interface for multinomial naive Bayes model-based training
21 // in the distributed processing mode
22 //--
23 */
24 
25 #ifndef __NAIVE_BAYES_TRAINING_DISTRIBUTED_H__
26 #define __NAIVE_BAYES_TRAINING_DISTRIBUTED_H__
27 
28 #include "algorithms/algorithm.h"
29 #include "multinomial_naive_bayes_training_types.h"
30 
31 namespace daal
32 {
33 namespace algorithms
34 {
35 namespace multinomial_naive_bayes
36 {
37 namespace training
38 {
39 
40 namespace interface1
41 {
55 template<ComputeStep step, typename algorithmFPType, Method method, CpuType cpu>
56 class DistributedContainer;
57 
62 template<typename algorithmFPType, Method method, CpuType cpu>
63 class DistributedContainer<step2Master, algorithmFPType, method, cpu> : public TrainingContainerIface<distributed>
64 {
65 public:
71  DAAL_DEPRECATED DistributedContainer(daal::services::Environment::env *daalEnv);
73  DAAL_DEPRECATED ~DistributedContainer();
74 
81  DAAL_DEPRECATED services::Status compute() DAAL_C11_OVERRIDE;
88  DAAL_DEPRECATED services::Status finalizeCompute() DAAL_C11_OVERRIDE;
89 };
90 
103 template<ComputeStep step, typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = defaultDense>
104 class DAAL_EXPORT Distributed {};
105 
119 template<typename algorithmFPType, Method method>
120 class DAAL_EXPORT Distributed<step1Local, algorithmFPType, method> : public interface1::Online<algorithmFPType, method>
121 {
122 public:
123  typedef interface1::Online<algorithmFPType, method> super;
124 
125  typedef typename super::InputType InputType;
126  typedef typename super::ParameterType ParameterType;
127  typedef typename super::ResultType ResultType;
128  typedef typename super::PartialResultType PartialResultType;
129 
134  DAAL_DEPRECATED Distributed(size_t nClasses) : interface1::Online<algorithmFPType, method>::Online(nClasses) {}
135 
142  DAAL_DEPRECATED Distributed(const Distributed<step1Local, algorithmFPType, method> &other) :
143  interface1::Online<algorithmFPType, method>(other)
144  {}
145 
151  DAAL_DEPRECATED services::SharedPtr<Distributed<step1Local, algorithmFPType, method> > clone() const
152  {
153  return services::SharedPtr<Distributed<step1Local, algorithmFPType, method> >(cloneImpl());
154  }
155 
156 protected:
157  virtual Distributed<step1Local, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
158  {
159  return new interface1::Distributed<step1Local, algorithmFPType, method>(*this);
160  }
161 };
162 
176 template<typename algorithmFPType, Method method>
177 class DAAL_EXPORT Distributed<step2Master, algorithmFPType, method> : public Training<distributed>
178 {
179 public:
180  typedef algorithms::multinomial_naive_bayes::training::DistributedInput InputType;
181  typedef algorithms::multinomial_naive_bayes::interface1::Parameter ParameterType;
182  typedef algorithms::multinomial_naive_bayes::training::Result ResultType;
183  typedef algorithms::multinomial_naive_bayes::training::PartialResult PartialResultType;
184 
185  ParameterType parameter;
186  InputType input;
192  DAAL_DEPRECATED Distributed(size_t nClasses) : parameter(nClasses)
193  {
194  initialize();
195  }
196 
203  DAAL_DEPRECATED Distributed(const Distributed<step2Master, algorithmFPType, method> &other) :
204  Training<distributed>(other), input(other.input), parameter(other.parameter)
205  {
206  initialize();
207  }
208 
209  DAAL_DEPRECATED_VIRTUAL virtual ~Distributed() {}
210 
215  DAAL_DEPRECATED_VIRTUAL virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)method; }
216 
221  DAAL_DEPRECATED services::Status setPartialResult(const PartialResultPtr& partialResult)
222  {
223  DAAL_CHECK(partialResult, services::ErrorNullPartialResult);
224  _partialResult = partialResult;
225  _pres = _partialResult.get();
226  return services::Status();
227  }
228 
233  DAAL_DEPRECATED PartialResultPtr getPartialResult() { return _partialResult; }
234 
241  DAAL_DEPRECATED services::Status setResult(const ResultPtr& result)
242  {
243  DAAL_CHECK(result, services::ErrorNullResult)
244  _result = result;
245  _res = _result.get();
246  return services::Status();
247  }
248 
253  DAAL_DEPRECATED ResultPtr getResult()
254  {
255  return ResultType::cast(_result);
256  }
257 
263  DAAL_DEPRECATED services::Status checkFinalizeComputeParams() DAAL_C11_OVERRIDE
264  {
265  PartialResultPtr partialResult = getPartialResult();
266  DAAL_CHECK(partialResult, services::ErrorNullResult);
267  services::Status s;
268  DAAL_CHECK_STATUS(s, partialResult->check(_par, method));
269  ResultPtr result = getResult();
270  DAAL_CHECK(result, services::ErrorNullResult);
271  DAAL_CHECK_STATUS(s, result->check(_pres, _par, method));
272  return s;
273  }
274 
280  DAAL_DEPRECATED services::SharedPtr<Distributed<step2Master, algorithmFPType, method> > clone() const
281  {
282  return services::SharedPtr<Distributed<step2Master, algorithmFPType, method> >(cloneImpl());
283  }
284 
285 protected:
286  PartialResultPtr _partialResult;
287  ResultPtr _result;
288 
289  virtual Distributed<step2Master, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
290  {
291  return new Distributed<step2Master, algorithmFPType, method>(*this);
292  }
293 
294  services::Status allocateResult() DAAL_C11_OVERRIDE
295  {
296  PartialResultPtr pres = getPartialResult();
297  ResultPtr res = getResult();
298  services::Status s = res->template allocate<algorithmFPType>(pres.get(), &parameter, (int)method);
299  _res = _result.get();
300  return s;
301  }
302 
303  services::Status allocatePartialResult() DAAL_C11_OVERRIDE
304  {
305  PartialResultPtr pres = getPartialResult();
306  services::Status s = pres->template allocate<algorithmFPType>((classifier::training::InputIface *)(&input), &parameter, (int)method);
307  _pres = _partialResult.get();
308  return s;
309  }
310 
311  services::Status initializePartialResult() DAAL_C11_OVERRIDE
312  {
313  return services::Status();
314  }
315 
316  void initialize()
317  {
318  _ac = new __DAAL_ALGORITHM_CONTAINER(distributed, interface1::DistributedContainer, step2Master, algorithmFPType, method)(&_env);
319  _in = &input;
320  _par = &parameter;
321  _result.reset(new ResultType());
322  _partialResult.reset(new PartialResultType());
323  }
324 };
326 } // namespace interface1
327 
328 namespace interface2
329 {
343 template<ComputeStep step, typename algorithmFPType, Method method, CpuType cpu>
344 class DistributedContainer;
345 
350 template<typename algorithmFPType, Method method, CpuType cpu>
351 class DistributedContainer<step2Master, algorithmFPType, method, cpu> : public TrainingContainerIface<distributed>
352 {
353 public:
359  DistributedContainer(daal::services::Environment::env *daalEnv);
361  ~DistributedContainer();
362 
369  services::Status compute() DAAL_C11_OVERRIDE;
376  services::Status finalizeCompute() DAAL_C11_OVERRIDE;
377 };
378 
391 template<ComputeStep step, typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = defaultDense>
392 class DAAL_EXPORT Distributed {};
393 
407 template<typename algorithmFPType, Method method>
408 class DAAL_EXPORT Distributed<step1Local, algorithmFPType, method> : public Online<algorithmFPType, method>
409 {
410 public:
411  typedef Online<algorithmFPType, method> super;
412 
413  typedef typename super::InputType InputType;
414  typedef typename super::ParameterType ParameterType;
415  typedef typename super::ResultType ResultType;
416  typedef typename super::PartialResultType PartialResultType;
417 
422  Distributed(size_t nClasses) : Online<algorithmFPType, method>::Online(nClasses) {}
423 
430  Distributed(const Distributed<step1Local, algorithmFPType, method> &other) :
431  Online<algorithmFPType, method>(other)
432  {}
433 
439  services::SharedPtr<Distributed<step1Local, algorithmFPType, method> > clone() const
440  {
441  return services::SharedPtr<Distributed<step1Local, algorithmFPType, method> >(cloneImpl());
442  }
443 
444 protected:
445  virtual Distributed<step1Local, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
446  {
447  return new Distributed<step1Local, algorithmFPType, method>(*this);
448  }
449 };
450 
464 template<typename algorithmFPType, Method method>
465 class DAAL_EXPORT Distributed<step2Master, algorithmFPType, method> : public Training<distributed>
466 {
467 public:
468  typedef algorithms::multinomial_naive_bayes::training::DistributedInput InputType;
469  typedef algorithms::multinomial_naive_bayes::Parameter ParameterType;
470  typedef algorithms::multinomial_naive_bayes::training::Result ResultType;
471  typedef algorithms::multinomial_naive_bayes::training::PartialResult PartialResultType;
472 
473  ParameterType parameter;
474  InputType input;
480  Distributed(size_t nClasses) : parameter(nClasses)
481  {
482  initialize();
483  }
484 
491  Distributed(const Distributed<step2Master, algorithmFPType, method> &other) :
492  Training<distributed>(other), input(other.input), parameter(other.parameter)
493  {
494  initialize();
495  }
496 
497  virtual ~Distributed() {}
498 
503  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)method; }
504 
509  services::Status setPartialResult(const PartialResultPtr& partialResult)
510  {
511  DAAL_CHECK(partialResult, services::ErrorNullPartialResult);
512  _partialResult = partialResult;
513  _pres = _partialResult.get();
514  return services::Status();
515  }
516 
521  PartialResultPtr getPartialResult() { return _partialResult; }
522 
529  services::Status setResult(const ResultPtr& result)
530  {
531  DAAL_CHECK(result, services::ErrorNullResult)
532  _result = result;
533  _res = _result.get();
534  return services::Status();
535  }
536 
541  ResultPtr getResult()
542  {
543  return ResultType::cast(_result);
544  }
545 
551  services::Status checkFinalizeComputeParams() DAAL_C11_OVERRIDE
552  {
553  PartialResultPtr partialResult = getPartialResult();
554  DAAL_CHECK(partialResult, services::ErrorNullResult);
555  services::Status s;
556  DAAL_CHECK_STATUS(s, partialResult->check(_par, method));
557  ResultPtr result = getResult();
558  DAAL_CHECK(result, services::ErrorNullResult);
559  DAAL_CHECK_STATUS(s, result->check(_pres, _par, method));
560  return s;
561  }
562 
568  services::SharedPtr<Distributed<step2Master, algorithmFPType, method> > clone() const
569  {
570  return services::SharedPtr<Distributed<step2Master, algorithmFPType, method> >(cloneImpl());
571  }
572 
573 protected:
574  PartialResultPtr _partialResult;
575  ResultPtr _result;
576 
577  virtual Distributed<step2Master, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
578  {
579  return new Distributed<step2Master, algorithmFPType, method>(*this);
580  }
581 
582  services::Status allocateResult() DAAL_C11_OVERRIDE
583  {
584  PartialResultPtr pres = getPartialResult();
585  ResultPtr res = getResult();
586  services::Status s = res->template allocate<algorithmFPType>(pres.get(), &parameter, (int)method);
587  _res = _result.get();
588  return s;
589  }
590 
591  services::Status allocatePartialResult() DAAL_C11_OVERRIDE
592  {
593  PartialResultPtr pres = getPartialResult();
594  services::Status s = pres->template allocate<algorithmFPType>((classifier::training::InputIface *)(&input), &parameter, (int)method);
595  _pres = _partialResult.get();
596  return s;
597  }
598 
599  services::Status initializePartialResult() DAAL_C11_OVERRIDE
600  {
601  return services::Status();
602  }
603 
604  void initialize()
605  {
606  _ac = new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step2Master, algorithmFPType, method)(&_env);
607  _in = &input;
608  _par = &parameter;
609  _result.reset(new ResultType());
610  _partialResult.reset(new PartialResultType());
611  }
612 };
614 } // namespace interface2
615 using interface2::DistributedContainer;
616 using interface2::Distributed;
617 
618 } // namespace training
619 } // namespace multinomial_naive_bayes
620 } // namespace algorithms
621 } //namespace daal
622 #endif
daal::step1Local
Definition: daal_defines.h:123
daal::algorithms::multinomial_naive_bayes::training::interface1::Distributed< step2Master, algorithmFPType, method >::Distributed
DAAL_DEPRECATED Distributed(const Distributed< step2Master, algorithmFPType, method > &other)
Definition: multinomial_naive_bayes_training_distributed.h:203
daal::algorithms::multinomial_naive_bayes::training::interface2::Distributed< step1Local, algorithmFPType, method >::Distributed
Distributed(size_t nClasses)
Definition: multinomial_naive_bayes_training_distributed.h:422
daal::algorithms::multinomial_naive_bayes::training::interface2::Distributed< step2Master, algorithmFPType, method >::getResult
ResultPtr getResult()
Definition: multinomial_naive_bayes_training_distributed.h:541
daal::step2Master
Definition: daal_defines.h:124
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:120
daal::algorithms::multinomial_naive_bayes::training::interface1::Distributed< step2Master, algorithmFPType, method >::getPartialResult
DAAL_DEPRECATED PartialResultPtr getPartialResult()
Definition: multinomial_naive_bayes_training_distributed.h:233
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:177
daal::algorithms::multinomial_naive_bayes::training::interface1::Distributed< step1Local, algorithmFPType, method >::clone
DAAL_DEPRECATED services::SharedPtr< Distributed< step1Local, algorithmFPType, method > > clone() const
Definition: multinomial_naive_bayes_training_distributed.h:151
daal::algorithms::multinomial_naive_bayes::interface1::Parameter
Naive Bayes algorithm parameters.
Definition: multinomial_naive_bayes_model.h:60
daal::algorithms::multinomial_naive_bayes::training::interface1::Online
Algorithm class for training naive Bayes model.
Definition: multinomial_naive_bayes_training_online.h:98
daal::algorithms::multinomial_naive_bayes::training::interface1::Distributed< step2Master, algorithmFPType, method >::checkFinalizeComputeParams
DAAL_DEPRECATED services::Status checkFinalizeComputeParams() DAAL_C11_OVERRIDE
Definition: multinomial_naive_bayes_training_distributed.h:263
daal::services::ErrorNullResult
Definition: error_indexes.h:98
daal::algorithms::multinomial_naive_bayes::training::interface2::Distributed< step2Master, algorithmFPType, method >::parameter
ParameterType parameter
Definition: multinomial_naive_bayes_training_distributed.h:473
daal::algorithms::kmeans::init::interface2::Distributed
class DAAL_EXPORT Distributed
Computes initial clusters for K-Means algorithm in the distributed processing mode.
Definition: kmeans_init_distributed.h:277
daal::algorithms::multinomial_naive_bayes::training::interface1::Distributed< step2Master, algorithmFPType, method >::parameter
ParameterType parameter
Definition: multinomial_naive_bayes_training_distributed.h:185
daal::algorithms::multinomial_naive_bayes::training::interface1::Distributed< step2Master, algorithmFPType, method >::input
InputType input
Definition: multinomial_naive_bayes_training_distributed.h:186
daal::algorithms::multinomial_naive_bayes::training::interface1::Distributed< step2Master, algorithmFPType, method >::setResult
DAAL_DEPRECATED services::Status setResult(const ResultPtr &result)
Definition: multinomial_naive_bayes_training_distributed.h:241
daal::algorithms::multinomial_naive_bayes::training::interface2::Distributed< step2Master, algorithmFPType, method >::input
InputType input
Definition: multinomial_naive_bayes_training_distributed.h:474
daal::algorithms::multinomial_naive_bayes::training::interface2::Distributed< step1Local, algorithmFPType, method >::clone
services::SharedPtr< Distributed< step1Local, algorithmFPType, method > > clone() const
Definition: multinomial_naive_bayes_training_distributed.h:439
daal::algorithms::Training
Provides methods to train models that depend on the data provided. For example, these methods enable ...
Definition: training.h:62
daal::algorithms::multinomial_naive_bayes::training::interface1::Distributed< step2Master, algorithmFPType, method >::clone
DAAL_DEPRECATED services::SharedPtr< Distributed< step2Master, algorithmFPType, method > > clone() const
Definition: multinomial_naive_bayes_training_distributed.h:280
daal::algorithms::multinomial_naive_bayes::training::interface1::Distributed< step2Master, algorithmFPType, method >::getResult
DAAL_DEPRECATED ResultPtr getResult()
Definition: multinomial_naive_bayes_training_distributed.h:253
daal::algorithms::multinomial_naive_bayes::training::interface2::Distributed
Algorithm class for training naive Bayes model in the distributed processing mode.
Definition: multinomial_naive_bayes_training_distributed.h:392
daal::algorithms::multinomial_naive_bayes::training::interface1::Distributed< step2Master, algorithmFPType, method >::Distributed
DAAL_DEPRECATED Distributed(size_t nClasses)
Definition: multinomial_naive_bayes_training_distributed.h:192
daal::algorithms::multinomial_naive_bayes::training::interface2::Distributed< step1Local, algorithmFPType, method >
Algorithm class for training Naive Bayes partial model in the distributed processing mode...
Definition: multinomial_naive_bayes_training_distributed.h:408
daal::algorithms::multinomial_naive_bayes::training::interface2::DistributedContainer
Class containing methods to compute naive Bayes training results in the distributed processing mode...
Definition: multinomial_naive_bayes_training_distributed.h:344
daal::algorithms::classifier::interface1::Parameter
Base class for the parameters of the classification algorithm.
Definition: classifier_model.h:69
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:104
daal::algorithms::multinomial_naive_bayes::training::interface1::Distributed< step1Local, algorithmFPType, method >::Distributed
DAAL_DEPRECATED Distributed(size_t nClasses)
Definition: multinomial_naive_bayes_training_distributed.h:134
daal::algorithms::multinomial_naive_bayes::training::interface2::Online
Algorithm class for training naive Bayes model.
Definition: multinomial_naive_bayes_training_online.h:287
daal::algorithms::multinomial_naive_bayes::training::interface2::Distributed< step2Master, algorithmFPType, method >::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: multinomial_naive_bayes_training_distributed.h:503
daal::algorithms::multinomial_naive_bayes::training::interface2::Distributed< step2Master, algorithmFPType, method >::Distributed
Distributed(const Distributed< step2Master, algorithmFPType, method > &other)
Definition: multinomial_naive_bayes_training_distributed.h:491
daal::algorithms::multinomial_naive_bayes::training::interface2::Distributed< step2Master, algorithmFPType, method >::getPartialResult
PartialResultPtr getPartialResult()
Definition: multinomial_naive_bayes_training_distributed.h:521
daal::algorithms::multinomial_naive_bayes::training::interface1::DistributedContainer
Class containing methods to compute naive Bayes training results in the distributed processing mode...
Definition: multinomial_naive_bayes_training_distributed.h:56
daal::algorithms::multinomial_naive_bayes::training::interface2::Distributed< step2Master, algorithmFPType, method >::setPartialResult
services::Status setPartialResult(const PartialResultPtr &partialResult)
Definition: multinomial_naive_bayes_training_distributed.h:509
daal::algorithms::multinomial_naive_bayes::training::interface1::Distributed< step2Master, algorithmFPType, method >::setPartialResult
DAAL_DEPRECATED services::Status setPartialResult(const PartialResultPtr &partialResult)
Definition: multinomial_naive_bayes_training_distributed.h:221
daal::algorithms::multinomial_naive_bayes::training::interface2::Distributed< step1Local, algorithmFPType, method >::Distributed
Distributed(const Distributed< step1Local, algorithmFPType, method > &other)
Definition: multinomial_naive_bayes_training_distributed.h:430
daal::algorithms::multinomial_naive_bayes::training::interface2::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:465
daal::services::ErrorNullPartialResult
Definition: error_indexes.h:107
daal::algorithms::multinomial_naive_bayes::training::interface1::Distributed< step1Local, algorithmFPType, method >::Distributed
DAAL_DEPRECATED Distributed(const Distributed< step1Local, algorithmFPType, method > &other)
Definition: multinomial_naive_bayes_training_distributed.h:142
daal::algorithms::multinomial_naive_bayes::training::interface2::Distributed< step2Master, algorithmFPType, method >::clone
services::SharedPtr< Distributed< step2Master, algorithmFPType, method > > clone() const
Definition: multinomial_naive_bayes_training_distributed.h:568
daal::distributed
Definition: daal_defines.h:113
daal::algorithms::multinomial_naive_bayes::training::interface2::Distributed< step2Master, algorithmFPType, method >::setResult
services::Status setResult(const ResultPtr &result)
Definition: multinomial_naive_bayes_training_distributed.h:529
daal::algorithms::TrainingContainerIface
Abstract interface class that provides virtual methods to access and run implementations of the model...
Definition: training.h:52
daal::algorithms::multinomial_naive_bayes::training::interface2::Distributed< step2Master, algorithmFPType, method >::Distributed
Distributed(size_t nClasses)
Definition: multinomial_naive_bayes_training_distributed.h:480
daal::algorithms::multinomial_naive_bayes::training::interface1::Distributed< step2Master, algorithmFPType, method >::getMethod
virtual DAAL_DEPRECATED_VIRTUAL int getMethod() const DAAL_C11_OVERRIDE
Definition: multinomial_naive_bayes_training_distributed.h:215
daal::algorithms::multinomial_naive_bayes::training::interface2::Distributed< step2Master, algorithmFPType, method >::checkFinalizeComputeParams
services::Status checkFinalizeComputeParams() DAAL_C11_OVERRIDE
Definition: multinomial_naive_bayes_training_distributed.h:551

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