C++ API Reference for Intel® Data Analytics Acceleration Library 2020 Update 1

cross_entropy_loss_batch.h
1 /* file: cross_entropy_loss_batch.h */
2 /*******************************************************************************
3 * Copyright 2014-2020 Intel Corporation
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *******************************************************************************/
17 
18 /*
19 //++
20 // Implementation of the Cross-entropy loss objective function in the batch
21 // processing mode
22 //--
23 */
24 
25 #ifndef __CROSS_ENTROPY_BATCH_H__
26 #define __CROSS_ENTROPY_BATCH_H__
27 
28 #include "algorithms/algorithm.h"
29 #include "data_management/data/numeric_table.h"
30 #include "services/daal_defines.h"
31 #include "sum_of_functions_batch.h"
32 #include "cross_entropy_loss_types.h"
33 
34 namespace daal
35 {
36 namespace algorithms
37 {
38 namespace optimization_solver
39 {
40 namespace cross_entropy_loss
41 {
42 
43 namespace interface1
44 {
59 template<typename algorithmFPType, Method method, CpuType cpu>
60 class BatchContainer : public daal::algorithms::AnalysisContainerIface<batch>
61 {
62 public:
68  DAAL_DEPRECATED BatchContainer(daal::services::Environment::env *daalEnv);
70  DAAL_DEPRECATED_VIRTUAL virtual ~BatchContainer();
76  DAAL_DEPRECATED_VIRTUAL virtual services::Status compute() DAAL_C11_OVERRIDE;
77 };
78 
95 template<typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = defaultDense>
96 class DAAL_EXPORT Batch : public sum_of_functions::interface1::Batch
97 {
98 public:
99  typedef sum_of_functions::interface1::Batch super;
100 
101  typedef algorithms::optimization_solver::cross_entropy_loss::interface1::Input InputType;
102  typedef algorithms::optimization_solver::cross_entropy_loss::interface1::Parameter ParameterType;
103  typedef typename super::ResultType ResultType;
104 
108  DAAL_DEPRECATED Batch(size_t nClasses, size_t numberOfTerms) : sum_of_functions::interface1::Batch(numberOfTerms, &input, new ParameterType(nClasses, numberOfTerms))
109  {
110  initialize();
111  }
112 
113  DAAL_DEPRECATED_VIRTUAL virtual ~Batch() {}
114 
121  DAAL_DEPRECATED Batch(const Batch<algorithmFPType, method> &other) :
122  sum_of_functions::interface1::Batch(other.parameter().numberOfTerms, &input, new ParameterType(other.parameter())), input(other.input)
123  {
124  initialize();
125  }
126 
131  DAAL_DEPRECATED_VIRTUAL virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)method; }
132 
138  DAAL_DEPRECATED services::SharedPtr<Batch<algorithmFPType, method> > clone() const
139  {
140  return services::SharedPtr<Batch<algorithmFPType, method> >(cloneImpl());
141  }
142 
148  DAAL_DEPRECATED services::Status allocate()
149  {
150  return allocateResult();
151  }
152 
157  DAAL_DEPRECATED ParameterType& parameter() { return *static_cast<ParameterType*>(_par); }
158 
163  DAAL_DEPRECATED const ParameterType& parameter() const { return *static_cast<const ParameterType*>(_par); }
164 
171  DAAL_DEPRECATED static services::SharedPtr<Batch<algorithmFPType, method> > create(size_t nClasses, size_t numberOfTerms);
172 
173 protected:
174  virtual Batch<algorithmFPType, method> *cloneImpl() const DAAL_C11_OVERRIDE
175  {
176  return new Batch<algorithmFPType, method>(*this);
177  }
178 
179  virtual services::Status allocateResult() DAAL_C11_OVERRIDE
180  {
181  services::Status s = _result->allocate<algorithmFPType>(&input, _par, (int) method);
182  _res = _result.get();
183  return s;
184  }
185 
186  void initialize()
187  {
188  Analysis<batch>::_ac = new __DAAL_ALGORITHM_CONTAINER(batch, BatchContainer, algorithmFPType, method)(&_env);
189  _in = &input;
190  _par = sumOfFunctionsParameter;
191  }
192 
193 public:
194  InputType input;
195 };
197 } // namespace interface1
198 
199 namespace interface2
200 {
215 template<typename algorithmFPType, Method method, CpuType cpu>
216 class BatchContainer : public daal::algorithms::AnalysisContainerIface<batch>
217 {
218 public:
224  BatchContainer(daal::services::Environment::env *daalEnv);
226  virtual ~BatchContainer();
232  virtual services::Status compute() DAAL_C11_OVERRIDE;
233 };
234 
251 template<typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = defaultDense>
252 class DAAL_EXPORT Batch : public sum_of_functions::Batch
253 {
254 public:
255  typedef sum_of_functions::Batch super;
256 
257  typedef algorithms::optimization_solver::cross_entropy_loss::Input InputType;
258  typedef algorithms::optimization_solver::cross_entropy_loss::Parameter ParameterType;
259  typedef typename super::ResultType ResultType;
260 
264  Batch(size_t nClasses, size_t numberOfTerms);
265 
266  virtual ~Batch() {}
267 
274  Batch(const Batch<algorithmFPType, method> &other);
275 
280  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)method; }
281 
287  services::SharedPtr<Batch<algorithmFPType, method> > clone() const
288  {
289  return services::SharedPtr<Batch<algorithmFPType, method> >(cloneImpl());
290  }
291 
297  services::Status allocate()
298  {
299  return allocateResult();
300  }
301 
306  ParameterType& parameter() { return *static_cast<ParameterType*>(_par); }
307 
312  const ParameterType& parameter() const { return *static_cast<const ParameterType*>(_par); }
313 
320  static services::SharedPtr<Batch<algorithmFPType, method> > create(size_t nClasses, size_t numberOfTerms);
321 
322 protected:
323  virtual Batch<algorithmFPType, method> *cloneImpl() const DAAL_C11_OVERRIDE
324  {
325  return new Batch<algorithmFPType, method>(*this);
326  }
327 
328  virtual services::Status allocateResult() DAAL_C11_OVERRIDE
329  {
330  services::Status s = _result->allocate<algorithmFPType>(&input, _par, (int) method);
331  _res = _result.get();
332  return s;
333  }
334 
335  void initialize()
336  {
337  Analysis<batch>::_ac = new __DAAL_ALGORITHM_CONTAINER(batch, BatchContainer, algorithmFPType, method)(&_env);
338  _in = &input;
339  }
340 
341 public:
342  InputType input;
343 };
345 } // namespace interface2
346 using interface2::BatchContainer;
347 using interface2::Batch;
348 
349 } // namespace cross_entropy_loss
350 } // namespace optimization_solver
351 } // namespace algorithm
352 } // namespace daal
353 #endif
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:60
daal::batch
Definition: daal_defines.h:112
daal::algorithms::optimization_solver::cross_entropy_loss::interface2::Batch::clone
services::SharedPtr< Batch< algorithmFPType, method > > clone() const
Definition: cross_entropy_loss_batch.h:287
daal::algorithms::optimization_solver::cross_entropy_loss::interface1::BatchContainer::compute
virtual DAAL_DEPRECATED_VIRTUAL services::Status compute() DAAL_C11_OVERRIDE
daal::algorithms::optimization_solver::cross_entropy_loss::interface2::BatchContainer::~BatchContainer
virtual ~BatchContainer()
daal::algorithms::optimization_solver::cross_entropy_loss::interface1::Batch::getMethod
virtual DAAL_DEPRECATED_VIRTUAL int getMethod() const DAAL_C11_OVERRIDE
Definition: cross_entropy_loss_batch.h:131
daal::algorithms::optimization_solver::cross_entropy_loss::interface2::Batch::parameter
ParameterType & parameter()
Definition: cross_entropy_loss_batch.h:306
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:63
daal::algorithms::AnalysisContainerIface
Abstract interface class that provides virtual methods to access and run implementations of the analy...
Definition: analysis.h:55
daal::algorithms::optimization_solver::cross_entropy_loss::interface2::BatchContainer::compute
virtual services::Status compute() DAAL_C11_OVERRIDE
daal::algorithms::optimization_solver::cross_entropy_loss::interface2::Batch::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: cross_entropy_loss_batch.h:280
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:216
daal::algorithms::optimization_solver::cross_entropy_loss::interface1::Batch::Batch
DAAL_DEPRECATED Batch(size_t nClasses, size_t numberOfTerms)
Definition: cross_entropy_loss_batch.h:108
daal::algorithms::optimization_solver::cross_entropy_loss::interface2::BatchContainer::BatchContainer
BatchContainer(daal::services::Environment::env *daalEnv)
daal_defines.h
daal::algorithms::optimization_solver::cross_entropy_loss::interface1::Batch::parameter
DAAL_DEPRECATED const ParameterType & parameter() const
Definition: cross_entropy_loss_batch.h:163
daal::algorithms::optimization_solver::cross_entropy_loss::interface1::Parameter
Parameter for Cross-entropy loss objective function
Definition: cross_entropy_loss_types.h:87
daal::algorithms::optimization_solver::cross_entropy_loss::interface1::Batch::input
InputType input
Definition: cross_entropy_loss_batch.h:194
daal::algorithms::optimization_solver::cross_entropy_loss::interface2::Batch::allocate
services::Status allocate()
Definition: cross_entropy_loss_batch.h:297
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:96
daal::algorithms::optimization_solver::cross_entropy_loss::interface1::BatchContainer::BatchContainer
DAAL_DEPRECATED BatchContainer(daal::services::Environment::env *daalEnv)
daal::algorithms::optimization_solver::cross_entropy_loss::interface1::Input
Input objects for the Cross-entropy loss objective function
Definition: cross_entropy_loss_types.h:128
daal::algorithms::optimization_solver::cross_entropy_loss::interface1::Batch::parameter
DAAL_DEPRECATED ParameterType & parameter()
Definition: cross_entropy_loss_batch.h:157
daal::algorithms::optimization_solver::cross_entropy_loss::interface1::Batch::clone
DAAL_DEPRECATED services::SharedPtr< Batch< algorithmFPType, method > > clone() const
Definition: cross_entropy_loss_batch.h:138
daal::algorithms::optimization_solver::cross_entropy_loss::interface2::Batch::input
InputType input
Definition: cross_entropy_loss_batch.h:342
daal::algorithms::optimization_solver::cross_entropy_loss::interface1::BatchContainer::~BatchContainer
virtual DAAL_DEPRECATED_VIRTUAL ~BatchContainer()
daal::algorithms::optimization_solver::cross_entropy_loss::interface1::Batch::allocate
DAAL_DEPRECATED services::Status allocate()
Definition: cross_entropy_loss_batch.h:148
daal::algorithms::optimization_solver::cross_entropy_loss::interface1::Batch::Batch
DAAL_DEPRECATED Batch(const Batch< algorithmFPType, method > &other)
Definition: cross_entropy_loss_batch.h:121
daal::algorithms::Analysis
Provides methods for execution of operations over data, such as computation of Summary Statistics est...
Definition: analysis.h:70
daal::algorithms::optimization_solver::cross_entropy_loss::interface2::Batch::parameter
const ParameterType & parameter() const
Definition: cross_entropy_loss_batch.h:312
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:252

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