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

📄 property.h

📁 Amis - A maximum entropy estimator 一个最大熵模型统计工具
💻 H
字号:
////////////////////////////////////////////////////////////////////////////  Copyright (c) 2000, Yusuke Miyao///  You may distribute under the terms of the Artistic License.//////  <id>$Id: Property.h,v 1.12 2003/05/16 05:11:06 yusuke Exp $///  <collection>Maximum Entropy Estimator</collection>///  <name>Property.h</name>///  <overview>Program property manager</overview>///  <desc>///  This file provides a class for managing program properties///  specified with program arguments and property files///  </desc>/////////////////////////////////////////////////////////////////////////#ifndef Amis_Property_h_#define Amis_Property_h_#include <amis/configure.h>#include <amis/PropertyItem.h>#include <amis/ModelLauncher.h>#include <amis/EventSpaceLauncher.h>#include <amis/ModelFormatLauncher.h>#include <amis/EventFormatLauncher.h>#include <amis/EstimatorLauncher.h>#include <amis/GaussianPriorLauncher.h>#include <amis/ModelStatLauncher.h>#include <amis/ErrorBase.h>#include <amis/objstream.h>#include <iostream>AMIS_NAMESPACE_BEGIN///////////////////////////////////////////////////////////////////////// <classdef>/// <name>IllegalPropertyError</name>/// <overview>Exception for illegal properties</overview>/// <desc>/// The class signals illegal property specifications in/// command-line arguments and in a property file/// </desc>/// <body>class IllegalPropertyError : public ErrorBase { public:  IllegalPropertyError( const std::string& m ) : ErrorBase( m ) {}  /// Initialize with an error message  IllegalPropertyError( const char* m ) : ErrorBase( m ) {}  /// Initialize with an error message};/// </body>/// </classdef>///////////////////////////////////////////////////////////////////////// <classdef>/// <name>Property</name>/// <overview>Program property manager</overview>/// <desc>/// The class manages program properties/// specified with program arguments and property files/// </desc>/// <body>class Property {public:  static const std::string DEFAULT_PROPERTY_FILE;private:  static OptionManager option_manager;  static bool initialized;  static PropertyItemToggle help;  static PropertyItemToggle heavy_help;  static PropertyItemToggle show_option_status;  static PropertyItemToggle show_version;  static PropertyItem< std::string > feature_type;  static PropertyItemNamedInt< FeatureWeightType > feature_weight_type;  static PropertyItem< std::string > root_dir;  static PropertyItemVector< std::string > model_file_list;  static PropertyItemVector< std::string > event_file_list;  static PropertyItem< std::string > output_file;  static PropertyItem< std::string > log_file;  static PropertyItem< std::string > model_stat_file;  static PropertyItem< std::string > data_format;  static PropertyItem< std::string > estimation_algorithm;  static PropertyItem< int > num_iterations;  static PropertyItem< int > report_interval;  static PropertyItem< int > prec;  static PropertyItem< bool > event_on_file;  static PropertyItem< std::string > event_on_file_name;  static PropertyItem< int > num_threads;  static PropertyItem< bool > till_convergence;  static PropertyItem< bool > suppress_message;  static PropertyItem< std::string > variance_type;  static PropertyItem< bool > model_stat;  static ModelLauncher model_launcher;  static EventSpaceLauncher event_space_launcher;  static ModelFormatLauncher model_format_launcher;  static EventFormatLauncher event_format_launcher;  static EstimatorLauncher estimator_launcher;  static GaussianPriorLauncher gaussian_prior_launcher;  static ModelStatLauncher model_stat_launcher;  std::string property_file;  objstream* event_on_file_stream;public:  Property() {    property_file = DEFAULT_PROPERTY_FILE;    event_on_file_stream = NULL;    if ( ! initialized ) {      option_manager.initAllOptions();      model_launcher.initLauncherItems();      event_space_launcher.initLauncherItems();      model_format_launcher.initLauncherItems();      event_format_launcher.initLauncherItems();      estimator_launcher.initLauncherItems();      gaussian_prior_launcher.initLauncherItems();      model_stat_launcher.initLauncherItems();      initialized = true;    }  }  virtual ~Property() {    if ( event_on_file_stream != NULL ) {      delete event_on_file_stream;    }    event_on_file_stream = NULL;  }  const OptionManager& getOptionManager() const {    return option_manager;  }public:  // Import properties  void parseArguments( int argc, const char** argv );  void importProperty();public:  // Help messages  std::string getShortHelp() const {    OStringStream os;    os << "Usage: amis [list of options] [property file]\n";    os << option_manager.getShortDescription();    return os.str();  }  std::string getLongHelp() const {    OStringStream os;    os << "Usage: amis [list of options] [property file]\n";    os << option_manager.getFullDescription();    return os.str();  }  std::string getSpecificationStatus() const {    OStringStream os;    os << "Specified values of the options\n";    os << option_manager.getSpecificationStatus();    return os.str();  }protected:  std::string prefixByRootDir( const std::string& s ) const {    std::string ret = getRootDir();    ret += "/";    ret += s;    return ret;  }  std::vector< std::string > prefixByRootDir( const std::vector< std::string >& v ) const {    std::vector< std::string > ret;    for ( std::vector< std::string >::const_iterator itr = v.begin(); itr != v.end(); ++itr ) {      ret.push_back( prefixByRootDir( *itr ) );    }    return ret;  }public:  // Accessors of options  bool isHelp() const {    return help.getValue();  }  bool isHeavyHelp() const {    return heavy_help.getValue();  }  bool isShowOptionStatus() const {    return show_option_status.getValue();  }  bool isShowVersion() const {    return show_version.getValue();  }  const std::string& getFeatureType() const {    return feature_type.getValue();  }  FeatureWeightType getFeatureWeightType() const {    return feature_weight_type.getValue();  }  std::string getRootDir() const {    return root_dir.getValue();  }  std::vector< std::string > getModelFileList() const {    return prefixByRootDir( model_file_list.getValue() );  }  std::vector< std::string > getEventFileList() const {    return prefixByRootDir( event_file_list.getValue() );  }  std::string getOutputFile() const {    return prefixByRootDir( output_file.getValue() );  }  std::string getLogFile() const {    return prefixByRootDir( log_file.getValue() );  }  std::string getModelStatFile() const {    return prefixByRootDir( model_stat_file.getValue() );  }  const std::string& getDataFormat() const {    return data_format.getValue();  }  const std::string& getEstimationAlgorithm() const {    return estimation_algorithm.getValue();  }  int getNumIterations() const {    return num_iterations.getValue();  }  int getReportInterval() const {    return report_interval.getValue();  }  int getPrecision() const {    return prec.getValue();  }  bool isEventOnFile() const {    return event_on_file.getValue();  }  objstream* eventOnFileStream() {    if ( event_on_file_stream != NULL ) delete event_on_file_stream;    std::string tmp_file = prefixByRootDir( event_on_file_name.getValue() );    event_on_file_stream = new objstream( tmp_file );    if ( ! *event_on_file_stream ) {      throw IllegalPropertyError( "Cannot open temporary file: " + tmp_file );    }    return event_on_file_stream;  }  int getNumThreads() const {    return num_threads.getValue();  }  bool getTillConvergence() const {    return till_convergence.getValue();  }  bool getSuppressMessage() const {    return suppress_message.getValue();  }  const std::string& getVarianceType() const {    return variance_type.getValue();  }  bool getModelStat() {    return model_stat.getValue();  }public:  virtual ModelPtr newModel() {    return model_launcher.launch( getDataFormat(), this );  }  virtual EventSpacePtr newEventSpace() {    return event_space_launcher.launch( StringPair( getDataFormat(), getFeatureType() ), this );  }  virtual ModelFormatPtr newModelFormat() {    return model_format_launcher.launch( getDataFormat(), this );  }  virtual EventFormatPtr newEventFormat() {    return event_format_launcher.launch( StringPair( getDataFormat(), getFeatureType() ), this );  }  virtual EstimatorPtr newEstimator() {    EstimatorPtr estimator = estimator_launcher.launch( StringTriple( getEstimationAlgorithm(),								      getDataFormat(),								      getFeatureType() ),							this );    estimator->setSuppressMessage( getSuppressMessage() );    estimator->setTillConvergence( getTillConvergence() );    return estimator;  }  virtual GaussianPriorPtr newGaussianPrior() {    return gaussian_prior_launcher.launch( getVarianceType(), this );  }  virtual ModelStatPtr newModelStat() {    return model_stat_launcher.launch( StringPair( getDataFormat(), getFeatureType() ), this );  }};/// </body>/// </classdef>/*class Property {	enum KernelFunctionType {		INNER, POLY, GAUSSIAN	};	private:  bool write_heavy_stat;	// extensions by J.K. (experimental)	bool                       make_init_model_mode;	double                     valsum_threshold;	double                     count_threshold;	std::string                event_space_type_option;	KernelFunctionType         kernel_function_type;	std::string                kernel_function_args;	std::vector< std::string > kernel_reference_event_file_list;		bool                       loading_only;	bool                       show_model_info;	int                        top_feature_display_num; 	std::vector< std::string > original_model_file_list;	bool                       analyze_loop;	std::string                analyze_input;	std::string                analyze_output;	bool                       analyze_output_best;	double                     ubiquitous_ratio;	bool                       kNN_on;	int                        kNN_k;	bool                       post_normalize1;	bool                       post_normalize2;	bool                       kernel_cache_nonzero;	bool                       kernel_exclude_self;	bool                       kernel_include_original_history;	bool                           include_stabilizing_history;		//Model::FeatureFreezeType feature_freeze_type;	double                   feature_freeze_threshold;		double feature_ignore_ratio;		// prefix for all filenames	std::string              root_dir;	int                      kernel_first_ref_num;	bool                     take_all_kernel; // take kernels with all of the reference events.		bool                    use_box_constraint;	//ModelBC::ConstraintType box_constraint_type;	Real                    box_constraint_factor;	Real                    box_constraint_alpha;	Real                    box_constraint_beta;	Real                    box_constraint_init_value;	Real                    soft_box_constant;	bool                    check_KKT;	Real                    KKT_tolerance;	Real                    KKT_bad_feature_ratio;	Real                    KKT_max_failure_factor;		bool                    make_comb_feature;		Option                  opt;	bool writeHeavyStat( ) const { return write_heavy_stat; }		double valSumThreshold() const {		return valsum_threshold;	}		double countThreshold() const {		return count_threshold;	}		bool makeInitModelMode() const {		return make_init_model_mode;	}			KernelFunctionType kernelFunctionType() const {		return kernel_function_type;	}		const std::string& kernelFunctionArgs() const {		return kernel_function_args;	}		bool loadingOnly() const { return loading_only; }	bool showModelInfo() const { return show_model_info; }	bool topFeatureDisplayNum() const { return top_feature_display_num; }		const std::vector<std::string> kernelReferenceEventFileList() const {		return prefixByRootDir( kernel_reference_event_file_list );	}		const std::vector< std::string > originalModelFileList( void ) const {		return prefixByRootDir( original_model_file_list );	}		bool analyzeLoop() const { return analyze_loop; }	const std::string& analyzeInput() const { return analyze_input; }		const std::string& analyzeOutput() const { return analyze_output; }	bool analyzeOutputBest() const { return analyze_output_best; }		double ubiquitousRatio() const { return ubiquitous_ratio; }		const std::string& rootDir() const { return root_dir; }	bool postNormalize1() const { return post_normalize1; }	bool postNormalize2() const { return post_normalize2; }	bool kernelCacheNonzero() const { return kernel_cache_nonzero; }	bool kernelExcludeSelf() const { return kernel_exclude_self; }	bool kernelIncludeOriginalHistory() const { return kernel_include_original_history; }	bool includeStabilizingHistory() const { return include_stabilizing_history; }		bool tillConvergence() const { return till_convergence; }	int  kernelFirstRefNum() const { return kernel_first_ref_num; }	bool takeAllKernel() const { return take_all_kernel; }	 	Model::FeatureFreezeType featureFreezeType() const { 		return feature_freeze_type; 	}		double featureFreezeThreshold() const {		return feature_freeze_threshold;	}		double featureIgnoreRatio() const {		return feature_ignore_ratio;	}			bool useBoxConstraint() const { 		return use_box_constraint;	}		ModelBC::ConstraintType boxConstraintType() const {		return box_constraint_type;	}		Real boxConstraintFactor() const {		return box_constraint_factor;	}		Real boxConstraintAlpha() const {		return box_constraint_alpha;	}	Real boxConstraintBeta() const {		return box_constraint_beta;	}		Real boxConstraintInitValue() const {		return box_constraint_init_value;	}		Real softBoxConstant() const {		return soft_box_constant;	}			bool checkKKT() const {		return check_KKT;	}			Real KKTTolerance() const {		return KKT_tolerance;	}		Real KKTBadFeatureRatio() const {		return KKT_bad_feature_ratio;	}		Real KKTMaxFailureFactor() const {		return KKT_max_failure_factor;	}			bool makeCombFeature() const {		return make_comb_feature;	}};/// </body>/// </classdef>*/AMIS_NAMESPACE_END#endif // Amis_Property_h_// end of Property.h

⌨️ 快捷键说明

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