15 #include <shogun/lib/external/libqp.h>
64 while(cp_list_ptr->
address != icp)
66 cp_list_ptr=cp_list_ptr->
next;
69 if (cp_list_ptr==*head)
74 else if (cp_list_ptr==*tail)
85 map[cp_list_ptr->
idx]=
true;
109 while (cp_ptr != *tail)
111 if (icp_stats->
ICPcounter[tmp_idx++]>=cleanAfter)
117 icp_stats->
ACPs[cntACP++]=tmp_idx-1;
126 uint32_t nCP_new=bmrm.
nCP-cntICP;
128 for (uint32_t i=0; i<cntICP; ++i)
148 (bmrm.
nCP-tmp_idx)*
sizeof(uint32_t));
150 (bmrm.
nCP-tmp_idx)*
sizeof(uint32_t));
154 for (uint32_t i=0; i < nCP_new; ++i)
156 for (uint32_t j=0; j < nCP_new; ++j)
163 for (uint32_t i=0; i<nCP_new; ++i)
164 for (uint32_t j=0; j<nCP_new; ++j)
194 libqp_state_T qp_exitflag={0, 0, 0, 0};
196 float64_t R, *subgrad, *A, QPSolverTolRel, C=1.0, wdist=0.0;
197 floatmax_t rsum, sq_norm_W, sq_norm_Wdiff=0.0;
201 uint32_t nDim=model->
get_dim();
207 bmrm_ll *CPList_head, *CPList_tail, *cp_ptr, *cp_ptr2, *cp_list=NULL;
293 if (icp_stats.
ICPs==NULL)
300 if (icp_stats.
ACPs==NULL)
308 if (icp_stats.
H_buff==NULL)
322 memset( (
bool*) map,
true, BufSize);
345 R=machine->
risk(subgrad, W);
367 bmrm.
Fp=R+0.5*_lambda*sq_norm_W;
375 SG_SDEBUG(
"%4d: tim=%.3lf, Fp=%lf, Fd=%lf, R=%lf\n",
376 bmrm.
nIter, tstop-tstart, bmrm.
Fp, bmrm.
Fd, R);
400 for (uint32_t i=0; i<bmrm.
nCP; ++i)
439 qp_exitflag=libqp_splx_solver(&
get_col, diag_H, b, &C, I, &S, beta,
449 for (uint32_t aaa=0; aaa<bmrm.
nCP; ++aaa)
465 for (uint32_t j=0; j<bmrm.
nCP; ++j)
473 R = machine->
risk(subgrad, W);
481 for (uint32_t j=0; j<nDim; ++j)
483 sq_norm_Wdiff+=(W[j]-prevW[j])*(W[j]-prevW[j]);
486 bmrm.
Fp=R+0.5*_lambda*sq_norm_W;
487 bmrm.
Fd=-qp_exitflag.QP;
495 if (bmrm.
Fp - bmrm.
Fd <= TolAbs)
498 if (bmrm.
nCP >= BufSize)
506 SG_SDEBUG(
"%4d: tim=%.3lf, Fp=%lf, Fd=%lf, (Fp-Fd)=%lf, (Fp-Fd)/Fp=%lf, R=%lf, nCP=%d, nzA=%d, QPexitflag=%d\n",
508 (bmrm.
Fp-bmrm.
Fd)/bmrm.
Fp, R, bmrm.
nCP, bmrm.
nzA, qp_exitflag.exitflag);
517 if (bmrm.
nCP>=BufSize)
529 clean_icp(&icp_stats, bmrm, &CPList_head, &CPList_tail,
H, diag_H, beta, map, cleanAfter, b, I);
#define LIBBMRM_CALLOC(x, y)
Class Time that implements a stopwatch based on either cpu time or wall clock time.
static float64_t dot(const bool *v1, const bool *v2, int32_t n)
compute dot product between v1 and v2 (blas optimized)
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)
static T max(T *vec, int32_t len)
SGVector< float64_t > hist_wdist
void remove_cutting_plane(bmrm_ll **head, bmrm_ll **tail, bool *map, float64_t *icp)
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 float64_t average_loss(SGVector< float64_t > w, CStructuredModel *model)
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)
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 verbose)
SGVector< float64_t > hist_Fp
#define LIBBMRM_MEMCPY(x, y, z)
Class CStructuredModel that represents the application specific model and contains most of the applic...
#define LIBBMRM_INDEX(ROW, COL, NUM_ROWS)
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)
CStructuredModel * get_model() const
void resize_vector(int32_t n)
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)
static void vec1_plus_scalar_times_vec2(T *vec1, const T scalar, const T *vec2, int32_t n)
x=x+alpha*y