Skip to content

Commit e8e79d7

Browse files
committed
Use average rather than minimum probability from the probability bound.
Testing shows this is neutral on performance of produced segmentations vs min bound, but gives a pretty good reduction in brotli calls by making best case pruning more effective.
1 parent 922cbaa commit e8e79d7

File tree

4 files changed

+12
-14
lines changed

4 files changed

+12
-14
lines changed

ift/encoder/activation_condition.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -371,10 +371,10 @@ StatusOr<double> ActivationCondition::Probability(
371371
}
372372

373373
// TODO(garretrieger): The full probability bound should be utilized here.
374-
return calculator.ComputeMergedProbability(union_segments).Min();
374+
return calculator.ComputeMergedProbability(union_segments).Average();
375375
}
376376

377-
return calculator.ComputeConjunctiveProbability(conjunctive_segments).Min();
377+
return calculator.ComputeConjunctiveProbability(conjunctive_segments).Average();
378378
}
379379

380380
StatusOr<double> ActivationCondition::MergedProbability(
@@ -431,10 +431,10 @@ StatusOr<double> ActivationCondition::MergedProbability(
431431
union_segments.push_back(&merged_segment);
432432
}
433433

434-
return calculator.ComputeMergedProbability(union_segments).Min();
434+
return calculator.ComputeMergedProbability(union_segments).Average();
435435
}
436436

437-
return calculator.ComputeConjunctiveProbability(conjunctive_segments).Min();
437+
return calculator.ComputeConjunctiveProbability(conjunctive_segments).Average();
438438
}
439439

440440
} // namespace ift::encoder

ift/encoder/closure_glyph_segmenter.cc

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -176,19 +176,16 @@ struct SegmentOrdering {
176176

177177
bool operator<(const SegmentOrdering& other) const {
178178
if (group_index != other.group_index) {
179+
// Group index ascending.
179180
return group_index < other.group_index;
180181
}
181182

182-
if (probability.Min() != other.probability.Min()) {
183-
// Probability descending.
184-
return probability.Min() > other.probability.Min();
185-
}
186-
187-
if (probability.Max() != other.probability.Max()) {
188-
// Probability descending.
189-
return probability.Max() > other.probability.Max();
183+
if (probability.Average() != other.probability.Average()) {
184+
// Segment probability descending.
185+
return probability.Average() > other.probability.Average();
190186
}
191187

188+
// Break ties with original segment index ascending.
192189
return original_index < other.original_index;
193190
}
194191
};
@@ -595,7 +592,7 @@ StatusOr<SegmentationCost> ClosureGlyphSegmenter::TotalCost(
595592
double incremental_size =
596593
non_ift_font_size / (double)non_ift.codepoints.size();
597594
for (unsigned cp : non_ift.codepoints) {
598-
double Pcp = probability_calculator.ComputeProbability({cp}).Min();
595+
double Pcp = probability_calculator.ComputeProbability({cp}).Average();
599596
ideal_cost += Pcp * incremental_size;
600597
}
601598

ift/encoder/segment.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ struct Segment {
1010
Segment(SubsetDefinition definition, freq::ProbabilityBound probability)
1111
: definition(std::move(definition)), probability(probability) {}
1212

13-
double Probability() const { return probability.Min(); }
13+
double Probability() const { return probability.Average(); }
1414
const freq::ProbabilityBound& ProbabilityBound() const { return probability; }
1515

1616
const SubsetDefinition& Definition() const { return definition; }

ift/freq/probability_bound.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ struct ProbabilityBound {
1717

1818
double Min() const { return min_; }
1919
double Max() const { return max_; }
20+
double Average() const { return (min_ + max_) / 2.0; }
2021

2122
bool operator==(const ProbabilityBound& other) const {
2223
return min_ == other.min_ && max_ == other.max_;

0 commit comments

Comments
 (0)