| 55 | } |
| 56 | |
| 57 | void Controller::observe(const Choice& c, int accepted, int lookup_match) { |
| 58 | if (c.source == Source::None || c.k <= 0) return; |
| 59 | accepted = std::clamp(accepted, 0, c.k); |
| 60 | // Positions 0..accepted-1 were accepted given their prefix; position `accepted` (if drafted) was rejected. |
| 61 | const int seen = std::min(c.k, accepted + 1); |
| 62 | for (int i = 0; i < seen; ++i) { |
| 63 | const double hit = i < accepted ? 1.0 : 0.0; |
| 64 | if (c.source == Source::Mtp) mtp_p_[i] += ema_ * (hit - mtp_p_[i]); |
| 65 | else lookup_q_[bucket(lookup_match)] += ema_ * (hit - lookup_q_[bucket(lookup_match)]); |
| 66 | } |
| 67 | // Everything drafted was accepted: the positions beyond the window were never tested, so without this they |
| 68 | // keep their prior forever and the window can never grow. Pull them toward the deepest observed rate. |
| 69 | if (c.source == Source::Mtp && accepted == c.k && c.k < K_MAX) |
| 70 | for (int i = c.k; i < K_MAX; ++i) mtp_p_[i] += ema_ * (mtp_p_[c.k - 1] - mtp_p_[i]); |
| 71 | } |
| 72 | |
| 73 | } // namespace strata::spec |