当前位置: 首页>>代码示例>>C++>>正文


C++ CData::UpdateCompactMatrix方法代码示例

本文整理汇总了C++中CData::UpdateCompactMatrix方法的典型用法代码示例。如果您正苦于以下问题:C++ CData::UpdateCompactMatrix方法的具体用法?C++ CData::UpdateCompactMatrix怎么用?C++ CData::UpdateCompactMatrix使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CData的用法示例。


在下文中一共展示了CData::UpdateCompactMatrix方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: init_Y_in

void CParam::init_Y_in(CData &Data) {
  Y_in = Matrix(n_sample,n_var) ;
  Real* a = Y_in.data();
  Real* b = Data.D_initial.data();
  for (int i =0; i <n_sample * n_var; i++) { *a++ = log(*b++);}
  Y_in_compact= Matrix(n_sample,n_var_independent);
  Data.UpdateCompactMatrix(Y_in_compact,Y_in);
}
开发者ID:QuanliWang,项目名称:EditImputeCont,代码行数:8,代码来源:CParam.cpp

示例2: logN_unnorm

void CParam::S3_Z_in(CData &Data) {
  Data.UpdateCompactMatrix(Y_in_compact,Y_in);
  for (int i_sample=1; i_sample<=n_sample; i_sample++) {
    // calculate pi_tilde_in
    ColumnVector logN_unnorm(K);
    ColumnVector y_compact = (Y_in_compact.row(i_sample)).t() ;

    for (int k=1; k<=K; k++) {
      ColumnVector mu_k = Mu.column(k);
      logN_unnorm(k) = log_MVN_fn(y_compact, mu_k, LSIGMA_i[k-1],logdet_and_more(k));
    }
    double max_logN_unnorm = logN_unnorm.maximum();

    ColumnVector pi_tilde_in_unnorm(K); pi_tilde_in_unnorm = 0.0 ;
    for (int k=1; k<=K; k++){
      pi_tilde_in_unnorm(k) = pi(k) * exp(logN_unnorm(k)-max_logN_unnorm);
    }
    ColumnVector pi_tilde_in = (1.0/pi_tilde_in_unnorm.sum()) * pi_tilde_in_unnorm ;

    z_in(i_sample) = rdiscrete_fn( pi_tilde_in );
  }
}
开发者ID:QuanliWang,项目名称:EditImputeCont,代码行数:22,代码来源:CParam.cpp

示例3: z_out_large

void CParam::S4_Z_out(CData &Data) {
  int count_out = 0,   count_in = 0;

  ColumnVector z_out_large(toolarge_nout);
  Matrix Y_out_compact_large(toolarge_nout,n_var_independent);
  Matrix X_aux(n_sample,n_var);

  while ( (count_in < n_sample) && (count_out < toolarge_nout) ) {

    int k = rdiscrete_fn(pi);
    ColumnVector mu_k = Mu.column(k);			// Note that mu_k is Mu.column(k)
    ColumnVector y_compact_i = rMVN_fn( mu_k, LSIGMA[k-1] );

    // ADDED by HANG to check infinity value of x_full_i
    int check_infinity = 0 ;

    if (y_compact_i.maximum()>700){
      check_infinity = 1 ;
      if ( msg_level >= 1 ) {
		Rprintf( "   Warning: x_out from N(Mu_k,Sigma_k) > exp(700). There is no harm for convergence and inference, but the computation may get slower if you see this warning too often, e.g. every iteration\n");
      }
    }

    if (check_infinity==0){

      ColumnVector x_compact_i = exp_ColumnVector(y_compact_i);
      ColumnVector x_full_i(n_var) ;
      Data.UpdateFullVector(x_compact_i,x_full_i);
      Data.update_full_x_for_balance_edit(x_full_i);

      // do not need to consdier min(x_full_i)>0 since x_compact_i=exp(y_compact_i)
      if (Data.PassEdits(x_full_i)) {
        X_aux.row(++count_in) = x_full_i.t();
      } else {
        Y_out_compact_large.row(++count_out) = y_compact_i.t();
        z_out_large(count_out)=k;
      }

    } // if (check_infinity==0) : ADDED by HANG

  } // while ( (count_in < n_sample) && (count_out < toolarge_nout) )

  Matrix Y_out_compact = Y_out_compact_large.rows(1,count_out) ;    // cut extra space
  ColumnVector z_out = z_out_large.rows(1,count_out) ;    // cut extra space
  Prob_A = 1.0 * n_sample / (n_sample+count_out) ;

  // calculate n_z and Sum_groupX
  Data.UpdateCompactMatrix(Y_in_compact,Y_in);
  Y_aug_compact = Y_in_compact & Y_out_compact;
  z_aug = z_in & z_out;
  int n_aug = z_aug.nrows() ;

  n_z = 0 ;
  X_bar = Matrix(n_var_independent,K); X_bar= 0.0 ;
  for (int i_aug=1; i_aug<=n_aug; i_aug++) {
    int k = z_aug(i_aug);
    n_z(k) = n_z(k) + 1 ;
    RowVector y_compact_t = Y_aug_compact.row(i_aug);
    ColumnVector y_i_compact = y_compact_t.t() ;
    X_bar.column(k) += y_i_compact;
  }
  for (int k = 1; k <= K; k++) {
    if (n_z(k) > 0) {
      X_bar.column(k) *= (1.0/n_z(k));
    }
  }

}
开发者ID:QuanliWang,项目名称:EditImputeCont,代码行数:68,代码来源:CParam.cpp


注:本文中的CData::UpdateCompactMatrix方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。