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

pca_types.h
1 /* file: pca_types.h */
2 /*******************************************************************************
3 * Copyright 2014-2018 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 PCA algorithm interface.
19 //--
20 */
21 
22 #ifndef __PCA_TYPES_H__
23 #define __PCA_TYPES_H__
24 
25 #include "algorithms/algorithm.h"
26 #include "data_management/data/numeric_table.h"
27 #include "data_management/data/homogen_numeric_table.h"
28 #include "services/daal_defines.h"
29 #include "algorithms/covariance/covariance_batch.h"
30 #include "algorithms/covariance/covariance_online.h"
31 #include "algorithms/covariance/covariance_distributed.h"
32 #include "algorithms/normalization/zscore.h"
33 
34 namespace daal
35 {
36 namespace algorithms
37 {
47 namespace pca
48 {
53 enum Method
54 {
55  correlationDense = 0,
56  defaultDense = 0,
57  svdDense = 1
58 };
59 
64 enum InputDatasetId
65 {
66  data,
67  lastInputDatasetId = data
68 };
69 
74 enum InputCorrelationId
75 {
76  correlation,
77  lastInputCorrelationId = correlation
78 };
79 
84 enum Step2MasterInputId
85 {
86  partialResults,
87  lastStep2MasterInputId = partialResults
88 };
89 
94 enum PartialCorrelationResultId
95 {
96  nObservationsCorrelation, /* Number of processed observations */
97  crossProductCorrelation, /* Cross-product of the processed data */
98  sumCorrelation, /* Feature sums of the processed data */
99  lastPartialCorrelationResultId = sumCorrelation
100 };
101 
106 enum PartialSVDTableResultId
107 {
108  nObservationsSVD, /* Number of processed observations */
109  sumSVD, /* Feature sums of the processed data */
110  sumSquaresSVD, /* Feature sums of squares of the processed data */
111  lastPartialSVDTableResultId = sumSquaresSVD
112 };
113 
118 enum PartialSVDCollectionResultId
119 {
120  auxiliaryData = lastPartialSVDTableResultId + 1,
121  distributedInputs,
122  lastPartialSVDCollectionResultId = distributedInputs
123 };
124 
129 enum ResultId
130 {
131  eigenvalues,
132  eigenvectors,
133  means,
134  variances,
135  lastResultId = variances
136 };
137 
142 enum ResultCollectionId
143 {
144  dataForTransform
145 };
146 
152 enum ResultToComputeId
153 {
154  none = 0ULL,
155  mean = 0x00000001ULL,
156  variance = 0x00000002ULL,
157  eigenvalue = 0x00000004ULL
158 };
159 
163 namespace interface1
164 {
168 class DAAL_EXPORT InputIface : public daal::algorithms::Input
169 {
170 public:
171  InputIface(size_t nElements);
172  InputIface(const InputIface& other);
173 
178  virtual size_t getNFeatures() const = 0;
179 
184  virtual bool isCorrelation() const { return _isCorrelation; };
185 
186  virtual ~InputIface() {};
187 
188 protected:
189  bool _isCorrelation;
190 };
191 
196 class DAAL_EXPORT Input : public InputIface
197 {
198 public:
199  Input();
200  Input(const Input& other);
201 
202  virtual ~Input() {};
203 
209  data_management::NumericTablePtr get(InputDatasetId id) const;
210 
216  void set(InputDatasetId id, const data_management::NumericTablePtr &value);
217 
223  void set(InputCorrelationId id, const data_management::NumericTablePtr &value);
224 
229  size_t getNFeatures() const DAAL_C11_OVERRIDE;
230 
237  services::Status check(const daal::algorithms::Parameter *par, int method) const DAAL_C11_OVERRIDE;
238 };
239 
245 class PartialResultBase : public daal::algorithms::PartialResult
246 {
247 public:
248  PartialResultBase(const size_t nElements) : daal::algorithms::PartialResult(nElements) {};
249 
250  virtual size_t getNFeatures() const = 0;
251 
252  virtual ~PartialResultBase() {};
253 };
254 
260 template<Method method>
261 class PartialResult : public PartialResultBase {};
262 
268 template<> class DAAL_EXPORT PartialResult<daal::algorithms::pca::correlationDense> : public PartialResultBase
269 {
270 public:
271  DECLARE_SERIALIZABLE_CAST(PartialResult<daal::algorithms::pca::correlationDense>);
272  PartialResult();
273 
279  data_management::NumericTablePtr get(PartialCorrelationResultId id) const;
280 
281  virtual size_t getNFeatures() const DAAL_C11_OVERRIDE;
282 
288  void set(const PartialCorrelationResultId id, const data_management::NumericTablePtr &value);
289 
290  virtual ~PartialResult() {};
291 
299  services::Status check(const daal::algorithms::Input *input, const daal::algorithms::Parameter *parameter, int method) const DAAL_C11_OVERRIDE;
300 
301 
308  services::Status check(const daal::algorithms::Parameter *par, int method) const DAAL_C11_OVERRIDE;
309 
317  template <typename algorithmFPType>
318  DAAL_EXPORT services::Status allocate(const daal::algorithms::Input *input, const daal::algorithms::Parameter *parameter, const int method);
319 
327  template <typename algorithmFPType>
328  DAAL_EXPORT services::Status initialize(const daal::algorithms::Input *input, const daal::algorithms::Parameter *parameter, const int method);
329 protected:
330 
331  services::Status checkImpl(size_t nFeatures) const;
332 
334  template<typename Archive, bool onDeserialize>
335  services::Status serialImpl(Archive *arch)
336  {
337  return daal::algorithms::PartialResult::serialImpl<Archive, onDeserialize>(arch);
338  }
339 };
340 
346 template<> class DAAL_EXPORT PartialResult<daal::algorithms::pca::svdDense> : public PartialResultBase
347 {
348 public:
349  DECLARE_SERIALIZABLE_CAST(PartialResult<daal::algorithms::pca::svdDense>);
350  PartialResult();
351 
357  data_management::NumericTablePtr get(PartialSVDTableResultId id) const;
358 
359  virtual size_t getNFeatures() const DAAL_C11_OVERRIDE;
360 
366  data_management::DataCollectionPtr get(PartialSVDCollectionResultId id) const;
367 
374  data_management::NumericTablePtr get(PartialSVDCollectionResultId id, const size_t &elementId) const;
375 
381  void set(PartialSVDTableResultId id, const data_management::NumericTablePtr &value);
382 
388  void set(PartialSVDCollectionResultId id, const data_management::DataCollectionPtr &value);
389 
395  void add(const PartialSVDCollectionResultId &id, const data_management::DataCollectionPtr &value);
396 
404  services::Status check(const daal::algorithms::Input *input, const daal::algorithms::Parameter *parameter, int method) const DAAL_C11_OVERRIDE;
405 
412  services::Status check(const daal::algorithms::Parameter *par, int method) const DAAL_C11_OVERRIDE;
413 
414  virtual ~PartialResult() {};
415 
423  template <typename algorithmFPType>
424  DAAL_EXPORT services::Status allocate(const daal::algorithms::Input *input, const daal::algorithms::Parameter *parameter, const int method);
425 
433  template <typename algorithmFPType>
434  DAAL_EXPORT services::Status initialize(const daal::algorithms::Input *input, const daal::algorithms::Parameter *parameter, const int method);
435 
436 protected:
437 
438  services::Status checkImpl(size_t nFeatures) const;
439 
441  template<typename Archive, bool onDeserialize>
442  services::Status serialImpl(Archive *arch)
443  {
444  return daal::algorithms::PartialResult::serialImpl<Archive, onDeserialize>(arch);
445  }
446 };
447 
452 template<typename algorithmFPType, Method method = correlationDense>
453 class DAAL_EXPORT BaseParameter : public daal::algorithms::Parameter
454 {
455 public:
457  BaseParameter();
458 };
459 
464 template<typename algorithmFPType, Method method>
465 class OnlineParameter : public BaseParameter<algorithmFPType, method> {};
466 
471 template<typename algorithmFPType>
472 class DAAL_EXPORT OnlineParameter<algorithmFPType, correlationDense> : public BaseParameter<algorithmFPType, correlationDense>
473 {
474 public:
476  OnlineParameter(const services::SharedPtr<covariance::OnlineImpl> &covarianceForOnlineParameter =
477  services::SharedPtr<covariance::Online<algorithmFPType, covariance::defaultDense> >
478  (new covariance::Online<algorithmFPType, covariance::defaultDense>()));
479 
480  services::SharedPtr<covariance::OnlineImpl> covariance;
486  services::Status check() const DAAL_C11_OVERRIDE;
487 };
488 
489 
494 template<typename algorithmFPType>
495 class DAAL_EXPORT OnlineParameter<algorithmFPType, svdDense> : public BaseParameter<algorithmFPType, svdDense>
496 {
497 public:
499  OnlineParameter();
500 
505  services::Status check() const DAAL_C11_OVERRIDE;
506 };
507 
512 template<ComputeStep step, typename algorithmFPType, Method method>
513 class DistributedParameter : public BaseParameter<algorithmFPType, method> {};
514 
519 template<typename algorithmFPType>
520 class DAAL_EXPORT DistributedParameter<step2Master, algorithmFPType, correlationDense> : public BaseParameter<algorithmFPType, correlationDense>
521 {
522 public:
524  DistributedParameter(const services::SharedPtr<covariance::DistributedIface<step2Master> > &covarianceForDistributedParameter =
525  services::SharedPtr<covariance::Distributed<step2Master, algorithmFPType, covariance::defaultDense> >
526  (new covariance::Distributed<step2Master, algorithmFPType, covariance::defaultDense>()));
527 
528  services::SharedPtr<covariance::DistributedIface<step2Master> > covariance;
534  services::Status check() const DAAL_C11_OVERRIDE;
535 };
536 
541 template<Method method>
542 class DistributedInput {};
543 
548 template<> class DAAL_EXPORT DistributedInput<correlationDense> : public InputIface
549 {
550 public:
551  DistributedInput();
552  DistributedInput(const DistributedInput& other);
553 
559  void set(Step2MasterInputId id, const data_management::DataCollectionPtr &ptr);
560 
566  data_management::DataCollectionPtr get(Step2MasterInputId id) const;
567 
572  services::SharedPtr<PartialResult<correlationDense> > getPartialResult(size_t id) const;
573 
579  void add(Step2MasterInputId id, const services::SharedPtr<PartialResult<correlationDense> > &value);
580 
585  size_t getNFeatures() const DAAL_C11_OVERRIDE;
586 
593  services::Status check(const daal::algorithms::Parameter *parameter, int method) const DAAL_C11_OVERRIDE;
594 };
595 
600 template<> class DAAL_EXPORT DistributedInput<svdDense> : public InputIface
601 {
602 public:
603  DistributedInput();
604  DistributedInput(const DistributedInput& other);
605 
611  void set(Step2MasterInputId id, const data_management::DataCollectionPtr &ptr);
612 
618  data_management::DataCollectionPtr get(Step2MasterInputId id) const;
619 
625  void add(Step2MasterInputId id, const services::SharedPtr<PartialResult<svdDense> > &value);
626 
631  services::SharedPtr<PartialResult<svdDense> > getPartialResult(size_t id) const;
632 
639  services::Status check(const daal::algorithms::Parameter *parameter, int method) const DAAL_C11_OVERRIDE;
640 
645  size_t getNFeatures() const DAAL_C11_OVERRIDE;
646 };
647 
648 } // namespace interface1
649 
650 namespace interface2
651 {
656 class DAAL_EXPORT BaseBatchParameter : public daal::algorithms::Parameter
657 {
658 public:
660  BaseBatchParameter();
661 
662  DAAL_UINT64 resultsToCompute;
663  size_t nComponents;
664  bool isDeterministic;
665 };
666 
667 
672 template<typename algorithmFPType, Method method>
673 class BatchParameter {};
674 
675 
680 template<typename algorithmFPType>
681 class DAAL_EXPORT BatchParameter<algorithmFPType, correlationDense> : public BaseBatchParameter
682 {
683 public:
685  BatchParameter(const services::SharedPtr<covariance::BatchImpl> &covarianceForBatchParameter =
686  services::SharedPtr<covariance::Batch<algorithmFPType, covariance::defaultDense> >
687  (new covariance::Batch<algorithmFPType, covariance::defaultDense>()));
688 
689  services::SharedPtr<covariance::BatchImpl> covariance;
696  services::Status check() const DAAL_C11_OVERRIDE;
697 };
698 
703 template<typename algorithmFPType>
704 class DAAL_EXPORT BatchParameter<algorithmFPType, svdDense> : public BaseBatchParameter
705 {
706 public:
708  BatchParameter(const services::SharedPtr<normalization::zscore::BatchImpl> &normalizationForBatchParameter =
709  services::SharedPtr<normalization::zscore::Batch<algorithmFPType, normalization::zscore::defaultDense> >
710  (new normalization::zscore::Batch<algorithmFPType, normalization::zscore::defaultDense>()));
711 
712  services::SharedPtr<normalization::zscore::BatchImpl> normalization;
719  services::Status check() const DAAL_C11_OVERRIDE;
720 };
721 
722 
727 class DAAL_EXPORT Result : public daal::algorithms::Result
728 {
729 public:
730  DECLARE_SERIALIZABLE_CAST(Result);
731  Result(const Result& o);
732  Result();
733 
734  virtual ~Result() {};
735 
741  data_management::NumericTablePtr get(ResultId id) const;
742 
748  data_management::KeyValueDataCollectionPtr get(ResultCollectionId id) const;
749 
756  void set(ResultCollectionId id, data_management::KeyValueDataCollectionPtr& collection);
757 
758 
764  void set(ResultId id, const data_management::NumericTablePtr &value);
765 
772  template<typename algorithmFPType>
773  DAAL_EXPORT services::Status allocate(const daal::algorithms::Input *input, daal::algorithms::Parameter *parameter, const Method method);
774 
780  template<typename algorithmFPType>
781  DAAL_EXPORT services::Status allocate(const daal::algorithms::PartialResult *partialResult, daal::algorithms::Parameter *parameter, const Method method);
782 
790  services::Status check(const daal::algorithms::Input *_input, const daal::algorithms::Parameter *par, int method) const DAAL_C11_OVERRIDE;
791 
799  services::Status check(const daal::algorithms::PartialResult *pr, const daal::algorithms::Parameter *parameter, int method) const DAAL_C11_OVERRIDE;
800 
801 protected:
802 
811  services::Status checkImpl(size_t nFeatures, size_t nComponents, DAAL_UINT64 resultsToCompute) const;
812 
814  template<typename Archive, bool onDeserialize>
815  services::Status serialImpl(Archive *arch)
816  {
817  return daal::algorithms::Result::serialImpl<Archive, onDeserialize>(arch);
818  }
819 };
820 typedef services::SharedPtr<Result> ResultPtr;
821 
823 } // namespace interface1
824 using interface1::InputIface;
825 using interface1::Input;
826 using interface1::PartialResultBase;
827 using interface1::PartialResult;
828 using interface2::BatchParameter;
829 using interface2::BaseBatchParameter;
830 using interface1::OnlineParameter;
831 using interface1::DistributedParameter;
832 using interface1::DistributedInput;
833 using interface2::Result;
834 using interface2::ResultPtr;
835 
836 } // pca
837 } // algorithm
838 } // namespace daal
839 #endif
daal::algorithms::pca::defaultDense
Definition: pca_types.h:56
daal::algorithms::pca::interface1::DistributedParameter
Class that specifies the parameters of the PCA algorithm in the distributed computing mode...
Definition: pca_types.h:513
daal::algorithms::pca::data
Definition: pca_types.h:66
daal::algorithms::pca::PartialCorrelationResultId
PartialCorrelationResultId
Definition: pca_types.h:94
daal::algorithms::pca::interface1::DistributedInput
Input objects for the PCA algorithm in the distributed processing mode.
Definition: pca_types.h:542
daal::algorithms::pca::dataForTransform
Definition: pca_types.h:144
daal::algorithms::pca::auxiliaryData
Definition: pca_types.h:120
daal
Definition: algorithm_base_common.h:31
daal::algorithms::pca::interface1::BaseParameter
Class that specifies the common parameters of the PCA algorithm.
Definition: pca_types.h:453
daal::algorithms::pca::interface1::PartialResultBase
Provides interface to access partial results obtained with the compute() method of the PCA algorithm ...
Definition: pca_types.h:245
daal::algorithms::pca::ResultCollectionId
ResultCollectionId
Definition: pca_types.h:142
daal::algorithms::pca::eigenvalue
Definition: pca_types.h:157
daal::algorithms::pca::interface2::BatchParameter< algorithmFPType, correlationDense >::covariance
services::SharedPtr< covariance::BatchImpl > covariance
Definition: pca_types.h:689
daal::algorithms::pca::interface2::BaseBatchParameter
Class that specifies the common parameters of the PCA Batch algorithms.
Definition: pca_types.h:656
daal::algorithms::pca::eigenvalues
Definition: pca_types.h:131
daal::algorithms::pca::interface1::InputIface::isCorrelation
virtual bool isCorrelation() const
Definition: pca_types.h:184
daal::algorithms::pca::correlation
Definition: pca_types.h:76
daal::algorithms::pca::interface1::DistributedParameter< step2Master, algorithmFPType, correlationDense >::covariance
services::SharedPtr< covariance::DistributedIface< step2Master > > covariance
Definition: pca_types.h:528
daal_defines.h
daal::algorithms::pca::interface1::InputIface
Abstract class that specifies interface for classes that declare input of the PCA algorithm...
Definition: pca_types.h:168
daal::algorithms::pca::interface2::BaseBatchParameter::isDeterministic
bool isDeterministic
Definition: pca_types.h:664
daal::algorithms::pca::means
Definition: pca_types.h:133
daal::algorithms::pca::variance
Definition: pca_types.h:156
daal::algorithms::pca::interface2::Result
Provides methods to access results obtained with the PCA algorithm.
Definition: pca_types.h:727
daal::algorithms::pca::interface1::OnlineParameter
Class that specifies the parameters of the PCA algorithm in the online computing mode.
Definition: pca_types.h:465
daal::algorithms::pca::InputCorrelationId
InputCorrelationId
Definition: pca_types.h:74
daal::algorithms::pca::eigenvectors
Definition: pca_types.h:132
daal::algorithms::pca::interface1::PartialResult< daal::algorithms::pca::svdDense >
Provides methods to access partial results obtained with the compute() method of PCA SVD algorithm in...
Definition: pca_types.h:346
daal::algorithms::pca::Step2MasterInputId
Step2MasterInputId
Definition: pca_types.h:84
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::interface2::BaseBatchParameter::nComponents
size_t nComponents
Definition: pca_types.h:663
daal::algorithms::pca::InputDatasetId
InputDatasetId
Definition: pca_types.h:64
daal::algorithms::pca::variances
Definition: pca_types.h:134
daal::algorithms::pca::svdDense
Definition: pca_types.h:57
daal::algorithms::pca::PartialSVDTableResultId
PartialSVDTableResultId
Definition: pca_types.h:106
daal::algorithms::pca::Method
Method
Definition: pca_types.h:53
daal::algorithms::pca::ResultToComputeId
ResultToComputeId
Definition: pca_types.h:152
daal::algorithms::pca::interface1::OnlineParameter< algorithmFPType, correlationDense >::covariance
services::SharedPtr< covariance::OnlineImpl > covariance
Definition: pca_types.h:480
daal::algorithms::pca::interface2::BaseBatchParameter::resultsToCompute
DAAL_UINT64 resultsToCompute
Definition: pca_types.h:662
daal::algorithms::math::abs::value
Definition: abs_types.h:86
daal::algorithms::pca::interface1::PartialResult< daal::algorithms::pca::correlationDense >
Provides methods to access partial results obtained with the compute() method of the PCA Correlation ...
Definition: pca_types.h:268
daal::step2Master
Definition: daal_defines.h:118
daal::algorithms::pca::PartialSVDCollectionResultId
PartialSVDCollectionResultId
Definition: pca_types.h:118
daal::algorithms::pca::mean
Definition: pca_types.h:155
daal::algorithms::pca::distributedInputs
Definition: pca_types.h:121
daal::algorithms::pca::interface1::Input
Input objects for the PCA algorithm.
Definition: pca_types.h:196
daal::algorithms::pca::partialResults
Definition: pca_types.h:86
daal::algorithms::pca::interface2::BatchParameter< algorithmFPType, svdDense >::normalization
services::SharedPtr< normalization::zscore::BatchImpl > normalization
Definition: pca_types.h:712
daal::algorithms::pca::interface2::BatchParameter
Class that specifies the parameters of the PCA algorithm in the batch computing mode.
Definition: pca_types.h:673
daal::algorithms::pca::correlationDense
Definition: pca_types.h:55
daal::algorithms::pca::ResultId
ResultId
Definition: pca_types.h:129

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