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

📄 property.cc

📁 Amis - A maximum entropy estimator 一个最大熵模型统计工具
💻 CC
📖 第 1 页 / 共 2 页
字号:
//////////////////////////////////////////////////////////////////////////  Copyright (c) 2000, Yusuke Miyao//  You may distribute under the terms of the Artistic License.////  Property.cc - Program property manager//  $Id: Property.cc,v 1.13 2003/05/16 05:11:08 yusuke Exp $////////////////////////////////////////////////////////////////////////#include <amis/Property.h>#include <amis/Tokenizer.h>#include <amis/ArgumentParser.h>AMIS_NAMESPACE_BEGIN// Constantsconst std::string Property::DEFAULT_PROPERTY_FILE( "amis.conf" );// Static membersInitializer< OptionManager* >* PropertyItemBase::OPTION_QUEUE = NULL;OptionManager Property::option_manager( PropertyItemBase::OPTION_QUEUE );bool Property::initialized = false;//////////////////////////////////////////////////////////////////////// LaunchersModelLauncher Property::model_launcher;EventSpaceLauncher Property::event_space_launcher;ModelFormatLauncher Property::model_format_launcher;EventFormatLauncher Property::event_format_launcher;EstimatorLauncher Property::estimator_launcher;GaussianPriorLauncher Property::gaussian_prior_launcher;ModelStatLauncher Property::model_stat_launcher;//////////////////////////////////////////////////////////////////////// OptionsPropertyItemToggle Property::help( "", "", "-h", false, "Print help messages", true );PropertyItemToggle Property::heavy_help( "", "--help", "-hh", false, "Print detailed help messages", true );PropertyItemToggle Property::show_option_status( "", "--show-option-status", "-sos", false, "Show option status", true );PropertyItemToggle Property::show_version( "", "--version", "-v", false, "Show version", true );PropertyItem< std::string > Property::feature_type( "FEATURE_TYPE", "--feature-type", "-f", "binary", "The type of features" );class FeatureWeightHash : public StringHash< FeatureWeightType > {public:  FeatureWeightHash( void ) {    (*this)[ "alpha" ] = ALPHA;    (*this)[ "lambda" ] = LAMBDA;  }};namespace { FeatureWeightHash feature_weight_hash; };PropertyItemNamedInt< FeatureWeightType > Property::feature_weight_type( "FEATURE_WEIGHT_TYPE", "--feature-weight-type", "-w", feature_weight_hash, ALPHA, "The type of weights of features" );PropertyItem< std::string > Property::root_dir( "ROOT_DIR", "--root-dir", "-R", ".", "Root directory" );PropertyItemVector< std::string > Property::model_file_list( "MODEL_FILE", "--model-file", "-m", std::vector< std::string >( 1, "amis.model" ), "Model file name(s)" );PropertyItemVector< std::string > Property::event_file_list( "EVENT_FILE", "--event-file", "-e", std::vector< std::string >( 1, "amis.event" ), "Event file name(s)" );PropertyItem< std::string > Property::output_file( "OUTPUT_FILE", "--output-file", "-o", "amis.output", "The name of the output file" );PropertyItem< std::string > Property::log_file( "LOG_FILE", "--log-file", "-l", "amis.log", "The name of the log file" );PropertyItem< std::string > Property::model_stat_file( "MODEL_STAT_FILE", "--model-stat-file", "", "amis.stat", "The name of the file of the model statistics" );PropertyItem< std::string > Property::data_format( "DATA_FORMAT", "--data-format", "-d", "Amis", "Data format type (Amis, AmisTree, AmisFix, AmisFixKernel, or CMEE)" );PropertyItem< std::string > Property::estimation_algorithm( "ESTIMATION_ALGORITHM", "--estimation-algorithm", "-a", "GIS", "Estimation algorithm (GIS, IIS, BFGS, BFGSMAP, LMVM, LMVMMAP or LMVMVBC)" );PropertyItem< int > Property::num_iterations( "NUM_ITERATIONS", "--num-iterations", "-i", 200, "The number of iterations" );PropertyItem< int > Property::report_interval( "REPORT_INTERVAL", "--report-interval", "-r", 1, "The interval of interation report" );PropertyItem< int > Property::prec( "PRECISION", "--precision", "-p", 6, "The precision of the estimation" );PropertyItem< bool > Property::event_on_file( "EVENT_ON_FILE", "--event-on-file", "", false, "Store events on file during the estimation" );PropertyItem< std::string > Property::event_on_file_name( "EVENT_ON_FILE_NAME", "--event-on-file-name", "", "amis.event.tmp", "The name of temp event file used by EVENT_ON_FILE" );PropertyItem< int > Property::num_threads( "NUM_THREADS", "--num-threads", "-j", 1, "The level of parallelism of estimation" );PropertyItem< bool > Property::till_convergence( "TILL_CONVERGENCE", "--till-convergence", "-tc", false, "Run estimation till convergence (When using LMVM, LMVMMAP, and LMVMBC, TILL_CONVERGENCE is true always)" );PropertyItem< bool > Property::suppress_message( "SUPPRESS_MESSAGE", "--suppress-message", "", false, "Suppress profiling messages" );PropertyItem< std::string > Property::variance_type( "VARIANCE_TYPE", "--variance-type", "", "single", "Type of the variances used for MAP estimation" );PropertyItem< bool > Property::model_stat( "MODEL_STAT", "--model-stat", "", false, "Output the statistics of the model" );//////////////////////////////////////////////////////////////////////void Property::parseArguments( int argc, const char** argv ) {  ArgumentParser arguments( argc, argv );  bool property_file_initialized = false;  while ( ! arguments.empty() ) {    std::string arg = arguments.nextArgument( "Too few arguments" );    if ( arg[0] != '-' ) {      if ( property_file_initialized ) {	throw IllegalOptionError( "More than one arguments specified: " + arg );      }      property_file = arg;      property_file_initialized = true;    } else {      OptionBase* option = option_manager.findOptionLongName( arg );      if ( option == NULL ) {	option = option_manager.findOptionShortName( arg );	if ( option == NULL ) {	  throw IllegalOptionError( "Unknown option found: " + arg );	}      }      int num_args = option->getNumArguments();      if ( num_args < 0 ) {	// any number of arguments can be specified	while ( ! arguments.empty() ) {	  std::string arg = arguments.nextArgument( "Too few arguments" );	  if ( arg[0] == '-' ) {	    arguments.windBack();	    break;	  }	  option->setValueFromString( arg );	}      } else if ( num_args == 0 ) {	option->setValueFromString( "" );      } else {	for ( int i = 0; i < num_args; i++ ) {	  if ( arguments.empty() ) {	    OStringStream os;	    os << option->getNameDescription() << " requires " << num_args << " arguments.";	    throw IllegalOptionError( os.str() );	  }	  arg = arguments.nextArgument( "Too few arguments" );	  option->setValueFromString( arg );	}      }    }  }}void Property::importProperty( void ) {  std::ifstream pf( property_file.c_str() );  if ( ! pf ) {    throw IllegalPropertyError( "Can't open property file: " + property_file );  }  option_manager.resetToInit();  Tokenizer t( pf );  std::string attr, value, dummy;  while ( ! t.endOfStream() ) {    if ( ! t.nextToken( attr ) ) continue;  // empty line    OptionBase* option = option_manager.findOption( attr );    if ( option == NULL ) {      throw IllegalPropertyError( "Unknown property: " + attr );    }    int num_args = option->getNumArguments();    if ( num_args < 0 ) {      while( t.nextToken( value ) ) {	option->setValueFromString( value );      }    } else if ( num_args == 0 ) {      // toggle-type property      // Allow the following way      // PROP1   ==> !default_val      // PROP1 true  ==> true      // PROP2 false ==> false      option->setValueFromString( "" );      while ( t.nextToken( value ) ) {	option->setValueFromString( value );      }    } else {      for ( int i = 0; i < num_args; i++ ) {	if ( ! t.nextToken( value ) ) {	  OStringStream os;	  os << "Property: " << attr << " requires " << num_args << " arguments.";	  throw IllegalPropertyError( os.str() );	}	option->setValueFromString( value );      }    }  }}///////////////////////////////////////////////////////////////////////*Property::Property() {	// MODEL_STAT_FILE	opt.setOpt( new Opt< std::string >( "MODEL_STAT_FILE", "--model-stat-file", "-msf", &model_stat_file, "amis.model.stat", "Model statiscs are written to this file." ) );		opt.setOpt( new OptToggle( "WRITE_HEAVY_STAT", "--write-heavy-stat", "-whs", &write_heavy_stat, false, "Write heavy stats. Costs much file strage" ) );		// FEATURE_COUNT_HASH	opt.setOpt( new Opt<bool>( "FEATURE_COUNT_HASH", "--feature-count-hash", "-fch", &feature_count_hash, false, "Whether to use the feature count hash" ) );		// FEATURE_WEIGHT_TYPE

⌨️ 快捷键说明

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