⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 estimator.cc

📁 Amis - A maximum entropy estimator 一个最大熵模型统计工具
💻 CC
字号:
#include <amis/Estimator.h>#include <amis/EstimatorLauncher.h>AMIS_NAMESPACE_BEGINInitializer< Launcher< EstimatorPtr, Property*, StringTriple >* >* EstimatorLauncher::queue = NULL;Estimator::Estimator() {  iteration_count = 0;  report_interval = 0;  machine_epsilon = 0.0;  estimation_precision = 0;  log_likelihood = 0.0;  log_likelihood_per_event      = 0.0;  objective_function_value      = 0.0;  prev_objective_function_value = 0.0;  min_update = 0.0;  max_update = 0.0;  till_convergence = false;  suppress_message = false;}void Estimator::startupMessage() {  if( till_convergence ) {    AMIS_PROF_MESSAGE( "(iterate till convergence)\n" );  }  AMIS_PROF_MESSAGE( "------------------------------------------------------------------------------\n" );  AMIS_PROF_MESSAGE( "Iter.    | LL(log10)   | LL(norm)    | OBJ         | Min update  | Max update \n" );  AMIS_PROF_MESSAGE( "------------------------------------------------------------------------------\n" );}void Estimator::reportMessage() {  AMIS_PROF_MESSAGE( setiosflags( std::ios::right ) << std::setw( 7 ) << iteration_count );  AMIS_PROF_MESSAGE( setiosflags( std::ios::left ) << std::setw( 14 ) << log_likelihood / log( 10.0 ) );  AMIS_PROF_MESSAGE( setiosflags( std::ios::left ) << std::setw( 14 ) << log_likelihood_per_event / log( 10.0 ) );  AMIS_PROF_MESSAGE( setiosflags( std::ios::left ) << std::setw( 14 ) << objective_function_value );  AMIS_PROF_MESSAGE( setiosflags( std::ios::left ) << std::setw( 14 ) << min_update );  AMIS_PROF_MESSAGE( setiosflags( std::ios::left ) << std::setw( 14 ) << max_update << '\n' );}void Estimator::endingMessage() {  AMIS_PROF_MESSAGE( "-----------------------------------------------------------------------------\n" );  AMIS_PROF_MESSAGE( "Estimation took " << profile_timer.realTimeString() << '\n' );  AMIS_PROF_MESSAGE( "CPU Usage USER: " << profile_timer.userTimeString() << " SYSTEM: " << profile_timer.systemTimeString() << '\n' );}void Estimator::estimate( int num_iterations, int precision, int r ) {  AMIS_DEBUG_MESSAGE( 3, "Initialization...\n" );  machine_epsilon = pow( 0.1, precision + 1 );  estimation_precision = precision;	  ATOL = REAL_TOL;  RTOL = pow( 0.1, precision + 1);	  report_interval = r;      initialize();      profile_timer.initProf();  AMIS_DEBUG_MESSAGE( 3, "Start.\n" );  if ( ! suppress_message ) startupMessage();  profile_timer.startProf();  for ( iteration_count = 1; (till_convergence && iteration_count < MAX_NUM_ITERATIONS) || iteration_count <= num_iterations; ++iteration_count ) {    //log_likelihood = 0.0;    initMinMaxUpdate();    iteration();    if ( ! suppress_message && isReportIteration() ) reportMessage();    postIteration();    if ( isConverged() ) {      if ( ! suppress_message ) AMIS_PROF_MESSAGE( "Model converged at iteration " << iteration_count << '\n' );      break;    }  }  profile_timer.stopProf();  if ( ! suppress_message ) endingMessage();  finalize();}AMIS_NAMESPACE_END// end of Estimator.cc

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -