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

pca_online.h
1 /* file: pca_online.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 online processing mode
21 //--
22 */
23 
24 #ifndef __PCA_ONLINE_H__
25 #define __PCA_ONLINE_H__
26 
27 #include "algorithms/algorithm.h"
28 #include "data_management/data/numeric_table.h"
29 #include "services/daal_defines.h"
30 #include "services/daal_memory.h"
31 #include "algorithms/pca/pca_types.h"
32 
33 namespace daal
34 {
35 namespace algorithms
36 {
37 namespace pca
38 {
39 
40 namespace interface1
41 {
51 template<typename algorithmFPType, Method method, CpuType cpu>
52 class OnlineContainer : public AnalysisContainerIface<online> {};
53 
58 template<typename algorithmFPType, CpuType cpu>
59 class OnlineContainer<algorithmFPType, correlationDense, cpu> : public AnalysisContainerIface<online>
60 {
61 public:
67  OnlineContainer(daal::services::Environment::env *daalEnv);
69  ~OnlineContainer();
70 
74  services::Status compute() DAAL_C11_OVERRIDE;
78  services::Status finalizeCompute() DAAL_C11_OVERRIDE;
79 };
80 
85 template<typename algorithmFPType, CpuType cpu>
86 class OnlineContainer<algorithmFPType, svdDense, cpu> : public AnalysisContainerIface<online>
87 {
88 public:
94  OnlineContainer(daal::services::Environment::env *daalEnv);
96  ~OnlineContainer();
97 
101  services::Status compute() DAAL_C11_OVERRIDE;
105  services::Status finalizeCompute() DAAL_C11_OVERRIDE;
106 };
107 
115 template<typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = correlationDense>
116 class DAAL_EXPORT Online : public Analysis<online> {};
117 
125 template<typename algorithmFPType>
126 class DAAL_EXPORT Online<algorithmFPType, correlationDense> : public Analysis<online>
127 {
128 public:
129  typedef algorithms::pca::Input InputType;
130  typedef algorithms::pca::OnlineParameter<algorithmFPType, correlationDense> ParameterType;
131  typedef algorithms::pca::Result ResultType;
132  typedef algorithms::pca::PartialResult<correlationDense> PartialResultType;
133 
135  Online()
136  {
137  initialize();
138  }
139 
145  Online(const Online<algorithmFPType, correlationDense> &other) : input(other.input), parameter(other.parameter)
146  {
147  initialize();
148  }
149 
150  ~Online() {}
151 
156  int getMethod() const DAAL_C11_OVERRIDE { return(int)correlationDense; }
157 
162  services::Status setPartialResult(const services::SharedPtr<PartialResult<correlationDense> >& partialResult)
163  {
164  DAAL_CHECK(partialResult, services::ErrorNullPartialResult);
165  _partialResult = partialResult;
166  _pres = _partialResult.get();
167  return services::Status();
168  }
169 
174  services::Status setResult(const ResultPtr& res)
175  {
176  DAAL_CHECK(res, services::ErrorNullResult)
177  _result = res;
178  _res = _result.get();
179  return services::Status();
180  }
181 
186  services::SharedPtr<PartialResult<correlationDense> > getPartialResult()
187  {
188  return _partialResult;
189  }
190 
195  ResultPtr getResult()
196  {
197  return _result;
198  }
199 
205  services::SharedPtr<Online<algorithmFPType, correlationDense> > clone() const
206  {
207  return services::SharedPtr<Online<algorithmFPType, correlationDense> >(cloneImpl());
208  }
209 
210  InputType input;
211  OnlineParameter<algorithmFPType, correlationDense> parameter;
213 protected:
214  services::SharedPtr<PartialResult<correlationDense> > _partialResult;
215  ResultPtr _result;
216 
217  virtual Online<algorithmFPType, correlationDense> * cloneImpl() const DAAL_C11_OVERRIDE
218  {
219  return new Online<algorithmFPType, correlationDense>(*this);
220  }
221 
222  services::Status allocateResult() DAAL_C11_OVERRIDE
223  {
224  services::Status s = _result->allocate<algorithmFPType>(_pres, &parameter, correlationDense);
225  _res = _result.get();
226  return s;
227  }
228 
229  services::Status allocatePartialResult() DAAL_C11_OVERRIDE
230  {
231  services::Status s = _partialResult->allocate<algorithmFPType>(&input, &parameter, correlationDense);
232  _pres = _partialResult.get();
233  return s;
234  }
235 
236  services::Status initializePartialResult() DAAL_C11_OVERRIDE
237  {
238  services::Status s = _partialResult->initialize<algorithmFPType>(&input, &parameter, correlationDense);
239  _pres = _partialResult.get();
240  return s;
241  }
242 
243  void initialize()
244  {
245  _ac = new __DAAL_ALGORITHM_CONTAINER(online, OnlineContainer, algorithmFPType, correlationDense)(&_env);
246  _in = &input;
247  _par = &parameter;
248  _partialResult.reset(new PartialResult<correlationDense>());
249  _result.reset(new ResultType());
250  }
251 };
252 
260 template<typename algorithmFPType>
261 class DAAL_EXPORT Online<algorithmFPType, svdDense> : public Analysis<online>
262 {
263 public:
264  typedef algorithms::pca::Input InputType;
265  typedef algorithms::pca::OnlineParameter<algorithmFPType, svdDense> ParameterType;
266  typedef algorithms::pca::Result ResultType;
267  typedef algorithms::pca::PartialResult<svdDense> PartialResultType;
268 
270  Online()
271  {
272  initialize();
273  }
274 
280  Online(const Online<algorithmFPType, svdDense> &other) : input(other.input), parameter(other.parameter)
281  {
282  initialize();
283  }
284 
285  ~Online() {}
286 
291  int getMethod() const DAAL_C11_OVERRIDE { return(int)svdDense; }
292 
297  services::Status setPartialResult(const services::SharedPtr<PartialResult<svdDense> >& partialResult)
298  {
299  DAAL_CHECK(partialResult, services::ErrorNullPartialResult);
300  _partialResult = partialResult;
301  _pres = _partialResult.get();
302  return services::Status();
303  }
304 
309  services::Status setResult(const ResultPtr& res)
310  {
311  DAAL_CHECK(res, services::ErrorNullResult)
312  _result = res;
313  _res = _result.get();
314  return services::Status();
315  }
316 
321  services::SharedPtr<PartialResult<svdDense> > getPartialResult()
322  {
323  return _partialResult;
324  }
325 
330  ResultPtr getResult()
331  {
332  return _result;
333  }
334 
340  services::SharedPtr<Online<algorithmFPType, svdDense> > clone() const
341  {
342  return services::SharedPtr<Online<algorithmFPType, svdDense> >(cloneImpl());
343  }
344 
345  InputType input;
346  OnlineParameter<algorithmFPType, svdDense> parameter;
348 protected:
349  services::SharedPtr<PartialResult<svdDense> > _partialResult;
350  ResultPtr _result;
351 
352  virtual Online<algorithmFPType, svdDense> * cloneImpl() const DAAL_C11_OVERRIDE
353  {
354  return new Online<algorithmFPType, svdDense>(*this);
355  }
356 
357  services::Status allocateResult() DAAL_C11_OVERRIDE
358  {
359  services::Status s = _result->allocate<algorithmFPType>(_pres, &parameter, svdDense);
360  _res = _result.get();
361  return s;
362  }
363 
364  services::Status allocatePartialResult() DAAL_C11_OVERRIDE
365  {
366  services::Status s = _partialResult->allocate<algorithmFPType>(&input, &parameter, svdDense);
367  _pres = _partialResult.get();
368  return s;
369  }
370 
371  services::Status initializePartialResult() DAAL_C11_OVERRIDE
372  {
373  services::Status s = _partialResult->initialize<algorithmFPType>(&input, &parameter, svdDense);
374  _pres = _partialResult.get();
375  return s;
376  }
377 
378  void initialize()
379  {
380  _ac = new __DAAL_ALGORITHM_CONTAINER(online, OnlineContainer, algorithmFPType, svdDense)(&_env);
381  _in = &input;
382  _par = &parameter;
383  _partialResult.reset(new PartialResult<svdDense>());
384  _result.reset(new ResultType());
385  }
386 };
388 } // namespace interface1
389 using interface1::OnlineContainer;
390 using interface1::Online;
391 
392 }
393 }
394 }
395 #endif
daal::algorithms::pca::interface1::Online< algorithmFPType, correlationDense >::getMethod
int getMethod() const DAAL_C11_OVERRIDE
Definition: pca_online.h:156
daal::algorithms::pca::interface1::Online< algorithmFPType, svdDense >::Online
Online()
Definition: pca_online.h:270
daal::algorithms::pca::interface1::Online< algorithmFPType, correlationDense >::getPartialResult
services::SharedPtr< PartialResult< correlationDense > > getPartialResult()
Definition: pca_online.h:186
daal::algorithms::pca::interface1::Online< algorithmFPType, svdDense >::input
InputType input
Definition: pca_online.h:345
daal::algorithms::pca::interface1::Online< algorithmFPType, svdDense >::parameter
OnlineParameter< algorithmFPType, svdDense > parameter
Definition: pca_online.h:346
daal::algorithms::pca::interface1::Online< algorithmFPType, svdDense >::getPartialResult
services::SharedPtr< PartialResult< svdDense > > getPartialResult()
Definition: pca_online.h:321
daal::algorithms::pca::correlationDense
Definition: pca_types.h:57
daal::algorithms::pca::interface1::Online< algorithmFPType, svdDense >::setResult
services::Status setResult(const ResultPtr &res)
Definition: pca_online.h:309
daal::algorithms::pca::interface1::Online< algorithmFPType, svdDense >::getMethod
int getMethod() const DAAL_C11_OVERRIDE
Definition: pca_online.h:291
daal::algorithms::pca::interface1::Online< algorithmFPType, svdDense >::clone
services::SharedPtr< Online< algorithmFPType, svdDense > > clone() const
Definition: pca_online.h:340
daal::algorithms::pca::interface1::Online< algorithmFPType, svdDense >::setPartialResult
services::Status setPartialResult(const services::SharedPtr< PartialResult< svdDense > > &partialResult)
Definition: pca_online.h:297
daal::algorithms::pca::interface1::Online< algorithmFPType, correlationDense >::parameter
OnlineParameter< algorithmFPType, correlationDense > parameter
Definition: pca_online.h:211
daal::algorithms::pca::svdDense
Definition: pca_types.h:59
daal::algorithms::pca::interface1::Online< algorithmFPType, correlationDense >
Computes the results of the PCA Correlation algorithm.
Definition: pca_online.h:126
daal::algorithms::pca::interface1::Online< algorithmFPType, correlationDense >::input
InputType input
Definition: pca_online.h:210
daal::services::ErrorNullResult
Definition: error_indexes.h:98
daal::algorithms::pca::interface1::Online< algorithmFPType, svdDense >::Online
Online(const Online< algorithmFPType, svdDense > &other)
Definition: pca_online.h:280
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::OnlineParameter< algorithmFPType, svdDense >
Class that specifies the parameters of the PCA SVD algorithm in the online computing mode...
Definition: pca_types.h:497
daal_defines.h
daal::algorithms::pca::interface1::Online< algorithmFPType, correlationDense >::Online
Online()
Definition: pca_online.h:135
daal::algorithms::pca::interface1::Online< algorithmFPType, correlationDense >::getResult
ResultPtr getResult()
Definition: pca_online.h:195
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::Online< algorithmFPType, correlationDense >::clone
services::SharedPtr< Online< algorithmFPType, correlationDense > > clone() const
Definition: pca_online.h:205
daal::online
Definition: daal_defines.h:114
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::Online< algorithmFPType, svdDense >
Computes the results of the PCA SVD algorithm.
Definition: pca_online.h:261
daal::algorithms::pca::interface1::Online< algorithmFPType, correlationDense >::setPartialResult
services::Status setPartialResult(const services::SharedPtr< PartialResult< correlationDense > > &partialResult)
Definition: pca_online.h:162
daal::algorithms::pca::interface1::Online
Computes the results of the PCA algorithm.
Definition: pca_online.h:116
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::Online< algorithmFPType, correlationDense >::Online
Online(const Online< algorithmFPType, correlationDense > &other)
Definition: pca_online.h:145
daal::algorithms::pca::interface1::OnlineParameter< algorithmFPType, correlationDense >
Class that specifies the parameters of the PCA Correlation algorithm in the online computing mode...
Definition: pca_types.h:474
daal::algorithms::pca::interface1::Online< algorithmFPType, correlationDense >::setResult
services::Status setResult(const ResultPtr &res)
Definition: pca_online.h:174
daal::algorithms::pca::interface1::Online< algorithmFPType, svdDense >::getResult
ResultPtr getResult()
Definition: pca_online.h:330

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