All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
move_probability/featureSet.h
Go to the documentation of this file.
1 /* featureSet.h
2  */
3 #ifndef OSL_MOVE_PROBABILITY_FEATURESET_H
4 #define OSL_MOVE_PROBABILITY_FEATURESET_H
5 
9 #include "osl/stl/vector.h"
10 #include <boost/ptr_container/ptr_vector.hpp>
11 #include <boost/scoped_array.hpp>
12 
13 namespace osl
14 {
15  namespace move_probability
16  {
17  class Feature;
18  typedef std::pair<double,Move> WeightedMove;
19  typedef FixedCapacityVector<WeightedMove,Move::MaxUniqMoves> WeightedMoveVector;
20 
21  class FeatureSet
22  {
23  boost::ptr_vector<Feature> features;
24  osl::vector<int> offsets, light_features;
25  protected:
26  FeatureSet();
27  public:
28  ~FeatureSet();
29  void pushBack(Feature *, bool light=false);
30  void addFinished();
31  int dimension() const { return offsets.back(); }
32  public:
33  double matchExp(const StateInfo&, Move, const double *weights) const;
34  double matchNoExp(const StateInfo&, Move, const double *weights) const;
35  void generateLogProb(const StateInfo& state,
36  MoveLogProbVector& out, const double *weights) const;
37  double matchLight(const StateInfo&, Move, const double *weights) const;
38 
39  bool load(const char *base_filename, double *weights) const;
40  bool load_binary(const char *base_filename, double *weights) const;
41  void showSummary(const double *weights) const;
42  void analyze(const StateInfo& state, Move move, const double *weights) const;
43  // for fine control
44  double generateRating(const StateInfo& state,
45  WeightedMoveVector& out, const double *weights) const;
46  static void ratingToLogProb(const WeightedMoveVector& rating,
47  double sum, MoveLogProbVector& out);
48  };
49 
51  {
52  static boost::scoped_array<double> weights, tactical_weights;
54  public:
57 
58  static const StandardFeatureSet& instance(bool verbose=false);
59  static bool healthCheck();
60  void generateLogProb(const StateInfo& state, MoveLogProbVector& out) const;
61  void generateLogProb2(const StateInfo& state, MoveLogProbVector& out) const;
62  void generateLogProb(const StateInfo& state, int limit, MoveLogProbVector& out, bool in_pv) const;
63  int logProbTakeBack(const StateInfo& state, Move target) const;
64  int logProbSeePlus(const StateInfo& state, Move target) const;
65  double matchLight(const StateInfo&, Move) const;
66  double matchExp(const StateInfo&, Move) const;
67  double matchNoExp(const StateInfo&, Move) const;
68  bool setUp(bool verbose=false);
69  bool ok() const { return initialized; }
70  private:
71  int tacticalLogProb(int offset, double sum) const;
72  };
73  }
74 }
75 #endif /* OSL_MOVE_PROBABILITY_FEATURESET_H */
76 // ;;; Local Variables:
77 // ;;; mode:c++
78 // ;;; c-basic-offset:2
79 // ;;; End: