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

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

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