mirror of
https://github.com/allenai/olmocr.git
synced 2025-09-25 16:30:28 +00:00
More fixes
This commit is contained in:
parent
b2fe82db9b
commit
743e48e4ad
@ -321,28 +321,33 @@ def compare_rendered_equations(reference: RenderedEquation, hypothesis: Rendered
|
||||
return True
|
||||
|
||||
# Fallback: neighbor-based matching using the spans.
|
||||
H = hypothesis.spans
|
||||
R = reference.spans
|
||||
# First, print out the original span lists.
|
||||
# print("Hypothesis spans:")
|
||||
# for s in hypothesis.spans:
|
||||
# print(s)
|
||||
# print("---")
|
||||
# print("Reference spans:")
|
||||
# for s in reference.spans:
|
||||
# print(s)
|
||||
# print("---")
|
||||
|
||||
print("\n".join(str(x) for x in H))
|
||||
print("---")
|
||||
print("\n".join(str(x) for x in R))
|
||||
print("---")
|
||||
# We swap H and R so that we are effectively checking if the reference is contained in the hypothesis.
|
||||
H, R = reference.spans, hypothesis.spans
|
||||
|
||||
# Oops, we had to flip these, basically, you want to see if the reference exists anywhere in the hypothesis
|
||||
H, R = R, H
|
||||
H = [span for span in H if span.text != "\u200b"]
|
||||
R = [span for span in R if span.text != "\u200b"]
|
||||
|
||||
# For each hypothesis span, record candidate indices in reference that have the same text.
|
||||
# Build candidate map: for each span in H (reference), record indices in R with matching text.
|
||||
candidate_map = {}
|
||||
for i, hspan in enumerate(H):
|
||||
candidate_map[i] = [j for j, rsp in enumerate(R) if rsp.text == hspan.text]
|
||||
if not candidate_map[i]:
|
||||
print("Not found for", i, hspan)
|
||||
return False # if no candidate for a given hypothesis span, fail immediately
|
||||
return False # no candidate for a given span, so we fail immediately
|
||||
|
||||
# print("Candidate Map:")
|
||||
# print(candidate_map)
|
||||
|
||||
# Compute neighbor mappings for a list of spans.
|
||||
# For each span (by index), we compute the index of the closest span immediately
|
||||
# above, below, left, and right (if any) using the center of the bounding box.
|
||||
# Function to compute neighbor mappings for a list of spans.
|
||||
def compute_neighbors(spans, tol=5):
|
||||
neighbors = {}
|
||||
for i, span in enumerate(spans):
|
||||
@ -384,9 +389,12 @@ def compare_rendered_equations(reference: RenderedEquation, hypothesis: Rendered
|
||||
|
||||
hyp_neighbors = compute_neighbors(H)
|
||||
ref_neighbors = compute_neighbors(R)
|
||||
|
||||
print(H, hyp_neighbors)
|
||||
print(R, ref_neighbors)
|
||||
# print("Neighbor Map for Reference spans (H):")
|
||||
# for i, nb in hyp_neighbors.items():
|
||||
# print(f"Span {i}: {nb}")
|
||||
# print("Neighbor Map for Hypothesis spans (R):")
|
||||
# for i, nb in ref_neighbors.items():
|
||||
# print(f"Span {i}: {nb}")
|
||||
|
||||
# Backtracking search for an injection f: {0,...,n-1} -> {indices in R} that preserves neighbor relations.
|
||||
n = len(H)
|
||||
@ -399,7 +407,7 @@ def compare_rendered_equations(reference: RenderedEquation, hypothesis: Rendered
|
||||
for cand in candidate_map[i]:
|
||||
if used[cand]:
|
||||
continue
|
||||
# Tentatively assign hypothesis span i to reference span cand.
|
||||
# Tentatively assign hypothesis span i (from H) to reference span cand (in R).
|
||||
assignment[i] = cand
|
||||
used[cand] = True
|
||||
valid = True
|
||||
@ -409,29 +417,31 @@ def compare_rendered_equations(reference: RenderedEquation, hypothesis: Rendered
|
||||
ref_nb = ref_neighbors[cand].get(direction)
|
||||
if hyp_nb is not None:
|
||||
expected_text = H[hyp_nb].text
|
||||
# The candidate reference span must have a neighbor in that direction.
|
||||
# The candidate in R must have a neighbor in that direction.
|
||||
if ref_nb is None:
|
||||
valid = False
|
||||
break
|
||||
# If the neighbor in hypothesis is already assigned, check that it matches.
|
||||
# If the neighbor in H is already assigned, then the candidate neighbor must match.
|
||||
if hyp_nb in assignment:
|
||||
if assignment[hyp_nb] != ref_nb:
|
||||
valid = False
|
||||
break
|
||||
else:
|
||||
# If not yet assigned, at least the reference neighbor must have the expected text.
|
||||
# If not yet assigned, the neighbor text in R must match the expected text.
|
||||
if R[ref_nb].text != expected_text:
|
||||
valid = False
|
||||
break
|
||||
if valid:
|
||||
if backtrack(i + 1):
|
||||
return True
|
||||
# Backtrack.
|
||||
# Backtrack this candidate assignment.
|
||||
used[cand] = False
|
||||
del assignment[i]
|
||||
return False
|
||||
|
||||
return backtrack(0)
|
||||
result = backtrack(0)
|
||||
|
||||
return result
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,41 @@
|
||||
Proof. Let $S$ be the generating set associated with $D$ as described in Proposition 2.5. By the circulant diagonalization theorem, the spectrum of $G_R(D) = \Gamma(R, S)$ is the multiset $\{\lambda_g\}_{g \in R}$ where
|
||||
|
||||
$$
|
||||
\lambda_g = \sum_{s \in S} \zeta_n^{\psi(gs)} = \sum_{i=1}^{k} \left[ \sum_{s, Rs=I_i} \zeta_n^{\psi(gs)} \right].
|
||||
$$
|
||||
|
||||
We remark that by Corollary 2.7, if $s \in R$ such that $Rs = I_i = Rx_i$ then $s$ has a unique representation of the form $s = \hat{u}x_i$ where $u \in (R/\text{Ann}_R(x_i))^\times$ and $\hat{u}$ is a fixed lift of $u$ to $R^\times$. With this presentation, we can write
|
||||
|
||||
$$
|
||||
\sum_{s, Rs=I_i} \zeta_n^{\psi(gs)} = \sum_{u \in (R/\text{Ann}_R(x_i))^\times} \zeta_n^{\psi(gux_i)} = \sum_{u \in (R/\text{Ann}_R(x_i))^\times} \zeta_n^{\psi_{x_i}(gu)} = c(g, R/\text{Ann}_R(x_i)).
|
||||
$$
|
||||
|
||||
Here we recall that $\psi_{x_i}$ is the induced linear functional on $R/\text{Ann}_R(x_i)$. We conclude that $\lambda_g = \sum_{i=1}^{k} c(g, R/\text{Ann}_R(x_i))$. \qed
|
||||
|
||||
The following corollary is simple yet important for our future work on perfect state transfers on gcd-graphs.
|
||||
|
||||
**Corollary 4.17.** Suppose that $g' = ug$ for some $u \in R^\times$. Then $\lambda_g = \lambda_{g'}$.
|
||||
|
||||
**Acknowledgements**
|
||||
|
||||
We thank the Department of Mathematics and Computer Science at Lake Forest College for their generous financial support through an Overleaf subscription. We also thank Ján Mináč for his constant encouragement and support.
|
||||
|
||||
**References**
|
||||
|
||||
1. Reza Akhtar, Megan Boggess, Tiffany Jackson-Henderson, Isidora Jiménez, Rachel Karpman, Amanda Kinzel, and Dan Pritikin, *On the unitary Cayley graph of a finite ring*, Electron. J. Combin. 16 (2009), no. 1, Research Paper 117, 13 pages.
|
||||
|
||||
2. Milan Bašić, Aleksandar Ilić, and Aleksandar Stamenković, *Maximal diameter of integral circulant graphs*, Information and Computation 301 (2024), 105208.
|
||||
|
||||
3. Maria Chudnovsky, Michal Cizek, Logan Crew, Ján Mináč, Tung T. Nguyen, Sophie Spirkl, and Nguyễn Duy Tân, *On prime Cayley graphs*, arXiv:2401.06062, to appear in Journal of Combinatorics (2024).
|
||||
|
||||
4. Thomas Honold, *Characterization of finite frobenius rings*, Archiv der Mathematik 76 (2001), no. 6, 406–415.
|
||||
|
||||
5. Irving Kaplansky, *Elementary divisors and modules*, Transactions of the American Mathematical Society 66 (1949), no. 2, 464–491.
|
||||
|
||||
6. Walter Klotz and Torsten Sander, *Some properties of unitary Cayley graphs*, The Electronic Journal of Combinatorics 14 (2007), no. 1, R45, 12 pages.
|
||||
|
||||
7. Erich Lamprecht, *Allgemeine theorie der Gaußschen Summen in endlichen kommutativen Ringen*, Mathematische Nachrichten 9 (1953), no. 3, 149–196.
|
||||
|
||||
8. Ján Mináč, Tung T Nguyen, and Nguyen Duy Tân, *Isomorphic gcd-graphs over polynomial rings*, arXiv preprint arXiv:2411.01768 (2024).
|
||||
|
||||
9. ———, *On the gcd graphs over polynomial rings*, arXiv preprint arXiv:2409.01929 (2024).
|
Loading…
x
Reference in New Issue
Block a user