25 #ifndef __KMEANS_DISTRIBITED_H__
26 #define __KMEANS_DISTRIBITED_H__
28 #include "algorithms/algorithm.h"
29 #include "data_management/data/numeric_table.h"
30 #include "services/daal_defines.h"
31 #include "algorithms/kmeans/kmeans_types.h"
56 template<ComputeStep step,
typename algorithmFPType, Method method, CpuType cpu>
57 class DistributedContainer;
63 template<
typename algorithmFPType, Method method, CpuType cpu>
64 class DistributedContainer<step1Local, algorithmFPType, method, cpu> :
public
65 daal::algorithms::AnalysisContainerIface<distributed>
73 DistributedContainer(daal::services::Environment::env *daalEnv);
75 virtual ~DistributedContainer();
80 virtual services::Status compute() DAAL_C11_OVERRIDE;
85 virtual services::Status finalizeCompute() DAAL_C11_OVERRIDE;
92 template<
typename algorithmFPType, Method method, CpuType cpu>
93 class DistributedContainer<step2Master, algorithmFPType, method, cpu> :
public
94 daal::algorithms::AnalysisContainerIface<distributed>
102 DistributedContainer(daal::services::Environment::env *daalEnv);
104 virtual ~DistributedContainer();
109 virtual services::Status compute() DAAL_C11_OVERRIDE;
114 virtual services::Status finalizeCompute() DAAL_C11_OVERRIDE;
134 template<ComputeStep step,
typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = lloydDense>
135 class DAAL_EXPORT Distributed {};
150 template<
typename algorithmFPType, Method method>
151 class DAAL_EXPORT Distributed<step1Local, algorithmFPType, method> :
public daal::algorithms::Analysis<distributed>
154 typedef algorithms::kmeans::Input InputType;
155 typedef algorithms::kmeans::Parameter ParameterType;
156 typedef algorithms::kmeans::Result ResultType;
157 typedef algorithms::kmeans::PartialResult PartialResultType;
164 Distributed(
size_t nClusters,
bool assignFlag =
false) : parameter(nClusters, 1)
167 parameter.assignFlag = assignFlag;
176 Distributed(
const Distributed<step1Local, algorithmFPType, method> &other) : parameter(other.parameter)
179 input.set(data, other.input.get(data));
180 input.set(inputCentroids, other.input.get(inputCentroids));
187 virtual int getMethod() const DAAL_C11_OVERRIDE {
return(
int) method; }
193 ResultPtr getResult()
202 services::Status setResult(
const ResultPtr& result)
204 DAAL_CHECK(result, services::ErrorNullResult)
206 _res = _result.get();
207 return services::Status();
214 PartialResultPtr getPartialResult()
216 return _partialResult;
222 services::Status setPartialResult(
const PartialResultPtr& partialRes)
224 DAAL_CHECK(partialRes, services::ErrorNullPartialResult);
225 _partialResult = partialRes;
226 _pres = _partialResult.get();
227 return services::Status();
233 services::Status checkFinalizeComputeParams() DAAL_C11_OVERRIDE
235 return services::Status();
243 services::SharedPtr<Distributed<step1Local, algorithmFPType, method> > clone()
const
245 return services::SharedPtr<Distributed<step1Local, algorithmFPType, method> >(cloneImpl());
249 virtual Distributed<step1Local, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
251 return new Distributed<step1Local, algorithmFPType, method>(*this);
254 virtual services::Status allocateResult() DAAL_C11_OVERRIDE
256 _result.reset(
new ResultType());
257 services::Status s = _result->allocate<algorithmFPType>(_in, _par, (int) method);
258 _res = _result.get();
262 virtual services::Status allocatePartialResult() DAAL_C11_OVERRIDE
264 _partialResult.reset(
new PartialResultType());
265 services::Status s = _partialResult->allocate<algorithmFPType>(&input, _par, (int) method);
266 _pres = _partialResult.get();
270 virtual services::Status initializePartialResult() DAAL_C11_OVERRIDE
272 return services::Status();
277 Analysis<distributed>::_ac =
new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step1Local, algorithmFPType, method)(&_env);
284 ParameterType parameter;
287 PartialResultPtr _partialResult;
307 template<
typename algorithmFPType, Method method>
308 class DAAL_EXPORT Distributed<step2Master, algorithmFPType, method>:
public daal::algorithms::Analysis<distributed>
311 typedef algorithms::kmeans::DistributedStep2MasterInput InputType;
312 typedef algorithms::kmeans::Parameter ParameterType;
313 typedef algorithms::kmeans::Result ResultType;
314 typedef algorithms::kmeans::PartialResult PartialResultType;
321 Distributed(
size_t nClusters,
size_t nIterations = 1) : parameter(nClusters, nIterations)
324 parameter.assignFlag =
false;
333 Distributed(
const Distributed<step2Master, algorithmFPType, method> &other) : parameter(other.parameter)
336 input.set(partialResults, other.input.get(partialResults));
343 virtual int getMethod() const DAAL_C11_OVERRIDE {
return(
int) method; }
349 ResultPtr getResult()
358 services::Status setResult(
const ResultPtr& result)
360 DAAL_CHECK(result, services::ErrorNullResult)
362 _res = _result.get();
363 return services::Status();
370 PartialResultPtr getPartialResult()
372 return _partialResult;
378 services::Status setPartialResult(
const PartialResultPtr& partialRes)
380 DAAL_CHECK(partialRes, services::ErrorNullPartialResult);
381 _partialResult = partialRes;
382 _pres = _partialResult.get();
383 return services::Status();
389 services::Status checkFinalizeComputeParams() DAAL_C11_OVERRIDE
394 s |= _partialResult->check(_par, method);
395 if (!s) {
return s; }
399 return services::Status(services::ErrorNullResult);
404 s |= _result->check(_partialResult.get(), _par, method);
408 return services::Status(services::ErrorNullResult);
418 services::SharedPtr<Distributed<step2Master, algorithmFPType, method> > clone()
const
420 return services::SharedPtr<Distributed<step2Master, algorithmFPType, method> >(cloneImpl());
424 virtual Distributed<step2Master, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
426 return new Distributed<step2Master, algorithmFPType, method>(*this);
429 virtual services::Status allocateResult() DAAL_C11_OVERRIDE
431 _result.reset(
new ResultType());
432 services::Status s = _result->allocate<algorithmFPType>(_pres, _par, (int) method);
433 _res = _result.get();
437 virtual services::Status allocatePartialResult() DAAL_C11_OVERRIDE
439 _partialResult.reset(
new PartialResultType());
440 services::Status s = _partialResult->allocate<algorithmFPType>(&input, _par, (int) method);
441 _pres = _partialResult.get();
445 virtual services::Status initializePartialResult() DAAL_C11_OVERRIDE
447 return services::Status();
452 Analysis<distributed>::_ac =
new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step2Master, algorithmFPType, method)(&_env);
459 ParameterType parameter;
462 PartialResultPtr _partialResult;
467 using interface1::DistributedContainer;
468 using interface1::Distributed;
daal::step1Local
Definition: daal_defines.h:123
daal::algorithms::kmeans::interface1::Distributed< step2Master, algorithmFPType, method >::clone
services::SharedPtr< Distributed< step2Master, algorithmFPType, method > > clone() const
Definition: kmeans_distributed.h:418
daal::algorithms::kmeans::interface1::Distributed< step2Master, algorithmFPType, method >
Computes the results of K-Means algorithm in the second step of the distributed processing mode...
Definition: kmeans_distributed.h:308
daal::algorithms::kmeans::interface1::Distributed< step1Local, algorithmFPType, method >
Computes the results of K-Means algorithm in the first step of the distributed processing mode...
Definition: kmeans_distributed.h:151
daal::algorithms::kmeans::nIterations
Definition: kmeans_types.h:113
daal::algorithms::kmeans::interface1::Distributed< step2Master, algorithmFPType, method >::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: kmeans_distributed.h:343
daal::algorithms::kmeans::interface1::Distributed< step2Master, algorithmFPType, method >::input
InputType input
Definition: kmeans_distributed.h:458
daal::algorithms::kmeans::interface1::Distributed< step2Master, algorithmFPType, method >::Distributed
Distributed(size_t nClusters, size_t nIterations=1)
Definition: kmeans_distributed.h:321
daal::step2Master
Definition: daal_defines.h:124
daal::algorithms::kmeans::interface1::Distributed< step2Master, algorithmFPType, method >::setPartialResult
services::Status setPartialResult(const PartialResultPtr &partialRes)
Definition: kmeans_distributed.h:378
daal::algorithms::kmeans::data
Definition: kmeans_types.h:72
daal::algorithms::kmeans::interface1::Distributed< step2Master, algorithmFPType, method >::checkFinalizeComputeParams
services::Status checkFinalizeComputeParams() DAAL_C11_OVERRIDE
Definition: kmeans_distributed.h:389
daal::algorithms::kmeans::interface1::Distributed< step1Local, algorithmFPType, method >::parameter
ParameterType parameter
Definition: kmeans_distributed.h:284
daal::services::ErrorNullResult
Definition: error_indexes.h:98
daal::algorithms::kmeans::interface1::DistributedContainer
Provides methods to run implementations of K-Means algorithm. This class is associated with the daal:...
Definition: kmeans_distributed.h:57
daal::algorithms::AnalysisContainerIface
Abstract interface class that provides virtual methods to access and run implementations of the analy...
Definition: analysis.h:55
daal::algorithms::kmeans::interface1::Distributed< step2Master, algorithmFPType, method >::setResult
services::Status setResult(const ResultPtr &result)
Definition: kmeans_distributed.h:358
daal::algorithms::kmeans::init::interface2::Distributed
class DAAL_EXPORT Distributed
Computes initial clusters for K-Means algorithm in the distributed processing mode.
Definition: kmeans_init_distributed.h:277
daal::algorithms::kmeans::interface1::Distributed< step2Master, algorithmFPType, method >::getResult
ResultPtr getResult()
Definition: kmeans_distributed.h:349
daal::algorithms::kmeans::interface1::Distributed< step1Local, algorithmFPType, method >::setPartialResult
services::Status setPartialResult(const PartialResultPtr &partialRes)
Definition: kmeans_distributed.h:222
daal::algorithms::kmeans::interface1::Distributed< step1Local, algorithmFPType, method >::Distributed
Distributed(const Distributed< step1Local, algorithmFPType, method > &other)
Definition: kmeans_distributed.h:176
daal::algorithms::kmeans::interface1::Distributed< step1Local, algorithmFPType, method >::clone
services::SharedPtr< Distributed< step1Local, algorithmFPType, method > > clone() const
Definition: kmeans_distributed.h:243
daal::algorithms::kmeans::partialResults
Definition: kmeans_types.h:83
daal::algorithms::kmeans::interface1::Distributed< step2Master, algorithmFPType, method >::Distributed
Distributed(const Distributed< step2Master, algorithmFPType, method > &other)
Definition: kmeans_distributed.h:333
daal::algorithms::kmeans::interface1::Distributed< step2Master, algorithmFPType, method >::getPartialResult
PartialResultPtr getPartialResult()
Definition: kmeans_distributed.h:370
daal::algorithms::kmeans::interface1::Distributed< step1Local, algorithmFPType, method >::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: kmeans_distributed.h:187
daal::algorithms::kmeans::interface1::Distributed< step1Local, algorithmFPType, method >::getPartialResult
PartialResultPtr getPartialResult()
Definition: kmeans_distributed.h:214
daal::algorithms::kmeans::inputCentroids
Definition: kmeans_types.h:73
daal::algorithms::kmeans::interface1::Distributed< step1Local, algorithmFPType, method >::input
InputType input
Definition: kmeans_distributed.h:283
daal::algorithms::kmeans::interface1::Distributed< step1Local, algorithmFPType, method >::getResult
ResultPtr getResult()
Definition: kmeans_distributed.h:193
daal::algorithms::kmeans::interface1::Distributed< step1Local, algorithmFPType, method >::Distributed
Distributed(size_t nClusters, bool assignFlag=false)
Definition: kmeans_distributed.h:164
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::distributed
Definition: daal_defines.h:113
daal::algorithms::kmeans::interface1::Distributed< step2Master, algorithmFPType, method >::parameter
ParameterType parameter
Definition: kmeans_distributed.h:459
daal::algorithms::kmeans::interface1::Distributed< step1Local, algorithmFPType, method >::checkFinalizeComputeParams
services::Status checkFinalizeComputeParams() DAAL_C11_OVERRIDE
Definition: kmeans_distributed.h:233
daal::algorithms::kmeans::interface1::Distributed
Computes the results of K-Means algorithm in the distributed processing mode.
Definition: kmeans_distributed.h:135
daal::algorithms::kmeans::interface1::Distributed< step1Local, algorithmFPType, method >::setResult
services::Status setResult(const ResultPtr &result)
Definition: kmeans_distributed.h:202