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

pca_distributed.h
1 /* file: pca_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 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:
203  Distributed() : Online<algorithmFPType, method>() {}
204 
210  Distributed(const Distributed<step1Local, algorithmFPType, method> &other) :
211  Online<algorithmFPType, method>(other)
212  {}
213 
219  services::SharedPtr<Distributed<step1Local, algorithmFPType, method> > clone() const
220  {
221  return services::SharedPtr<Distributed<step1Local, algorithmFPType, method> >(cloneImpl());
222  }
223 
224 protected:
225  virtual Distributed<step1Local, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
226  {
227  return new Distributed<step1Local, algorithmFPType, method>(*this);
228  }
229 };
230 
238 template<typename algorithmFPType>
239 class DAAL_EXPORT Distributed<step2Master, algorithmFPType, correlationDense> : public Analysis<distributed>
240 {
241 public:
243  Distributed()
244  {
245  initialize();
246  }
247 
253  Distributed(const Distributed<step2Master, algorithmFPType, correlationDense> &other) :
254  input(other.input), parameter(other.parameter)
255  {
256  initialize();
257  }
258 
259  ~Distributed() {}
260 
265  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)correlationDense; }
266 
271  services::Status setPartialResult(const services::SharedPtr<PartialResult<correlationDense> >& partialResult)
272  {
273  DAAL_CHECK(partialResult, services::ErrorNullPartialResult);
274  _partialResult = partialResult;
275  _pres = _partialResult.get();
276  return services::Status();
277  }
278 
283  services::SharedPtr<PartialResult<correlationDense> > getPartialResult()
284  {
285  _partialResult->set(sumCorrelation, parameter.covariance->getPartialResult()->get(covariance::sum));
286  _partialResult->set(nObservationsCorrelation, parameter.covariance->getPartialResult()->get(covariance::nObservations));
287  _partialResult->set(crossProductCorrelation, parameter.covariance->getPartialResult()->get(covariance::crossProduct));
288  return _partialResult;
289  }
290 
295  services::Status setResult(const ResultPtr& res)
296  {
297  DAAL_CHECK(res, services::ErrorNullResult)
298  _result = res;
299  _res = _result.get();
300  return services::Status();
301  }
302 
307  ResultPtr getResult()
308  {
309  return _result;
310  }
311 
317  services::SharedPtr<Distributed<step2Master, algorithmFPType, correlationDense> > clone() const
318  {
319  return services::SharedPtr<Distributed<step2Master, algorithmFPType, correlationDense> >(cloneImpl());
320  }
321 
322  DistributedInput<correlationDense> input;
323  DistributedParameter<step2Master, algorithmFPType, correlationDense> parameter;
325 protected:
326  services::SharedPtr<PartialResult<correlationDense> > _partialResult;
327  ResultPtr _result;
328 
329  virtual Distributed<step2Master, algorithmFPType, correlationDense> * cloneImpl() const DAAL_C11_OVERRIDE
330  {
331  return new Distributed<step2Master, algorithmFPType, correlationDense>(*this);
332  }
333 
334  services::Status allocateResult() DAAL_C11_OVERRIDE
335  {
336  services::Status s =_result->allocate<algorithmFPType>(_pres, &parameter, correlationDense);
337  _res = _result.get();
338  return s;
339  }
340 
341  services::Status allocatePartialResult() DAAL_C11_OVERRIDE
342  {
343  services::Status s = _partialResult->allocate<algorithmFPType>(&input, &parameter, correlationDense);
344  _pres = _partialResult.get();
345  return s;
346  }
347 
348  services::Status initializePartialResult() DAAL_C11_OVERRIDE { return services::Status(); }
349 
350  void initialize()
351  {
352  _ac = new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step2Master, algorithmFPType, correlationDense)(&_env);
353  _in = &input;
354  _par = &parameter;
355  _partialResult.reset(new PartialResult<correlationDense>());
356  _result.reset(new Result());
357  }
358 };
359 
367 template<typename algorithmFPType>
368 class DAAL_EXPORT Distributed<step2Master, algorithmFPType, svdDense> : public Analysis<distributed>
369 {
370 public:
372  Distributed()
373  {
374  initialize();
375  }
376 
382  Distributed(const Distributed<step2Master, algorithmFPType, svdDense> &other) :
383  input(other.input), parameter(other.parameter)
384  {
385  initialize();
386  }
387 
388  ~Distributed() {}
389 
394  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)svdDense; }
395 
400  services::Status setPartialResult(const services::SharedPtr<PartialResult<svdDense> >& partialResult)
401  {
402  DAAL_CHECK(partialResult, services::ErrorNullPartialResult);
403  _partialResult = partialResult;
404  _pres = _partialResult.get();
405  return services::Status();
406  }
407 
412  services::SharedPtr<PartialResult<svdDense> > getPartialResult()
413  {
414  return _partialResult;
415  }
416 
421  services::Status setResult(const ResultPtr& res)
422  {
423  DAAL_CHECK(res, services::ErrorNullResult)
424  _result = res;
425  _res = _result.get();
426  return services::Status();
427  }
428 
433  ResultPtr getResult()
434  {
435  return _result;
436  }
437 
443  services::SharedPtr<Distributed<step2Master, algorithmFPType, svdDense> > clone() const
444  {
445  return services::SharedPtr<Distributed<step2Master, algorithmFPType, svdDense> >(cloneImpl());
446  }
447 
448  DistributedInput<svdDense> input;
449  DistributedParameter<step2Master, algorithmFPType, svdDense> parameter;
451 protected:
452  services::SharedPtr<PartialResult<svdDense> > _partialResult;
453  ResultPtr _result;
454 
455  virtual Distributed<step2Master, algorithmFPType, svdDense> * cloneImpl() const DAAL_C11_OVERRIDE
456  {
457  return new Distributed<step2Master, algorithmFPType, svdDense>(*this);
458  }
459 
460  services::Status allocateResult() DAAL_C11_OVERRIDE
461  {
462  services::Status s = _result->allocate<algorithmFPType>(_pres, &parameter, svdDense);
463  _res = _result.get();
464  return s;
465  }
466 
467  services::Status allocatePartialResult() DAAL_C11_OVERRIDE
468  {
469  services::Status s = _partialResult->allocate<algorithmFPType>(&input, &parameter, svdDense);
470  _pres = _partialResult.get();
471  return s;
472  }
473  services::Status initializePartialResult() DAAL_C11_OVERRIDE{ return services::Status(); }
474 
475  void initialize()
476  {
477  _ac = new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step2Master, algorithmFPType, svdDense)(&_env);
478  _in = &input;
479  _par = &parameter;
480  _partialResult.reset(new PartialResult<svdDense>());
481  _result.reset(new Result());
482  }
483 };
485 } // namespace interface1
486 using interface1::DistributedContainer;
487 using interface1::Distributed;
488 
489 }
490 }
491 }
492 
493 #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:199
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, correlationDense >::Distributed
Distributed()
Definition: pca_distributed.h:243
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, svdDense >::input
DistributedInput< svdDense > input
Definition: pca_distributed.h:448
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:253
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::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, svdDense >::getResult
ResultPtr getResult()
Definition: pca_distributed.h:433
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:421
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:239
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::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< step2Master, algorithmFPType, svdDense >::getPartialResult
services::SharedPtr< PartialResult< svdDense > > getPartialResult()
Definition: pca_distributed.h:412
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, correlationDense >::input
DistributedInput< correlationDense > input
Definition: pca_distributed.h:322
daal::algorithms::pca::svdDense
Definition: pca_types.h:83
daal::algorithms::pca::interface1::Distributed< step1Local, algorithmFPType, method >::Distributed
Distributed(const Distributed< step1Local, algorithmFPType, method > &other)
Definition: pca_distributed.h:210
daal::algorithms::pca::interface1::Distributed< step1Local, algorithmFPType, method >::clone
services::SharedPtr< Distributed< step1Local, algorithmFPType, method > > clone() const
Definition: pca_distributed.h:219
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:372
daal::algorithms::pca::interface1::Distributed< step1Local, algorithmFPType, method >::Distributed
Distributed()
Definition: pca_distributed.h:203
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, svdDense >::Distributed
Distributed(const Distributed< step2Master, algorithmFPType, svdDense > &other)
Definition: pca_distributed.h:382
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:323
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:142
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, svdDense >
Computes the result of the PCA SVD algorithm on local nodes.
Definition: pca_distributed.h:368
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, svdDense >::setPartialResult
services::Status setPartialResult(const services::SharedPtr< PartialResult< svdDense > > &partialResult)
Definition: pca_distributed.h:400
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, correlationDense >::setResult
services::Status setResult(const ResultPtr &res)
Definition: pca_distributed.h:295
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, correlationDense >::getPartialResult
services::SharedPtr< PartialResult< correlationDense > > getPartialResult()
Definition: pca_distributed.h:283
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, correlationDense >::setPartialResult
services::Status setPartialResult(const services::SharedPtr< PartialResult< correlationDense > > &partialResult)
Definition: pca_distributed.h:271
daal::step2Master
Definition: daal_defines.h:143
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, svdDense >::clone
services::SharedPtr< Distributed< step2Master, algorithmFPType, svdDense > > clone() const
Definition: pca_distributed.h:443
daal::algorithms::pca::interface1::DistributedContainer< step1Local, algorithmFPType, correlationDense, cpu >::DistributedContainer
DistributedContainer(daal::services::Environment::env *daalEnv)
Constructor.
Definition: pca_distributed.h:91
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:265
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:449
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, svdDense >::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: pca_distributed.h:394
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, correlationDense >::clone
services::SharedPtr< Distributed< step2Master, algorithmFPType, correlationDense > > clone() const
Definition: pca_distributed.h:317
daal::algorithms::pca::correlationDense
Definition: pca_types.h:81
daal::algorithms::pca::interface1::Distributed< step2Master, algorithmFPType, correlationDense >::getResult
ResultPtr getResult()
Definition: pca_distributed.h:307

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