49 #ifndef __KMEANS_DISTRIBITED_H__
50 #define __KMEANS_DISTRIBITED_H__
52 #include "algorithms/algorithm.h"
53 #include "data_management/data/numeric_table.h"
54 #include "services/daal_defines.h"
55 #include "algorithms/kmeans/kmeans_types.h"
80 template<ComputeStep step,
typename algorithmFPType, Method method, CpuType cpu>
81 class DAAL_EXPORT DistributedContainer;
87 template<
typename algorithmFPType, Method method, CpuType cpu>
88 class DAAL_EXPORT DistributedContainer<step1Local, algorithmFPType, method, cpu> :
public
89 daal::algorithms::AnalysisContainerIface<distributed>
97 DistributedContainer(daal::services::Environment::env *daalEnv);
99 virtual ~DistributedContainer();
104 virtual services::Status compute() DAAL_C11_OVERRIDE;
109 virtual services::Status finalizeCompute() DAAL_C11_OVERRIDE;
116 template<
typename algorithmFPType, Method method, CpuType cpu>
117 class DAAL_EXPORT DistributedContainer<step2Master, algorithmFPType, method, cpu> :
public
118 daal::algorithms::AnalysisContainerIface<distributed>
126 DistributedContainer(daal::services::Environment::env *daalEnv);
128 virtual ~DistributedContainer();
133 virtual services::Status compute() DAAL_C11_OVERRIDE;
138 virtual services::Status finalizeCompute() DAAL_C11_OVERRIDE;
158 template<ComputeStep step,
typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = lloydDense>
159 class DAAL_EXPORT Distributed {};
174 template<
typename algorithmFPType, Method method>
175 class DAAL_EXPORT Distributed<step1Local, algorithmFPType, method> :
public daal::algorithms::Analysis<distributed>
183 Distributed(
size_t nClusters,
bool assignFlag =
false) : parameter(nClusters, 1)
186 parameter.assignFlag = assignFlag;
195 Distributed(
const Distributed<step1Local, algorithmFPType, method> &other) : parameter(other.parameter)
198 input.set(data, other.input.get(data));
199 input.set(inputCentroids, other.input.get(inputCentroids));
206 virtual int getMethod() const DAAL_C11_OVERRIDE {
return(
int) method; }
212 ResultPtr getResult()
221 services::Status setResult(
const ResultPtr& result)
223 DAAL_CHECK(result, services::ErrorNullResult)
225 _res = _result.get();
226 return services::Status();
233 PartialResultPtr getPartialResult()
235 return _partialResult;
241 services::Status setPartialResult(
const PartialResultPtr& partialRes)
243 DAAL_CHECK(partialRes, services::ErrorNullPartialResult);
244 _partialResult = partialRes;
245 _pres = _partialResult.get();
246 return services::Status();
252 services::Status checkFinalizeComputeParams() DAAL_C11_OVERRIDE
254 return services::Status();
262 services::SharedPtr<Distributed<step1Local, algorithmFPType, method> > clone()
const
264 return services::SharedPtr<Distributed<step1Local, algorithmFPType, method> >(cloneImpl());
268 virtual Distributed<step1Local, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
270 return new Distributed<step1Local, algorithmFPType, method>(*this);
273 virtual services::Status allocateResult() DAAL_C11_OVERRIDE
275 _result.reset(
new Result());
276 services::Status s = _result->allocate<algorithmFPType>(_in, _par, (int) method);
277 _res = _result.get();
281 virtual services::Status allocatePartialResult() DAAL_C11_OVERRIDE
283 _partialResult.reset(
new PartialResult());
284 services::Status s = _partialResult->allocate<algorithmFPType>(&input, _par, (int) method);
285 _pres = _partialResult.get();
289 virtual services::Status initializePartialResult() DAAL_C11_OVERRIDE
291 return services::Status();
296 Analysis<distributed>::_ac =
new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step1Local, algorithmFPType, method)(&_env);
306 PartialResultPtr _partialResult;
326 template<
typename algorithmFPType, Method method>
327 class DAAL_EXPORT Distributed<step2Master, algorithmFPType, method>:
public daal::algorithms::Analysis<distributed>
335 Distributed(
size_t nClusters,
size_t nIterations = 1) : parameter(nClusters, nIterations)
338 parameter.assignFlag =
false;
347 Distributed(
const Distributed<step2Master, algorithmFPType, method> &other) : parameter(other.parameter)
350 input.set(partialResults, other.input.get(partialResults));
357 virtual int getMethod() const DAAL_C11_OVERRIDE {
return(
int) method; }
363 ResultPtr getResult()
372 services::Status setResult(
const ResultPtr& result)
374 DAAL_CHECK(result, services::ErrorNullResult)
376 _res = _result.get();
377 return services::Status();
384 PartialResultPtr getPartialResult()
386 return _partialResult;
392 services::Status setPartialResult(
const PartialResultPtr& partialRes)
394 DAAL_CHECK(partialRes, services::ErrorNullPartialResult);
395 _partialResult = partialRes;
396 _pres = _partialResult.get();
397 return services::Status();
403 services::Status checkFinalizeComputeParams() DAAL_C11_OVERRIDE
408 s |= _partialResult->check(_par, method);
409 if (!s) {
return s; }
413 return services::Status(services::ErrorNullResult);
418 s |= _result->check(_partialResult.get(), _par, method);
422 return services::Status(services::ErrorNullResult);
432 services::SharedPtr<Distributed<step2Master, algorithmFPType, method> > clone()
const
434 return services::SharedPtr<Distributed<step2Master, algorithmFPType, method> >(cloneImpl());
438 virtual Distributed<step2Master, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
440 return new Distributed<step2Master, algorithmFPType, method>(*this);
443 virtual services::Status allocateResult() DAAL_C11_OVERRIDE
445 _result.reset(
new Result());
446 services::Status s = _result->allocate<algorithmFPType>(_pres, _par, (int) method);
447 _res = _result.get();
451 virtual services::Status allocatePartialResult() DAAL_C11_OVERRIDE
453 _partialResult.reset(
new PartialResult());
454 services::Status s = _partialResult->allocate<algorithmFPType>(&input, _par, (int) method);
455 _pres = _partialResult.get();
459 virtual services::Status initializePartialResult() DAAL_C11_OVERRIDE
461 return services::Status();
466 Analysis<distributed>::_ac =
new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step2Master, algorithmFPType, method)(&_env);
472 DistributedStep2MasterInput input;
476 PartialResultPtr _partialResult;
481 using interface1::DistributedContainer;
482 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:159
daal::algorithms::kmeans::interface1::Parameter
Parameters for the K-Means algorithm.
Definition: kmeans_types.h:153
daal::algorithms::kmeans::interface1::Distributed< step1Local, algorithmFPType, method >::Distributed
Distributed(const Distributed< step1Local, algorithmFPType, method > &other)
Definition: kmeans_distributed.h:195
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::kmeans::interface1::Distributed< step1Local, algorithmFPType, method >::setResult
services::Status setResult(const ResultPtr &result)
Definition: kmeans_distributed.h:221
daal::algorithms::kmeans::interface1::Distributed< step1Local, algorithmFPType, method >::getPartialResult
PartialResultPtr getPartialResult()
Definition: kmeans_distributed.h:233
daal::algorithms::kmeans::interface1::Distributed< step1Local, algorithmFPType, method >::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: kmeans_distributed.h:206
daal::services::ErrorNullPartialResult
Definition: error_indexes.h:131
daal::algorithms::kmeans::interface1::Distributed< step1Local, algorithmFPType, method >::getResult
ResultPtr getResult()
Definition: kmeans_distributed.h:212
daal::algorithms::kmeans::interface1::Distributed< step2Master, algorithmFPType, method >::input
DistributedStep2MasterInput input
Definition: kmeans_distributed.h:472
daal::algorithms::kmeans::nIterations
Definition: kmeans_types.h:135
daal::algorithms::kmeans::interface1::Distributed< step2Master, algorithmFPType, method >::getPartialResult
PartialResultPtr getPartialResult()
Definition: kmeans_distributed.h:384
daal::algorithms::kmeans::inputCentroids
Definition: kmeans_types.h:97
daal::algorithms::kmeans::interface1::Distributed< step2Master, algorithmFPType, method >::setPartialResult
services::Status setPartialResult(const PartialResultPtr &partialRes)
Definition: kmeans_distributed.h:392
daal::algorithms::kmeans::interface1::Distributed< step2Master, algorithmFPType, method >::getResult
ResultPtr getResult()
Definition: kmeans_distributed.h:363
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::kmeans::interface1::Distributed< step2Master, algorithmFPType, method >::clone
services::SharedPtr< Distributed< step2Master, algorithmFPType, method > > clone() const
Definition: kmeans_distributed.h:432
daal::algorithms::kmeans::data
Definition: kmeans_types.h:96
daal::algorithms::kmeans::interface1::Distributed< step1Local, algorithmFPType, method >::clone
services::SharedPtr< Distributed< step1Local, algorithmFPType, method > > clone() const
Definition: kmeans_distributed.h:262
daal::algorithms::kmeans::interface1::Distributed< step1Local, algorithmFPType, method >::parameter
Parameter parameter
Definition: kmeans_distributed.h:303
daal::algorithms::kmeans::interface1::Distributed< step2Master, algorithmFPType, method >::checkFinalizeComputeParams
services::Status checkFinalizeComputeParams() DAAL_C11_OVERRIDE
Definition: kmeans_distributed.h:403
daal::algorithms::kmeans::interface1::Distributed< step2Master, algorithmFPType, method >::Distributed
Distributed(const Distributed< step2Master, algorithmFPType, method > &other)
Definition: kmeans_distributed.h:347
daal::algorithms::Analysis
Provides methods for execution of operations over data, such as computation of Summary Statistics est...
Definition: analysis.h:94
daal::algorithms::kmeans::partialResults
Definition: kmeans_types.h:107
daal::algorithms::kmeans::interface1::Distributed< step1Local, algorithmFPType, method >::checkFinalizeComputeParams
services::Status checkFinalizeComputeParams() DAAL_C11_OVERRIDE
Definition: kmeans_distributed.h:252
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:327
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::algorithms::kmeans::interface1::Distributed< step2Master, algorithmFPType, method >::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: kmeans_distributed.h:357
daal::step2Master
Definition: daal_defines.h:143
daal::algorithms::kmeans::interface1::Distributed< step1Local, algorithmFPType, method >::input
Input input
Definition: kmeans_distributed.h:302
daal::algorithms::kmeans::interface1::Distributed< step2Master, algorithmFPType, method >::setResult
services::Status setResult(const ResultPtr &result)
Definition: kmeans_distributed.h:372
daal::algorithms::kmeans::interface1::Distributed< step2Master, algorithmFPType, method >::parameter
Parameter parameter
Definition: kmeans_distributed.h:473
daal::algorithms::kmeans::interface1::Distributed< step1Local, algorithmFPType, method >::Distributed
Distributed(size_t nClusters, bool assignFlag=false)
Definition: kmeans_distributed.h:183
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:175
daal::algorithms::kmeans::interface1::Distributed< step2Master, algorithmFPType, method >::Distributed
Distributed(size_t nClusters, size_t nIterations=1)
Definition: kmeans_distributed.h:335
daal::services::ErrorNullResult
Definition: error_indexes.h:122
daal::algorithms::kmeans::interface1::Distributed< step1Local, algorithmFPType, method >::setPartialResult
services::Status setPartialResult(const PartialResultPtr &partialRes)
Definition: kmeans_distributed.h:241