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-15 23:09:01 +04:00
# include "Types.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 23:09:01 +04:00
Optimizer ( unsigned Pd , vector < unsigned > i2O , parameters_t 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 23:09:01 +04:00
statscore_t Run ( Point & ) const ;
2008-05-14 20:19:00 +04:00
/**main function that perform an optimization*/
2008-05-15 23:09:01 +04:00
virtual statscore_t 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 23:09:01 +04:00
statscore_t 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 23:09:01 +04:00
statscore_t GetStatScore ( const Point & param ) const ;
vector < statscore_t > GetIncStatScore ( vector < unsigned > ref , vector < vector < pair < unsigned , unsigned > > > ) const ;
statscore_t 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 {
2008-05-15 23:09:01 +04:00
private :
static float eps ;
2008-05-14 15:00:59 +04:00
public :
2008-05-15 23:09:01 +04:00
SimpleOptimizer ( unsigned dim , vector < unsigned > i2O , parameters_t start ) : Optimizer ( dim , i2O , start ) { } ;
virtual statscore_t TrueRun ( Point & ) const ;
2008-05-14 18:25:07 +04:00
} ;
2008-05-14 15:00:59 +04:00
2008-05-15 23:09:01 +04:00
Optimizer * BuildOptimizer ( unsigned dim , vector < unsigned > tooptimize , parameters_t start , string type ) ;
2008-05-15 18:04:42 +04:00
2008-05-14 15:00:59 +04:00
# endif