Beispiel #1
0
// A CostFunc that takes the variance of step into account in the cost.
    inT64 DPPoint::CostWithVariance(const DPPoint *prev) {
        if (prev == NULL || prev == this) {
            UpdateIfBetter(0, 1, NULL, 0, 0, 0);
            return 0;
        }

        int delta = this - prev;
        inT32 n = prev->n_ + 1;
        inT32 sig_x = prev->sig_x_ + delta;
        inT64 sig_xsq = prev->sig_xsq_ + delta * delta;
        inT64 cost = (sig_xsq - sig_x * sig_x / n) / n;
        cost += prev->total_cost_;
        UpdateIfBetter(cost, prev->total_steps_ + 1, prev, n, sig_x, sig_xsq);
        return cost;
    }
Beispiel #2
0
// A CostFunc that takes the variance of step into account in the cost.
int64_t DPPoint::CostWithVariance(const DPPoint* prev) {
  if (prev == nullptr || prev == this) {
    UpdateIfBetter(0, 1, nullptr, 0, 0, 0);
    return 0;
  }

  int delta = this - prev;
  int32_t n = prev->n_ + 1;
  int32_t sig_x = prev->sig_x_ + delta;
  int64_t sig_xsq = prev->sig_xsq_ + delta * delta;
  int64_t cost = (sig_xsq - sig_x * sig_x / n) / n;
  cost += prev->total_cost_;
  UpdateIfBetter(cost, prev->total_steps_ + 1, prev, n, sig_x, sig_xsq);
  return cost;
}