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

logistic_regression_model_builder.h
1 /* file: logistic_regression_model_builder.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 class defining the logistic regression model builder
19 //--
20 */
21 
22 #ifndef __LOGISTIC_REGRESSION_MODEL_BUILDER_H__
23 #define __LOGISTIC_REGRESSION_MODEL_BUILDER_H__
24 
25 #include "algorithms/logistic_regression/logistic_regression_model.h"
26 
27 namespace daal
28 {
29 namespace algorithms
30 {
39 namespace logistic_regression
40 {
44 namespace interface1
45 {
58 template<typename modelFPType = DAAL_ALGORITHM_FP_TYPE>
59 class DAAL_EXPORT ModelBuilder
60 {
61 public:
62 
68  ModelBuilder(size_t nFeatures, size_t nClasses);
69 
77  template<typename RandomIterator>
78  void setBeta(RandomIterator first, RandomIterator last)
79  {
80  data_management::BlockDescriptor<modelFPType> pBlock;
81  const size_t nVectorsBeta = _nClasses == 2 ? 1 : _nClasses;
82  _modelPtr->getBeta()->getBlockOfRows(0, nVectorsBeta, data_management::readWrite, pBlock);
83  modelFPType* sp = pBlock.getBlockPtr();
84  if((last - first) == _nFeatures*nVectorsBeta)
85  {
86  setInterceptFlag(false);
87  size_t i = 0;
88  while(first != last)
89  {
90  if((i % (_nFeatures + 1)) == 0)
91  {
92  sp[i] = 0;
93  ++i;
94  }
95  sp[i] = *first;
96  ++first;
97  ++i;
98  }
99  }
100  else if((last - first) == (_nFeatures + 1)*nVectorsBeta)
101  {
102  setInterceptFlag(true);
103  while(first != last)
104  {
105  *sp = *first;
106  ++first;
107  ++sp;
108  }
109  }
110  else
111  {
112  _s = services::Status(services::ErrorIncorrectParameter);
113  services::throwIfPossible(_s);
114  }
115  _modelPtr->getBeta()->releaseBlockOfRows(pBlock);
116  }
117 
122  ModelPtr getModel()
123  {
124  return _modelPtr;
125  }
126 
131  services::Status getStatus()
132  {
133  return _s;
134  }
135 
136 private:
137  ModelPtr _modelPtr;
138  services::Status _s;
139  size_t _nFeatures;
140  size_t _nClasses;
141 
142  void setInterceptFlag(bool interceptFlag);
143 };
144 
146 } // namespace interface1
147 using interface1::ModelBuilder;
148 
149 } // namespace logistic_regression
150 } // namespace algorithms
151 } // namespace daal
152 #endif
daal
Definition: algorithm_base_common.h:31
daal::algorithms::logistic_regression::interface1::ModelBuilder::setBeta
void setBeta(RandomIterator first, RandomIterator last)
Definition: logistic_regression_model_builder.h:78
daal::algorithms::logistic_regression::interface1::ModelBuilder
Class for building model of the logistic regression algorithm
Definition: logistic_regression_model_builder.h:59
daal::services::ErrorIncorrectParameter
Definition: error_indexes.h:97
daal::algorithms::logistic_regression::interface1::ModelBuilder::getModel
ModelPtr getModel()
Definition: logistic_regression_model_builder.h:122
daal::algorithms::logistic_regression::interface1::ModelBuilder::getStatus
services::Status getStatus()
Definition: logistic_regression_model_builder.h:131

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