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

linear_regression_model_builder.h
1 /* file: linear_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 linear regression model builder
19 //--
20 */
21 
22 #ifndef __LINEAR_REGRESSION_MODEL_BUILDER_H__
23 #define __LINEAR_REGRESSION_MODEL_BUILDER_H__
24 
25 #include "algorithms/linear_regression/linear_regression_model.h"
26 
27 namespace daal
28 {
29 namespace algorithms
30 {
36 namespace linear_regression
37 {
38 
42 namespace interface1
43 {
56 template<typename modelFPType = DAAL_ALGORITHM_FP_TYPE>
57 class DAAL_EXPORT ModelBuilder
58 {
59 public:
60 
66  ModelBuilder(size_t nFeatures, size_t nResponses);
67 
75  template<typename RandomIterator>
76  void setBeta(RandomIterator first, RandomIterator last)
77  {
78  data_management::BlockDescriptor<modelFPType> pBlock;
79  _modelPtr->getBeta()->getBlockOfRows(0, _nResponses, data_management::readWrite, pBlock);
80  modelFPType* sp = pBlock.getBlockPtr();
81  if( (last - first) == ((_nFeatures)*_nResponses) )
82  {
83  setInterceptFlag(false);
84  size_t i = 0;
85  while(first != last)
86  {
87  if( (i % (_nFeatures + 1)) == 0)
88  {
89  sp[i] = 0;
90  ++i;
91  }
92  sp[i] = *first;
93  ++first;
94  ++i;
95  }
96  }
97  else if( (last - first) == ((_nFeatures + 1)*_nResponses) )
98  {
99  setInterceptFlag(true);
100  while(first != last)
101  {
102  *sp = *first;
103  ++first;
104  ++sp;
105  }
106  }
107  else
108  {
109  _s = services::Status(services::ErrorIncorrectParameter);
110  services::throwIfPossible(_s);
111  }
112  _modelPtr->getBeta()->releaseBlockOfRows(pBlock);
113  }
114 
119  ModelPtr getModel()
120  {
121  return _modelPtr;
122  }
123 
128  services::Status getStatus()
129  {
130  return _s;
131  }
132 
133 private:
134  ModelPtr _modelPtr;
135  services::Status _s;
136  size_t _nFeatures;
137  size_t _nResponses;
138 
139  void setInterceptFlag(bool interceptFlag);
140 };
141 
143 } // namespace interface1
144 using interface1::ModelBuilder;
145 
146 } // namespace linear_regression
147 } // namespace algorithms
148 } // namespace daal
149 #endif
daal::algorithms::linear_regression::interface1::ModelBuilder
Class for building model of the linear regression algorithm
Definition: linear_regression_model_builder.h:57
daal
Definition: algorithm_base_common.h:31
daal::services::ErrorIncorrectParameter
Definition: error_indexes.h:97
daal::algorithms::linear_regression::interface1::ModelBuilder::setBeta
void setBeta(RandomIterator first, RandomIterator last)
Definition: linear_regression_model_builder.h:76
daal::algorithms::linear_regression::interface1::ModelBuilder::getStatus
services::Status getStatus()
Definition: linear_regression_model_builder.h:128
daal::algorithms::linear_regression::interface1::ModelBuilder::getModel
ModelPtr getModel()
Definition: linear_regression_model_builder.h:119

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