featureSet.h
Go to the documentation of this file.
00001 /* featureSet.h
00002  */
00003 #ifndef OSL_MOVE_PROBABILITY_FEATURESET_H
00004 #define OSL_MOVE_PROBABILITY_FEATURESET_H
00005 
00006 #include "osl/move_probability/stateInfo.h"
00007 #include "osl/state/numEffectState.h"
00008 #include "osl/container/moveLogProbVector.h"
00009 #include "osl/stl/vector.h"
00010 #include <boost/ptr_container/ptr_vector.hpp>
00011 #include <boost/scoped_array.hpp>
00012 
00013 namespace osl
00014 {
00015   namespace move_probability
00016   {
00017     class Feature;
00018     typedef std::pair<double,Move> WeightedMove;
00019     typedef FixedCapacityVector<WeightedMove,Move::MaxUniqMoves> WeightedMoveVector;
00020 
00021     class FeatureSet
00022     {
00023       boost::ptr_vector<Feature> features;
00024       osl::vector<int> offsets, light_features;
00025     protected:
00026       FeatureSet();
00027     public:
00028       ~FeatureSet();
00029       void pushBack(Feature *, bool light=false);
00030       void addFinished();
00031       int dimension() const { return offsets.back(); }
00032     public:
00033       double matchExp(const StateInfo&, Move, const double *weights) const;    
00034       void generateLogProb(const StateInfo& state,
00035                            MoveLogProbVector& out, const double *weights) const;
00036       double matchLight(const StateInfo&, Move, const double *weights) const;
00037 
00038       bool load(const char *base_filename, double *weights) const;
00039       bool load_binary(const char *base_filename, double *weights) const;
00040       void showSummary(const double *weights) const;
00041       void analyze(const StateInfo& state, Move move, const double *weights) const;
00042       // for fine control
00043       double generateRating(const StateInfo& state,
00044                             WeightedMoveVector& out, const double *weights) const;
00045       static void ratingToLogProb(const WeightedMoveVector& rating,
00046                                   double sum, MoveLogProbVector& out);
00047     };
00048 
00049     class StandardFeatureSet : public FeatureSet
00050     {
00051       static boost::scoped_array<double> weights, tactical_weights;
00052     public:
00053       StandardFeatureSet();
00054       ~StandardFeatureSet();
00055       
00056       static const StandardFeatureSet& instance();
00057       void generateLogProb(const StateInfo& state, MoveLogProbVector& out) const;
00058       void generateLogProb2(const StateInfo& state, MoveLogProbVector& out) const;
00059       void generateLogProb(const StateInfo& state, int limit, MoveLogProbVector& out, bool in_pv) const;
00060       int logProbTakeBack(const StateInfo& state, Move target) const;
00061       int logProbSeePlus(const StateInfo& state, Move target) const;      
00062       double matchLight(const StateInfo&, Move) const;    
00063       bool setUp();
00064     private:
00065       int tacticalLogProb(int offset, double sum) const;
00066     };
00067   }
00068 }
00069 #endif /* OSL_MOVE_PROBABILITY_FEATURESET_H */
00070 // ;;; Local Variables:
00071 // ;;; mode:c++
00072 // ;;; c-basic-offset:2
00073 // ;;; End:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines