2008-05-14 15:00:59 +04:00
# ifndef OPTIMIZER_H
# define OPTIMIZER_H
2008-05-15 20:03:49 +04:00
# include <vector>
2008-05-14 15:00:59 +04:00
# include "FeatureStats.h"
# include "FeatureData.h"
# include "FeatureArray.h"
2008-05-14 16:49:45 +04:00
# include "Scorer.h"
# include "Point.h"
2008-05-14 15:00:59 +04:00
typedef float featurescore ;
using namespace std ;
2008-05-15 18:04:42 +04:00
/**abstract virtual class*/
2008-05-14 15:00:59 +04:00
class Optimizer {
2008-05-15 14:57:20 +04:00
protected :
Scorer * scorer ; //no accessor for them only child can use them
2008-05-15 18:04:42 +04:00
FeatureData * FData ; //no accessor for them only child can use them
2008-05-14 15:00:59 +04:00
public :
2008-05-15 14:57:20 +04:00
Optimizer ( unsigned Pd , vector < unsigned > i2O , vector < lambda > start ) ;
2008-05-14 15:00:59 +04:00
void SetScorer ( Scorer * S ) ;
void SetFData ( FeatureData * F ) ;
2008-05-15 14:57:20 +04:00
virtual ~ Optimizer ( ) ;
unsigned size ( ) const { return ( FData ? FData - > size ( ) : 0 ) ; }
2008-05-14 20:19:00 +04:00
/**Generic wrapper around TrueRun to check a few things. Non virtual*/
2008-05-15 18:04:42 +04:00
statscore Run ( Point & ) const ;
2008-05-14 20:19:00 +04:00
/**main function that perform an optimization*/
2008-05-15 18:04:42 +04:00
virtual statscore TrueRun ( Point & ) const = 0 ;
2008-05-14 15:00:59 +04:00
/**given a set of lambdas, get the nbest for each sentence*/
2008-05-15 14:57:20 +04:00
void Get1bests ( const Point & param , vector < unsigned > & bests ) const ;
2008-05-14 15:00:59 +04:00
/**given a set of nbests, get the Statistical score*/
2008-05-15 14:57:20 +04:00
statscore GetStatScore ( const vector < unsigned > & nbests ) const { scorer - > score ( nbests ) ; } ;
2008-05-14 15:00:59 +04:00
/**given a set of lambdas, get the total statistical score*/
2008-05-15 14:57:20 +04:00
statscore GetStatScore ( const Point & param ) const ;
2008-05-15 18:17:34 +04:00
vector < statscore > GetIncStatScore ( vector < unsigned > ref , vector < vector < pair < unsigned , unsigned > > > ) const ;
2008-05-15 14:57:20 +04:00
statscore LineOptimize ( const Point & start , const Point & direction , Point & best ) const ; //Get the optimal Lambda and the best score in a particular direction from a given Point
2008-05-14 18:25:07 +04:00
} ;
2008-05-14 15:00:59 +04:00
2008-05-15 14:57:20 +04:00
2008-05-14 15:00:59 +04:00
/**default basic optimizer*/
class SimpleOptimizer : public Optimizer {
private : float eps ;
public :
2008-05-15 18:04:42 +04:00
SimpleOptimizer ( unsigned dim , vector < unsigned > i2O , vector < lambda > start ) : Optimizer ( dim , i2O , start ) , eps ( 0.001 ) { } ;
virtual statscore TrueRun ( Point & ) const ;
2008-05-14 18:25:07 +04:00
} ;
2008-05-14 15:00:59 +04:00
2008-05-15 18:04:42 +04:00
Optimizer * BuildOptimizer ( unsigned dim , vector < unsigned > tooptimize , vector < lambda > start , string type ) ;
2008-05-14 15:00:59 +04:00
# endif