📄 eventfix.h
字号:
// ========================================================// Time-stamp: <2003-05-14 17:37:37 yusuke>// File:// Author: Jun'ichi KAZAMA// Description:// License: // ========================================================#ifndef Amis_EventFix_h_#define Amis_EventFix_h_#include <amis/configure.h>#include <amis/Event.h>#include <amis/FeatureList.h>#include <amis/objstream.h>#include <amis/ModelFix.h>#include <vector>AMIS_NAMESPACE_BEGINtemplate <class Feature_>class FeatureRange{ public: typedef Feature_ Feature; typedef typename Feature::FeatureFreq FeatureFreq; protected: FeatureID start_id; FeatureID end_id; FeatureFreq freq; public: FeatureRange(FeatureID si = 0, FeatureID ei = 0, FeatureFreq fr = FeatureFreq() ) : start_id(si), end_id(ei), freq(fr) { } FeatureID startID() const { return start_id; } FeatureID endID() const { return end_id; } FeatureFreq getFreq() const { return freq; }};//////////////////////////////////////////////////////////////////////template <class Feature_>class EventFix {public: typedef Feature_ Feature; typedef typename Feature::FeatureFreq FeatureFreq; typedef FeatureListFreq EventFreq; typedef EventFix<Feature> Self;private: FeatureListFreq freq; FeatureList< Feature > history_list; FeatureID active_target; int num_targets; /* bool feature_counts_inited; std::vector< FeatureFreq > feature_counts; */ /*private: void init_feature_counts() const { feature_counts = std::vector<FeatureFreq>( numTargets() ); fill( feature_counts.begin(), feature_counts.end(), (FeatureFreq)( 0 ) ); std::vector< FeatureList<Feature> > fls( numTargets() ); getFeatureLists( fls ); for(int i = 0; i < numTargets(); i++){ feature_counts[i] = (FeatureFreq)( 0 ); FeatureList<Feature>& fl = fls[i]; for(typename FeatureList<Feature>::const_iterator feat = fl.begin(); feat != fl.end(); ++feat){ feature_counts[i] += feat->freq(); } } feature_counts_inited = true; } */public: EventFix() { //model = 0; freq = 0; active_target = 0; num_targets = 0; //feature_counts_inited = false; } /* EventFix(const ModelFix* m) : feature_counts( m->numTargets() ){ model = m; freq = 0; feature_counts_inited = false; } EventFix( const EventFix<Feature>& e ) { model = e.getModel(); freq = e.eventFrequency(); active_target = e.getActiveTargetID(); history_list = e.getHistoryList(); feature_counts_inited = false; } const EventFix& operator=(const EventFix<Feature>& e ) { if ( this != &e ) { model = e.getModel(); freq = e.eventFrequency(); active_target = e.getActiveTargetID(); history_list = e.getHistoryList(); feature_counts_inited = false; } return (*this); } */ virtual ~EventFix(){ } /* const ModelFix* getModel() const { return model; } void setModel(ModelFix* m) { model = m; } */ bool isValid() const { return true; } int numFeatureList() const { return numTargets(); } int numTargets() const { return num_targets; } int historySize() const { return history_list.size(); } FeatureID observedEventID() const { return active_target; } const FeatureList<Feature>& getHistoryList() const { return history_list; } /* const std::vector<FeatureFreq>& getFeatureCounts() const { if(!feature_counts_inited){ init_feature_counts(); } return feature_counts; } */ /* void getActiveFeatureList( FeatureList<Feature>& to ) const { std::vector< FeatureList<Feature> > fls( numTargets() ); getFeatureLists( fls ); to = fls[ active_target ]; } */ /* void getFeatureLists( std::vector< FeatureList<Feature> >& to ) const { to.resize( numTargets() ); std::vector< std::vector<Feature> > fvs( numTargets() ); const FeatureList<Feature>& hist_list = getHistoryList(); FeatureID active_tid = getActiveTargetID(); for(typename FeatureList<Feature>::const_iterator itr = hist_list.begin(); itr != hist_list.end(); ++itr){ FeatureID hid = itr->id(); FeatureFreq freq = itr->freq(); const std::vector< std::pair<FeatureID, FeatureID> >& fv = model->getFeaturesForHistory(hid); for(int k = 0; k < fv.size(); k++){ FeatureID tid = fv[k].first; FeatureID fid = fv[k].second; fvs[tid].push_back( Feature(fid, freq) ); } } for(int i = 0; i < numTargets(); i++){ FeatureListFreq f = (FeatureListFreq)( 0 ); if ( i == active_target ){ f = eventFrequency(); } to[i] = FeatureList<Feature>( fvs[i], f ); } } */ void add( FeatureID tid, FeatureListFreq f, const FeatureList<Feature>& hl, int num ) { freq = f; history_list = hl; active_target = tid; num_targets = num; //feature_counts_inited = false; } EventFreq eventFrequency( void ) const { return freq; } FeatureListFreq frequency() const { return freq; } Real eventProbability() const { return 1.0; } const FeatureFreq featureCount( FeatureID tid ) const { /* if(!feature_counts_inited){ init_feature_counts(); } return feature_counts[ tid ]; */ return history_list.featureCount(); } const FeatureFreq maxFeatureCount( void ) const { return history_list.featureCount(); } //////////////////////////////////////////////////////////////////////public: void readObject( objstream& is ) { is >> freq; is >> active_target; is >> num_targets; history_list.readObject( is ); } /// Read an object from a stream void writeObject( objstream& os ) const { os << freq; os << active_target; os << num_targets; history_list.writeObject( os ); } /// Write an object into a stream};AMIS_NAMESPACE_END#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -