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>
178 typedef algorithms::kmeans::Input InputType;
179 typedef algorithms::kmeans::Parameter ParameterType;
180 typedef algorithms::kmeans::Result ResultType;
181 typedef algorithms::kmeans::PartialResult PartialResultType;
188 Distributed(
size_t nClusters,
bool assignFlag =
false) : parameter(nClusters, 1)
191 parameter.assignFlag = assignFlag;
200 Distributed(
const Distributed<step1Local, algorithmFPType, method> &other) : parameter(other.parameter)
203 input.set(data, other.input.get(data));
204 input.set(inputCentroids, other.input.get(inputCentroids));
211 virtual int getMethod() const DAAL_C11_OVERRIDE {
return(
int) method; }
217 ResultPtr getResult()
226 services::Status setResult(
const ResultPtr& result)
228 DAAL_CHECK(result, services::ErrorNullResult)
230 _res = _result.get();
231 return services::Status();
238 PartialResultPtr getPartialResult()
240 return _partialResult;
246 services::Status setPartialResult(
const PartialResultPtr& partialRes)
248 DAAL_CHECK(partialRes, services::ErrorNullPartialResult);
249 _partialResult = partialRes;
250 _pres = _partialResult.get();
251 return services::Status();
257 services::Status checkFinalizeComputeParams() DAAL_C11_OVERRIDE
259 return services::Status();
267 services::SharedPtr<Distributed<step1Local, algorithmFPType, method> > clone()
const 269 return services::SharedPtr<Distributed<step1Local, algorithmFPType, method> >(cloneImpl());
273 virtual Distributed<step1Local, algorithmFPType, method> * cloneImpl()
const DAAL_C11_OVERRIDE
275 return new Distributed<step1Local, algorithmFPType, method>(*this);
278 virtual services::Status allocateResult() DAAL_C11_OVERRIDE
280 _result.reset(
new ResultType());
281 services::Status s = _result->allocate<algorithmFPType>(_in, _par, (int) method);
282 _res = _result.get();
286 virtual services::Status allocatePartialResult() DAAL_C11_OVERRIDE
288 _partialResult.reset(
new PartialResultType());
289 services::Status s = _partialResult->allocate<algorithmFPType>(&input, _par, (int) method);
290 _pres = _partialResult.get();
294 virtual services::Status initializePartialResult() DAAL_C11_OVERRIDE
296 return services::Status();
301 Analysis<distributed>::_ac =
new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step1Local, algorithmFPType, method)(&_env);
308 ParameterType parameter;
311 PartialResultPtr _partialResult;
331 template<
typename algorithmFPType, Method method>
332 class DAAL_EXPORT Distributed<step2Master, algorithmFPType, method>:
public daal::algorithms::Analysis<distributed>
335 typedef algorithms::kmeans::DistributedStep2MasterInput InputType;
336 typedef algorithms::kmeans::Parameter ParameterType;
337 typedef algorithms::kmeans::Result ResultType;
338 typedef algorithms::kmeans::PartialResult PartialResultType;
345 Distributed(
size_t nClusters,
size_t nIterations = 1) : parameter(nClusters, nIterations)
348 parameter.assignFlag =
false;
357 Distributed(
const Distributed<step2Master, algorithmFPType, method> &other) : parameter(other.parameter)
360 input.set(partialResults, other.input.get(partialResults));
367 virtual int getMethod() const DAAL_C11_OVERRIDE {
return(
int) method; }
373 ResultPtr getResult()
382 services::Status setResult(
const ResultPtr& result)
384 DAAL_CHECK(result, services::ErrorNullResult)
386 _res = _result.get();
387 return services::Status();
394 PartialResultPtr getPartialResult()
396 return _partialResult;
402 services::Status setPartialResult(
const PartialResultPtr& partialRes)
404 DAAL_CHECK(partialRes, services::ErrorNullPartialResult);
405 _partialResult = partialRes;
406 _pres = _partialResult.get();
407 return services::Status();
413 services::Status checkFinalizeComputeParams() DAAL_C11_OVERRIDE
418 s |= _partialResult->check(_par, method);
419 if (!s) {
return s; }
423 return services::Status(services::ErrorNullResult);
428 s |= _result->check(_partialResult.get(), _par, method);
432 return services::Status(services::ErrorNullResult);
442 services::SharedPtr<Distributed<step2Master, algorithmFPType, method> > clone()
const 444 return services::SharedPtr<Distributed<step2Master, algorithmFPType, method> >(cloneImpl());
448 virtual Distributed<step2Master, algorithmFPType, method> * cloneImpl()
const DAAL_C11_OVERRIDE
450 return new Distributed<step2Master, algorithmFPType, method>(*this);
453 virtual services::Status allocateResult() DAAL_C11_OVERRIDE
455 _result.reset(
new ResultType());
456 services::Status s = _result->allocate<algorithmFPType>(_pres, _par, (int) method);
457 _res = _result.get();
461 virtual services::Status allocatePartialResult() DAAL_C11_OVERRIDE
463 _partialResult.reset(
new PartialResultType());
464 services::Status s = _partialResult->allocate<algorithmFPType>(&input, _par, (int) method);
465 _pres = _partialResult.get();
469 virtual services::Status initializePartialResult() DAAL_C11_OVERRIDE
471 return services::Status();
476 Analysis<distributed>::_ac =
new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step2Master, algorithmFPType, method)(&_env);
483 ParameterType parameter;
486 PartialResultPtr _partialResult;
491 using interface1::DistributedContainer;
492 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:155
daal::algorithms::kmeans::interface1::Result
Results obtained with the compute() method of the K-Means algorithm in the batch processing mode...
Definition: kmeans_types.h:303
daal::algorithms::kmeans::interface1::Distributed< step1Local, algorithmFPType, method >::Distributed
Distributed(const Distributed< step1Local, algorithmFPType, method > &other)
Definition: kmeans_distributed.h:200
daal::services::interface1::Environment::_envStruct
The environment structure.
Definition: env_detect.h:95
daal::services::interface1::Status
Class that holds the results of API calls. In case of API routine failure it contains the list of err...
Definition: error_handling.h:491
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:226
daal::algorithms::kmeans::interface1::Distributed< step1Local, algorithmFPType, method >::getPartialResult
PartialResultPtr getPartialResult()
Definition: kmeans_distributed.h:238
daal::algorithms::kmeans::interface1::PartialResult
Partial results obtained with the compute() method of the K-Means algorithm in the batch processing m...
Definition: kmeans_types.h:236
daal::algorithms::kmeans::interface1::Distributed< step1Local, algorithmFPType, method >::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: kmeans_distributed.h:211
daal::algorithms::kmeans::interface1::Distributed< step2Master, algorithmFPType, method >::input
InputType input
Definition: kmeans_distributed.h:482
daal::services::ErrorNullPartialResult
Definition: error_indexes.h:131
daal::algorithms::kmeans::interface1::Distributed< step1Local, algorithmFPType, method >::getResult
ResultPtr getResult()
Definition: kmeans_distributed.h:217
daal::algorithms::kmeans::data
Definition: kmeans_types.h:96
daal::algorithms::kmeans::interface1::Distributed< step2Master, algorithmFPType, method >::getPartialResult
PartialResultPtr getPartialResult()
Definition: kmeans_distributed.h:394
daal::algorithms::kmeans::interface1::Distributed< step2Master, algorithmFPType, method >::setPartialResult
services::Status setPartialResult(const PartialResultPtr &partialRes)
Definition: kmeans_distributed.h:402
daal::algorithms::kmeans::nIterations
Definition: kmeans_types.h:137
daal::algorithms::kmeans::interface1::Distributed< step2Master, algorithmFPType, method >::getResult
ResultPtr getResult()
Definition: kmeans_distributed.h:373
daal::algorithms::kmeans::interface1::Distributed< step1Local, algorithmFPType, method >::clone
services::SharedPtr< Distributed< step1Local, algorithmFPType, method > > clone() const
Definition: kmeans_distributed.h:267
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:133
daal::services::interface1::SharedPtr
Shared pointer that retains shared ownership of an object through a pointer. Several SharedPtr object...
Definition: daal_shared_ptr.h:187
daal::services::interface1::SharedPtr::get
T * get() const
Definition: daal_shared_ptr.h:332
daal::algorithms::kmeans::interface1::Distributed< step2Master, algorithmFPType, method >::clone
services::SharedPtr< Distributed< step2Master, algorithmFPType, method > > clone() const
Definition: kmeans_distributed.h:442
daal::algorithms::kmeans::inputCentroids
Definition: kmeans_types.h:97
daal::algorithms::kmeans::partialResults
Definition: kmeans_types.h:107
daal::algorithms::kmeans::interface1::Distributed< step2Master, algorithmFPType, method >::checkFinalizeComputeParams
services::Status checkFinalizeComputeParams() DAAL_C11_OVERRIDE
Definition: kmeans_distributed.h:413
daal::algorithms::kmeans::interface1::Distributed< step2Master, algorithmFPType, method >::Distributed
Distributed(const Distributed< step2Master, algorithmFPType, method > &other)
Definition: kmeans_distributed.h:357
daal::algorithms::kmeans::interface1::Distributed< step1Local, algorithmFPType, method >::parameter
ParameterType parameter
Definition: kmeans_distributed.h:308
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::interface1::Distributed< step2Master, algorithmFPType, method >::parameter
ParameterType parameter
Definition: kmeans_distributed.h:483
daal::algorithms::kmeans::interface1::Distributed< step1Local, algorithmFPType, method >::checkFinalizeComputeParams
services::Status checkFinalizeComputeParams() DAAL_C11_OVERRIDE
Definition: kmeans_distributed.h:257
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:332
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::algorithms::kmeans::interface1::Distributed< step1Local, algorithmFPType, method >::input
InputType input
Definition: kmeans_distributed.h:307
daal::step1Local
Definition: daal_defines.h:143
daal::algorithms::kmeans::interface1::Distributed< step2Master, algorithmFPType, method >::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: kmeans_distributed.h:367
daal::step2Master
Definition: daal_defines.h:144
daal::algorithms::kmeans::interface1::Distributed< step2Master, algorithmFPType, method >::setResult
services::Status setResult(const ResultPtr &result)
Definition: kmeans_distributed.h:382
daal::algorithms::kmeans::interface1::Distributed< step1Local, algorithmFPType, method >::Distributed
Distributed(size_t nClusters, bool assignFlag=false)
Definition: kmeans_distributed.h:188
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:345
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:246