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 ] );
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;
243 REQUIRE(BufSize < (std::numeric_limits<size_t>::max() / nDim),
244 "overflow: %u * %u > %u -- biggest possible BufSize=%u or nDim=%u\n",
245 BufSize, nDim, std::numeric_limits<size_t>::max(),
246 (std::numeric_limits<size_t>::max() / nDim),
247 (std::numeric_limits<size_t>::max() / BufSize));
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;
390 SG_SPRINT(
"%4d: tim=%.3lf, Fp=%lf, Fd=%lf, R=%lf\n",
391 bmrm.
nIter, tstop-tstart, bmrm.
Fp, bmrm.
Fd, R);
415 for (uint32_t i=0; i<bmrm.
nCP; ++i)
455 qp_exitflag=libqp_splx_solver(&
get_col, diag_H, b, &C, I, &S, beta,
465 for (uint32_t aaa=0; aaa<bmrm.
nCP; ++aaa)
467 if (beta[aaa]>epsilon)
481 for (uint32_t j=0; j<bmrm.
nCP; ++j)
489 R = machine->
risk(subgrad, W);
497 for (uint32_t j=0; j<nDim; ++j)
499 sq_norm_Wdiff+=(W[j]-prevW[j])*(W[j]-prevW[j]);
502 bmrm.
Fp=R+0.5*_lambda*sq_norm_W;
503 bmrm.
Fd=-qp_exitflag.QP;
510 if (bmrm.
Fp - bmrm.
Fd <= TolAbs)
517 SG_SPRINT(
"%4d: tim=%.3lf, Fp=%lf, Fd=%lf, (Fp-Fd)=%lf, (Fp-Fd)/Fp=%lf, R=%lf, nCP=%d, nzA=%d, QPexitflag=%d\n",
519 (bmrm.
Fp-bmrm.
Fd)/bmrm.
Fp, R, bmrm.
nCP, bmrm.
nzA, qp_exitflag.exitflag);
522 if (bmrm.
nIter >= histSize)
542 clean_icp(&icp_stats, bmrm, &CPList_head, &CPList_tail, H, diag_H, beta, map, cleanAfter, b, I);
547 if (bmrm.
nCP+1 >= BufSize)
561 SG_SPRINT(
"%4d: add_debug_info: tim=%.3lf, primal=%.3lf, train_error=%lf\n",
562 bmrm.
nIter, debug_tstop-debug_tstart, primal, train_error);
#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
bool loglevel_above(EMessageType type) const
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)
#define SG_UNLIKELY(expr)
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)
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)
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