/* file: linear_regression_model.h */ /******************************************************************************* * Copyright 2014-2016 Intel Corporation All Rights Reserved. * * The source code, information and material ("Material") contained herein is * owned by Intel Corporation or its suppliers or licensors, and title to such * Material remains with Intel Corporation or its suppliers or licensors. The * Material contains proprietary information of Intel or its suppliers and * licensors. The Material is protected by worldwide copyright laws and treaty * provisions. No part of the Material may be used, copied, reproduced, * modified, published, uploaded, posted, transmitted, distributed or disclosed * in any way without Intel's prior express written permission. No license under * any patent, copyright or other intellectual property rights in the Material * is granted to or conferred upon you, either expressly, by implication, * inducement, estoppel or otherwise. Any license under such intellectual * property rights must be express and approved by Intel in writing. * * Unless otherwise agreed by Intel in writing, you may not remove or alter this * notice or any other notice embedded in Materials by Intel or Intel's * suppliers or licensors in any way. *******************************************************************************/ /* //++ // Implementation of the class defining the linear regression model //-- */ #ifndef __LINREG_MODEL_H__ #define __LINREG_MODEL_H__ #include "data_management/data/numeric_table.h" #include "data_management/data/homogen_numeric_table.h" #include "algorithms/model.h" namespace daal { namespace algorithms { namespace linear_regression { /** * \brief Contains version 1.0 of the Intel(R) Data Analytics Acceleration Library (Intel(R) DAAL) interface. */ namespace interface1 { /** * @ingroup linear_regression * @{ */ /** * * \brief Parameters for the linear regression algorithm * * \snippet linear_regression/linear_regression_model.h Parameter source code */ /* [Parameter source code] */ class DAAL_EXPORT Parameter : public daal::algorithms::Parameter { public: Parameter(){ interceptFlag=false; }; bool interceptFlag; /*!< Flag that indicates whether the intercept needs to be computed */ }; /* [Parameter source code] */ /** * * \brief %Base class for models trained with the linear regression algorithm * * \tparam modelFPType Data type to store linear regression model data, double or float * * \par References * - Parameter class * - ModelNormEq class * - ModelQR class * - \ref training::interface1::Batch "training::Batch" class * - \ref training::interface1::Online "training::Online" class * - \ref training::interface1::Distributed "training::Distributed" class * - \ref prediction::interface1::Batch "prediction::Batch" class */ class DAAL_EXPORT Model : public daal::algorithms::Model { public: /** * Constructs the linear regression model * \param[in] featnum Number of features in the training data * \param[in] nrhs Number of responses in the training data * \param[in] par Linear regression parameters * \param[in] dummy Dummy variable for the templated constructor */ template DAAL_EXPORT Model(size_t featnum, size_t nrhs, const Parameter &par, modelFPType dummy) : daal::algorithms::Model() { _coefdim = fetnum + 1; _nrhs = nrhs; _interceptFlag = false; _beta = services::SharedPtr( new data_management::HomogenNumericTable(_coefdim, _nrhs, data_management::NumericTableIface::doAllocate, 0)); } /** * Constructs the linear regression model * \param[in] beta Numeric table that contains linear regression coefficients * \param[in] par Linear regression parameters */ Model(data_management::NumericTablePtr &beta, const Parameter &par = Parameter()); /** * Empty constructor for deserialization */ Model() : daal::algorithms::Model() {} /** * Initializes linear regression coefficients of the linear regression model */ virtual void initialize(); virtual ~Model() {} /** * Returns the number of regression coefficients * \return Number of regression coefficients */ size_t getNumberOfBetas(); /** * Returns the number of features in the training data set * \return Number of features in the training data set */ size_t getNumberOfFeatures(); /** * Returns the number of responses in the training data set * \return Number of responses in the training data set */ size_t getNumberOfResponses(); /** * Returns true if the linear regression model contains the intercept term, and false otherwise * \return True if the linear regression model contains the intercept term, and false otherwise */ bool getInterceptFlag(){return _interceptFlag;} /** * Returns the numeric table that contains regression coefficients * \return Table that contains regression coefficients */ data_management::NumericTablePtr getBeta(); /** * Returns the serialization tag of the linear regression model * \return Serialization tag of the linear regression model */ int getSerializationTag() DAAL_C11_OVERRIDE { return 0; } /** * Serializes a linear regression model object * \param[in] archive Storage for a serialized model object or data structure */ void serializeImpl(data_management::InputDataArchive *archive) DAAL_C11_OVERRIDE {} /** * Deserializes a linear regression model object * \param[in] archive Storage for a deserialized model object or data structure */ void deserializeImpl(data_management::OutputDataArchive *archive) DAAL_C11_OVERRIDE {} protected: bool _interceptFlag; /* Flag. True if the linear regression model contains the intercept term; false otherwise. */ size_t _coefdim; /* Number of regression coefficients */ size_t _nrhs; /* Number of responses in the training data set */ data_management::NumericTablePtr _beta; /* Table that contains resulting coefficients */ void setToZero(data_management::NumericTable *table); /** \private */ template void serialImpl(Archive *arch) { daal::algorithms::Model::serialImpl(arch); arch->set(_interceptFlag); arch->set(_coefdim ); arch->set(_nrhs ); arch->setSharedPtrObj(_beta); } }; /** @} */ } // namespace interface1 using interface1::Parameter; using interface1::Model; /** * Checks the correctness of linear regression model * \param[in] model The model to check * \param[in] par The parameter of linear regression algorithm * \param[out] errors The collection of errors * \param[in] coefdim Required number of linear regression coefficients * \param[in] nrhs Required number of responses on the training stage * \param[in] method Computation method */ DAAL_EXPORT void checkModel(linear_regression::Model* model, const daal::algorithms::Parameter *par, services::ErrorCollection *errors, const size_t coefdim, const size_t nrhs, int method); } } } #endif