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

cross_entropy_loss_batch.h
1 /* file: cross_entropy_loss_batch.h */
2 /*******************************************************************************
3 * Copyright 2014-2018 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::Batch
95 {
96 public:
97  typedef sum_of_functions::Batch super;
98 
99  typedef algorithms::optimization_solver::cross_entropy_loss::Input InputType;
100  typedef algorithms::optimization_solver::cross_entropy_loss::Parameter ParameterType;
101  typedef typename super::ResultType ResultType;
102 
106  Batch(size_t nClasses, size_t numberOfTerms) : sum_of_functions::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::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 using interface1::BatchContainer;
197 using interface1::Batch;
198 
199 } // namespace cross_entropy_loss
200 } // namespace optimization_solver
201 } // namespace algorithm
202 } // namespace daal
203 #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
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::Batch
Computes the Cross-entropy loss objective function in the batch processing mode.
Definition: cross_entropy_loss_batch.h:94
daal_defines.h
daal::batch
Definition: daal_defines.h:106
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::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::interface1::Batch::allocate
services::Status allocate()
Definition: cross_entropy_loss_batch.h:146

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