All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
mlPredictor.cc
Go to the documentation of this file.
1 /* mlPredictor.cc
2  */
4 
5 const double predictor_coef[5][9] =
6  {
7  // all
8  {-3.7460724, 1.5899403, 1.5218839,
9  1.8912265, 2.2698081, 2.9564733,
10  1.8364091, 0.4818582, 0.2046128},
11  // ~ 100 nodes
12  { -4.502173, 1.866922, 1.075071,
13  1.785152, 2.904015, 3.546099,
14  2.217401, 1.037181, 0.198456},
15  // ~ 1,000 nodes
16  {-4.2651299, 1.8346520, 1.4515673,
17  1.8766168, 2.8202449, 3.2856799,
18  2.0692834, 0.7330482, 0.2069689},
19  // 1,000 ~ 10,000 nodes
20  {-3.8450811, 1.5901365, 1.6039122,
21  1.9947154, 2.2830698, 2.9788201,
22  1.8998258, 0.4654985, 0.2174952},
23  // 10,000 ~
24  {-3.3149250, 1.3827221, 1.4877458,
25  1.8048604, 1.6804844, 2.7207930,
26  1.6221641, 0.3460561, 0.1866114,}
27  };
28 
29 double osl::threatmate::MlPredictor::predict(const NumEffectState& state,
30  const Move move, size_t index){
31  const Player turn = alt(state.turn());
32  const Square oking = state.kingSquare(alt(turn));
33  King8Info K(state.Iking8Info(alt(turn)));
34  osl::progress::ml::NewProgress tprogress(state);
35 
36  const double* coef = predictor_coef[index];
37  double sum = coef[0];
38 
39  const int npiece = (int)(move.capturePtype());
40  if (npiece) {
41  for (int i=0; i<3; i++)
42  if (npiece%8 == i+5)
43  sum += coef[i+1];
44  if (npiece == 9)
45  sum += coef[4];
46  }
47 
48  int moveCandidate;
49  if(turn==BLACK) moveCandidate=K.countMoveCandidate<BLACK>(state);
50  else moveCandidate=K.countMoveCandidate<WHITE>(state);
51  sum += coef[5] * ( Neighboring8Direct::hasEffect(state, newPtypeO(turn, move.ptype()),
52  move.to(), oking) ) +
53  coef[6] * moveCandidate +
54  coef[7] * ( misc::BitOp::countBit(K.dropCandidate()) )+
55  coef[8] * ( tprogress.progressAttack(alt(turn)).value() );
56 
57  return sum;
58 }
59 double osl::threatmate::MlPredictor::probability(const NumEffectState& state,
60  const Move move, size_t index){
61  return 1.0 / (1.0 + exp (- predict(state,move,index) ));
62 }
63 // ;;; Local Variables:
64 // ;;; mode:c++
65 // ;;; c-basic-offset:2
66 // ;;; End: