src/utils/cluster_utils.cc
//! \param coll Collector containing the algorithm chain
//! \return     Index of the iteration containing the best estimate
\param coll Collector containing the algorithm chain
\return     Index of the iteration containing the best estimate
\ param coll Collector containing the algorithm chain \ return Index of the iteration containing the best estimate
Eigen::VectorXd bayesmix::cluster_estimate(
    const Eigen::MatrixXd &alloc_chain) {
  unsigned n_iter = alloc_chain.rows();
  unsigned int n_data = alloc_chain.cols();
  std::vector<Eigen::SparseMatrix<double> > all_diss;
  progresscpp::ProgressBar bar(n_iter, 60);
  std::cout << "(Computing mean dissimilarity... " << std::flush;
  Eigen::MatrixXd mean_diss = bayesmix::posterior_similarity(alloc_chain);
  std::cout << "Done)" << std::endl;
  Eigen::VectorXd errors(n_iter);
  for (int k = 0; k < n_iter; k++) {
    for (int i = 0; i < n_data; i++) {
      for (int j = 0; j < i; j++) {
        int x = (alloc_chain(k, i) == alloc_chain(k, j));
        errors(k) += (x - mean_diss(i, j)) * (x - mean_diss(i, j));
      }
    }
    ++bar;
    bar.display();
  }
  bar.done();
  std::ptrdiff_t ibest;
  unsigned int min_err = errors.minCoeff(&ibest);
  return alloc_chain.row(ibest).transpose();
}
Eigen :: VectorXd bayesmix :: cluster_estimate ( const Eigen :: MatrixXd & alloc_chain ) { unsigned n_iter = alloc_chain . rows ( ) ; unsigned int n_data = alloc_chain . cols ( ) ; std :: vector < Eigen :: SparseMatrix < double > > all_diss ; progresscpp :: ProgressBar bar ( n_iter , 60 ) ; std :: cout << " " << std :: flush ; Eigen :: MatrixXd mean_diss = bayesmix :: posterior_similarity ( alloc_chain ) ; std :: cout << " " << std :: endl ; Eigen :: VectorXd errors ( n_iter ) ; for ( int k = 0 ; k < n_iter ; k ++ ) { for ( int i = 0 ; i < n_data ; i ++ ) { for ( int j = 0 ; j < i ; j ++ ) { int x = ( alloc_chain ( k , i ) == alloc_chain ( k , j ) ) ; errors ( k ) += ( x - mean_diss ( i , j ) ) * ( x - mean_diss ( i , j ) ) ; } } ++ bar ; bar . display ( ) ; } bar . done ( ) ; std :: ptrdiff_t ibest ; unsigned int min_err = errors . minCoeff ( & ibest ) ; return alloc_chain . row ( ibest ) . transpose ( ) ; }
\param coll Collector containing the algorithm chain
\return     Index of the iteration containing the best estimate
\ param coll Collector containing the algorithm chain \ return Index of the iteration containing the best estimate
// Initialize objects // Compute mean // Compute Frobenius norm error of all iterations // Progress bar // Find iteration with the least error