src/ccstruct/dppoint.cpp
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;
}
// A CostFunc that takes the variance of step into account in the cost.
A CostFunc that takes the variance of step into account in the cost.
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;
}
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 ; }
A CostFunc that takes the variance of step into account in the cost.
A CostFunc that takes the variance of step into account in the cost .