22 #ifndef __PRECOMPUTED_BATCH_H__
23 #define __PRECOMPUTED_BATCH_H__
25 #include "algorithms/algorithm.h"
26 #include "services/daal_defines.h"
27 #include "objective_function_batch.h"
28 #include "sum_of_functions_batch.h"
29 #include "precomputed_types.h"
35 namespace optimization_solver
56 template<
typename algorithmFPType, Method method>
57 class DAAL_EXPORT BatchContainer :
public daal::algorithms::AnalysisContainerIface<batch>
65 BatchContainer(daal::services::Environment::env *daalEnv) {}
66 virtual ~BatchContainer() {}
72 virtual services::Status compute()
75 return services::Status();
93 template<
typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = defaultDense>
94 class DAAL_EXPORT Batch :
public sum_of_functions::interface1::Batch
97 typedef sum_of_functions::interface1::Batch super;
99 typedef typename super::InputType InputType;
100 typedef typename super::ParameterType ParameterType;
101 typedef typename super::ResultType ResultType;
105 ParameterType parameter;
110 Batch() : parameter(1), super(1, &input, ¶meter)
123 Batch(
const Batch<algorithmFPType, method> &other) :
124 parameter(other.parameter), super(other.parameter.numberOfTerms, &input, ¶meter), input(other.input)
127 const ResultType *otherResult =
const_cast<Batch<algorithmFPType, method> &
>(other).getResult().get();
130 bool isResultInitialized =
false;
131 isResultInitialized = (isResultInitialized || otherResult->get(objective_function::gradientIdx));
132 _result->set(objective_function::gradientIdx, otherResult->get(objective_function::gradientIdx));
133 isResultInitialized = (isResultInitialized || otherResult->get(objective_function::valueIdx));
134 _result->set(objective_function::valueIdx, otherResult->get(objective_function::valueIdx));
135 isResultInitialized = (isResultInitialized || otherResult->get(objective_function::hessianIdx));
136 _result->set(objective_function::hessianIdx, otherResult->get(objective_function::hessianIdx));
137 if (isResultInitialized)
139 _res = _result.get();
148 virtual int getMethod() const DAAL_C11_OVERRIDE {
return (
int)method; }
155 services::SharedPtr<Batch<algorithmFPType, method> > clone()
const
157 return services::SharedPtr<Batch<algorithmFPType, method> >(cloneImpl());
165 services::Status allocate()
167 return allocateResult();
171 virtual Batch<algorithmFPType, method> *cloneImpl() const DAAL_C11_OVERRIDE
173 return new Batch<algorithmFPType, method>(*this);
176 virtual services::Status allocateResult() DAAL_C11_OVERRIDE
178 services::Status s = _result->allocate<algorithmFPType>(&input, ¶meter, (int) method);
179 _res = _result.get();
185 Analysis<batch>::_ac =
new BatchContainer<algorithmFPType, method>(&_env);
188 _result = objective_function::ResultPtr(
new ResultType());
212 template<
typename algorithmFPType, Method method>
213 class DAAL_EXPORT BatchContainer :
public daal::algorithms::AnalysisContainerIface<batch>
221 BatchContainer(daal::services::Environment::env *daalEnv) {}
222 virtual ~BatchContainer() {}
228 virtual services::Status compute()
231 return services::Status();
249 template<
typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = defaultDense>
250 class DAAL_EXPORT Batch :
public sum_of_functions::Batch
253 typedef sum_of_functions::Batch super;
255 typedef typename super::InputType InputType;
256 typedef typename super::ParameterType ParameterType;
257 typedef typename super::ResultType ResultType;
261 ParameterType parameter;
266 Batch() : parameter(1), super(1, &input, ¶meter)
279 Batch(
const Batch<algorithmFPType, method> &other) :
280 parameter(other.parameter), super(other.parameter.numberOfTerms, &input, ¶meter), input(other.input)
283 const ResultType *otherResult =
const_cast<Batch<algorithmFPType, method> &
>(other).getResult().get();
286 bool isResultInitialized =
false;
287 isResultInitialized = (isResultInitialized || otherResult->get(objective_function::gradientIdx));
288 _result->set(objective_function::gradientIdx, otherResult->get(objective_function::gradientIdx));
289 isResultInitialized = (isResultInitialized || otherResult->get(objective_function::valueIdx));
290 _result->set(objective_function::valueIdx, otherResult->get(objective_function::valueIdx));
291 isResultInitialized = (isResultInitialized || otherResult->get(objective_function::hessianIdx));
292 _result->set(objective_function::hessianIdx, otherResult->get(objective_function::hessianIdx));
293 if (isResultInitialized)
295 _res = _result.get();
304 virtual int getMethod() const DAAL_C11_OVERRIDE {
return (
int)method; }
311 services::SharedPtr<Batch<algorithmFPType, method> > clone()
const
313 return services::SharedPtr<Batch<algorithmFPType, method> >(cloneImpl());
321 services::Status allocate()
323 return allocateResult();
327 virtual Batch<algorithmFPType, method> *cloneImpl() const DAAL_C11_OVERRIDE
329 return new Batch<algorithmFPType, method>(*this);
332 virtual services::Status allocateResult() DAAL_C11_OVERRIDE
334 services::Status s = _result->allocate<algorithmFPType>(&input, ¶meter, (int) method);
335 _res = _result.get();
341 Analysis<batch>::_ac =
new BatchContainer<algorithmFPType, method>(&_env);
344 _result = objective_function::ResultPtr(
new ResultType());
349 using interface2::BatchContainer;
350 using interface2::Batch;
daal::algorithms::optimization_solver::precomputed::interface1::Batch::Batch
Batch()
Definition: precomputed_batch.h:110
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::optimization_solver::precomputed::interface2::Batch::allocate
services::Status allocate()
Definition: precomputed_batch.h:321
daal::algorithms::optimization_solver::precomputed::interface1::BatchContainer
Provides methods to run implementations of the objective function with precomputed characteristics...
Definition: precomputed_batch.h:57
daal::algorithms::optimization_solver::precomputed::interface2::BatchContainer::compute
virtual services::Status compute()
Definition: precomputed_batch.h:228
daal::algorithms::optimization_solver::precomputed::interface1::BatchContainer::BatchContainer
BatchContainer(daal::services::Environment::env *daalEnv)
Definition: precomputed_batch.h:65
daal::algorithms::optimization_solver::precomputed::interface1::Batch::input
InputType input
Definition: precomputed_batch.h:103
daal::algorithms::optimization_solver::precomputed::interface2::Batch::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: precomputed_batch.h:304
daal::algorithms::optimization_solver::precomputed::interface2::Batch::Batch
Batch()
Definition: precomputed_batch.h:266
daal::algorithms::optimization_solver::objective_function::gradientIdx
Definition: objective_function_types.h:84
daal::algorithms::optimization_solver::sum_of_functions::interface1::Batch
Interface for computing the Sum of functions in the batch processing mode.
Definition: sum_of_functions_batch.h:61
daal::algorithms::optimization_solver::objective_function::hessianIdx
Definition: objective_function_types.h:86
daal::algorithms::optimization_solver::sum_of_functions::interface1::Parameter
Parameter for the Sum of functions
Definition: sum_of_functions_types.h:69
daal::algorithms::optimization_solver::objective_function::valueIdx
Definition: objective_function_types.h:85
daal::algorithms::optimization_solver::precomputed::interface1::Batch
Computes the objective function with precomputed characteristics in the batch processing mode...
Definition: precomputed_batch.h:94
daal::algorithms::optimization_solver::precomputed::interface2::Batch
Computes the objective function with precomputed characteristics in the batch processing mode...
Definition: precomputed_batch.h:250
daal::algorithms::optimization_solver::precomputed::interface1::Batch::clone
services::SharedPtr< Batch< algorithmFPType, method > > clone() const
Definition: precomputed_batch.h:155
daal::algorithms::optimization_solver::precomputed::interface1::Batch::Batch
Batch(const Batch< algorithmFPType, method > &other)
Definition: precomputed_batch.h:123
daal::algorithms::optimization_solver::precomputed::interface1::Batch::parameter
ParameterType parameter
Definition: precomputed_batch.h:105
daal::algorithms::Analysis
Provides methods for execution of operations over data, such as computation of Summary Statistics est...
Definition: analysis.h:68
daal::algorithms::optimization_solver::precomputed::interface1::BatchContainer::compute
virtual services::Status compute()
Definition: precomputed_batch.h:72
daal::algorithms::optimization_solver::precomputed::interface1::Batch::allocate
services::Status allocate()
Definition: precomputed_batch.h:165
daal::algorithms::optimization_solver::precomputed::interface2::Batch::clone
services::SharedPtr< Batch< algorithmFPType, method > > clone() const
Definition: precomputed_batch.h:311
daal::algorithms::optimization_solver::precomputed::interface2::BatchContainer
Provides methods to run implementations of the objective function with precomputed characteristics...
Definition: precomputed_batch.h:213
daal::algorithms::optimization_solver::precomputed::interface2::Batch::input
InputType input
Definition: precomputed_batch.h:259
daal::algorithms::optimization_solver::precomputed::interface2::Batch::parameter
ParameterType parameter
Definition: precomputed_batch.h:261
daal::algorithms::optimization_solver::precomputed::interface1::Batch::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: precomputed_batch.h:148
daal::algorithms::optimization_solver::precomputed::interface2::BatchContainer::BatchContainer
BatchContainer(daal::services::Environment::env *daalEnv)
Definition: precomputed_batch.h:221
daal::algorithms::optimization_solver::precomputed::interface2::Batch::Batch
Batch(const Batch< algorithmFPType, method > &other)
Definition: precomputed_batch.h:279