15 #include <shogun/lib/external/libqp.h>
38 "add_cutting_plane: CP index %u is not free\n", free_idx)
67 while(cp_list_ptr->
address != icp)
69 cp_list_ptr=cp_list_ptr->
next;
72 if (cp_list_ptr==*head)
77 else if (cp_list_ptr==*tail)
88 map[cp_list_ptr->
idx]=
true;
112 while (cp_ptr != *tail)
114 if (icp_stats->
ICPcounter[tmp_idx++]>=cleanAfter)
120 icp_stats->
ACPs[cntACP++]=tmp_idx-1;
129 uint32_t nCP_new=bmrm.
nCP-cntICP;
131 for (uint32_t i=0; i<cntICP; ++i)
151 (bmrm.
nCP-tmp_idx)*
sizeof(uint32_t));
153 (bmrm.
nCP-tmp_idx)*
sizeof(uint32_t));
157 for (uint32_t i=0; i < nCP_new; ++i)
159 for (uint32_t j=0; j < nCP_new; ++j)
166 for (uint32_t i=0; i<nCP_new; ++i)
167 for (uint32_t j=0; j<nCP_new; ++j)
181 return( &H[ BufSize*i ] );
195 bool store_train_info)
198 libqp_state_T qp_exitflag={0, 0, 0, 0};
200 float64_t R, *subgrad, *A, QPSolverTolRel, C=1.0, wdist=0.0;
201 floatmax_t rsum, sq_norm_W, sq_norm_Wdiff=0.0;
205 uint32_t nDim=model->
get_dim();
211 bmrm_ll *CPList_head, *CPList_tail, *cp_ptr, *cp_ptr2, *cp_list=NULL;
243 "overflow: %u * %u > %u -- biggest possible BufSize=%u or nDim=%u\n",
307 if (icp_stats.
ICPs==NULL)
314 if (icp_stats.
ACPs==NULL)
322 if (icp_stats.
H_buff==NULL)
336 memset( (
bool*) map,
true, BufSize);
359 R=machine->
risk(subgrad, W);
381 bmrm.
Fp=R+0.5*_lambda*sq_norm_W;
387 SG_SINFO(
"%4d: tim=%.3lf, Fp=%lf, Fd=%lf, R=%lf\n",
388 bmrm.
nIter, tstop-tstart, bmrm.
Fp, bmrm.
Fd, R);
395 if (store_train_info)
412 for (uint32_t i=0; i<bmrm.
nCP; ++i)
452 qp_exitflag=libqp_splx_solver(&
get_col, diag_H, b, &C, I, &S, beta,
462 for (uint32_t aaa=0; aaa<bmrm.
nCP; ++aaa)
464 if (beta[aaa]>epsilon)
478 for (uint32_t j=0; j<bmrm.
nCP; ++j)
486 R = machine->
risk(subgrad, W);
494 for (uint32_t j=0; j<nDim; ++j)
496 sq_norm_Wdiff+=(W[j]-prevW[j])*(W[j]-prevW[j]);
499 bmrm.
Fp=R+0.5*_lambda*sq_norm_W;
500 bmrm.
Fd=-qp_exitflag.QP;
507 if (bmrm.
Fp - bmrm.
Fd <= TolAbs)
513 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",
515 (bmrm.
Fp-bmrm.
Fd)/bmrm.
Fp, R, bmrm.
nCP, bmrm.
nzA, qp_exitflag.exitflag);
518 if (bmrm.
nIter >= histSize)
538 clean_icp(&icp_stats, bmrm, &CPList_head, &CPList_tail, H, diag_H, beta, map, cleanAfter, b, I);
543 if (bmrm.
nCP+1 >= BufSize)
547 if (store_train_info)
558 SG_SINFO(
"On iteration %4d, tim=%.3lf, primal=%.3lf, train_error=%lf\n", bmrm.
nIter, info_tstop-info_tstart, primal, train_error);
563 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)
static T max(T a, T b)
return the maximum of two integers
SGVector< float64_t > hist_Fp
#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
static float64_t dot(const bool *v1, const bool *v2, int32_t n)
Compute dot product between v1 and v2 (blas optimized)
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)
x^0.5
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)