15 #include <shogun/lib/external/libqp.h>
39 "add_cutting_plane: CP index %u is not free\n", free_idx)
68 while(cp_list_ptr->
address != icp)
70 cp_list_ptr=cp_list_ptr->
next;
73 if (cp_list_ptr==*head)
78 else if (cp_list_ptr==*tail)
89 map[cp_list_ptr->
idx]=
true;
113 while (cp_ptr != *tail)
115 if (icp_stats->
ICPcounter[tmp_idx++]>=cleanAfter)
121 icp_stats->
ACPs[cntACP++]=tmp_idx-1;
130 uint32_t nCP_new=bmrm.
nCP-cntICP;
132 for (uint32_t i=0; i<cntICP; ++i)
152 (bmrm.
nCP-tmp_idx)*
sizeof(uint32_t));
154 (bmrm.
nCP-tmp_idx)*
sizeof(uint32_t));
158 for (uint32_t i=0; i < nCP_new; ++i)
160 for (uint32_t j=0; j < nCP_new; ++j)
167 for (uint32_t i=0; i<nCP_new; ++i)
168 for (uint32_t j=0; j<nCP_new; ++j)
182 return( &H[ BufSize*i ] );
196 bool store_train_info)
199 libqp_state_T qp_exitflag={0, 0, 0, 0};
201 float64_t R, *subgrad, *A, QPSolverTolRel, C=1.0, wdist=0.0;
202 floatmax_t rsum, sq_norm_W, sq_norm_Wdiff=0.0;
206 uint32_t nDim=model->
get_dim();
212 bmrm_ll *CPList_head, *CPList_tail, *cp_ptr, *cp_ptr2, *cp_list=NULL;
244 "overflow: %u * %u > %u -- biggest possible BufSize=%u or nDim=%u\n",
308 if (icp_stats.
ICPs==NULL)
315 if (icp_stats.
ACPs==NULL)
323 if (icp_stats.
H_buff==NULL)
337 memset( (
bool*) map,
true, BufSize);
360 R=machine->
risk(subgrad, W);
382 bmrm.
Fp=R+0.5*_lambda*sq_norm_W;
388 SG_SINFO(
"%4d: tim=%.3lf, Fp=%lf, Fd=%lf, R=%lf\n",
389 bmrm.
nIter, tstop-tstart, bmrm.
Fp, bmrm.
Fd, R);
396 if (store_train_info)
413 for (uint32_t i=0; i<bmrm.
nCP; ++i)
453 qp_exitflag=libqp_splx_solver(&
get_col, diag_H, b, &C, I, &S, beta,
463 for (uint32_t aaa=0; aaa<bmrm.
nCP; ++aaa)
465 if (beta[aaa]>epsilon)
479 for (uint32_t j=0; j<bmrm.
nCP; ++j)
487 R = machine->
risk(subgrad, W);
495 for (uint32_t j=0; j<nDim; ++j)
497 sq_norm_Wdiff+=(W[j]-prevW[j])*(W[j]-prevW[j]);
500 bmrm.
Fp=R+0.5*_lambda*sq_norm_W;
501 bmrm.
Fd=-qp_exitflag.QP;
508 if (bmrm.
Fp - bmrm.
Fd <= TolAbs)
514 SG_SINFO(
"%4d: tim=%.3lf, Fp=%lf, Fd=%lf, (Fp-Fd)=%lf, (Fp-Fd)/Fp=%lf, R=%lf, nCP=%d, nzA=%d, QPexitflag=%d\n",
516 (bmrm.
Fp-bmrm.
Fd)/bmrm.
Fp, R, bmrm.
nCP, bmrm.
nzA, qp_exitflag.exitflag);
519 if (bmrm.
nIter >= histSize)
539 clean_icp(&icp_stats, bmrm, &CPList_head, &CPList_tail, H, diag_H, beta, map, cleanAfter, b, I);
544 if (bmrm.
nCP+1 >= BufSize)
548 if (store_train_info)
559 SG_SINFO(
"On iteration %4d, tim=%.3lf, primal=%.3lf, train_error=%lf\n", bmrm.
nIter, info_tstop-info_tstart, primal, train_error);
564 if (store_train_info)
#define LIBBMRM_CALLOC(x, y)
Class Time that implements a stopwatch based on either cpu time or wall clock time.
static const double * get_col(uint32_t j)
Class DualLibQPBMSOSVM that uses Bundle Methods for Regularized Risk Minimization algorithms for stru...
float64_t * get_cutting_plane(bmrm_ll *ptr)
CSOSVMHelper * get_helper() const
#define LIBBMRM_MEMMOVE(x, y, z)
SGVector< float64_t > hist_wdist
void remove_cutting_plane(bmrm_ll **head, bmrm_ll **tail, bool *map, float64_t *icp)
BmrmStatistics svm_bmrm_solver(CDualLibQPBMSOSVM *machine, float64_t *W, float64_t TolRel, float64_t TolAbs, float64_t _lambda, uint32_t _BufSize, bool cleanICP, uint32_t cleanAfter, float64_t K, uint32_t Tmax, bool store_train_info)
SGVector< float64_t > hist_Fd
static float64_t primal_objective(SGVector< float64_t > w, CStructuredModel *model, float64_t lbda)
virtual int32_t get_dim() const =0
uint32_t find_free_idx(bool *map, uint32_t size)
static const float64_t epsilon
float64_t cur_time_diff(bool verbose=false)
static const uint32_t QPSolverMaxIter
class CSOSVMHelper contains helper functions to compute primal objectives, dual objectives, average training losses, duality gaps etc. These values will be recorded to check convergence. This class is inspired by the matlab implementation of the block coordinate Frank-Wolfe SOSVM solver [1].
virtual float64_t risk(float64_t *subgrad, float64_t *W, TMultipleCPinfo *info=0, EStructRiskType rtype=N_SLACK_MARGIN_RESCALING)
SGVector< float64_t > hist_Fp
static float64_t dot(const bool *v1, const bool *v2, int32_t n)
Compute dot product between v1 and v2 (blas optimized)
#define LIBBMRM_MEMCPY(x, y, z)
static float64_t average_loss(SGVector< float64_t > w, CStructuredModel *model, bool is_ub=false)
static void vec1_plus_scalar_times_vec2(T *vec1, const T scalar, const T *vec2, int32_t n)
x=x+alpha*y
Class CStructuredModel that represents the application specific model and contains most of the applic...
#define LIBBMRM_INDEX(ROW, COL, NUM_ROWS)
all of classes and functions are contained in the shogun namespace
virtual void add_debug_info(float64_t primal, float64_t eff_pass, float64_t train_error, float64_t dual=-1, float64_t dgap=-1)
void add_cutting_plane(bmrm_ll **tail, bool *map, float64_t *A, uint32_t free_idx, float64_t *cp_data, uint32_t dim)
void scale(Matrix A, Matrix B, typename Matrix::Scalar alpha)
CStructuredModel * get_model() const
void resize_vector(int32_t n)
Matrix::Scalar max(Matrix m)
static float32_t sqrt(float32_t x)
void clean_icp(ICP_stats *icp_stats, BmrmStatistics &bmrm, bmrm_ll **head, bmrm_ll **tail, float64_t *&Hmat, float64_t *&diag_H, float64_t *&beta, bool *&map, uint32_t cleanAfter, float64_t *&b, uint32_t *&I, uint32_t cp_models)