📄 empiricalexpect.h
字号:
//////////////////////////////////////////////////////////////////////////// Copyright (c) 2000, Yusuke Miyao/// You may distribute under the terms of the Artistic License.////// <id>$Id: EmpiricalExpect.h,v 1.13 2003/05/16 12:10:44 yusuke Exp $</id>/// <collection>Maximum Entropy Estimator</collection>/// <name>EmpiricalExpect.h</name>/// <overview>Feature expectations given by the training data</overview>/////////////////////////////////////////////////////////////////////////#ifndef Amis_EmpiricalExpect_h_#define Amis_EmpiricalExpect_h_#include <amis/configure.h>#include <amis/Real.h>#include <amis/ModelBase.h>#include <amis/EventSpace.h>#include <amis/ModelFunction.h>#include <vector>#include <iostream>AMIS_NAMESPACE_BEGIN//////////////////////////////////////////////////////////////////////class EmpiricalExpectBase : public std::vector< Real > {public: EmpiricalExpectBase() {} virtual ~EmpiricalExpectBase() {} virtual void debugInfo( std::ostream& ostr ) const { for ( std::vector< Real >::const_iterator it = this->begin(); it != this->end(); ++it ) { ostr << *it << '\n'; } } /// Print data};inline std::ostream& operator<<( std::ostream& os, const EmpiricalExpectBase& e ) { e.debugInfo( os ); return os;}//////////////////////////////////////////////////////////////////////template < class Model, class EventSpace, bool EnableJointProb = false >class EmpiricalExpect : public EmpiricalExpectBase {public: typedef typename EventSpace::FeatureType Feature; typedef typename Feature::FeatureFreq FeatureFreq; typedef typename EventSpace::EventType Event;private: const Model* model; const EventSpace* event_space;public: EmpiricalExpect() { model = NULL; event_space = NULL; } virtual ~EmpiricalExpect() {}public: void add( FeatureID id, FeatureFreq freq, Real prob ) { (*this)[ id ] += static_cast< Real >( prob * freq ); } void initialize( const Model& init_model, const EventSpace& init_event_space ) { model = &init_model; event_space = &init_event_space; assign( model->numFeatures(), 0.0 ); } void setEmpiricalExpectation() { AMIS_DEBUG_MESSAGE( 5, "Start setEmpiricalExpectation" ); for( int i = 0; i < event_space->numEvents(); ++i ) { //model->addEventCount( 1 ); AMIS_DEBUG_MESSAGE( 5, "Event " << i << "\n" ); const Event& event = (*event_space)[ i ]; ModelFunction< Model, Event >().setEmpiricalExpectation( *model, event, *this ); // EnableJointProb? } AMIS_DEBUG_MESSAGE( 5, "END 1st for loop\n" ); for ( size_type i = 0; i < size(); i++) { if ( (*this)[i] == 0.0 ) { AMIS_ERROR_MESSAGE( "Empirical count of " << model->featureNameString( i ) << " is 0\n" ); } else { (*this)[i] *= event_space->eventEmpiricalExpectation(); } } //cerr << "Emp. Expect.\n"; AMIS_DEBUG_MESSAGE( 5, "END setEmpiricalExpectation( void )\n" ); //AMIS_DEBUG_MESSAGE( 5, "Feature Freezing" ); //model->freezeSomeFeatures( *this, *val_sums, *vval_sums, *emp_cnt ); } /// Set empirical expectations of features};//////////////////////////////////////////////////////////////////////AMIS_NAMESPACE_END#endif // Amis_EmpiricalExpect_h_// end of EmpiricalExpect.h
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -