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

covariance_distributed.h
1 /* file: covariance_distributed.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 the interface for the correlation or variance-covariance
19 // matrix algorithm in the distributed processing mode
20 //--
21 */
22 
23 #ifndef __COVARIANCE_DISTRIBUTED_H__
24 #define __COVARIANCE_DISTRIBUTED_H__
25 
26 #include "algorithms/algorithm.h"
27 #include "data_management/data/numeric_table.h"
28 #include "services/daal_defines.h"
29 #include "algorithms/covariance/covariance_types.h"
30 #include "algorithms/covariance/covariance_online.h"
31 
32 namespace daal
33 {
34 namespace algorithms
35 {
36 namespace covariance
37 {
38 
39 namespace interface1
40 {
54 template<ComputeStep step>
55 class DistributedContainerIface
56 {};
57 
66 template<>
67 class DistributedContainerIface<step2Master> : public daal::algorithms::AnalysisContainerIface<distributed>
68 {
69 public:
70  DistributedContainerIface() {};
71  virtual ~DistributedContainerIface() {};
72 
77  virtual services::Status compute() = 0;
82  virtual services::Status finalizeCompute() = 0;
83 };
84 
95 template<ComputeStep step, typename algorithmFPType, Method method, CpuType cpu>
96 class DAAL_EXPORT DistributedContainer
97 {};
98 
104 template<typename algorithmFPType, Method method, CpuType cpu>
105 class DAAL_EXPORT DistributedContainer<step2Master, algorithmFPType, method, cpu> : public DistributedContainerIface<step2Master>
106 {
107 public:
113  DistributedContainer(daal::services::Environment::env *daalEnv);
115  virtual ~DistributedContainer();
120  virtual services::Status compute() DAAL_C11_OVERRIDE;
125  virtual services::Status finalizeCompute() DAAL_C11_OVERRIDE;
126 };
127 
149 template<ComputeStep step>
150 class DAAL_EXPORT DistributedIface : public daal::algorithms::Analysis<distributed>
151 {};
152 
174 template<>
175 class DistributedIface<step1Local> : public OnlineImpl
176 {
177 public:
178  typedef OnlineImpl super;
179 
180  typedef algorithms::covariance::DistributedInput<step1Local> InputType;
181  typedef super::ParameterType ParameterType;
182  typedef super::ResultType ResultType;
183  typedef super::PartialResultType PartialResultType;
184 
186  DistributedIface() : OnlineImpl()
187  {}
188 
196  DistributedIface(const DistributedIface<step1Local> &other) : OnlineImpl(other)
197  {}
198 
205  services::SharedPtr<DistributedIface<step1Local> > clone() const
206  {
207  return services::SharedPtr<DistributedIface<step1Local> >(cloneImpl());
208  }
209 
210 protected:
211  virtual DistributedIface<step1Local> * cloneImpl() const DAAL_C11_OVERRIDE = 0;
212 };
213 
235 template<>
236 class DAAL_EXPORT DistributedIface<step2Master> : public daal::algorithms::Analysis<distributed>
237 {
238 public:
239  typedef algorithms::covariance::DistributedInput<step2Master> InputType;
240  typedef algorithms::covariance::Parameter ParameterType;
241  typedef algorithms::covariance::Result ResultType;
242  typedef algorithms::covariance::PartialResult PartialResultType;
243 
245  DistributedIface()
246  {
247  initialize();
248  };
249 
257  DistributedIface(const DistributedIface<step2Master> &other) : parameter(other.parameter)
258  {
259  initialize();
260  data_management::DataCollectionPtr collection = other.input.get(partialResults);
261  for (size_t i = 0; i < collection->size(); i++)
262  {
263  input.add(partialResults,
264  services::staticPointerCast<PartialResultType, data_management::SerializationIface>((*collection)[i]));
265  }
266  }
267 
268  virtual ~DistributedIface() {}
269 
274  ResultPtr getResult()
275  {
276  return _result;
277  }
278 
283  virtual services::Status setResult(const ResultPtr &result)
284  {
285  DAAL_CHECK(result, services::ErrorNullResult)
286  _result = result;
287  _res = _result.get();
288  return services::Status();
289  }
290 
295  PartialResultPtr getPartialResult()
296  {
297  return _partialResult;
298  }
299 
305  virtual services::Status setPartialResult(const PartialResultPtr &partialResult, bool initFlag = false)
306  {
307  DAAL_CHECK(partialResult, services::ErrorNullPartialResult);
308  _partialResult = partialResult;
309  _pres = _partialResult.get();
310  setInitFlag(initFlag);
311  return services::Status();
312  }
313 
317  services::Status checkFinalizeComputeParams() DAAL_C11_OVERRIDE
318  {
319  services::Status s;
320  if(this->_partialResult)
321  {
322  s |= this->_partialResult->check(this->_par, getMethod());
323  if (!s) return s;
324  }
325  else
326  {
327  return services::Status(services::ErrorNullResult);
328  }
329 
330  if(this->_result)
331  {
332  s |= this->_result->check(this->_pres, this->_par, getMethod());
333  if (!s) return s;
334  }
335  else
336  {
337  return services::Status(services::ErrorNullResult);
338  }
339  return s;
340  }
341 
348  services::SharedPtr<DistributedIface<step2Master> > clone() const
349  {
350  return services::SharedPtr<DistributedIface<step2Master> >(cloneImpl());
351  }
352 
353  DistributedInput<step2Master> input;
354  ParameterType parameter;
356 protected:
357  virtual services::Status initializePartialResult() DAAL_C11_OVERRIDE
358  {
359  return services::Status();
360  }
361 
362  void initialize()
363  {
364  _in = &input;
365  _par = &parameter;
366  _result.reset(new ResultType());
367  _partialResult.reset(new PartialResultType());
368  }
369 
370  virtual DistributedIface<step2Master> * cloneImpl() const DAAL_C11_OVERRIDE = 0;
371 
372  PartialResultPtr _partialResult;
373  ResultPtr _result;
374 };
375 
397 template<ComputeStep step, typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = defaultDense>
398 class DAAL_EXPORT Distributed : public DistributedIface<step>
399 {};
400 
422 template<typename algorithmFPType, Method method>
423 class DAAL_EXPORT Distributed<step1Local, algorithmFPType, method> : public Online<algorithmFPType, method>
424 {
425 public:
426  typedef Online<algorithmFPType, method> super;
427 
428  typedef algorithms::covariance::DistributedInput<step1Local> InputType;
429  typedef typename super::ParameterType ParameterType;
430  typedef typename super::ResultType ResultType;
431  typedef typename super::PartialResultType PartialResultType;
432 
433  Distributed<step1Local, algorithmFPType, method>() : Online<algorithmFPType, method>()
434  {}
435 
443  Distributed(const Distributed<step1Local, algorithmFPType, method> &other) :
444  Online<algorithmFPType, method>(other)
445  {}
446 
453  services::SharedPtr<Distributed<step1Local, algorithmFPType, method> > clone() const
454  {
455  return services::SharedPtr<Distributed<step1Local, algorithmFPType, method> >(cloneImpl());
456  }
457 
458 protected:
459  virtual Distributed<step1Local, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
460  {
461  return new Distributed<step1Local, algorithmFPType, method>(*this);
462  }
463 };
464 
486 template<typename algorithmFPType, Method method>
487 class DAAL_EXPORT Distributed<step2Master, algorithmFPType, method> : public DistributedIface<step2Master>
488 {
489 public:
490  typedef DistributedIface<step2Master> super;
491 
492  typedef typename super::InputType InputType;
493  typedef typename super::ParameterType ParameterType;
494  typedef typename super::ResultType ResultType;
495  typedef typename super::PartialResultType PartialResultType;
496 
498  Distributed()
499  {
500  initialize();
501  }
502 
510  Distributed(const Distributed<step2Master, algorithmFPType, method> &other) :
511  DistributedIface<step2Master>(other)
512  {
513  initialize();
514  }
515 
516  virtual ~Distributed() {}
517 
522  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)method; }
523 
530  services::SharedPtr<Distributed<step2Master, algorithmFPType, method> > clone() const
531  {
532  return services::SharedPtr<Distributed<step2Master, algorithmFPType, method> >(cloneImpl());
533  }
534 
535 protected:
536  virtual Distributed<step2Master, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
537  {
538  return new Distributed<step2Master, algorithmFPType, method>(*this);
539  }
540 
541  virtual services::Status allocateResult() DAAL_C11_OVERRIDE
542  {
543  ResultPtr result = this->getResult();
544  services::Status s = result->template allocate<algorithmFPType>(this->_partialResult.get(), this->_par, (int)method);
545  this->_res = this->_result.get();
546  this->_pres = this->_partialResult.get();
547  return s;
548  }
549 
550  virtual services::Status allocatePartialResult() DAAL_C11_OVERRIDE
551  {
552  services::Status s = this->_partialResult->template allocate<algorithmFPType>(&(this->input), this->_par, (int)method);
553  this->_pres = this->_partialResult.get();
554  return s;
555  }
556 
557  void initialize()
558  {
559  this->_ac = new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step2Master, algorithmFPType, method)(&_env);
560  }
561 };
563 } // namespace interface1
564 using interface1::DistributedContainerIface;
565 using interface1::DistributedContainer;
566 using interface1::DistributedIface;
567 using interface1::Distributed;
568 
569 }
570 }
571 }
572 #endif // __COVARIANCE_DISTRIBUTED_H__
daal::algorithms::covariance::interface1::DistributedIface< step2Master >::setResult
virtual services::Status setResult(const ResultPtr &result)
Definition: covariance_distributed.h:283
daal::algorithms::covariance::interface1::DistributedIface< step2Master >
Interface for correlation or variance-covariance matrix computation algorithms in the distributed pro...
Definition: covariance_distributed.h:236
daal::algorithms::covariance::interface1::DistributedIface< step2Master >::DistributedIface
DistributedIface(const DistributedIface< step2Master > &other)
Definition: covariance_distributed.h:257
daal
Definition: algorithm_base_common.h:31
daal::algorithms::AnalysisContainerIface
Abstract interface class that provides virtual methods to access and run implementations of the analy...
Definition: analysis.h:53
daal::algorithms::covariance::interface1::Distributed< step1Local, algorithmFPType, method >::clone
services::SharedPtr< Distributed< step1Local, algorithmFPType, method > > clone() const
Definition: covariance_distributed.h:453
daal::algorithms::covariance::interface1::Distributed< step1Local, algorithmFPType, method >::Distributed
Distributed(const Distributed< step1Local, algorithmFPType, method > &other)
Definition: covariance_distributed.h:443
daal::algorithms::covariance::interface1::DistributedIface< step2Master >::parameter
ParameterType parameter
Definition: covariance_distributed.h:354
daal::services::ErrorNullPartialResult
Definition: error_indexes.h:105
daal::algorithms::covariance::interface1::DistributedIface< step2Master >::clone
services::SharedPtr< DistributedIface< step2Master > > clone() const
Definition: covariance_distributed.h:348
daal::ComputeStep
ComputeStep
Definition: daal_defines.h:115
daal::algorithms::covariance::interface1::OnlineImpl
Abstract class that specifies interface of the algorithms for computing correlation or variance-covar...
Definition: covariance_online.h:287
daal::algorithms::covariance::interface1::DistributedIface< step1Local >::clone
services::SharedPtr< DistributedIface< step1Local > > clone() const
Definition: covariance_distributed.h:205
daal::algorithms::covariance::Method
Method
Definition: covariance_types.h:46
daal::algorithms::covariance::interface1::Online
Computes correlation or variance-covariance matrix in the online processing mode. ...
Definition: covariance_online.h:410
daal::algorithms::covariance::interface1::Distributed< step2Master, algorithmFPType, method >
Computes correlation or variance-covariance matrix in the second step of the distributed processing m...
Definition: covariance_distributed.h:487
daal::algorithms::covariance::interface1::DistributedContainer
Provides methods to run implementations of the correlation or variance-covariance matrix algorithm in...
Definition: covariance_distributed.h:96
daal::algorithms::covariance::interface1::DistributedIface
Interface for the correlation or variance-covariance matrix algorithm in the distributed processing m...
Definition: covariance_distributed.h:150
daal_defines.h
daal::algorithms::covariance::interface1::Distributed< step2Master, algorithmFPType, method >::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: covariance_distributed.h:522
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:255
daal::distributed
Definition: daal_defines.h:107
daal::algorithms::covariance::interface1::DistributedIface< step2Master >::input
DistributedInput< step2Master > input
Definition: covariance_distributed.h:353
daal::algorithms::covariance::interface1::Distributed< step2Master, algorithmFPType, method >::Distributed
Distributed()
Definition: covariance_distributed.h:498
daal::algorithms::covariance::partialResults
Definition: covariance_types.h:110
daal::algorithms::covariance::interface1::DistributedIface< step2Master >::setPartialResult
virtual services::Status setPartialResult(const PartialResultPtr &partialResult, bool initFlag=false)
Definition: covariance_distributed.h:305
daal::algorithms::covariance::interface1::DistributedIface< step2Master >::getPartialResult
PartialResultPtr getPartialResult()
Definition: covariance_distributed.h:295
daal::algorithms::covariance::interface1::DistributedIface< step1Local >::DistributedIface
DistributedIface()
Definition: covariance_distributed.h:186
daal::algorithms::covariance::interface1::Distributed< step2Master, algorithmFPType, method >::clone
services::SharedPtr< Distributed< step2Master, algorithmFPType, method > > clone() const
Definition: covariance_distributed.h:530
daal::algorithms::covariance::interface1::Distributed< step1Local, algorithmFPType, method >
Computes correlation or variance-covariance matrix in the first step of the distributed processing mo...
Definition: covariance_distributed.h:423
daal::algorithms::covariance::interface1::DistributedContainerIface
Class that spcifies interfaces of the correlation or variance-covariance matrix algorithm. This class is associated with daal::algorithms::covariance::DistributedIface class.
Definition: covariance_distributed.h:55
daal::algorithms::covariance::interface1::DistributedIface< step2Master >::getResult
ResultPtr getResult()
Definition: covariance_distributed.h:274
daal::algorithms::covariance::interface1::DistributedIface< step2Master >::DistributedIface
DistributedIface()
Definition: covariance_distributed.h:245
daal::algorithms::Analysis
Provides methods for execution of operations over data, such as computation of Summary Statistics est...
Definition: analysis.h:68
daal::algorithms::covariance::covariance
Definition: covariance_types.h:88
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:55
daal::step1Local
Definition: daal_defines.h:117
daal::step2Master
Definition: daal_defines.h:118
daal::algorithms::covariance::interface1::Distributed
Computes correlation or variance-covariance matrix in the distributed processing mode.
Definition: covariance_distributed.h:398
daal::algorithms::covariance::interface1::DistributedIface< step1Local >
Interface for correlation or variance-covariance matrix computation algorithms in the distributed pro...
Definition: covariance_distributed.h:175
daal::algorithms::covariance::defaultDense
Definition: covariance_types.h:48
daal::algorithms::covariance::interface1::DistributedIface< step1Local >::DistributedIface
DistributedIface(const DistributedIface< step1Local > &other)
Definition: covariance_distributed.h:196
daal::algorithms::covariance::interface1::DistributedInput< step2Master >
Input parameters of the distributed Covariance algorithm. Represents inputs of the algorithm on maste...
Definition: covariance_types.h:393
daal::algorithms::covariance::interface1::DistributedIface< step2Master >::checkFinalizeComputeParams
services::Status checkFinalizeComputeParams() DAAL_C11_OVERRIDE
Definition: covariance_distributed.h:317
daal::algorithms::covariance::interface1::DistributedInput< step2Master >::get
data_management::DataCollectionPtr get(MasterInputId id) const
daal::services::ErrorNullResult
Definition: error_indexes.h:96
daal::algorithms::covariance::interface1::Distributed< step2Master, algorithmFPType, method >::Distributed
Distributed(const Distributed< step2Master, algorithmFPType, method > &other)
Definition: covariance_distributed.h:510

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