C++ API Reference for Intel® Data Analytics Acceleration Library 2019 Update 5

cross_entropy_loss_batch.h
1 /* file: cross_entropy_loss_batch.h */
2 /*******************************************************************************
3 * Copyright 2014-2019 Intel Corporation.
4 *
5 * This software and the related documents are Intel copyrighted materials, and
6 * your use of them is governed by the express license under which they were
7 * provided to you (License). Unless the License provides otherwise, you may not
8 * use, modify, copy, publish, distribute, disclose or transmit this software or
9 * the related documents without Intel's prior written permission.
10 *
11 * This software and the related documents are provided as is, with no express
12 * or implied warranties, other than those that are expressly stated in the
13 * License.
14 *******************************************************************************/
15 
16 /*
17 //++
18 // Implementation of the Cross-entropy loss objective function in the batch
19 // processing mode
20 //--
21 */
22 
23 #ifndef __CROSS_ENTROPY_BATCH_H__
24 #define __CROSS_ENTROPY_BATCH_H__
25 
26 #include "algorithms/algorithm.h"
27 #include "data_management/data/numeric_table.h"
28 #include "services/daal_defines.h"
29 #include "sum_of_functions_batch.h"
30 #include "cross_entropy_loss_types.h"
31 
32 namespace daal
33 {
34 namespace algorithms
35 {
36 namespace optimization_solver
37 {
38 namespace cross_entropy_loss
39 {
40 
41 namespace interface1
42 {
57 template<typename algorithmFPType, Method method, CpuType cpu>
58 class DAAL_EXPORT BatchContainer : public daal::algorithms::AnalysisContainerIface<batch>
59 {
60 public:
66  BatchContainer(daal::services::Environment::env *daalEnv);
68  virtual ~BatchContainer();
74  virtual services::Status compute() DAAL_C11_OVERRIDE;
75 };
76 
93 template<typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = defaultDense>
94 class DAAL_EXPORT Batch : public sum_of_functions::interface1::Batch
95 {
96 public:
97  typedef sum_of_functions::interface1::Batch super;
98 
99  typedef algorithms::optimization_solver::cross_entropy_loss::interface1::Input InputType;
100  typedef algorithms::optimization_solver::cross_entropy_loss::interface1::Parameter ParameterType;
101  typedef typename super::ResultType ResultType;
102 
106  Batch(size_t nClasses, size_t numberOfTerms) : sum_of_functions::interface1::Batch(numberOfTerms, &input, new ParameterType(nClasses, numberOfTerms))
107  {
108  initialize();
109  }
110 
111  virtual ~Batch() {}
112 
119  Batch(const Batch<algorithmFPType, method> &other) :
120  sum_of_functions::interface1::Batch(other.parameter().numberOfTerms, &input, new ParameterType(other.parameter())), input(other.input)
121  {
122  initialize();
123  }
124 
129  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)method; }
130 
136  services::SharedPtr<Batch<algorithmFPType, method> > clone() const
137  {
138  return services::SharedPtr<Batch<algorithmFPType, method> >(cloneImpl());
139  }
140 
146  services::Status allocate()
147  {
148  return allocateResult();
149  }
150 
155  ParameterType& parameter() { return *static_cast<ParameterType*>(_par); }
156 
161  const ParameterType& parameter() const { return *static_cast<const ParameterType*>(_par); }
162 
169  static services::SharedPtr<Batch<algorithmFPType, method> > create(size_t nClasses, size_t numberOfTerms);
170 
171 protected:
172  virtual Batch<algorithmFPType, method> *cloneImpl() const DAAL_C11_OVERRIDE
173  {
174  return new Batch<algorithmFPType, method>(*this);
175  }
176 
177  virtual services::Status allocateResult() DAAL_C11_OVERRIDE
178  {
179  services::Status s = _result->allocate<algorithmFPType>(&input, _par, (int) method);
180  _res = _result.get();
181  return s;
182  }
183 
184  void initialize()
185  {
186  Analysis<batch>::_ac = new __DAAL_ALGORITHM_CONTAINER(batch, BatchContainer, algorithmFPType, method)(&_env);
187  _in = &input;
188  _par = sumOfFunctionsParameter;
189  }
190 
191 public:
192  InputType input;
193 };
195 } // namespace interface1
196 
197 namespace interface2
198 {
213 template<typename algorithmFPType, Method method, CpuType cpu>
214 class DAAL_EXPORT BatchContainer : public daal::algorithms::AnalysisContainerIface<batch>
215 {
216 public:
222  BatchContainer(daal::services::Environment::env *daalEnv);
224  virtual ~BatchContainer();
230  virtual services::Status compute() DAAL_C11_OVERRIDE;
231 };
232 
249 template<typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = defaultDense>
250 class DAAL_EXPORT Batch : public sum_of_functions::Batch
251 {
252 public:
253  typedef sum_of_functions::Batch super;
254 
255  typedef algorithms::optimization_solver::cross_entropy_loss::Input InputType;
256  typedef algorithms::optimization_solver::cross_entropy_loss::Parameter ParameterType;
257  typedef typename super::ResultType ResultType;
258 
262  Batch(size_t nClasses, size_t numberOfTerms);
263 
264  virtual ~Batch() {}
265 
272  Batch(const Batch<algorithmFPType, method> &other);
273 
278  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)method; }
279 
285  services::SharedPtr<Batch<algorithmFPType, method> > clone() const
286  {
287  return services::SharedPtr<Batch<algorithmFPType, method> >(cloneImpl());
288  }
289 
295  services::Status allocate()
296  {
297  return allocateResult();
298  }
299 
304  ParameterType& parameter() { return *static_cast<ParameterType*>(_par); }
305 
310  const ParameterType& parameter() const { return *static_cast<const ParameterType*>(_par); }
311 
318  static services::SharedPtr<Batch<algorithmFPType, method> > create(size_t nClasses, size_t numberOfTerms);
319 
320 protected:
321  virtual Batch<algorithmFPType, method> *cloneImpl() const DAAL_C11_OVERRIDE
322  {
323  return new Batch<algorithmFPType, method>(*this);
324  }
325 
326  virtual services::Status allocateResult() DAAL_C11_OVERRIDE
327  {
328  services::Status s = _result->allocate<algorithmFPType>(&input, _par, (int) method);
329  _res = _result.get();
330  return s;
331  }
332 
333  void initialize()
334  {
335  Analysis<batch>::_ac = new __DAAL_ALGORITHM_CONTAINER(batch, BatchContainer, algorithmFPType, method)(&_env);
336  _in = &input;
337  }
338 
339 public:
340  InputType input;
341 };
343 } // namespace interface2
344 using interface2::BatchContainer;
345 using interface2::Batch;
346 
347 } // namespace cross_entropy_loss
348 } // namespace optimization_solver
349 } // namespace algorithm
350 } // namespace daal
351 #endif
daal::algorithms::optimization_solver::cross_entropy_loss::interface1::Batch::Batch
Batch(size_t nClasses, size_t numberOfTerms)
Definition: cross_entropy_loss_batch.h:106
daal::algorithms::optimization_solver::cross_entropy_loss::interface1::Parameter
Parameter for Cross-entropy loss objective function
Definition: cross_entropy_loss_types.h:85
daal::algorithms::optimization_solver::cross_entropy_loss::interface2::Batch::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: cross_entropy_loss_batch.h:278
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::cross_entropy_loss::interface1::Input
Input objects for the Cross-entropy loss objective function
Definition: cross_entropy_loss_types.h:126
daal::algorithms::optimization_solver::cross_entropy_loss::interface1::Batch
Computes the Cross-entropy loss objective function in the batch processing mode.
Definition: cross_entropy_loss_batch.h:94
daal::algorithms::optimization_solver::cross_entropy_loss::interface2::Batch
Computes the Cross-entropy loss objective function in the batch processing mode.
Definition: cross_entropy_loss_batch.h:250
daal_defines.h
daal::algorithms::optimization_solver::cross_entropy_loss::interface2::Batch::allocate
services::Status allocate()
Definition: cross_entropy_loss_batch.h:295
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::batch
Definition: daal_defines.h:110
daal::algorithms::optimization_solver::cross_entropy_loss::interface2::Batch::parameter
const ParameterType & parameter() const
Definition: cross_entropy_loss_batch.h:310
daal::algorithms::optimization_solver::cross_entropy_loss::interface2::BatchContainer
Provides methods to run implementations of the Cross-entropy loss objective function. This class is associated with the Batch class and supports the method of computing the Cross-entropy loss objective function in the batch processing mode.
Definition: cross_entropy_loss_batch.h:214
daal::algorithms::optimization_solver::cross_entropy_loss::interface1::Batch::input
InputType input
Definition: cross_entropy_loss_batch.h:192
daal::algorithms::optimization_solver::cross_entropy_loss::interface1::Batch::clone
services::SharedPtr< Batch< algorithmFPType, method > > clone() const
Definition: cross_entropy_loss_batch.h:136
daal::algorithms::optimization_solver::cross_entropy_loss::interface1::Batch::parameter
ParameterType & parameter()
Definition: cross_entropy_loss_batch.h:155
daal::algorithms::optimization_solver::cross_entropy_loss::interface1::Batch::parameter
const ParameterType & parameter() const
Definition: cross_entropy_loss_batch.h:161
daal::algorithms::optimization_solver::cross_entropy_loss::interface2::Batch::parameter
ParameterType & parameter()
Definition: cross_entropy_loss_batch.h:304
daal::algorithms::optimization_solver::cross_entropy_loss::interface1::Batch::Batch
Batch(const Batch< algorithmFPType, method > &other)
Definition: cross_entropy_loss_batch.h:119
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::cross_entropy_loss::interface1::Batch::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: cross_entropy_loss_batch.h:129
daal::algorithms::optimization_solver::cross_entropy_loss::interface1::BatchContainer
Provides methods to run implementations of the Cross-entropy loss objective function. This class is associated with the Batch class and supports the method of computing the Cross-entropy loss objective function in the batch processing mode.
Definition: cross_entropy_loss_batch.h:58
daal::algorithms::optimization_solver::cross_entropy_loss::interface2::Batch::clone
services::SharedPtr< Batch< algorithmFPType, method > > clone() const
Definition: cross_entropy_loss_batch.h:285
daal::algorithms::optimization_solver::cross_entropy_loss::interface1::Batch::allocate
services::Status allocate()
Definition: cross_entropy_loss_batch.h:146
daal::algorithms::optimization_solver::cross_entropy_loss::interface2::Batch::input
InputType input
Definition: cross_entropy_loss_batch.h:340

For more complete information about compiler optimizations, see our Optimization Notice.