4 #include <Eigen/Sparse> 25 const size_t nvals = values.size();
26 _beta = VectorXd::Zero(nvals);
27 for (
size_t i=0; i != nvals; ++i) {
28 _beta(i) = values.at(i);
35 Eigen::VectorXd beta =
_beta;
36 if (0 == beta.size()) {
37 beta = VectorXd::Zero(
_X.cols());
41 int nbeta = beta.size();
44 Eigen::VectorXd
y =
Gety();
45 Eigen::MatrixXd
X =
GetX();
50 for (
int j=0; j<nbeta; j++) {
51 norm(j) = X.col(j).squaredNorm();
53 cerr <<
"warning: the " << j <<
"th variable is not used, please consider removing it." <<
endl;
57 double tol2 =
TOL*
TOL*nbeta;
60 Eigen::VectorXd ydX(nbeta);
61 Eigen::SparseMatrix<double> XdX(nbeta,nbeta);
62 for (
int i=0;i!=nbeta;i++){
63 ydX(i) = y.dot(X.col(i));
65 for (
int j=0;j!=nbeta;j++){
66 double value = X.col(i).dot(X.col(j));
68 XdX.insert(i,j) =
value;
79 VectorXd betalast = beta;
82 for (
int j=0;j!=nbeta;j++){
85 for (SparseMatrix<double>::InnerIterator it(XdX,j); it; ++it){
88 beta(j) -= it.value() * beta(it.row());
103 VectorXd diff = beta - betalast;
107 if (diff.squaredNorm()<tol2) {
108 if (double_check!=1) {
110 for (
int k=0;
k<nbeta;
k++) {
std::vector< bool > _active_beta
virtual void Setbeta(Eigen::VectorXd beta)
LassoModel(double lambda=1., int max_iter=100000, double TOL=1e-3, bool non_negtive=true)
double _soft_thresholding(double x, double lambda_)
Eigen::VectorXd & Getbeta()
auto norm(Vector const &v)
Return norm of the specified vector.
const GenericPointer< typename T::ValueType > T2 value
void Set_init_values(std::vector< double > values)
Eigen::VectorXd lambda_weight
QTextStream & endl(QTextStream &s)