#include <ElasticNetModel.h>
Definition at line 10 of file ElasticNetModel.h.
WireCell::ElasticNetModel::ElasticNetModel |
( |
double |
lambda = 1. , |
|
|
double |
alpha = 1. , |
|
|
int |
max_iter = 100000 , |
|
|
double |
TOL = 1e-3 , |
|
|
bool |
non_negtive = true |
|
) |
| |
WireCell::ElasticNetModel::~ElasticNetModel |
( |
| ) |
|
double WireCell::ElasticNetModel::_soft_thresholding |
( |
double |
x, |
|
|
double |
lambda_ |
|
) |
| |
|
protected |
Definition at line 98 of file ElasticNetModel.cxx.
101 if (delta > lambda_) {
102 return delta - lambda_;
109 if (delta < -lambda_) {
110 return delta + lambda_;
void WireCell::ElasticNetModel::Fit |
( |
| ) |
|
|
virtual |
Reimplemented from WireCell::LinearModel.
Reimplemented in WireCell::LassoModel.
Definition at line 26 of file ElasticNetModel.cxx.
29 Eigen::VectorXd beta =
_beta;
30 if (0 == beta.size()) {
31 beta = VectorXd::Zero(
_X.cols());
35 int nbeta = beta.size();
39 Eigen::VectorXd
y =
Gety();
40 Eigen::MatrixXd
X =
GetX();
46 for (
int j=0; j<nbeta; j++) {
47 norm(j) = X.col(j).squaredNorm();
49 cerr <<
"warning: the " << j <<
"th variable is not used, please consider removing it." <<
endl;
53 double tol2 =
TOL*
TOL*nbeta;
57 VectorXd betalast = beta;
58 for (
int j=0; j<nbeta; j++) {
60 VectorXd X_j = X.col(j);
61 VectorXd beta_tmp = beta;
63 VectorXd r_j = (y - X * beta_tmp);
64 double delta_j = X_j.dot(r_j);
76 VectorXd diff = beta - betalast;
79 if (diff.squaredNorm()<tol2) {
80 if (double_check!=1) {
82 for (
int k=0;
k<nbeta;
k++) {
std::vector< bool > _active_beta
virtual void Setbeta(Eigen::VectorXd beta)
double _soft_thresholding(double x, double lambda_)
auto norm(Vector const &v)
Return norm of the specified vector.
Eigen::VectorXd lambda_weight
QTextStream & endl(QTextStream &s)
void WireCell::ElasticNetModel::SetLambdaWeight |
( |
Eigen::VectorXd |
w | ) |
|
|
inline |
void WireCell::ElasticNetModel::SetLambdaWeight |
( |
int |
i, |
|
|
double |
weight |
|
) |
| |
|
inline |
void WireCell::ElasticNetModel::SetX |
( |
Eigen::MatrixXd |
X | ) |
|
|
inlinevirtual |
double WireCell::ElasticNetModel::alpha |
double WireCell::ElasticNetModel::lambda |
Eigen::VectorXd WireCell::ElasticNetModel::lambda_weight |
int WireCell::ElasticNetModel::max_iter |
bool WireCell::ElasticNetModel::non_negtive |
double WireCell::ElasticNetModel::TOL |
The documentation for this class was generated from the following files: