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

covariance_distributed.h
1 /* file: covariance_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 correlation or variance-covariance
45 // matrix algorithm in the distributed processing mode
46 //--
47 */
48 
49 #ifndef __COVARIANCE_DISTRIBUTED_H__
50 #define __COVARIANCE_DISTRIBUTED_H__
51 
52 #include "algorithms/algorithm.h"
53 #include "data_management/data/numeric_table.h"
54 #include "services/daal_defines.h"
55 #include "algorithms/covariance/covariance_types.h"
56 #include "algorithms/covariance/covariance_online.h"
57 
58 namespace daal
59 {
60 namespace algorithms
61 {
62 namespace covariance
63 {
64 
65 namespace interface1
66 {
80 template<ComputeStep step>
81 class DistributedContainerIface
82 {};
83 
92 template<>
93 class DistributedContainerIface<step2Master> : public daal::algorithms::AnalysisContainerIface<distributed>
94 {
95 public:
96  DistributedContainerIface() {};
97  virtual ~DistributedContainerIface() {};
98 
103  virtual services::Status compute() = 0;
108  virtual services::Status finalizeCompute() = 0;
109 };
110 
121 template<ComputeStep step, typename algorithmFPType, Method method, CpuType cpu>
122 class DAAL_EXPORT DistributedContainer
123 {};
124 
130 template<typename algorithmFPType, Method method, CpuType cpu>
131 class DAAL_EXPORT DistributedContainer<step2Master, algorithmFPType, method, cpu> : public DistributedContainerIface<step2Master>
132 {
133 public:
139  DistributedContainer(daal::services::Environment::env *daalEnv);
141  virtual ~DistributedContainer();
146  virtual services::Status compute() DAAL_C11_OVERRIDE;
151  virtual services::Status finalizeCompute() DAAL_C11_OVERRIDE;
152 };
153 
175 template<ComputeStep step>
176 class DAAL_EXPORT DistributedIface : public daal::algorithms::Analysis<distributed>
177 {};
178 
200 template<>
201 class DistributedIface<step1Local> : public OnlineImpl
202 {
203 public:
205  DistributedIface() : OnlineImpl()
206  {}
207 
215  DistributedIface(const DistributedIface<step1Local> &other) : OnlineImpl(other)
216  {}
217 
224  services::SharedPtr<DistributedIface<step1Local> > clone() const
225  {
226  return services::SharedPtr<DistributedIface<step1Local> >(cloneImpl());
227  }
228 
229 protected:
230  virtual DistributedIface<step1Local> * cloneImpl() const DAAL_C11_OVERRIDE = 0;
231 };
232 
254 template<>
255 class DAAL_EXPORT DistributedIface<step2Master> : public daal::algorithms::Analysis<distributed>
256 {
257 public:
259  DistributedIface()
260  {
261  initialize();
262  };
263 
271  DistributedIface(const DistributedIface<step2Master> &other) : parameter(other.parameter)
272  {
273  initialize();
274  data_management::DataCollectionPtr collection = other.input.get(partialResults);
275  for (size_t i = 0; i < collection->size(); i++)
276  {
277  input.add(partialResults,
278  services::staticPointerCast<PartialResult, data_management::SerializationIface>((*collection)[i]));
279  }
280  }
281 
282  virtual ~DistributedIface() {}
283 
288  ResultPtr getResult()
289  {
290  return _result;
291  }
292 
297  virtual services::Status setResult(const ResultPtr &result)
298  {
299  DAAL_CHECK(result, services::ErrorNullResult)
300  _result = result;
301  _res = _result.get();
302  return services::Status();
303  }
304 
309  PartialResultPtr getPartialResult()
310  {
311  return _partialResult;
312  }
313 
319  virtual services::Status setPartialResult(const PartialResultPtr &partialResult, bool initFlag = false)
320  {
321  DAAL_CHECK(partialResult, services::ErrorNullPartialResult);
322  _partialResult = partialResult;
323  _pres = _partialResult.get();
324  setInitFlag(initFlag);
325  return services::Status();
326  }
327 
331  services::Status checkFinalizeComputeParams() DAAL_C11_OVERRIDE
332  {
333  services::Status s;
334  if(this->_partialResult)
335  {
336  s |= this->_partialResult->check(this->_par, getMethod());
337  if (!s) return s;
338  }
339  else
340  {
341  return services::Status(services::ErrorNullResult);
342  }
343 
344  if(this->_result)
345  {
346  s |= this->_result->check(this->_pres, this->_par, getMethod());
347  if (!s) return s;
348  }
349  else
350  {
351  return services::Status(services::ErrorNullResult);
352  }
353  return s;
354  }
355 
362  services::SharedPtr<DistributedIface<step2Master> > clone() const
363  {
364  return services::SharedPtr<DistributedIface<step2Master> >(cloneImpl());
365  }
366 
367  DistributedInput<step2Master> input;
368  Parameter parameter;
370 protected:
371  virtual services::Status initializePartialResult() DAAL_C11_OVERRIDE
372  {
373  return services::Status();
374  }
375 
376  void initialize()
377  {
378  _in = &input;
379  _par = &parameter;
380  _result.reset(new Result());
381  _partialResult.reset(new PartialResult());
382  }
383 
384  virtual DistributedIface<step2Master> * cloneImpl() const DAAL_C11_OVERRIDE = 0;
385 
386  PartialResultPtr _partialResult;
387  ResultPtr _result;
388 };
389 
411 template<ComputeStep step, typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = defaultDense>
412 class DAAL_EXPORT Distributed : public DistributedIface<step>
413 {};
414 
436 template<typename algorithmFPType, Method method>
437 class DAAL_EXPORT Distributed<step1Local, algorithmFPType, method> : public Online<algorithmFPType, method>
438 {
439 public:
440  Distributed<step1Local, algorithmFPType, method>() : Online<algorithmFPType, method>()
441  {}
442 
450  Distributed(const Distributed<step1Local, algorithmFPType, method> &other) :
451  Online<algorithmFPType, method>(other)
452  {}
453 
460  services::SharedPtr<Distributed<step1Local, algorithmFPType, method> > clone() const
461  {
462  return services::SharedPtr<Distributed<step1Local, algorithmFPType, method> >(cloneImpl());
463  }
464 
465 protected:
466  virtual Distributed<step1Local, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
467  {
468  return new Distributed<step1Local, algorithmFPType, method>(*this);
469  }
470 };
471 
493 template<typename algorithmFPType, Method method>
494 class DAAL_EXPORT Distributed<step2Master, algorithmFPType, method> : public DistributedIface<step2Master>
495 {
496 public:
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:297
daal::algorithms::covariance::interface1::DistributedIface< step2Master >::parameter
Parameter parameter
Definition: covariance_distributed.h:368
daal::algorithms::covariance::interface1::DistributedIface< step2Master >
Interface for correlation or variance-covariance matrix computation algorithms in the distributed pro...
Definition: covariance_distributed.h:255
daal::algorithms::covariance::interface1::DistributedIface< step2Master >::DistributedIface
DistributedIface(const DistributedIface< step2Master > &other)
Definition: covariance_distributed.h:271
daal
Definition: algorithm_base_common.h:57
daal::algorithms::AnalysisContainerIface
Abstract interface class that provides virtual methods to access and run implementations of the analy...
Definition: analysis.h:79
daal::algorithms::covariance::interface1::Distributed< step1Local, algorithmFPType, method >::clone
services::SharedPtr< Distributed< step1Local, algorithmFPType, method > > clone() const
Definition: covariance_distributed.h:460
daal::algorithms::covariance::interface1::Distributed< step1Local, algorithmFPType, method >::Distributed
Distributed(const Distributed< step1Local, algorithmFPType, method > &other)
Definition: covariance_distributed.h:450
daal::services::ErrorNullPartialResult
Definition: error_indexes.h:131
daal::algorithms::covariance::interface1::Parameter
Parameters of the correlation or variance-covariance matrix algorithm.
Definition: covariance_types.h:284
daal::algorithms::covariance::interface1::DistributedIface< step2Master >::clone
services::SharedPtr< DistributedIface< step2Master > > clone() const
Definition: covariance_distributed.h:362
daal::ComputeStep
ComputeStep
Definition: daal_defines.h:140
daal::algorithms::covariance::interface1::OnlineImpl
Abstract class that specifies interface of the algorithms for computing correlation or variance-covar...
Definition: covariance_online.h:313
daal::algorithms::covariance::interface1::DistributedIface< step1Local >::clone
services::SharedPtr< DistributedIface< step1Local > > clone() const
Definition: covariance_distributed.h:224
daal::algorithms::covariance::Method
Method
Definition: covariance_types.h:72
daal::algorithms::covariance::interface1::Online
Computes correlation or variance-covariance matrix in the online processing mode. ...
Definition: covariance_online.h:431
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:494
daal::algorithms::covariance::interface1::DistributedContainer
Provides methods to run implementations of the correlation or variance-covariance matrix algorithm in...
Definition: covariance_distributed.h:122
daal::algorithms::covariance::interface1::DistributedIface
Interface for the correlation or variance-covariance matrix algorithm in the distributed processing m...
Definition: covariance_distributed.h:176
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:281
daal::distributed
Definition: daal_defines.h:132
daal::algorithms::covariance::interface1::DistributedIface< step2Master >::input
DistributedInput< step2Master > input
Definition: covariance_distributed.h:367
daal::algorithms::covariance::interface1::Distributed< step2Master, algorithmFPType, method >::Distributed
Distributed()
Definition: covariance_distributed.h:498
daal::algorithms::covariance::interface1::Result
Provides methods to access final results obtained with the compute() method of the correlation or var...
Definition: covariance_types.h:317
daal::algorithms::covariance::partialResults
Definition: covariance_types.h:136
daal::algorithms::covariance::interface1::DistributedIface< step2Master >::setPartialResult
virtual services::Status setPartialResult(const PartialResultPtr &partialResult, bool initFlag=false)
Definition: covariance_distributed.h:319
daal::algorithms::covariance::interface1::PartialResult
Provides methods to access partial results obtained with the compute() method of the correlation or v...
Definition: covariance_types.h:204
daal::algorithms::covariance::interface1::DistributedIface< step2Master >::getPartialResult
PartialResultPtr getPartialResult()
Definition: covariance_distributed.h:309
daal::algorithms::covariance::interface1::DistributedIface< step1Local >::DistributedIface
DistributedIface()
Definition: covariance_distributed.h:205
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:437
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:81
daal::algorithms::covariance::interface1::DistributedIface< step2Master >::getResult
ResultPtr getResult()
Definition: covariance_distributed.h:288
daal::algorithms::covariance::interface1::DistributedIface< step2Master >::DistributedIface
DistributedIface()
Definition: covariance_distributed.h:259
daal::algorithms::Analysis
Provides methods for execution of operations over data, such as computation of Summary Statistics est...
Definition: analysis.h:94
daal::algorithms::covariance::covariance
Definition: covariance_types.h:114
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::step2Master
Definition: daal_defines.h:143
daal::algorithms::covariance::interface1::Distributed
Computes correlation or variance-covariance matrix in the distributed processing mode.
Definition: covariance_distributed.h:412
daal::algorithms::covariance::interface1::DistributedIface< step1Local >
Interface for correlation or variance-covariance matrix computation algorithms in the distributed pro...
Definition: covariance_distributed.h:201
daal::algorithms::covariance::defaultDense
Definition: covariance_types.h:74
daal::algorithms::covariance::interface1::DistributedIface< step1Local >::DistributedIface
DistributedIface(const DistributedIface< step1Local > &other)
Definition: covariance_distributed.h:215
daal::algorithms::covariance::interface1::DistributedInput< step2Master >
Input parameters of the distributed Covariance algorithm. Represents inputs of the algorithm on maste...
Definition: covariance_types.h:419
daal::algorithms::covariance::interface1::DistributedIface< step2Master >::checkFinalizeComputeParams
services::Status checkFinalizeComputeParams() DAAL_C11_OVERRIDE
Definition: covariance_distributed.h:331
daal::algorithms::covariance::interface1::DistributedInput< step2Master >::get
data_management::DataCollectionPtr get(MasterInputId id) const
daal::services::ErrorNullResult
Definition: error_indexes.h:122
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.