Skip to content

Commit

Permalink
fix: utils/stats.py: Add the metric name as a parameter. Clean up code
Browse files Browse the repository at this point in the history
Signed-off-by: Nikos Livathinos <[email protected]>
  • Loading branch information
nikos-livathinos committed Jan 14, 2025
1 parent 2f417ab commit 36b0722
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions docling_eval/utils/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,27 @@ def check_bins_and_hist_lengths(cls, values):
raise ValueError("`bins` must have exactly one more element than `hist`.")
return values

def to_table(self) -> Tuple[List[List[str]], List[str]]:

headers = ["x0<=TEDS", "TEDS<=x1", "prob [%]", "acc [%]", "1-acc [%]", "total"]

# Calculate bin widths
bin_widths = [
self.bins[i + 1] - self.bins[i] for i in range(len(self.bins) - 1)
def to_table(self, metric_name: str = "TEDS") -> Tuple[List[List[str]], List[str]]:

headers = [
f"x0<={metric_name}",
f"{metric_name}<=x1",
"prob [%]",
"acc [%]",
"1-acc [%]",
"total",
]
bin_middle = [
(self.bins[i + 1] + self.bins[i]) / 2.0 for i in range(len(self.bins) - 1)
]

cumsum: float = 0.0

table = []
for i in range(len(self.bins) - 1):
table.append(
[
f"{self.bins[i+0]:.3f}",
f"{self.bins[i+1]:.3f}",
f"{100.0*float(self.hist[i])/float(self.total):.2f}",
f"{100.0*cumsum:.2f}",
f"{100.0*(1.0-cumsum):.2f}",
f"{self.bins[i + 0]:.3f}",
f"{self.bins[i + 1]:.3f}",
f"{100.0 * float(self.hist[i]) / float(self.total):.2f}",
f"{100.0 * cumsum:.2f}",
f"{100.0 * (1.0-cumsum):.2f}",
f"{self.hist[i]}",
]
)
Expand Down

0 comments on commit 36b0722

Please sign in to comment.