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

pca_distributed.h
1 /* file: pca_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 the PCA algorithm in the distributed
45 // processing mode
46 //--
47 */
48 
49 #ifndef __PCA_DISTRIBUTED_H__
50 #define __PCA_DISTRIBUTED_H__
51 
52 #include "algorithms/algorithm.h"
53 #include "data_management/data/numeric_table.h"
54 #include "services/daal_defines.h"
55 #include "services/daal_memory.h"
56 #include "algorithms/pca/pca_types.h"
57 #include "algorithms/pca/pca_online.h"
58 
59 namespace daal
60 {
61 namespace algorithms
62 {
63 namespace pca
64 {
65 
66 namespace interface1
67 {
77 template<ComputeStep computeStep, typename algorithmFPType, Method method, CpuType cpu>
78 class DAAL_EXPORT DistributedContainer
79 {};
80 
85 template<typename algorithmFPType, CpuType cpu>
86 class DAAL_EXPORT DistributedContainer<step1Local, algorithmFPType, correlationDense, cpu> : public
87  OnlineContainer<algorithmFPType, correlationDense, cpu>
88 {
89 public:
91  DistributedContainer(daal::services::Environment::env *daalEnv) : OnlineContainer<algorithmFPType, correlationDense, cpu>(daalEnv) {};
92  virtual ~DistributedContainer() {}
93 };
94 
99 template<typename algorithmFPType, CpuType cpu>
100 class DAAL_EXPORT DistributedContainer<step2Master, algorithmFPType, correlationDense, cpu> : public AnalysisContainerIface<distributed>
101 {
102 public:
108  DistributedContainer(daal::services::Environment::env *daalEnv);
110  virtual ~DistributedContainer();
111 
116  services::Status compute() DAAL_C11_OVERRIDE;
121  services::Status finalizeCompute() DAAL_C11_OVERRIDE;
122 };
123 
124 
129 template<typename algorithmFPType, CpuType cpu>
130 class DAAL_EXPORT DistributedContainer<step1Local, algorithmFPType, svdDense, cpu> : public OnlineContainer<algorithmFPType, svdDense, cpu>
131 {
132 public:
134  DistributedContainer(daal::services::Environment::env *daalEnv) : OnlineContainer<algorithmFPType, svdDense, cpu>(daalEnv) {};
135  virtual ~DistributedContainer() {}
136 };
137 
142 template<typename algorithmFPType, CpuType cpu>
143 class DAAL_EXPORT DistributedContainer<step2Master, algorithmFPType, svdDense, cpu> : public AnalysisContainerIface<distributed>
144 {
145 public:
151  DistributedContainer(daal::services::Environment::env *daalEnv);
153  ~DistributedContainer();
154 
159  services::Status compute() DAAL_C11_OVERRIDE;
164  services::Status finalizeCompute() DAAL_C11_OVERRIDE;
165 };
166 
181 template<ComputeStep computeStep, typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = correlationDense>
182 class DAAL_EXPORT Distributed : public Analysis<distributed> {};
183 
198 template<typename algorithmFPType, Method method>
199 class DAAL_EXPORT Distributed<step1Local, algorithmFPType, method> : public Online<algorithmFPType, method>
200 {
201 public:
202  typedef Online<algorithmFPType, method> super;
203 
204  typedef typename super::InputType InputType;
205  typedef typename super::ParameterType ParameterType;
206  typedef typename super::ResultType ResultType;
207  typedef typename super::PartialResultType PartialResultType;
208 
210  Distributed() : Online<algorithmFPType, method>() {}
211 
217  Distributed(const Distributed<step1Local, algorithmFPType, method> &other) :
218  Online<algorithmFPType, method>(other)
219  {}
220 
226  services::SharedPtr<Distributed<step1Local, algorithmFPType, method> > clone() const
227  {
228  return services::SharedPtr<Distributed<step1Local, algorithmFPType, method> >(cloneImpl());
229  }
230 
231 protected:
232  virtual Distributed<step1Local, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
233  {
234  return new Distributed<step1Local, algorithmFPType, method>(*this);
235  }
236 };
237 
245 template<typename algorithmFPType>
246 class DAAL_EXPORT Distributed<step2Master, algorithmFPType, correlationDense> : public Analysis<distributed>
247 {
248 public:
249  typedef algorithms::pca::DistributedInput<correlationDense> InputType;
250  typedef algorithms::pca::DistributedParameter<step2Master, algorithmFPType, correlationDense> ParameterType;
251  typedef algorithms::pca::Result ResultType;
252  typedef algorithms::pca::PartialResult<correlationDense> PartialResultType;
253 
255  Distributed()
256  {
257  initialize();
258  }
259 
265  Distributed(const Distributed<step2Master, algorithmFPType, correlationDense> &other) :
266  input(other.input), parameter(other.parameter)
267  {
268  initialize();
269  }
270 
271  ~Distributed() {}
272 
277  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)correlationDense; }
278 
283  services::Status setPartialResult(const services::SharedPtr<PartialResult<correlationDense> >& partialResult)
284  {
285  DAAL_CHECK(partialResult, services::ErrorNullPartialResult);
286  _partialResult = partialResult;
287  _pres = _partialResult.get();
288  return services::Status();
289  }
290 
295  services::SharedPtr<PartialResult<correlationDense> > getPartialResult()
296  {
297  _partialResult->set(sumCorrelation, parameter.covariance->getPartialResult()->get(covariance::sum));
298  _partialResult->set(nObservationsCorrelation, parameter.covariance->getPartialResult()->get(covariance::nObservations));
299  _partialResult->set(crossProductCorrelation, parameter.covariance->getPartialResult()->get(covariance::crossProduct));
300  return _partialResult;
301  }
302 
307  services::Status setResult(const ResultPtr& res)
308  {
309  DAAL_CHECK(res, services::ErrorNullResult)
310  _result = res;
311  _res = _result.get();
312  return services::Status();
313  }
314 
319  ResultPtr getResult()
320  {
321  return _result;
322  }
323 
329  services::SharedPtr<Distributed<step2Master, algorithmFPType, correlationDense> > clone() const
330  {
331  return services::SharedPtr<Distributed<step2Master, algorithmFPType, correlationDense> >(cloneImpl());
332  }
333 
334  DistributedInput<correlationDense> input;
335  DistributedParameter<step2Master, algorithmFPType, correlationDense> parameter;
337 protected:
338  services::SharedPtr<PartialResult<correlationDense> > _partialResult;
339  ResultPtr _result;
340 
341  virtual Distributed<step2Master, algorithmFPType, correlationDense> * cloneImpl() const DAAL_C11_OVERRIDE
342  {
343  return new Distributed<step2Master, algorithmFPType, correlationDense>(*this);
344  }
345 
346  services::Status allocateResult() DAAL_C11_OVERRIDE
347  {
348  services::Status s =_result->allocate<algorithmFPType>(_pres, &parameter, correlationDense);
349  _res = _result.get();
350  return s;
351  }
352 
353  services::Status allocatePartialResult() DAAL_C11_OVERRIDE
354  {
355  services::Status s = _partialResult->allocate<algorithmFPType>(&input, &parameter, correlationDense);
356  _pres = _partialResult.get();
357  return s;
358  }
359 
360  services::Status initializePartialResult() DAAL_C11_OVERRIDE { return services::Status(); }
361 
362  void initialize()
363  {
364  _ac = new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step2Master, algorithmFPType, correlationDense)(&_env);
365  _in = &input;
366  _par = &parameter;
367  _partialResult.reset(new PartialResult<correlationDense>());
368  _result.reset(new ResultType());
369  }
370 };
371 
379 template<typename algorithmFPType>
380 class DAAL_EXPORT Distributed<step2Master, algorithmFPType, svdDense> : public Analysis<distributed>
381 {
382 public:
383  typedef algorithms::pca::DistributedInput<svdDense> InputType;
384  typedef algorithms::pca::DistributedParameter<step2Master, algorithmFPType, svdDense> ParameterType;
385  typedef algorithms::pca::Result ResultType;
386  typedef algorithms::pca::PartialResult<svdDense> PartialResultType;
387 
389  Distributed()
390  {
391  initialize();
392  }
393 
399  Distributed(const Distributed<step2Master, algorithmFPType, svdDense> &other) :
400  input(other.input), parameter(other.parameter)
401  {
402  initialize();
403  }
404 
405  ~Distributed() {}
406 
411  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)svdDense; }
412 
417  services::Status setPartialResult(const services::SharedPtr<PartialResult<svdDense> >& partialResult)
418  {
419  DAAL_CHECK(partialResult, services::ErrorNullPartialResult);
420  _partialResult = partialResult;
421  _pres = _partialResult.get();
422  return services::Status();
423  }
424 
429  services::SharedPtr<PartialResult<svdDense> > getPartialResult()
430  {
431  return _partialResult;
432  }
433 
438  services::Status setResult(const ResultPtr& res)
439  {
440  DAAL_CHECK(res, services::ErrorNullResult)
441  _result = res;
442  _res = _result.get();
443  return services::Status();
444  }
445 
450  ResultPtr getResult()
451  {
452  return _result;
453  }
454 
460  services::SharedPtr<Distributed<step2Master, algorithmFPType, svdDense> > clone() const
461  {
462  return services::SharedPtr<Distributed<step2Master, algorithmFPType, svdDense> >(cloneImpl());
463  }
464 
465  DistributedInput<svdDense> input;
466  DistributedParameter<step2Master, algorithmFPType, svdDense> parameter;
468 protected:
469  services::SharedPtr<PartialResult<svdDense> > _partialResult;
470  ResultPtr _result;
471 
472  virtual Distributed<step2Master, algorithmFPType, svdDense> * cloneImpl() const DAAL_C11_OVERRIDE
473  {
474  return new Distributed<step2Master, algorithmFPType, svdDense>(*this);
475  }
476 
477  services::Status allocateResult() DAAL_C11_OVERRIDE
478  {
479  services::Status s = _result->allocate<algorithmFPType>(_pres, &parameter, svdDense);
480  _res = _result.get();
481  return s;
482  }
483 
484  services::Status allocatePartialResult() DAAL_C11_OVERRIDE
485  {
486  services::Status s = _partialResult->allocate<algorithmFPType>(&input, &parameter, svdDense);
487  _pres = _partialResult.get();
488  return s;
489  }
490  services::Status initializePartialResult() DAAL_C11_OVERRIDE{ return services::Status(); }
491 
492  void initialize()
493  {
494  _ac = new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step2Master, algorithmFPType, svdDense)(&_env);
495  _in = &input;
496  _par = &parameter;
497  _partialResult.reset(new PartialResult<svdDense>());
498  _result.reset(new ResultType());
499  }
500 };
502 } // namespace interface1
503 using interface1::DistributedContainer;
504 using interface1::Distributed;
505 
506 }
507 }
508 }
509 
510 #endif
daal::algorithms::pca::interface1::DistributedParameter
Class that specifies the parameters of the PCA algorithm in the distributed computing mode...
Definition: pca_types.h:539
daal::algorithms::pca::interface1::Distributed< step1Local, algorithmFPType, method >
Computes the results of the PCA algorithm on the local nodes.
Definition: pca_distributed.h:199
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, correlationDense >::Distributed
Distributed()
Definition: pca_distributed.h:255
daal::algorithms::pca::interface1::DistributedInput
Input objects for the PCA algorithm in the distributed processing mode.
Definition: pca_types.h:568
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, svdDense >::input
DistributedInput< svdDense > input
Definition: pca_distributed.h:465
daal::algorithms::covariance::crossProduct
Definition: covariance_types.h:103
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, correlationDense >::Distributed
Distributed(const Distributed< step2Master, algorithmFPType, correlationDense > &other)
Definition: pca_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::pca::interface1::Online
Computes the results of the PCA algorithm.
Definition: pca_online.h:140
daal::algorithms::AnalysisContainerIface
Abstract interface class that provides virtual methods to access and run implementations of the analy...
Definition: analysis.h:79
daal::services::ErrorNullPartialResult
Definition: error_indexes.h:131
daal::algorithms::pca::interface1::OnlineContainer
Class containing methods to compute the result of the PCA algorithm.
Definition: pca_online.h:76
daal::algorithms::pca::interface1::DistributedInput< correlationDense >
Input objects for the PCA Correlation algorithm in the distributed processing mode.
Definition: pca_types.h:574
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, svdDense >::setResult
services::Status setResult(const ResultPtr &res)
Definition: pca_distributed.h:438
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:626
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, correlationDense >
Computes the result of the PCA Correlation algorithm on local nodes.
Definition: pca_distributed.h:246
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::pca::interface2::Result
Provides methods to access results obtained with the PCA algorithm.
Definition: pca_types.h:753
daal::algorithms::covariance::sum
Definition: covariance_types.h:104
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:287
daal::algorithms::pca::interface1::Distributed< step1Local, algorithmFPType, method >::clone
services::SharedPtr< Distributed< step1Local, algorithmFPType, method > > clone() const
Definition: pca_distributed.h:226
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, svdDense >::getPartialResult
services::SharedPtr< PartialResult< svdDense > > getPartialResult()
Definition: pca_distributed.h:429
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, svdDense >::clone
services::SharedPtr< Distributed< step2Master, algorithmFPType, svdDense > > clone() const
Definition: pca_distributed.h:460
daal::services::interface1::SharedPtr::get
T * get() const
Definition: daal_shared_ptr.h:332
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, correlationDense >::input
DistributedInput< correlationDense > input
Definition: pca_distributed.h:334
daal::algorithms::pca::svdDense
Definition: pca_types.h:83
daal::services::interface1::SharedPtr::reset
void reset()
Definition: daal_shared_ptr.h:265
daal::algorithms::pca::interface1::Distributed< step1Local, algorithmFPType, method >::Distributed
Distributed(const Distributed< step1Local, algorithmFPType, method > &other)
Definition: pca_distributed.h:217
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:78
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, svdDense >::Distributed
Distributed()
Definition: pca_distributed.h:389
daal::algorithms::pca::interface1::Distributed< step1Local, algorithmFPType, method >::Distributed
Distributed()
Definition: pca_distributed.h:210
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, svdDense >::Distributed
Distributed(const Distributed< step2Master, algorithmFPType, svdDense > &other)
Definition: pca_distributed.h:399
daal::algorithms::Analysis
Provides methods for execution of operations over data, such as computation of Summary Statistics est...
Definition: analysis.h:94
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, correlationDense >::parameter
DistributedParameter< step2Master, algorithmFPType, correlationDense > parameter
Definition: pca_distributed.h:335
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:81
daal::step1Local
Definition: daal_defines.h:143
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, svdDense >
Computes the result of the PCA SVD algorithm on local nodes.
Definition: pca_distributed.h:380
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, svdDense >::setPartialResult
services::Status setPartialResult(const services::SharedPtr< PartialResult< svdDense > > &partialResult)
Definition: pca_distributed.h:417
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, correlationDense >::setResult
services::Status setResult(const ResultPtr &res)
Definition: pca_distributed.h:307
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, correlationDense >::getPartialResult
services::SharedPtr< PartialResult< correlationDense > > getPartialResult()
Definition: pca_distributed.h:295
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, correlationDense >::setPartialResult
services::Status setPartialResult(const services::SharedPtr< PartialResult< correlationDense > > &partialResult)
Definition: pca_distributed.h:283
daal::step2Master
Definition: daal_defines.h:144
daal::algorithms::pca::interface1::DistributedContainer< step1Local, algorithmFPType, correlationDense, cpu >::DistributedContainer
DistributedContainer(daal::services::Environment::env *daalEnv)
Constructor.
Definition: pca_distributed.h:91
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, correlationDense >::clone
services::SharedPtr< Distributed< step2Master, algorithmFPType, correlationDense > > clone() const
Definition: pca_distributed.h:329
daal::algorithms::covariance::nObservations
Definition: covariance_types.h:102
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:546
daal::algorithms::pca::interface1::DistributedContainer< step1Local, algorithmFPType, svdDense, cpu >::DistributedContainer
DistributedContainer(daal::services::Environment::env *daalEnv)
Constructor.
Definition: pca_distributed.h:134
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, correlationDense >::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: pca_distributed.h:277
daal::services::ErrorNullResult
Definition: error_indexes.h:122
daal::algorithms::pca::interface1::Distributed
Computes the result of the PCA algorithm.
Definition: pca_distributed.h:182
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, svdDense >::parameter
DistributedParameter< step2Master, algorithmFPType, svdDense > parameter
Definition: pca_distributed.h:466
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, svdDense >::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: pca_distributed.h:411
daal::algorithms::pca::correlationDense
Definition: pca_types.h:81

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