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

multinomial_naive_bayes_training_distributed.h
1 /* file: multinomial_naive_bayes_training_distributed.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 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:
151  Distributed(size_t nClasses) : Online<algorithmFPType, method>::Online(nClasses) {}
152 
159  Distributed(const Distributed<step1Local, algorithmFPType, method> &other) :
160  Online<algorithmFPType, method>(other)
161  {}
162 
168  services::SharedPtr<Distributed<step1Local, algorithmFPType, method> > clone() const
169  {
170  return services::SharedPtr<Distributed<step1Local, algorithmFPType, method> >(cloneImpl());
171  }
172 
173 protected:
174  virtual Distributed<step1Local, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
175  {
176  return new Distributed<step1Local, algorithmFPType, method>(*this);
177  }
178 };
179 
193 template<typename algorithmFPType, Method method>
194 class DAAL_EXPORT Distributed<step2Master, algorithmFPType, method> : public Training<distributed>
195 {
196 public:
197  Parameter parameter;
198  DistributedInput input;
204  Distributed(size_t nClasses) : parameter(nClasses)
205  {
206  initialize();
207  }
208 
215  Distributed(const Distributed<step2Master, algorithmFPType, method> &other) :
216  Training<distributed>(other), input(other.input), parameter(other.parameter)
217  {
218  initialize();
219  }
220 
221  virtual ~Distributed() {}
222 
227  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)method; }
228 
233  services::Status setPartialResult(const PartialResultPtr& partialResult)
234  {
235  DAAL_CHECK(partialResult, services::ErrorNullPartialResult);
236  _partialResult = partialResult;
237  _pres = _partialResult.get();
238  return services::Status();
239  }
240 
245  PartialResultPtr getPartialResult() { return _partialResult; }
246 
253  services::Status setResult(const ResultPtr& result)
254  {
255  DAAL_CHECK(result, services::ErrorNullResult)
256  _result = result;
257  _res = _result.get();
258  return services::Status();
259  }
260 
265  ResultPtr getResult()
266  {
267  return Result::cast(_result);
268  }
269 
275  services::Status checkFinalizeComputeParams() DAAL_C11_OVERRIDE
276  {
277  PartialResultPtr partialResult = getPartialResult();
278  DAAL_CHECK(partialResult, services::ErrorNullResult);
279  services::Status s;
280  DAAL_CHECK_STATUS(s, partialResult->check(_par, method));
281  ResultPtr result = getResult();
282  DAAL_CHECK(result, services::ErrorNullResult);
283  DAAL_CHECK_STATUS(s, result->check(_pres, _par, method));
284  return s;
285  }
286 
292  services::SharedPtr<Distributed<step2Master, algorithmFPType, method> > clone() const
293  {
294  return services::SharedPtr<Distributed<step2Master, algorithmFPType, method> >(cloneImpl());
295  }
296 
297 protected:
298  PartialResultPtr _partialResult;
299  ResultPtr _result;
300 
301  virtual Distributed<step2Master, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
302  {
303  return new Distributed<step2Master, algorithmFPType, method>(*this);
304  }
305 
306  services::Status allocateResult() DAAL_C11_OVERRIDE
307  {
308  PartialResultPtr pres = getPartialResult();
309  ResultPtr res = getResult();
310  services::Status s = res->template allocate<algorithmFPType>(pres.get(), &parameter, (int)method);
311  _res = _result.get();
312  return s;
313  }
314 
315  services::Status allocatePartialResult() DAAL_C11_OVERRIDE
316  {
317  PartialResultPtr pres = getPartialResult();
318  services::Status s = pres->template allocate<algorithmFPType>((classifier::training::InputIface *)(&input), &parameter, (int)method);
319  _pres = _partialResult.get();
320  return s;
321  }
322 
323  services::Status initializePartialResult() DAAL_C11_OVERRIDE
324  {
325  return services::Status();
326  }
327 
328  void initialize()
329  {
330  _ac = new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step2Master, algorithmFPType, method)(&_env);
331  _in = &input;
332  _par = &parameter;
333  _result.reset(new Result());
334  _partialResult.reset(new PartialResult());
335  }
336 };
338 } // namespace interface1
339 using interface1::DistributedContainer;
340 using interface1::Distributed;
341 
342 } // namespace training
343 } // namespace multinomial_naive_bayes
344 } // namespace algorithms
345 } //namespace daal
346 #endif
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:253
daal
Definition: algorithm_base_common.h:57
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:168
daal::algorithms::multinomial_naive_bayes::training::interface1::Distributed< step2Master, algorithmFPType, method >::getPartialResult
PartialResultPtr getPartialResult()
Definition: multinomial_naive_bayes_training_distributed.h:245
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:233
daal::algorithms::multinomial_naive_bayes::training::interface1::Distributed< step2Master, algorithmFPType, method >::getResult
ResultPtr getResult()
Definition: multinomial_naive_bayes_training_distributed.h:265
daal::algorithms::multinomial_naive_bayes::training::interface1::Distributed< step1Local, algorithmFPType, method >::Distributed
Distributed(size_t nClasses)
Definition: multinomial_naive_bayes_training_distributed.h:151
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:227
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:132
daal::algorithms::multinomial_naive_bayes::training::interface1::Distributed< step2Master, algorithmFPType, method >::Distributed
Distributed(size_t nClasses)
Definition: multinomial_naive_bayes_training_distributed.h:204
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:194
daal::algorithms::multinomial_naive_bayes::training::interface1::Distributed< step2Master, algorithmFPType, method >::parameter
Parameter parameter
Definition: multinomial_naive_bayes_training_distributed.h:197
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:215
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 >::Distributed
Distributed(const Distributed< step1Local, algorithmFPType, method > &other)
Definition: multinomial_naive_bayes_training_distributed.h:159
daal::step1Local
Definition: daal_defines.h:142
daal::step2Master
Definition: daal_defines.h:143
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:292
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
DistributedInput input
Definition: multinomial_naive_bayes_training_distributed.h:198
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:275

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