📄 modelformat.h
字号:
//////////////////////////////////////////////////////////////////////////// Copyright (c) 2000, Yusuke Miyao/// You may distribute under the terms of the Artistic License.////// <id>$Id: ModelFormat.h,v 1.4 2003/05/16 05:29:08 yusuke Exp $</id>/// <collection>Maximum Entropy Estimator</collection>/// <name>ModelFormat.h</name>/// <overview>Basic interface for reading model files</overview>/// <desc>/// This file provides a base class for reading model files/// Data formats should be defined in derived classes./// </desc>/////////////////////////////////////////////////////////////////////////#ifndef Amis_ModelFormat_h_#define Amis_ModelFormat_h_#include <amis/configure.h>#include <amis/ModelBase.h>#include <amis/ErrorBase.h>#include <amis/StringStream.h>#include <memory>#include <string>AMIS_NAMESPACE_BEGINenum FeatureWeightType { LAMBDA, ALPHA};///////////////////////////////////////////////////////////////////////// <classdef>/// <name>IllegalModelFormatError</name>/// <overview>Error exception for illegal model format</overview>/// <desc>/// The exception class is thrown by the ModelFormat class to signal/// an invalid data in a model file./// </desc>/// <see>ModelFormat</see>/// <body>class IllegalModelFormatError : public ErrorBase {public: IllegalModelFormatError( const std::string& s, int num ) : ErrorBase() { OStringStream os; os << s << " at line " << num + 1; m = os.str(); } /// Initialize with an error message IllegalModelFormatError( char* s, int num ) : ErrorBase() { OStringStream os; os << s << " at line " << num + 1; m = os.str(); } /// Initialize with an error message};/// </body>/// </classdef>///////////////////////////////////////////////////////////////////////// <classdef>/// <name>ModelFormat</name>/// <overview>Base class for reading model files</overview>/// <desc>/// The class provides a basic interface for importing model/// data from specified data files./// Derived classes should handle format-specific data./// </desc>/// <see>Model, Event</see>/// <body>class ModelFormat {public: ModelFormat() {} /// Constructor virtual ~ModelFormat() {} /// Destructor virtual std::string modelFormatName() const = 0; /// Name of the model format virtual void inputModel( std::istream& s, ModelBase& model ) = 0; /// Input model data from an input stream virtual void outputModel( const ModelBase& model, std::ostream& s, int precision = DEFAULT_PRECISION ) const = 0; /// Output model data into an output stream static const int DEFAULT_PRECISION = 6; /// Default value for a precision of an outputpublic: template < FeatureWeightType FW > static Real inputLambda( Real x ); template < FeatureWeightType FW > static Real outputLambda( Real x );};template <>inline Real ModelFormat::inputLambda< LAMBDA >( Real x ) { return x; }template <>inline Real ModelFormat::inputLambda< ALPHA >( Real x ) { return log( x ); }template <>inline Real ModelFormat::outputLambda< LAMBDA >( Real x ) { return x; }template <>inline Real ModelFormat::outputLambda< ALPHA >( Real x ) { return exp( x ); }/// </body>/// </classdef>typedef std::auto_ptr< ModelFormat > ModelFormatPtr;AMIS_NAMESPACE_END#endif // DataFile_h_// end of DataFile.h
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -