C++ API Reference for Intel® Data Analytics Acceleration Library 2019 Update 5

pca_distributed.h
1 /* file: pca_distributed.h */
2 /*******************************************************************************
3 * Copyright 2014-2019 Intel Corporation.
4 *
5 * This software and the related documents are Intel copyrighted materials, and
6 * your use of them is governed by the express license under which they were
7 * provided to you (License). Unless the License provides otherwise, you may not
8 * use, modify, copy, publish, distribute, disclose or transmit this software or
9 * the related documents without Intel's prior written permission.
10 *
11 * This software and the related documents are provided as is, with no express
12 * or implied warranties, other than those that are expressly stated in the
13 * License.
14 *******************************************************************************/
15 
16 /*
17 //++
18 // Implementation of the interface for the PCA algorithm in the distributed
19 // processing mode
20 //--
21 */
22 
23 #ifndef __PCA_DISTRIBUTED_H__
24 #define __PCA_DISTRIBUTED_H__
25 
26 #include "algorithms/algorithm.h"
27 #include "data_management/data/numeric_table.h"
28 #include "services/daal_defines.h"
29 #include "services/daal_memory.h"
30 #include "algorithms/pca/pca_types.h"
31 #include "algorithms/pca/pca_online.h"
32 
33 namespace daal
34 {
35 namespace algorithms
36 {
37 namespace pca
38 {
39 
40 namespace interface1
41 {
51 template<ComputeStep computeStep, typename algorithmFPType, Method method, CpuType cpu>
52 class DAAL_EXPORT DistributedContainer
53 {};
54 
59 template<typename algorithmFPType, CpuType cpu>
60 class DAAL_EXPORT DistributedContainer<step1Local, algorithmFPType, correlationDense, cpu> : public
61  OnlineContainer<algorithmFPType, correlationDense, cpu>
62 {
63 public:
65  DistributedContainer(daal::services::Environment::env *daalEnv) : OnlineContainer<algorithmFPType, correlationDense, cpu>(daalEnv) {};
66  virtual ~DistributedContainer() {}
67 };
68 
73 template<typename algorithmFPType, CpuType cpu>
74 class DAAL_EXPORT DistributedContainer<step2Master, algorithmFPType, correlationDense, cpu> : public AnalysisContainerIface<distributed>
75 {
76 public:
82  DistributedContainer(daal::services::Environment::env *daalEnv);
84  virtual ~DistributedContainer();
85 
90  services::Status compute() DAAL_C11_OVERRIDE;
95  services::Status finalizeCompute() DAAL_C11_OVERRIDE;
96 };
97 
98 
103 template<typename algorithmFPType, CpuType cpu>
104 class DAAL_EXPORT DistributedContainer<step1Local, algorithmFPType, svdDense, cpu> : public OnlineContainer<algorithmFPType, svdDense, cpu>
105 {
106 public:
108  DistributedContainer(daal::services::Environment::env *daalEnv) : OnlineContainer<algorithmFPType, svdDense, cpu>(daalEnv) {};
109  virtual ~DistributedContainer() {}
110 };
111 
116 template<typename algorithmFPType, CpuType cpu>
117 class DAAL_EXPORT DistributedContainer<step2Master, algorithmFPType, svdDense, cpu> : public AnalysisContainerIface<distributed>
118 {
119 public:
125  DistributedContainer(daal::services::Environment::env *daalEnv);
127  ~DistributedContainer();
128 
133  services::Status compute() DAAL_C11_OVERRIDE;
138  services::Status finalizeCompute() DAAL_C11_OVERRIDE;
139 };
140 
155 template<ComputeStep computeStep, typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = correlationDense>
156 class DAAL_EXPORT Distributed : public Analysis<distributed> {};
157 
172 template<typename algorithmFPType, Method method>
173 class DAAL_EXPORT Distributed<step1Local, algorithmFPType, method> : public Online<algorithmFPType, method>
174 {
175 public:
176  typedef Online<algorithmFPType, method> super;
177 
178  typedef typename super::InputType InputType;
179  typedef typename super::ParameterType ParameterType;
180  typedef typename super::ResultType ResultType;
181  typedef typename super::PartialResultType PartialResultType;
182 
184  Distributed() : Online<algorithmFPType, method>() {}
185 
191  Distributed(const Distributed<step1Local, algorithmFPType, method> &other) :
192  Online<algorithmFPType, method>(other)
193  {}
194 
200  services::SharedPtr<Distributed<step1Local, algorithmFPType, method> > clone() const
201  {
202  return services::SharedPtr<Distributed<step1Local, algorithmFPType, method> >(cloneImpl());
203  }
204 
205 protected:
206  virtual Distributed<step1Local, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
207  {
208  return new Distributed<step1Local, algorithmFPType, method>(*this);
209  }
210 };
211 
219 template<typename algorithmFPType>
220 class DAAL_EXPORT Distributed<step2Master, algorithmFPType, correlationDense> : public Analysis<distributed>
221 {
222 public:
223  typedef algorithms::pca::DistributedInput<correlationDense> InputType;
224  typedef algorithms::pca::DistributedParameter<step2Master, algorithmFPType, correlationDense> ParameterType;
225  typedef algorithms::pca::Result ResultType;
226  typedef algorithms::pca::PartialResult<correlationDense> PartialResultType;
227 
229  Distributed()
230  {
231  initialize();
232  }
233 
239  Distributed(const Distributed<step2Master, algorithmFPType, correlationDense> &other) :
240  input(other.input), parameter(other.parameter)
241  {
242  initialize();
243  }
244 
245  ~Distributed() {}
246 
251  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)correlationDense; }
252 
257  services::Status setPartialResult(const services::SharedPtr<PartialResult<correlationDense> >& partialResult)
258  {
259  DAAL_CHECK(partialResult, services::ErrorNullPartialResult);
260  _partialResult = partialResult;
261  _pres = _partialResult.get();
262  return services::Status();
263  }
264 
269  services::SharedPtr<PartialResult<correlationDense> > getPartialResult()
270  {
271  _partialResult->set(sumCorrelation, parameter.covariance->getPartialResult()->get(covariance::sum));
272  _partialResult->set(nObservationsCorrelation, parameter.covariance->getPartialResult()->get(covariance::nObservations));
273  _partialResult->set(crossProductCorrelation, parameter.covariance->getPartialResult()->get(covariance::crossProduct));
274  return _partialResult;
275  }
276 
281  services::Status setResult(const ResultPtr& res)
282  {
283  DAAL_CHECK(res, services::ErrorNullResult)
284  _result = res;
285  _res = _result.get();
286  return services::Status();
287  }
288 
293  ResultPtr getResult()
294  {
295  return _result;
296  }
297 
303  services::SharedPtr<Distributed<step2Master, algorithmFPType, correlationDense> > clone() const
304  {
305  return services::SharedPtr<Distributed<step2Master, algorithmFPType, correlationDense> >(cloneImpl());
306  }
307 
308  DistributedInput<correlationDense> input;
309  DistributedParameter<step2Master, algorithmFPType, correlationDense> parameter;
311 protected:
312  services::SharedPtr<PartialResult<correlationDense> > _partialResult;
313  ResultPtr _result;
314 
315  virtual Distributed<step2Master, algorithmFPType, correlationDense> * cloneImpl() const DAAL_C11_OVERRIDE
316  {
317  return new Distributed<step2Master, algorithmFPType, correlationDense>(*this);
318  }
319 
320  services::Status allocateResult() DAAL_C11_OVERRIDE
321  {
322  services::Status s =_result->allocate<algorithmFPType>(_pres, &parameter, correlationDense);
323  _res = _result.get();
324  return s;
325  }
326 
327  services::Status allocatePartialResult() DAAL_C11_OVERRIDE
328  {
329  services::Status s = _partialResult->allocate<algorithmFPType>(&input, &parameter, correlationDense);
330  _pres = _partialResult.get();
331  return s;
332  }
333 
334  services::Status initializePartialResult() DAAL_C11_OVERRIDE { return services::Status(); }
335 
336  void initialize()
337  {
338  _ac = new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step2Master, algorithmFPType, correlationDense)(&_env);
339  _in = &input;
340  _par = &parameter;
341  _partialResult.reset(new PartialResult<correlationDense>());
342  _result.reset(new ResultType());
343  }
344 };
345 
353 template<typename algorithmFPType>
354 class DAAL_EXPORT Distributed<step2Master, algorithmFPType, svdDense> : public Analysis<distributed>
355 {
356 public:
357  typedef algorithms::pca::DistributedInput<svdDense> InputType;
358  typedef algorithms::pca::DistributedParameter<step2Master, algorithmFPType, svdDense> ParameterType;
359  typedef algorithms::pca::Result ResultType;
360  typedef algorithms::pca::PartialResult<svdDense> PartialResultType;
361 
363  Distributed()
364  {
365  initialize();
366  }
367 
373  Distributed(const Distributed<step2Master, algorithmFPType, svdDense> &other) :
374  input(other.input), parameter(other.parameter)
375  {
376  initialize();
377  }
378 
379  ~Distributed() {}
380 
385  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)svdDense; }
386 
391  services::Status setPartialResult(const services::SharedPtr<PartialResult<svdDense> >& partialResult)
392  {
393  DAAL_CHECK(partialResult, services::ErrorNullPartialResult);
394  _partialResult = partialResult;
395  _pres = _partialResult.get();
396  return services::Status();
397  }
398 
403  services::SharedPtr<PartialResult<svdDense> > getPartialResult()
404  {
405  return _partialResult;
406  }
407 
412  services::Status setResult(const ResultPtr& res)
413  {
414  DAAL_CHECK(res, services::ErrorNullResult)
415  _result = res;
416  _res = _result.get();
417  return services::Status();
418  }
419 
424  ResultPtr getResult()
425  {
426  return _result;
427  }
428 
434  services::SharedPtr<Distributed<step2Master, algorithmFPType, svdDense> > clone() const
435  {
436  return services::SharedPtr<Distributed<step2Master, algorithmFPType, svdDense> >(cloneImpl());
437  }
438 
439  DistributedInput<svdDense> input;
440  DistributedParameter<step2Master, algorithmFPType, svdDense> parameter;
442 protected:
443  services::SharedPtr<PartialResult<svdDense> > _partialResult;
444  ResultPtr _result;
445 
446  virtual Distributed<step2Master, algorithmFPType, svdDense> * cloneImpl() const DAAL_C11_OVERRIDE
447  {
448  return new Distributed<step2Master, algorithmFPType, svdDense>(*this);
449  }
450 
451  services::Status allocateResult() DAAL_C11_OVERRIDE
452  {
453  services::Status s = _result->allocate<algorithmFPType>(_pres, &parameter, svdDense);
454  _res = _result.get();
455  return s;
456  }
457 
458  services::Status allocatePartialResult() DAAL_C11_OVERRIDE
459  {
460  services::Status s = _partialResult->allocate<algorithmFPType>(&input, &parameter, svdDense);
461  _pres = _partialResult.get();
462  return s;
463  }
464  services::Status initializePartialResult() DAAL_C11_OVERRIDE{ return services::Status(); }
465 
466  void initialize()
467  {
468  _ac = new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step2Master, algorithmFPType, svdDense)(&_env);
469  _in = &input;
470  _par = &parameter;
471  _partialResult.reset(new PartialResult<svdDense>());
472  _result.reset(new ResultType());
473  }
474 };
476 } // namespace interface1
477 using interface1::DistributedContainer;
478 using interface1::Distributed;
479 
480 }
481 }
482 }
483 
484 #endif
daal::algorithms::pca::interface1::DistributedParameter< step2Master, algorithmFPType, svdDense >
daal::algorithms::pca::interface1::Distributed< step1Local, algorithmFPType, method >
Computes the results of the PCA algorithm on the local nodes.
Definition: pca_distributed.h:173
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, correlationDense >::Distributed
Distributed()
Definition: pca_distributed.h:229
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, svdDense >::input
DistributedInput< svdDense > input
Definition: pca_distributed.h:439
daal::algorithms::covariance::crossProduct
Definition: covariance_types.h:77
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, correlationDense >::Distributed
Distributed(const Distributed< step2Master, algorithmFPType, correlationDense > &other)
Definition: pca_distributed.h:239
daal
Definition: algorithm_base_common.h:31
daal::algorithms::pca::interface1::Online
Computes the results of the PCA algorithm.
Definition: pca_online.h:114
daal::algorithms::AnalysisContainerIface
Abstract interface class that provides virtual methods to access and run implementations of the analy...
Definition: analysis.h:53
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, svdDense >::getResult
ResultPtr getResult()
Definition: pca_distributed.h:424
daal::services::ErrorNullPartialResult
Definition: error_indexes.h:105
daal::algorithms::pca::interface1::OnlineContainer
Class containing methods to compute the result of the PCA algorithm.
Definition: pca_online.h:50
daal::algorithms::pca::interface1::DistributedInput< correlationDense >
Input objects for the PCA Correlation algorithm in the distributed processing mode.
Definition: pca_types.h:548
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, svdDense >::setResult
services::Status setResult(const ResultPtr &res)
Definition: pca_distributed.h:412
daal_defines.h
daal::algorithms::pca::interface1::DistributedInput< svdDense >
Input objects of the PCA SVD algorithm in the distributed processing mode.
Definition: pca_types.h:600
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, correlationDense >
Computes the result of the PCA Correlation algorithm on local nodes.
Definition: pca_distributed.h:220
daal::algorithms::kmeans::init::interface2::Distributed
class DAAL_EXPORT Distributed
Computes initial clusters for the K-Means algorithm in the distributed processing mode...
Definition: kmeans_init_distributed.h:275
daal::distributed
Definition: daal_defines.h:111
daal::algorithms::covariance::sum
Definition: covariance_types.h:78
daal::algorithms::pca::interface1::PartialResult
Provides methods to access partial results obtained with the compute() method of the PCA algorithm in...
Definition: pca_types.h:261
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, svdDense >::getPartialResult
services::SharedPtr< PartialResult< svdDense > > getPartialResult()
Definition: pca_distributed.h:403
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, correlationDense >::input
DistributedInput< correlationDense > input
Definition: pca_distributed.h:308
daal::algorithms::pca::svdDense
Definition: pca_types.h:57
daal::algorithms::pca::interface1::Distributed< step1Local, algorithmFPType, method >::Distributed
Distributed(const Distributed< step1Local, algorithmFPType, method > &other)
Definition: pca_distributed.h:191
daal::algorithms::pca::interface1::Distributed< step1Local, algorithmFPType, method >::clone
services::SharedPtr< Distributed< step1Local, algorithmFPType, method > > clone() const
Definition: pca_distributed.h:200
daal::algorithms::pca::interface1::DistributedContainer
Class containing methods to compute the results of the PCA algorithm in the distributed processing mo...
Definition: pca_distributed.h:52
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, svdDense >::Distributed
Distributed()
Definition: pca_distributed.h:363
daal::algorithms::pca::interface1::Distributed< step1Local, algorithmFPType, method >::Distributed
Distributed()
Definition: pca_distributed.h:184
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, svdDense >::Distributed
Distributed(const Distributed< step2Master, algorithmFPType, svdDense > &other)
Definition: pca_distributed.h:373
daal::algorithms::Analysis
Provides methods for execution of operations over data, such as computation of Summary Statistics est...
Definition: analysis.h:68
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, correlationDense >::parameter
DistributedParameter< step2Master, algorithmFPType, correlationDense > parameter
Definition: pca_distributed.h:309
daal::algorithms::kmeans::interface1::DistributedContainer
class DAAL_EXPORT DistributedContainer
Provides methods to run implementations of the K-Means algorithm. This class is associated with the d...
Definition: kmeans_distributed.h:55
daal::step1Local
Definition: daal_defines.h:121
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, svdDense >
Computes the result of the PCA SVD algorithm on local nodes.
Definition: pca_distributed.h:354
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, svdDense >::setPartialResult
services::Status setPartialResult(const services::SharedPtr< PartialResult< svdDense > > &partialResult)
Definition: pca_distributed.h:391
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, correlationDense >::setResult
services::Status setResult(const ResultPtr &res)
Definition: pca_distributed.h:281
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, correlationDense >::getPartialResult
services::SharedPtr< PartialResult< correlationDense > > getPartialResult()
Definition: pca_distributed.h:269
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, correlationDense >::setPartialResult
services::Status setPartialResult(const services::SharedPtr< PartialResult< correlationDense > > &partialResult)
Definition: pca_distributed.h:257
daal::step2Master
Definition: daal_defines.h:122
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, svdDense >::clone
services::SharedPtr< Distributed< step2Master, algorithmFPType, svdDense > > clone() const
Definition: pca_distributed.h:434
daal::algorithms::pca::interface1::DistributedContainer< step1Local, algorithmFPType, correlationDense, cpu >::DistributedContainer
DistributedContainer(daal::services::Environment::env *daalEnv)
Constructor.
Definition: pca_distributed.h:65
daal::algorithms::covariance::nObservations
Definition: covariance_types.h:76
daal::algorithms::pca::interface1::DistributedParameter< step2Master, algorithmFPType, correlationDense >
Class that specifies the parameters of the PCA Correlation algorithm in the distributed computing mod...
Definition: pca_types.h:520
daal::algorithms::pca::interface1::DistributedContainer< step1Local, algorithmFPType, svdDense, cpu >::DistributedContainer
DistributedContainer(daal::services::Environment::env *daalEnv)
Constructor.
Definition: pca_distributed.h:108
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, correlationDense >::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: pca_distributed.h:251
daal::services::ErrorNullResult
Definition: error_indexes.h:96
daal::algorithms::pca::interface1::Distributed
Computes the result of the PCA algorithm.
Definition: pca_distributed.h:156
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, svdDense >::parameter
DistributedParameter< step2Master, algorithmFPType, svdDense > parameter
Definition: pca_distributed.h:440
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, svdDense >::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: pca_distributed.h:385
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, correlationDense >::clone
services::SharedPtr< Distributed< step2Master, algorithmFPType, correlationDense > > clone() const
Definition: pca_distributed.h:303
daal::algorithms::pca::correlationDense
Definition: pca_types.h:55
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, correlationDense >::getResult
ResultPtr getResult()
Definition: pca_distributed.h:293

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