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

pca_distributed.h
1 /* file: pca_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 the PCA algorithm in the distributed
21 // processing mode
22 //--
23 */
24 
25 #ifndef __PCA_DISTRIBUTED_H__
26 #define __PCA_DISTRIBUTED_H__
27 
28 #include "algorithms/algorithm.h"
29 #include "data_management/data/numeric_table.h"
30 #include "services/daal_defines.h"
31 #include "services/daal_memory.h"
32 #include "algorithms/pca/pca_types.h"
33 #include "algorithms/pca/pca_online.h"
34 
35 namespace daal
36 {
37 namespace algorithms
38 {
39 namespace pca
40 {
41 
42 namespace interface1
43 {
53 template<ComputeStep computeStep, typename algorithmFPType, Method method, CpuType cpu>
54 class DistributedContainer
55 {};
56 
61 template<typename algorithmFPType, CpuType cpu>
62 class DistributedContainer<step1Local, algorithmFPType, correlationDense, cpu> : public
63  OnlineContainer<algorithmFPType, correlationDense, cpu>
64 {
65 public:
67  DistributedContainer(daal::services::Environment::env *daalEnv) : OnlineContainer<algorithmFPType, correlationDense, cpu>(daalEnv) {};
68  virtual ~DistributedContainer() {}
69 };
70 
75 template<typename algorithmFPType, CpuType cpu>
76 class DistributedContainer<step2Master, algorithmFPType, correlationDense, cpu> : public AnalysisContainerIface<distributed>
77 {
78 public:
84  DistributedContainer(daal::services::Environment::env *daalEnv);
86  virtual ~DistributedContainer();
87 
92  services::Status compute() DAAL_C11_OVERRIDE;
97  services::Status finalizeCompute() DAAL_C11_OVERRIDE;
98 };
99 
100 
105 template<typename algorithmFPType, CpuType cpu>
106 class DistributedContainer<step1Local, algorithmFPType, svdDense, cpu> : public OnlineContainer<algorithmFPType, svdDense, cpu>
107 {
108 public:
110  DistributedContainer(daal::services::Environment::env *daalEnv) : OnlineContainer<algorithmFPType, svdDense, cpu>(daalEnv) {};
111  virtual ~DistributedContainer() {}
112 };
113 
118 template<typename algorithmFPType, CpuType cpu>
119 class DistributedContainer<step2Master, algorithmFPType, svdDense, cpu> : public AnalysisContainerIface<distributed>
120 {
121 public:
127  DistributedContainer(daal::services::Environment::env *daalEnv);
129  ~DistributedContainer();
130 
135  services::Status compute() DAAL_C11_OVERRIDE;
140  services::Status finalizeCompute() DAAL_C11_OVERRIDE;
141 };
142 
157 template<ComputeStep computeStep, typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = correlationDense>
158 class DAAL_EXPORT Distributed : public Analysis<distributed> {};
159 
174 template<typename algorithmFPType, Method method>
175 class DAAL_EXPORT Distributed<step1Local, algorithmFPType, method> : public Online<algorithmFPType, method>
176 {
177 public:
178  typedef Online<algorithmFPType, method> super;
179 
180  typedef typename super::InputType InputType;
181  typedef typename super::ParameterType ParameterType;
182  typedef typename super::ResultType ResultType;
183  typedef typename super::PartialResultType PartialResultType;
184 
186  Distributed() : Online<algorithmFPType, method>() {}
187 
193  Distributed(const Distributed<step1Local, algorithmFPType, method> &other) :
194  Online<algorithmFPType, method>(other)
195  {}
196 
202  services::SharedPtr<Distributed<step1Local, algorithmFPType, method> > clone() const
203  {
204  return services::SharedPtr<Distributed<step1Local, algorithmFPType, method> >(cloneImpl());
205  }
206 
207 protected:
208  virtual Distributed<step1Local, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
209  {
210  return new Distributed<step1Local, algorithmFPType, method>(*this);
211  }
212 };
213 
221 template<typename algorithmFPType>
222 class DAAL_EXPORT Distributed<step2Master, algorithmFPType, correlationDense> : public Analysis<distributed>
223 {
224 public:
225  typedef algorithms::pca::DistributedInput<correlationDense> InputType;
226  typedef algorithms::pca::DistributedParameter<step2Master, algorithmFPType, correlationDense> ParameterType;
227  typedef algorithms::pca::Result ResultType;
228  typedef algorithms::pca::PartialResult<correlationDense> PartialResultType;
229 
231  Distributed()
232  {
233  initialize();
234  }
235 
241  Distributed(const Distributed<step2Master, algorithmFPType, correlationDense> &other) :
242  input(other.input), parameter(other.parameter)
243  {
244  initialize();
245  }
246 
247  ~Distributed() {}
248 
253  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)correlationDense; }
254 
259  services::Status setPartialResult(const services::SharedPtr<PartialResult<correlationDense> >& partialResult)
260  {
261  DAAL_CHECK(partialResult, services::ErrorNullPartialResult);
262  _partialResult = partialResult;
263  _pres = _partialResult.get();
264  return services::Status();
265  }
266 
271  services::SharedPtr<PartialResult<correlationDense> > getPartialResult()
272  {
273  _partialResult->set(sumCorrelation, parameter.covariance->getPartialResult()->get(covariance::sum));
274  _partialResult->set(nObservationsCorrelation, parameter.covariance->getPartialResult()->get(covariance::nObservations));
275  _partialResult->set(crossProductCorrelation, parameter.covariance->getPartialResult()->get(covariance::crossProduct));
276  return _partialResult;
277  }
278 
283  services::Status setResult(const ResultPtr& res)
284  {
285  DAAL_CHECK(res, services::ErrorNullResult)
286  _result = res;
287  _res = _result.get();
288  return services::Status();
289  }
290 
295  ResultPtr getResult()
296  {
297  return _result;
298  }
299 
305  services::SharedPtr<Distributed<step2Master, algorithmFPType, correlationDense> > clone() const
306  {
307  return services::SharedPtr<Distributed<step2Master, algorithmFPType, correlationDense> >(cloneImpl());
308  }
309 
310  DistributedInput<correlationDense> input;
311  DistributedParameter<step2Master, algorithmFPType, correlationDense> parameter;
313 protected:
314  services::SharedPtr<PartialResult<correlationDense> > _partialResult;
315  ResultPtr _result;
316 
317  virtual Distributed<step2Master, algorithmFPType, correlationDense> * cloneImpl() const DAAL_C11_OVERRIDE
318  {
319  return new Distributed<step2Master, algorithmFPType, correlationDense>(*this);
320  }
321 
322  services::Status allocateResult() DAAL_C11_OVERRIDE
323  {
324  services::Status s =_result->allocate<algorithmFPType>(_pres, &parameter, correlationDense);
325  _res = _result.get();
326  return s;
327  }
328 
329  services::Status allocatePartialResult() DAAL_C11_OVERRIDE
330  {
331  services::Status s = _partialResult->allocate<algorithmFPType>(&input, &parameter, correlationDense);
332  _pres = _partialResult.get();
333  return s;
334  }
335 
336  services::Status initializePartialResult() DAAL_C11_OVERRIDE { return services::Status(); }
337 
338  void initialize()
339  {
340  _ac = new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step2Master, algorithmFPType, correlationDense)(&_env);
341  _in = &input;
342  _par = &parameter;
343  _partialResult.reset(new PartialResult<correlationDense>());
344  _result.reset(new ResultType());
345  }
346 };
347 
355 template<typename algorithmFPType>
356 class DAAL_EXPORT Distributed<step2Master, algorithmFPType, svdDense> : public Analysis<distributed>
357 {
358 public:
359  typedef algorithms::pca::DistributedInput<svdDense> InputType;
360  typedef algorithms::pca::DistributedParameter<step2Master, algorithmFPType, svdDense> ParameterType;
361  typedef algorithms::pca::Result ResultType;
362  typedef algorithms::pca::PartialResult<svdDense> PartialResultType;
363 
365  Distributed()
366  {
367  initialize();
368  }
369 
375  Distributed(const Distributed<step2Master, algorithmFPType, svdDense> &other) :
376  input(other.input), parameter(other.parameter)
377  {
378  initialize();
379  }
380 
381  ~Distributed() {}
382 
387  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)svdDense; }
388 
393  services::Status setPartialResult(const services::SharedPtr<PartialResult<svdDense> >& partialResult)
394  {
395  DAAL_CHECK(partialResult, services::ErrorNullPartialResult);
396  _partialResult = partialResult;
397  _pres = _partialResult.get();
398  return services::Status();
399  }
400 
405  services::SharedPtr<PartialResult<svdDense> > getPartialResult()
406  {
407  return _partialResult;
408  }
409 
414  services::Status setResult(const ResultPtr& res)
415  {
416  DAAL_CHECK(res, services::ErrorNullResult)
417  _result = res;
418  _res = _result.get();
419  return services::Status();
420  }
421 
426  ResultPtr getResult()
427  {
428  return _result;
429  }
430 
436  services::SharedPtr<Distributed<step2Master, algorithmFPType, svdDense> > clone() const
437  {
438  return services::SharedPtr<Distributed<step2Master, algorithmFPType, svdDense> >(cloneImpl());
439  }
440 
441  DistributedInput<svdDense> input;
442  DistributedParameter<step2Master, algorithmFPType, svdDense> parameter;
444 protected:
445  services::SharedPtr<PartialResult<svdDense> > _partialResult;
446  ResultPtr _result;
447 
448  virtual Distributed<step2Master, algorithmFPType, svdDense> * cloneImpl() const DAAL_C11_OVERRIDE
449  {
450  return new Distributed<step2Master, algorithmFPType, svdDense>(*this);
451  }
452 
453  services::Status allocateResult() DAAL_C11_OVERRIDE
454  {
455  services::Status s = _result->allocate<algorithmFPType>(_pres, &parameter, svdDense);
456  _res = _result.get();
457  return s;
458  }
459 
460  services::Status allocatePartialResult() DAAL_C11_OVERRIDE
461  {
462  services::Status s = _partialResult->allocate<algorithmFPType>(&input, &parameter, svdDense);
463  _pres = _partialResult.get();
464  return s;
465  }
466  services::Status initializePartialResult() DAAL_C11_OVERRIDE{ return services::Status(); }
467 
468  void initialize()
469  {
470  _ac = new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step2Master, algorithmFPType, svdDense)(&_env);
471  _in = &input;
472  _par = &parameter;
473  _partialResult.reset(new PartialResult<svdDense>());
474  _result.reset(new ResultType());
475  }
476 };
478 } // namespace interface1
479 using interface1::DistributedContainer;
480 using interface1::Distributed;
481 
482 }
483 }
484 }
485 
486 #endif
daal::step1Local
Definition: daal_defines.h:123
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, svdDense >
Computes the result of the PCA SVD algorithm on local nodes.
Definition: pca_distributed.h:356
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, svdDense >::parameter
DistributedParameter< step2Master, algorithmFPType, svdDense > parameter
Definition: pca_distributed.h:442
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, svdDense >::Distributed
Distributed()
Definition: pca_distributed.h:365
daal::algorithms::pca::interface1::Distributed< step1Local, algorithmFPType, method >::Distributed
Distributed(const Distributed< step1Local, algorithmFPType, method > &other)
Definition: pca_distributed.h:193
daal::algorithms::pca::interface1::Distributed< step1Local, algorithmFPType, method >::clone
services::SharedPtr< Distributed< step1Local, algorithmFPType, method > > clone() const
Definition: pca_distributed.h:202
daal::algorithms::pca::correlationDense
Definition: pca_types.h:57
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, correlationDense >::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: pca_distributed.h:253
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, svdDense >::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: pca_distributed.h:387
daal::algorithms::pca::interface1::DistributedInput< svdDense >
Input objects of the PCA SVD algorithm in the distributed processing mode.
Definition: pca_types.h:602
daal::algorithms::pca::interface1::Distributed
Computes the result of the PCA algorithm.
Definition: pca_distributed.h:158
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:522
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, correlationDense >::Distributed
Distributed()
Definition: pca_distributed.h:231
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, svdDense >::Distributed
Distributed(const Distributed< step2Master, algorithmFPType, svdDense > &other)
Definition: pca_distributed.h:375
daal::algorithms::pca::interface1::DistributedContainer< step1Local, algorithmFPType, correlationDense, cpu >::DistributedContainer
DistributedContainer(daal::services::Environment::env *daalEnv)
Constructor.
Definition: pca_distributed.h:67
daal::step2Master
Definition: daal_defines.h:124
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, correlationDense >::setResult
services::Status setResult(const ResultPtr &res)
Definition: pca_distributed.h:283
daal::algorithms::pca::interface1::DistributedParameter< step2Master, algorithmFPType, svdDense >
daal::algorithms::covariance::nObservations
Definition: covariance_types.h:78
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, correlationDense >
Computes the result of the PCA Correlation algorithm on local nodes.
Definition: pca_distributed.h:222
daal::algorithms::pca::svdDense
Definition: pca_types.h:59
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, svdDense >::setResult
services::Status setResult(const ResultPtr &res)
Definition: pca_distributed.h:414
daal::algorithms::pca::interface1::Distributed< step1Local, algorithmFPType, method >
Computes the results of the PCA algorithm on the local nodes.
Definition: pca_distributed.h:175
daal::services::ErrorNullResult
Definition: error_indexes.h:98
daal::algorithms::AnalysisContainerIface
Abstract interface class that provides virtual methods to access and run implementations of the analy...
Definition: analysis.h:55
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, svdDense >::getResult
ResultPtr getResult()
Definition: pca_distributed.h:426
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_defines.h
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, correlationDense >::getResult
ResultPtr getResult()
Definition: pca_distributed.h:295
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, correlationDense >::parameter
DistributedParameter< step2Master, algorithmFPType, correlationDense > parameter
Definition: pca_distributed.h:311
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, svdDense >::setPartialResult
services::Status setPartialResult(const services::SharedPtr< PartialResult< svdDense > > &partialResult)
Definition: pca_distributed.h:393
daal::algorithms::pca::interface1::OnlineContainer
Class containing methods to compute the result of the PCA algorithm.
Definition: pca_online.h:52
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, correlationDense >::input
DistributedInput< correlationDense > input
Definition: pca_distributed.h:310
daal::algorithms::covariance::crossProduct
Definition: covariance_types.h:79
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:54
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:263
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, svdDense >::getPartialResult
services::SharedPtr< PartialResult< svdDense > > getPartialResult()
Definition: pca_distributed.h:405
daal::algorithms::pca::interface1::DistributedContainer< step1Local, algorithmFPType, svdDense, cpu >::DistributedContainer
DistributedContainer(daal::services::Environment::env *daalEnv)
Constructor.
Definition: pca_distributed.h:110
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, correlationDense >::setPartialResult
services::Status setPartialResult(const services::SharedPtr< PartialResult< correlationDense > > &partialResult)
Definition: pca_distributed.h:259
daal::algorithms::covariance::sum
Definition: covariance_types.h:80
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, svdDense >::clone
services::SharedPtr< Distributed< step2Master, algorithmFPType, svdDense > > clone() const
Definition: pca_distributed.h:436
daal::algorithms::pca::interface1::Online
Computes the results of the PCA algorithm.
Definition: pca_online.h:116
daal::algorithms::pca::interface1::DistributedInput< correlationDense >
Input objects for the PCA Correlation algorithm in the distributed processing mode.
Definition: pca_types.h:550
daal::algorithms::Analysis
Provides methods for execution of operations over data, such as computation of Summary Statistics est...
Definition: analysis.h:70
daal::services::ErrorNullPartialResult
Definition: error_indexes.h:107
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, correlationDense >::Distributed
Distributed(const Distributed< step2Master, algorithmFPType, correlationDense > &other)
Definition: pca_distributed.h:241
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, svdDense >::input
DistributedInput< svdDense > input
Definition: pca_distributed.h:441
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, correlationDense >::clone
services::SharedPtr< Distributed< step2Master, algorithmFPType, correlationDense > > clone() const
Definition: pca_distributed.h:305
daal::distributed
Definition: daal_defines.h:113
daal::algorithms::pca::interface1::Distributed< step1Local, algorithmFPType, method >::Distributed
Distributed()
Definition: pca_distributed.h:186
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, correlationDense >::getPartialResult
services::SharedPtr< PartialResult< correlationDense > > getPartialResult()
Definition: pca_distributed.h:271

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