Skip to content

Commit

Permalink
Attempt to fix LPBoost
Browse files Browse the repository at this point in the history
  • Loading branch information
lisitsyn committed Jun 6, 2012
1 parent 84fbbe6 commit 45d89d9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
8 changes: 3 additions & 5 deletions src/shogun/classifier/LPBoost.cpp
Expand Up @@ -79,7 +79,7 @@ float64_t CLPBoost::find_max_violator(int32_t& max_dim)
for (int32_t j=0; j<sfeat[i].num_feat_entries; j++)
{
int32_t idx=sfeat[i].features[j].feat_index;
float64_t v=u[idx]*m_labels->get_label(idx)*sfeat[i].features[j].entry;
float64_t v=u[idx]*((CBinaryLabels*)m_labels)->get_confidence(idx)*sfeat[i].features[j].entry;
valplus+=v;
valminus-=v;
}
Expand Down Expand Up @@ -110,10 +110,8 @@ bool CLPBoost::train_machine(CFeatures* data)
int32_t num_vec=features->get_num_vectors();

ASSERT(num_vec==num_train_labels);
SG_FREE(w);
w=SG_MALLOC(float64_t, num_feat);
memset(w,0,sizeof(float64_t)*num_feat);
w_dim=num_feat;
w = SGVector<float64_t>(num_feat);
memset(w.vector,0,sizeof(float64_t)*num_feat);

CCplex solver;
solver.init(E_LINEAR);
Expand Down
18 changes: 9 additions & 9 deletions src/shogun/mathematics/Cplex.cpp
Expand Up @@ -85,7 +85,7 @@ bool CCplex::init(E_PROB_TYPE typ, int32_t timeout)
}

bool CCplex::setup_subgradientlpm_QP(
float64_t C, CLabels* labels, CSparseFeatures<float64_t>* features,
float64_t C, CBinaryLabels* labels, CSparseFeatures<float64_t>* features,
int32_t* idx_bound, int32_t num_bound, int32_t* w_zero, int32_t num_zero,
float64_t* vee, int32_t num_dim, bool use_bias)
{
Expand Down Expand Up @@ -156,7 +156,7 @@ bool CCplex::setup_subgradientlpm_QP(
cmatbeg[i]=offs;
cmatcnt[i]=vlen;

float64_t val= -C*labels->get_label(idx);
float64_t val= -C*labels->get_confidence(idx);

if (vlen>0)
{
Expand Down Expand Up @@ -291,7 +291,7 @@ bool CCplex::setup_lpboost(float64_t C, int32_t num_cols)

bool CCplex::add_lpboost_constraint(
float64_t factor, SGSparseVectorEntry<float64_t>* h, int32_t len, int32_t ulen,
CLabels* label)
CBinaryLabels* label)
{
int amatbeg[1]; /* for calling external lib */
int amatind[len+1]; /* for calling external lib */
Expand All @@ -308,7 +308,7 @@ bool CCplex::add_lpboost_constraint(
int32_t idx=h[i].feat_index;
float64_t val=factor*h[i].entry;
amatind[i]=idx;
amatval[i]=label->get_label(idx)*val;
amatval[i]=label->get_confidence(idx)*val;
}

int32_t status = CPXaddrows (env, lp, 0, 1, len, rhs, sense, amatbeg, amatind, amatval, NULL, NULL);
Expand All @@ -320,7 +320,7 @@ bool CCplex::add_lpboost_constraint(
}

bool CCplex::setup_lpm(
float64_t C, CSparseFeatures<float64_t>* x, CLabels* y, bool use_bias)
float64_t C, CSparseFeatures<float64_t>* x, CBinaryLabels* y, bool use_bias)
{
ASSERT(x);
ASSERT(y);
Expand Down Expand Up @@ -391,7 +391,7 @@ bool CCplex::setup_lpm(
for (int32_t i=0; i<num_vec; i++)
{
amatind[offs]=i;
amatval[offs]=-y->get_label(i);
amatval[offs]=-y->get_confidence(i);
offs++;
}

Expand All @@ -412,7 +412,7 @@ bool CCplex::setup_lpm(
float64_t val=sfeat[i].features[j].entry;

amatind[offs]=row;
amatval[offs]=-y->get_label(row)*val;
amatval[offs]=-y->get_confidence(row)*val;
offs++;
}
}
Expand All @@ -428,9 +428,9 @@ bool CCplex::setup_lpm(
float64_t val=sfeat[i].features[j].entry;

amatind[offs]=row;
amatval[offs]=y->get_label(row)*val;
amatval[offs]=y->get_confidence(row)*val;
offs++;
}

}

x->clean_tsparse(sfeat, num_svec);
Expand Down
6 changes: 3 additions & 3 deletions src/shogun/mathematics/Cplex.h
Expand Up @@ -53,14 +53,14 @@ class CCplex : public CSGObject
// A = [ E Z_w Z_x ] dim(A)=(num_dim+1, num_dim+1 + num_zero + num_bound)
// (+1 for bias!)
bool setup_subgradientlpm_QP(
float64_t C, CLabels* labels, CSparseFeatures<float64_t>* features,
float64_t C, CBinaryLabels* labels, CSparseFeatures<float64_t>* features,
int32_t* idx_bound, int32_t num_bound, int32_t* w_zero,
int32_t num_zero, float64_t* vee, int32_t num_dim, bool use_bias);

bool setup_lpboost(float64_t C, int32_t num_cols);
bool add_lpboost_constraint(
float64_t factor, SGSparseVectorEntry<float64_t>* h, int32_t len,
int32_t ulen, CLabels* label);
int32_t ulen, CBinaryLabels* label);

// given N sparse inputs x_i, and corresponding labels y_i i=0...N-1
// create the following 1-norm SVM problem & transfer to cplex
Expand Down Expand Up @@ -99,7 +99,7 @@ class CCplex : public CSGObject
//
// b = -1 -1 -1 -1 ...
bool setup_lpm(
float64_t C, CSparseFeatures<float64_t>* x, CLabels* y, bool use_bias);
float64_t C, CSparseFeatures<float64_t>* x, CBinaryLabels* y, bool use_bias);

// call this to setup linear part
//
Expand Down

0 comments on commit 45d89d9

Please sign in to comment.