本文整理汇总了C++中CDotFeatures::add_to_dense_vec方法的典型用法代码示例。如果您正苦于以下问题:C++ CDotFeatures::add_to_dense_vec方法的具体用法?C++ CDotFeatures::add_to_dense_vec怎么用?C++ CDotFeatures::add_to_dense_vec使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CDotFeatures
的用法示例。
在下文中一共展示了CDotFeatures::add_to_dense_vec方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: add_new_cut
/*----------------------------------------------------------------------------------
sparse_add_new_cut( new_col_H, new_cut, cut_length, nSel ) does the following:
new_a = sum(data_X(:,find(new_cut ~=0 )),2);
new_col_H = [sparse_A(:,1:nSel)'*new_a ; new_a'*new_a];
sparse_A(:,nSel+1) = new_a;
---------------------------------------------------------------------------------*/
int CSVMOcas::add_new_cut(
float64_t *new_col_H, uint32_t *new_cut, uint32_t cut_length,
uint32_t nSel, void* ptr)
{
CSVMOcas* o = (CSVMOcas*) ptr;
CDotFeatures* f = o->features;
uint32_t nDim=(uint32_t) o->w_dim;
float64_t* y = o->lab.vector;
float64_t** c_val = o->cp_value;
uint32_t** c_idx = o->cp_index;
uint32_t* c_nzd = o->cp_nz_dims;
float64_t* c_bias = o->cp_bias;
float64_t sq_norm_a;
uint32_t i, j, nz_dims;
/* temporary vector */
float64_t* new_a = o->tmp_a_buf;
memset(new_a, 0, sizeof(float64_t)*nDim);
for(i=0; i < cut_length; i++)
{
f->add_to_dense_vec(y[new_cut[i]], new_cut[i], new_a, nDim);
if (o->use_bias)
c_bias[nSel]+=y[new_cut[i]];
}
/* compute new_a'*new_a and count number of non-zerou dimensions */
nz_dims = 0;
sq_norm_a = CMath::sq(c_bias[nSel]);
for(j=0; j < nDim; j++ ) {
if(new_a[j] != 0) {
nz_dims++;
sq_norm_a += new_a[j]*new_a[j];
}
}
/* sparsify new_a and insert it to the last column of sparse_A */
c_nzd[nSel] = nz_dims;
c_idx[nSel]=NULL;
c_val[nSel]=NULL;
if(nz_dims > 0)
{
c_idx[nSel]=SG_MALLOC(uint32_t, nz_dims);
c_val[nSel]=SG_MALLOC(float64_t, nz_dims);
uint32_t idx=0;
for(j=0; j < nDim; j++ )
{
if(new_a[j] != 0)
{
c_idx[nSel][idx] = j;
c_val[nSel][idx++] = new_a[j];
}
}
}
new_col_H[nSel] = sq_norm_a;
for(i=0; i < nSel; i++)
{
float64_t tmp = c_bias[nSel]*c_bias[i];
for(j=0; j < c_nzd[i]; j++)
tmp += new_a[c_idx[i][j]]*c_val[i][j];
new_col_H[i] = tmp;
}
//CMath::display_vector(new_col_H, nSel+1, "new_col_H");
//CMath::display_vector((int32_t*) c_idx[nSel], (int32_t) nz_dims, "c_idx");
//CMath::display_vector((float64_t*) c_val[nSel], nz_dims, "c_val");
return 0;
}