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

📄 modelfix.h

📁 Amis - A maximum entropy estimator 一个最大熵模型统计工具
💻 H
字号:
// ========================================================// Time-stamp: <2003-05-13 14:44:56 yusuke>// File:// Author:      Jun'ichi KAZAMA// Description:// License:    // ========================================================#ifndef Amis_ModelFix_h_#define Amis_ModelFix_h_#include <amis/configure.h>#include <amis/Real.h>#include <amis/Model.h>#include <amis/NameTable.h>#include <amis/Feature.h>#include <amis/StringStream.h>#include <utility>#include <map>#include <cmath>#include <string>AMIS_NAMESPACE_BEGINclass ModelFixBase : public ModelBase {protected:  std::vector< std::vector< std::pair< FeatureID, FeatureID > > > features;  int num_targets;  int num_histories;public:  ModelFixBase() : ModelBase() {    num_targets = 0;    num_histories = 0;  }  virtual ~ModelFixBase() {}  std::string modelName() const { return "ModelFixBase"; }  virtual std::string targetNameString( FeatureID tid ) const = 0;  virtual std::string historyNameString( FeatureID hid ) const = 0;public:  int numTargets() const { return num_targets; }  int numHistories() const { return num_histories; }  const std::vector< std::pair< FeatureID, FeatureID > >& getFeatures( FeatureID i ) const {    return features[ i ];  }  FeatureID newTarget() { return num_targets++; }  FeatureID newHistory() { return num_histories++; }  FeatureID newFeature( FeatureID hid, FeatureID tid, Real init_lambda ) {    FeatureID fid = ModelBase::newFeature( init_lambda );    std::pair< FeatureID, FeatureID > p( tid, fid );    features[ hid ].push_back( p );    return fid;  }};//////////////////////////////////////////////////////////////////////template < class Name = std::string >class ModelFix : public ModelFixBase {private:  NameTable< Name > target_name;  NameTable< Name > history_name;  NameTable< Name > feature_name;public:  ModelFix() : ModelFixBase() {}  virtual ~ModelFix() {}  std::string modelName() const { return "ModelFix"; }  const Name& targetName( FeatureID tid ) const {    return target_name.featureName( tid );  }  const Name& historyName( FeatureID hid ) const {    return history_name.featureName( hid );  }  const Name& featureName( FeatureID fid ) const {    return feature_name.featureName( fid );  }  std::string targetNameString( FeatureID tid ) const {    return target_name.featureNameString( tid );  }  std::string historyNameString( FeatureID hid ) const {    return history_name.featureNameString( hid );  }  std::string featureNameString( FeatureID fid ) const {    return feature_name.featureNameString( fid );  }  FeatureID targetID( const Name& name ) const {    return target_name.featureID( name );  }  FeatureID historyID( const Name& name ) const {    return history_name.featureID( name );  }  FeatureID featureID( const Name& name ) const {    return feature_name.featureID( name );  }public:  virtual FeatureID newTarget( const Name& name ) {    AMIS_DEBUG_MESSAGE(3,  "newTarget(): " << name << '\n');    FeatureID new_id = ModelFixBase::newTarget();    target_name.registerNewFeature( name, new_id );    return new_id;  }  virtual FeatureID newHistory( const Name& name ) {    AMIS_DEBUG_MESSAGE(3,  "newHistory(): " << name << '\n');    FeatureID new_id = ModelFixBase::newHistory();    history_name.registerNewFeature( name, new_id );    std::vector< std::pair<FeatureID,FeatureID> > v;    v.resize(0);    features.push_back( v );    return new_id;  }  virtual FeatureID newFeature( FeatureID hid, FeatureID tid, const Name& fname, Real init_lambda ) {    AMIS_DEBUG_MESSAGE(3, "newFeature: fname = " << fname << '\n' << std::flush);    FeatureID fid = ModelFixBase::newFeature( hid, tid, init_lambda );    feature_name.registerNewFeature( fname, fid );    return fid;  }public:  // Debugging  void debugInfo( std::ostream& ostr ) const {    ostr << "====================\n";    ostr << "Feature\tLambda\n";    for ( int i = 0; i < numFeatures(); ++i )      ostr << feature_name.featureNameString( i ) << '\t' << getLambda( i ) << '\n';    ostr << "====================\n";  }};AMIS_NAMESPACE_END#endif // Amis_ModelFix_h_// end of ModelFix.h

⌨️ 快捷键说明

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