23 #ifndef __KMEANS_DISTRIBITED_H__
24 #define __KMEANS_DISTRIBITED_H__
26 #include "algorithms/algorithm.h"
27 #include "data_management/data/numeric_table.h"
28 #include "services/daal_defines.h"
29 #include "algorithms/kmeans/kmeans_types.h"
54 template<ComputeStep step,
typename algorithmFPType, Method method, CpuType cpu>
55 class DAAL_EXPORT DistributedContainer;
61 template<
typename algorithmFPType, Method method, CpuType cpu>
62 class DAAL_EXPORT DistributedContainer<step1Local, algorithmFPType, method, cpu> :
public
63 daal::algorithms::AnalysisContainerIface<distributed>
71 DistributedContainer(daal::services::Environment::env *daalEnv);
73 virtual ~DistributedContainer();
78 virtual services::Status compute() DAAL_C11_OVERRIDE;
83 virtual services::Status finalizeCompute() DAAL_C11_OVERRIDE;
90 template<
typename algorithmFPType, Method method, CpuType cpu>
91 class DAAL_EXPORT DistributedContainer<step2Master, algorithmFPType, method, cpu> :
public
92 daal::algorithms::AnalysisContainerIface<distributed>
100 DistributedContainer(daal::services::Environment::env *daalEnv);
102 virtual ~DistributedContainer();
107 virtual services::Status compute() DAAL_C11_OVERRIDE;
112 virtual services::Status finalizeCompute() DAAL_C11_OVERRIDE;
132 template<ComputeStep step,
typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = lloydDense>
133 class DAAL_EXPORT Distributed {};
148 template<
typename algorithmFPType, Method method>
149 class DAAL_EXPORT Distributed<step1Local, algorithmFPType, method> :
public daal::algorithms::Analysis<distributed>
152 typedef algorithms::kmeans::Input InputType;
153 typedef algorithms::kmeans::Parameter ParameterType;
154 typedef algorithms::kmeans::Result ResultType;
155 typedef algorithms::kmeans::PartialResult PartialResultType;
162 Distributed(
size_t nClusters,
bool assignFlag =
false) : parameter(nClusters, 1)
165 parameter.assignFlag = assignFlag;
174 Distributed(
const Distributed<step1Local, algorithmFPType, method> &other) : parameter(other.parameter)
177 input.set(data, other.input.get(data));
178 input.set(inputCentroids, other.input.get(inputCentroids));
185 virtual int getMethod() const DAAL_C11_OVERRIDE {
return(
int) method; }
191 ResultPtr getResult()
200 services::Status setResult(
const ResultPtr& result)
202 DAAL_CHECK(result, services::ErrorNullResult)
204 _res = _result.get();
205 return services::Status();
212 PartialResultPtr getPartialResult()
214 return _partialResult;
220 services::Status setPartialResult(
const PartialResultPtr& partialRes)
222 DAAL_CHECK(partialRes, services::ErrorNullPartialResult);
223 _partialResult = partialRes;
224 _pres = _partialResult.get();
225 return services::Status();
231 services::Status checkFinalizeComputeParams() DAAL_C11_OVERRIDE
233 return services::Status();
241 services::SharedPtr<Distributed<step1Local, algorithmFPType, method> > clone()
const
243 return services::SharedPtr<Distributed<step1Local, algorithmFPType, method> >(cloneImpl());
247 virtual Distributed<step1Local, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
249 return new Distributed<step1Local, algorithmFPType, method>(*this);
252 virtual services::Status allocateResult() DAAL_C11_OVERRIDE
254 _result.reset(
new ResultType());
255 services::Status s = _result->allocate<algorithmFPType>(_in, _par, (int) method);
256 _res = _result.get();
260 virtual services::Status allocatePartialResult() DAAL_C11_OVERRIDE
262 _partialResult.reset(
new PartialResultType());
263 services::Status s = _partialResult->allocate<algorithmFPType>(&input, _par, (int) method);
264 _pres = _partialResult.get();
268 virtual services::Status initializePartialResult() DAAL_C11_OVERRIDE
270 return services::Status();
275 Analysis<distributed>::_ac =
new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step1Local, algorithmFPType, method)(&_env);
282 ParameterType parameter;
285 PartialResultPtr _partialResult;
305 template<
typename algorithmFPType, Method method>
306 class DAAL_EXPORT Distributed<step2Master, algorithmFPType, method>:
public daal::algorithms::Analysis<distributed>
309 typedef algorithms::kmeans::DistributedStep2MasterInput InputType;
310 typedef algorithms::kmeans::Parameter ParameterType;
311 typedef algorithms::kmeans::Result ResultType;
312 typedef algorithms::kmeans::PartialResult PartialResultType;
319 Distributed(
size_t nClusters,
size_t nIterations = 1) : parameter(nClusters, nIterations)
322 parameter.assignFlag =
false;
331 Distributed(
const Distributed<step2Master, algorithmFPType, method> &other) : parameter(other.parameter)
334 input.set(partialResults, other.input.get(partialResults));
341 virtual int getMethod() const DAAL_C11_OVERRIDE {
return(
int) method; }
347 ResultPtr getResult()
356 services::Status setResult(
const ResultPtr& result)
358 DAAL_CHECK(result, services::ErrorNullResult)
360 _res = _result.get();
361 return services::Status();
368 PartialResultPtr getPartialResult()
370 return _partialResult;
376 services::Status setPartialResult(
const PartialResultPtr& partialRes)
378 DAAL_CHECK(partialRes, services::ErrorNullPartialResult);
379 _partialResult = partialRes;
380 _pres = _partialResult.get();
381 return services::Status();
387 services::Status checkFinalizeComputeParams() DAAL_C11_OVERRIDE
392 s |= _partialResult->check(_par, method);
393 if (!s) {
return s; }
397 return services::Status(services::ErrorNullResult);
402 s |= _result->check(_partialResult.get(), _par, method);
406 return services::Status(services::ErrorNullResult);
416 services::SharedPtr<Distributed<step2Master, algorithmFPType, method> > clone()
const
418 return services::SharedPtr<Distributed<step2Master, algorithmFPType, method> >(cloneImpl());
422 virtual Distributed<step2Master, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
424 return new Distributed<step2Master, algorithmFPType, method>(*this);
427 virtual services::Status allocateResult() DAAL_C11_OVERRIDE
429 _result.reset(
new ResultType());
430 services::Status s = _result->allocate<algorithmFPType>(_pres, _par, (int) method);
431 _res = _result.get();
435 virtual services::Status allocatePartialResult() DAAL_C11_OVERRIDE
437 _partialResult.reset(
new PartialResultType());
438 services::Status s = _partialResult->allocate<algorithmFPType>(&input, _par, (int) method);
439 _pres = _partialResult.get();
443 virtual services::Status initializePartialResult() DAAL_C11_OVERRIDE
445 return services::Status();
450 Analysis<distributed>::_ac =
new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step2Master, algorithmFPType, method)(&_env);
457 ParameterType parameter;
460 PartialResultPtr _partialResult;
465 using interface1::DistributedContainer;
466 using interface1::Distributed;
daal::algorithms::kmeans::interface1::Distributed
Computes the results of the K-Means algorithm in the distributed processing mode. ...
Definition: kmeans_distributed.h:133
daal::algorithms::kmeans::interface1::Distributed< step1Local, algorithmFPType, method >::Distributed
Distributed(const Distributed< step1Local, algorithmFPType, method > &other)
Definition: kmeans_distributed.h:174
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::kmeans::interface1::Distributed< step1Local, algorithmFPType, method >::setResult
services::Status setResult(const ResultPtr &result)
Definition: kmeans_distributed.h:200
daal::algorithms::kmeans::interface1::Distributed< step1Local, algorithmFPType, method >::getPartialResult
PartialResultPtr getPartialResult()
Definition: kmeans_distributed.h:212
daal::algorithms::kmeans::interface1::Distributed< step1Local, algorithmFPType, method >::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: kmeans_distributed.h:185
daal::algorithms::kmeans::interface1::Distributed< step2Master, algorithmFPType, method >::input
InputType input
Definition: kmeans_distributed.h:456
daal::services::ErrorNullPartialResult
Definition: error_indexes.h:105
daal::algorithms::kmeans::interface1::Distributed< step1Local, algorithmFPType, method >::getResult
ResultPtr getResult()
Definition: kmeans_distributed.h:191
daal::algorithms::kmeans::nIterations
Definition: kmeans_types.h:111
daal::algorithms::kmeans::interface1::Distributed< step2Master, algorithmFPType, method >::getPartialResult
PartialResultPtr getPartialResult()
Definition: kmeans_distributed.h:368
daal::algorithms::kmeans::inputCentroids
Definition: kmeans_types.h:71
daal::algorithms::kmeans::interface1::Distributed< step2Master, algorithmFPType, method >::setPartialResult
services::Status setPartialResult(const PartialResultPtr &partialRes)
Definition: kmeans_distributed.h:376
daal::algorithms::kmeans::interface1::Distributed< step2Master, algorithmFPType, method >::getResult
ResultPtr getResult()
Definition: kmeans_distributed.h:347
daal::algorithms::kmeans::init::interface2::Distributed
class DAAL_EXPORT Distributed
Computes initial clusters for the K-Means algorithm in the distributed processing mode...
Definition: kmeans_init_distributed.h:275
daal::distributed
Definition: daal_defines.h:111
daal::algorithms::kmeans::interface1::Distributed< step2Master, algorithmFPType, method >::clone
services::SharedPtr< Distributed< step2Master, algorithmFPType, method > > clone() const
Definition: kmeans_distributed.h:416
daal::algorithms::kmeans::data
Definition: kmeans_types.h:70
daal::algorithms::kmeans::interface1::Distributed< step1Local, algorithmFPType, method >::clone
services::SharedPtr< Distributed< step1Local, algorithmFPType, method > > clone() const
Definition: kmeans_distributed.h:241
daal::algorithms::kmeans::interface1::Distributed< step2Master, algorithmFPType, method >::checkFinalizeComputeParams
services::Status checkFinalizeComputeParams() DAAL_C11_OVERRIDE
Definition: kmeans_distributed.h:387
daal::algorithms::kmeans::interface1::Distributed< step2Master, algorithmFPType, method >::Distributed
Distributed(const Distributed< step2Master, algorithmFPType, method > &other)
Definition: kmeans_distributed.h:331
daal::algorithms::kmeans::interface1::Distributed< step1Local, algorithmFPType, method >::parameter
ParameterType parameter
Definition: kmeans_distributed.h:282
daal::algorithms::Analysis
Provides methods for execution of operations over data, such as computation of Summary Statistics est...
Definition: analysis.h:68
daal::algorithms::kmeans::interface1::Distributed< step2Master, algorithmFPType, method >::parameter
ParameterType parameter
Definition: kmeans_distributed.h:457
daal::algorithms::kmeans::partialResults
Definition: kmeans_types.h:81
daal::algorithms::kmeans::interface1::Distributed< step1Local, algorithmFPType, method >::checkFinalizeComputeParams
services::Status checkFinalizeComputeParams() DAAL_C11_OVERRIDE
Definition: kmeans_distributed.h:231
daal::algorithms::kmeans::interface1::Distributed< step2Master, algorithmFPType, method >
Computes the results of the K-Means algorithm in the second step of the distributed processing mode...
Definition: kmeans_distributed.h:306
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::algorithms::kmeans::interface1::Distributed< step1Local, algorithmFPType, method >::input
InputType input
Definition: kmeans_distributed.h:281
daal::step1Local
Definition: daal_defines.h:121
daal::algorithms::dbscan::nClusters
Definition: dbscan_types.h:94
daal::algorithms::kmeans::interface1::Distributed< step2Master, algorithmFPType, method >::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: kmeans_distributed.h:341
daal::step2Master
Definition: daal_defines.h:122
daal::algorithms::kmeans::interface1::Distributed< step2Master, algorithmFPType, method >::setResult
services::Status setResult(const ResultPtr &result)
Definition: kmeans_distributed.h:356
daal::algorithms::kmeans::interface1::Distributed< step1Local, algorithmFPType, method >::Distributed
Distributed(size_t nClusters, bool assignFlag=false)
Definition: kmeans_distributed.h:162
daal::algorithms::kmeans::interface1::Distributed< step1Local, algorithmFPType, method >
Computes the results of the K-Means algorithm in the first step of the distributed processing mode...
Definition: kmeans_distributed.h:149
daal::algorithms::kmeans::interface1::Distributed< step2Master, algorithmFPType, method >::Distributed
Distributed(size_t nClusters, size_t nIterations=1)
Definition: kmeans_distributed.h:319
daal::services::ErrorNullResult
Definition: error_indexes.h:96
daal::algorithms::kmeans::interface1::Distributed< step1Local, algorithmFPType, method >::setPartialResult
services::Status setPartialResult(const PartialResultPtr &partialRes)
Definition: kmeans_distributed.h:220