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

pca_types.h
1 /* file: pca_types.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 PCA algorithm interface.
21 //--
22 */
23 
24 #ifndef __PCA_TYPES_H__
25 #define __PCA_TYPES_H__
26 
27 #include "algorithms/algorithm.h"
28 #include "data_management/data/numeric_table.h"
29 #include "data_management/data/homogen_numeric_table.h"
30 #include "services/daal_defines.h"
31 #include "algorithms/covariance/covariance_batch.h"
32 #include "algorithms/covariance/covariance_online.h"
33 #include "algorithms/covariance/covariance_distributed.h"
34 #include "algorithms/normalization/zscore.h"
35 
36 namespace daal
37 {
38 namespace algorithms
39 {
49 namespace pca
50 {
55 enum Method
56 {
57  correlationDense = 0,
58  defaultDense = 0,
59  svdDense = 1
60 };
61 
66 enum InputDatasetId
67 {
68  data,
69  lastInputDatasetId = data
70 };
71 
76 enum InputCorrelationId
77 {
78  correlation,
79  lastInputCorrelationId = correlation
80 };
81 
86 enum Step2MasterInputId
87 {
88  partialResults,
89  lastStep2MasterInputId = partialResults
90 };
91 
96 enum PartialCorrelationResultId
97 {
98  nObservationsCorrelation, /* Number of processed observations */
99  crossProductCorrelation, /* Cross-product of the processed data */
100  sumCorrelation, /* Feature sums of the processed data */
101  lastPartialCorrelationResultId = sumCorrelation
102 };
103 
108 enum PartialSVDTableResultId
109 {
110  nObservationsSVD, /* Number of processed observations */
111  sumSVD, /* Feature sums of the processed data */
112  sumSquaresSVD, /* Feature sums of squares of the processed data */
113  lastPartialSVDTableResultId = sumSquaresSVD
114 };
115 
120 enum PartialSVDCollectionResultId
121 {
122  auxiliaryData = lastPartialSVDTableResultId + 1,
123  distributedInputs,
124  lastPartialSVDCollectionResultId = distributedInputs
125 };
126 
131 enum ResultId
132 {
133  eigenvalues,
134  eigenvectors,
135  means,
136  variances,
137  lastResultId = variances
138 };
139 
144 enum ResultCollectionId
145 {
146  dataForTransform
147 };
148 
154 enum ResultToComputeId
155 {
156  none = 0ULL,
157  mean = 0x00000001ULL,
158  variance = 0x00000002ULL,
159  eigenvalue = 0x00000004ULL
160 };
161 
165 namespace interface1
166 {
170 class DAAL_EXPORT InputIface : public daal::algorithms::Input
171 {
172 public:
173  InputIface(size_t nElements);
174  InputIface(const InputIface& other);
175 
180  virtual size_t getNFeatures() const = 0;
181 
186  virtual bool isCorrelation() const { return _isCorrelation; };
187 
188  virtual ~InputIface() {};
189 
190 protected:
191  bool _isCorrelation;
192 };
193 
198 class DAAL_EXPORT Input : public InputIface
199 {
200 public:
201  Input();
202  Input(const Input& other);
203 
204  virtual ~Input() {};
205 
211  data_management::NumericTablePtr get(InputDatasetId id) const;
212 
218  void set(InputDatasetId id, const data_management::NumericTablePtr &value);
219 
225  void set(InputCorrelationId id, const data_management::NumericTablePtr &value);
226 
231  size_t getNFeatures() const DAAL_C11_OVERRIDE;
232 
239  services::Status check(const daal::algorithms::Parameter *par, int method) const DAAL_C11_OVERRIDE;
240 };
241 
247 class PartialResultBase : public daal::algorithms::PartialResult
248 {
249 public:
250  PartialResultBase(const size_t nElements) : daal::algorithms::PartialResult(nElements) {};
251 
252  virtual size_t getNFeatures() const = 0;
253 
254  virtual ~PartialResultBase() {};
255 };
256 
262 template<Method method>
263 class PartialResult : public PartialResultBase {};
264 
270 template<> class DAAL_EXPORT PartialResult<daal::algorithms::pca::correlationDense> : public PartialResultBase
271 {
272 public:
273  DECLARE_SERIALIZABLE_CAST(PartialResult<daal::algorithms::pca::correlationDense>);
274  PartialResult();
275 
281  data_management::NumericTablePtr get(PartialCorrelationResultId id) const;
282 
283  virtual size_t getNFeatures() const DAAL_C11_OVERRIDE;
284 
290  void set(const PartialCorrelationResultId id, const data_management::NumericTablePtr &value);
291 
292  virtual ~PartialResult() {};
293 
301  services::Status check(const daal::algorithms::Input *input, const daal::algorithms::Parameter *parameter, int method) const DAAL_C11_OVERRIDE;
302 
303 
310  services::Status check(const daal::algorithms::Parameter *par, int method) const DAAL_C11_OVERRIDE;
311 
319  template <typename algorithmFPType>
320  DAAL_EXPORT services::Status allocate(const daal::algorithms::Input *input, const daal::algorithms::Parameter *parameter, const int method);
321 
329  template <typename algorithmFPType>
330  DAAL_EXPORT services::Status initialize(const daal::algorithms::Input *input, const daal::algorithms::Parameter *parameter, const int method);
331 protected:
332 
333  services::Status checkImpl(size_t nFeatures) const;
334 
336  template<typename Archive, bool onDeserialize>
337  services::Status serialImpl(Archive *arch)
338  {
339  return daal::algorithms::PartialResult::serialImpl<Archive, onDeserialize>(arch);
340  }
341 };
342 
348 template<> class DAAL_EXPORT PartialResult<daal::algorithms::pca::svdDense> : public PartialResultBase
349 {
350 public:
351  DECLARE_SERIALIZABLE_CAST(PartialResult<daal::algorithms::pca::svdDense>);
352  PartialResult();
353 
359  data_management::NumericTablePtr get(PartialSVDTableResultId id) const;
360 
361  virtual size_t getNFeatures() const DAAL_C11_OVERRIDE;
362 
368  data_management::DataCollectionPtr get(PartialSVDCollectionResultId id) const;
369 
376  data_management::NumericTablePtr get(PartialSVDCollectionResultId id, const size_t &elementId) const;
377 
383  void set(PartialSVDTableResultId id, const data_management::NumericTablePtr &value);
384 
390  void set(PartialSVDCollectionResultId id, const data_management::DataCollectionPtr &value);
391 
397  void add(const PartialSVDCollectionResultId &id, const data_management::DataCollectionPtr &value);
398 
406  services::Status check(const daal::algorithms::Input *input, const daal::algorithms::Parameter *parameter, int method) const DAAL_C11_OVERRIDE;
407 
414  services::Status check(const daal::algorithms::Parameter *par, int method) const DAAL_C11_OVERRIDE;
415 
416  virtual ~PartialResult() {};
417 
425  template <typename algorithmFPType>
426  DAAL_EXPORT services::Status allocate(const daal::algorithms::Input *input, const daal::algorithms::Parameter *parameter, const int method);
427 
435  template <typename algorithmFPType>
436  DAAL_EXPORT services::Status initialize(const daal::algorithms::Input *input, const daal::algorithms::Parameter *parameter, const int method);
437 
438 protected:
439 
440  services::Status checkImpl(size_t nFeatures) const;
441 
443  template<typename Archive, bool onDeserialize>
444  services::Status serialImpl(Archive *arch)
445  {
446  return daal::algorithms::PartialResult::serialImpl<Archive, onDeserialize>(arch);
447  }
448 };
449 
454 template<typename algorithmFPType, Method method = correlationDense>
455 class DAAL_EXPORT BaseParameter : public daal::algorithms::Parameter
456 {
457 public:
459  BaseParameter();
460 };
461 
466 template<typename algorithmFPType, Method method>
467 class OnlineParameter : public BaseParameter<algorithmFPType, method> {};
468 
473 template<typename algorithmFPType>
474 class DAAL_EXPORT OnlineParameter<algorithmFPType, correlationDense> : public BaseParameter<algorithmFPType, correlationDense>
475 {
476 public:
478  OnlineParameter(const services::SharedPtr<covariance::OnlineImpl> &covarianceForOnlineParameter =
479  services::SharedPtr<covariance::Online<algorithmFPType, covariance::defaultDense> >
480  (new covariance::Online<algorithmFPType, covariance::defaultDense>()));
481 
482  services::SharedPtr<covariance::OnlineImpl> covariance;
488  services::Status check() const DAAL_C11_OVERRIDE;
489 };
490 
491 
496 template<typename algorithmFPType>
497 class DAAL_EXPORT OnlineParameter<algorithmFPType, svdDense> : public BaseParameter<algorithmFPType, svdDense>
498 {
499 public:
501  OnlineParameter();
502 
507  services::Status check() const DAAL_C11_OVERRIDE;
508 };
509 
514 template<ComputeStep step, typename algorithmFPType, Method method>
515 class DistributedParameter : public BaseParameter<algorithmFPType, method> {};
516 
521 template<typename algorithmFPType>
522 class DAAL_EXPORT DistributedParameter<step2Master, algorithmFPType, correlationDense> : public BaseParameter<algorithmFPType, correlationDense>
523 {
524 public:
526  DistributedParameter(const services::SharedPtr<covariance::DistributedIface<step2Master> > &covarianceForDistributedParameter =
527  services::SharedPtr<covariance::Distributed<step2Master, algorithmFPType, covariance::defaultDense> >
528  (new covariance::Distributed<step2Master, algorithmFPType, covariance::defaultDense>()));
529 
530  services::SharedPtr<covariance::DistributedIface<step2Master> > covariance;
536  services::Status check() const DAAL_C11_OVERRIDE;
537 };
538 
543 template<Method method>
544 class DistributedInput {};
545 
550 template<> class DAAL_EXPORT DistributedInput<correlationDense> : public InputIface
551 {
552 public:
553  DistributedInput();
554  DistributedInput(const DistributedInput& other);
555 
561  void set(Step2MasterInputId id, const data_management::DataCollectionPtr &ptr);
562 
568  data_management::DataCollectionPtr get(Step2MasterInputId id) const;
569 
574  services::SharedPtr<PartialResult<correlationDense> > getPartialResult(size_t id) const;
575 
581  void add(Step2MasterInputId id, const services::SharedPtr<PartialResult<correlationDense> > &value);
582 
587  size_t getNFeatures() const DAAL_C11_OVERRIDE;
588 
595  services::Status check(const daal::algorithms::Parameter *parameter, int method) const DAAL_C11_OVERRIDE;
596 };
597 
602 template<> class DAAL_EXPORT DistributedInput<svdDense> : public InputIface
603 {
604 public:
605  DistributedInput();
606  DistributedInput(const DistributedInput& other);
607 
613  void set(Step2MasterInputId id, const data_management::DataCollectionPtr &ptr);
614 
620  data_management::DataCollectionPtr get(Step2MasterInputId id) const;
621 
627  void add(Step2MasterInputId id, const services::SharedPtr<PartialResult<svdDense> > &value);
628 
633  services::SharedPtr<PartialResult<svdDense> > getPartialResult(size_t id) const;
634 
641  services::Status check(const daal::algorithms::Parameter *parameter, int method) const DAAL_C11_OVERRIDE;
642 
647  size_t getNFeatures() const DAAL_C11_OVERRIDE;
648 };
649 
650 } // namespace interface1
651 
655 namespace interface3
656 {
661 class DAAL_EXPORT BaseBatchParameter : public daal::algorithms::Parameter
662 {
663 public:
665  BaseBatchParameter();
666 
667  DAAL_UINT64 resultsToCompute;
668  size_t nComponents;
669  bool isDeterministic;
670 };
671 
672 
677 template<typename algorithmFPType, Method method>
678 class BatchParameter {};
679 
680 
685 template<typename algorithmFPType>
686 class DAAL_EXPORT BatchParameter<algorithmFPType, correlationDense> : public BaseBatchParameter
687 {
688 public:
690  BatchParameter(const services::SharedPtr<covariance::BatchImpl> &covarianceForBatchParameter =
691  services::SharedPtr<covariance::Batch<algorithmFPType, covariance::defaultDense> >
692  (new covariance::Batch<algorithmFPType, covariance::defaultDense>()));
693 
694  services::SharedPtr<covariance::BatchImpl> covariance;
701  services::Status check() const DAAL_C11_OVERRIDE;
702 };
703 
708 template<typename algorithmFPType>
709 class DAAL_EXPORT BatchParameter<algorithmFPType, svdDense> : public BaseBatchParameter
710 {
711 public:
713  BatchParameter(const services::SharedPtr<normalization::zscore::BatchImpl> &normalizationForBatchParameter =
714  services::SharedPtr<normalization::zscore::Batch<algorithmFPType, normalization::zscore::defaultDense> >
715  (new normalization::zscore::Batch<algorithmFPType, normalization::zscore::defaultDense>()));
716 
717  services::SharedPtr<normalization::zscore::BatchImpl> normalization;
724  services::Status check() const DAAL_C11_OVERRIDE;
725 };
726 
731 class DAAL_EXPORT Result : public daal::algorithms::Result
732 {
733 public:
734  DECLARE_SERIALIZABLE_CAST(Result);
735  Result(const Result& o);
736  Result();
737 
738  virtual ~Result() {};
739 
745  data_management::NumericTablePtr get(ResultId id) const;
746 
752  data_management::KeyValueDataCollectionPtr get(ResultCollectionId id) const;
753 
760  void set(ResultCollectionId id, data_management::KeyValueDataCollectionPtr& collection);
761 
762 
768  void set(ResultId id, const data_management::NumericTablePtr &value);
769 
776  template<typename algorithmFPType>
777  DAAL_EXPORT services::Status allocate(const daal::algorithms::Input *input, daal::algorithms::Parameter *parameter, const Method method);
778 
784  template<typename algorithmFPType>
785  DAAL_EXPORT services::Status allocate(const daal::algorithms::PartialResult *partialResult, daal::algorithms::Parameter *parameter, const Method method);
786 
794  services::Status check(const daal::algorithms::Input *_input, const daal::algorithms::Parameter *par, int method) const DAAL_C11_OVERRIDE;
795 
803  services::Status check(const daal::algorithms::PartialResult *pr, const daal::algorithms::Parameter *parameter, int method) const DAAL_C11_OVERRIDE;
804 
805 protected:
806 
815  services::Status checkImpl(size_t nFeatures, size_t nComponents, DAAL_UINT64 resultsToCompute) const;
816 
818  template<typename Archive, bool onDeserialize>
819  services::Status serialImpl(Archive *arch)
820  {
821  return daal::algorithms::Result::serialImpl<Archive, onDeserialize>(arch);
822  }
823 };
824 typedef services::SharedPtr<Result> ResultPtr;
825 
826 }
827 using interface1::InputIface;
828 using interface1::Input;
829 using interface1::PartialResultBase;
830 using interface1::PartialResult;
831 using interface3::BatchParameter;
832 using interface3::BaseBatchParameter;
833 using interface1::OnlineParameter;
834 using interface1::DistributedParameter;
835 using interface1::DistributedInput;
836 using interface3::Result;
837 using interface3::ResultPtr;
838 
839 } // pca
840 } // algorithm
841 } // namespace daal
842 #endif
daal::algorithms::pca::mean
Definition: pca_types.h:157
daal::algorithms::pca::eigenvalues
Definition: pca_types.h:133
daal::algorithms::pca::PartialSVDCollectionResultId
PartialSVDCollectionResultId
Definition: pca_types.h:120
daal::algorithms::pca::eigenvectors
Definition: pca_types.h:134
daal::algorithms::pca::correlationDense
Definition: pca_types.h:57
daal::algorithms::pca::ResultCollectionId
ResultCollectionId
Definition: pca_types.h:144
daal::algorithms::pca::variances
Definition: pca_types.h:136
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:270
daal::algorithms::pca::interface3::Result
Provides methods to access results obtained with the PCA algorithm.
Definition: pca_types.h:731
daal::algorithms::pca::interface1::BaseParameter
Class that specifies the common parameters of the PCA algorithm.
Definition: pca_types.h:455
daal::algorithms::pca::variance
Definition: pca_types.h:158
daal::algorithms::pca::interface3::BaseBatchParameter::resultsToCompute
DAAL_UINT64 resultsToCompute
Definition: pca_types.h:667
daal::step2Master
Definition: daal_defines.h:124
daal::algorithms::pca::interface3::BatchParameter
Class that specifies the parameters of the PCA algorithm in the batch computing mode.
Definition: pca_types.h:678
daal::algorithms::pca::data
Definition: pca_types.h:68
daal::algorithms::pca::interface1::DistributedParameter
Class that specifies the parameters of the PCA algorithm in the distributed computing mode...
Definition: pca_types.h:515
daal::algorithms::pca::Method
Method
Definition: pca_types.h:55
daal::algorithms::pca::svdDense
Definition: pca_types.h:59
daal::algorithms::pca::interface3::BaseBatchParameter::nComponents
size_t nComponents
Definition: pca_types.h:668
daal::algorithms::pca::defaultDense
Definition: pca_types.h:58
daal_defines.h
daal::algorithms::pca::interface1::Input
Input objects for the PCA algorithm.
Definition: pca_types.h:198
daal::algorithms::pca::ResultId
ResultId
Definition: pca_types.h:131
daal::algorithms::pca::auxiliaryData
Definition: pca_types.h:122
daal::algorithms::pca::interface1::InputIface
Abstract class that specifies interface for classes that declare input of the PCA algorithm...
Definition: pca_types.h:170
daal::algorithms::pca::interface1::PartialResultBase
Provides interface to access partial results obtained with the compute() method of the PCA algorithm ...
Definition: pca_types.h:247
daal::algorithms::pca::PartialCorrelationResultId
PartialCorrelationResultId
Definition: pca_types.h:96
daal::algorithms::pca::interface3::BaseBatchParameter
Class that specifies the common parameters of the PCA Batch algorithms.
Definition: pca_types.h:661
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::DistributedParameter< step2Master, algorithmFPType, correlationDense >::covariance
services::SharedPtr< covariance::DistributedIface< step2Master > > covariance
Definition: pca_types.h:530
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:348
daal::algorithms::pca::dataForTransform
Definition: pca_types.h:146
daal::algorithms::pca::eigenvalue
Definition: pca_types.h:159
daal::algorithms::pca::PartialSVDTableResultId
PartialSVDTableResultId
Definition: pca_types.h:108
daal::algorithms::pca::interface1::OnlineParameter< algorithmFPType, correlationDense >::covariance
services::SharedPtr< covariance::OnlineImpl > covariance
Definition: pca_types.h:482
daal::algorithms::pca::partialResults
Definition: pca_types.h:88
daal::algorithms::pca::interface1::InputIface::isCorrelation
virtual bool isCorrelation() const
Definition: pca_types.h:186
daal::algorithms::pca::InputCorrelationId
InputCorrelationId
Definition: pca_types.h:76
daal::algorithms::pca::means
Definition: pca_types.h:135
daal::algorithms::math::abs::value
Definition: abs_types.h:88
daal::algorithms::pca::interface3::BatchParameter< algorithmFPType, correlationDense >::covariance
services::SharedPtr< covariance::BatchImpl > covariance
Definition: pca_types.h:694
daal::algorithms::pca::correlation
Definition: pca_types.h:78
daal::algorithms::pca::interface3::BaseBatchParameter::isDeterministic
bool isDeterministic
Definition: pca_types.h:669
daal::algorithms::pca::distributedInputs
Definition: pca_types.h:123
daal::algorithms::pca::Step2MasterInputId
Step2MasterInputId
Definition: pca_types.h:86
daal::algorithms::pca::InputDatasetId
InputDatasetId
Definition: pca_types.h:66
daal::algorithms::pca::ResultToComputeId
ResultToComputeId
Definition: pca_types.h:154
daal::algorithms::pca::interface1::DistributedInput
Input objects for the PCA algorithm in the distributed processing mode.
Definition: pca_types.h:544
daal::algorithms::pca::interface3::BatchParameter< algorithmFPType, svdDense >::normalization
services::SharedPtr< normalization::zscore::BatchImpl > normalization
Definition: pca_types.h:717
daal::algorithms::pca::interface1::OnlineParameter
Class that specifies the parameters of the PCA algorithm in the online computing mode.
Definition: pca_types.h:467

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