Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Soeren Sonnenburg
committed
Jun 2, 2012
1 parent
80b8013
commit f0a2a12
Showing
5 changed files
with
220 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
|
||
/* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Copyright (C) 2012 Soeren Sonnenburg | ||
*/ | ||
|
||
#include <shogun/lib/config.h> | ||
#ifdef HAVE_LAPACK | ||
#include <shogun/regression/svr/LibLinearRegression.h> | ||
#include <shogun/mathematics/Math.h> | ||
#include <shogun/labels/RegressionLabels.h> | ||
|
||
using namespace shogun; | ||
|
||
CLibLinearRegression::CLibLinearRegression() : | ||
CLinearMachine() | ||
{ | ||
init_defaults(); | ||
} | ||
|
||
CLibLinearRegression::CLibLinearRegression(float64_t C, CDotFeatures* feats, CLabels* labs) : | ||
CLinearMachine() | ||
{ | ||
init_defaults(); | ||
set_C(C); | ||
set_features(feats); | ||
set_labels(labs); | ||
} | ||
|
||
void CLibLinearRegression::init_defaults() | ||
{ | ||
set_C(1.0); | ||
set_epsilon(1e-2); | ||
set_max_iter(10000); | ||
set_use_bias(false); | ||
} | ||
|
||
void CLibLinearRegression::register_parameters() | ||
{ | ||
SG_ADD(&m_C, "m_C", "regularization constant",MS_AVAILABLE); | ||
SG_ADD(&m_epsilon, "m_epsilon", "tolerance epsilon",MS_NOT_AVAILABLE); | ||
SG_ADD(&m_epsilon, "m_tube_epsilon", "svr tube epsilon",MS_AVAILABLE); | ||
SG_ADD(&m_max_iter, "m_max_iter", "max number of iterations",MS_NOT_AVAILABLE); | ||
SG_ADD(&m_use_bias, "m_use_bias", "indicates whether bias should be used",MS_NOT_AVAILABLE); | ||
} | ||
|
||
CLibLinearRegression::~CLibLinearRegression() | ||
{ | ||
} | ||
|
||
bool CLibLinearRegression::train_machine(CFeatures* data) | ||
{ | ||
if (data) | ||
set_features((CDotFeatures*)data); | ||
|
||
ASSERT(features); | ||
ASSERT(m_labels && m_labels->get_label_type()==LT_REGRESSION); | ||
//TODO | ||
return true; | ||
} | ||
#endif /* HAVE_LAPACK */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
/* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Copyright (C) 2012 Soeren Sonnenburg | ||
*/ | ||
|
||
#ifndef _REGRESSIONLIBLINEAR_H___ | ||
#define _REGRESSIONLIBLINEAR_H___ | ||
#include <shogun/lib/config.h> | ||
#ifdef HAVE_LAPACK | ||
#include <shogun/lib/common.h> | ||
#include <shogun/features/DotFeatures.h> | ||
#include <shogun/machine/LinearMachine.h> | ||
#include <shogun/lib/external/shogun_liblinear.h> | ||
|
||
namespace shogun | ||
{ | ||
|
||
/** @brief LibLinear for regression | ||
*/ | ||
class CLibLinearRegression : public CLinearMachine | ||
{ | ||
public: | ||
MACHINE_PROBLEM_TYPE(PT_REGRESSION) | ||
|
||
/** default constructor */ | ||
CLibLinearRegression(); | ||
|
||
/** standard constructor | ||
* @param C C regularization constant value | ||
* @param features features | ||
* @param labs labels | ||
*/ | ||
CLibLinearRegression(float64_t C, CDotFeatures* features, CLabels* labs); | ||
|
||
/** destructor */ | ||
virtual ~CLibLinearRegression(); | ||
|
||
/** get name */ | ||
virtual const char* get_name() const | ||
{ | ||
return "LibLinearRegression"; | ||
} | ||
|
||
/** set C | ||
* @param C C value | ||
*/ | ||
inline void set_C(float64_t C) | ||
{ | ||
ASSERT(C>0); | ||
m_C = C; | ||
} | ||
|
||
/** get C | ||
* @return C value | ||
*/ | ||
inline float64_t get_C() const { return m_C; } | ||
|
||
/** set tube epsilon | ||
* | ||
* @param eps new tube epsilon | ||
*/ | ||
inline void set_tube_epsilon(float64_t eps) { m_tube_epsilon=eps; } | ||
|
||
/** get tube epsilon | ||
* | ||
* @return tube epsilon | ||
*/ | ||
inline float64_t get_tube_epsilon() { return m_tube_epsilon; } | ||
|
||
|
||
/** set epsilon | ||
* @param epsilon epsilon value | ||
*/ | ||
inline void set_epsilon(float64_t epsilon) | ||
{ | ||
ASSERT(epsilon>0); | ||
m_epsilon = epsilon; | ||
} | ||
|
||
/** get epsilon | ||
* @return epsilon value | ||
*/ | ||
inline float64_t get_epsilon() const { return m_epsilon; } | ||
|
||
/** set use bias | ||
* @param use_bias use_bias value | ||
*/ | ||
inline void set_use_bias(bool use_bias) | ||
{ | ||
m_use_bias = use_bias; | ||
} | ||
/** get use bias | ||
* @return use_bias value | ||
*/ | ||
inline bool get_use_bias() const | ||
{ | ||
return m_use_bias; | ||
} | ||
|
||
/** set max iter | ||
* @param max_iter max iter value | ||
*/ | ||
inline void set_max_iter(int32_t max_iter) | ||
{ | ||
ASSERT(max_iter>0); | ||
m_max_iter = max_iter; | ||
} | ||
/** get max iter | ||
* @return max iter value | ||
*/ | ||
inline int32_t get_max_iter() const { return m_max_iter; } | ||
|
||
protected: | ||
|
||
/** train machine */ | ||
virtual bool train_machine(CFeatures* data = NULL); | ||
|
||
private: | ||
|
||
/** init defaults */ | ||
void init_defaults(); | ||
|
||
/** register parameters */ | ||
void register_parameters(); | ||
|
||
protected: | ||
|
||
/** regularization constant for each machine */ | ||
float64_t m_C; | ||
|
||
/** tolerance */ | ||
float64_t m_epsilon; | ||
|
||
/** tube epsilon for support vector regression*/ | ||
float64_t m_tube_epsilon; | ||
|
||
/** max number of iterations */ | ||
int32_t m_max_iter; | ||
|
||
/** use bias */ | ||
bool m_use_bias; | ||
}; | ||
} | ||
#endif /* HAVE_LAPACK */ | ||
#endif |