Posts: 489Threads: 34 Member details
Posts: 489
Threads: 34
Thanks Received: 375 in 184 posts
Thanks Given: 169
Joined: May 2024
Reputation:
3
Location: Barcelona
Country:
(19-02-2026, 12:28 PM)nablator wrote: You are not allowed to view links. Register or Login to view. (19-02-2026, 12:17 PM)quimqu wrote: You are not allowed to view links. Register or Login to view.It is this formula. It is essentially the mutual information between characters separated by exactly d positions, averaged over all such pairs in the corpus.
That's what worries me (potentially, I don't know, but I suspect a possible issue there): how do you average the MI of all the pairs at distance d? A simple mean?
For each distance d, I do not average individual MI values. I treat all character pairs at that distance as samples of two random variables: the character at position t and the character at position t+d. I then compute the mutual information between those two variables in the standard way, using their empirical joint and marginal distributions. So there is only one MI(d) per distance, not an average of many MIs. This is the python code for the calculation:
Code: # =========================
# MI(d) estimator (sparse joint, smoothed marginals)
# =========================
def mutual_information_lag_sparse(ids, lag, alpha=0.5):
x = ids[:-lag]
y = ids[lag:]
n = len(x)
if n <= 20:
return np.nan
V = int(max(ids)) + 1
cx = np.bincount(x, minlength=V).astype(np.float64)
cy = np.bincount(y, minlength=V).astype(np.float64)
px = (cx + alpha) / (n + alpha * V)
py = (cy + alpha) / (n + alpha * V)
joint = defaultdict(int)
for a, b in zip(x, y):
joint[(int(a), int(b))] += 1
mi = 0.0
inv_n = 1.0 / n
for (a, b), cnt in joint.items():
pxy = cnt * inv_n
mi += pxy * (math.log(pxy) - math.log(px[a]) - math.log(py[b]))
return float(mi)
The following 1 user says Thank You to quimqu for this post:1 user says Thank You to quimqu for this post
• nablator
Posts: 2,270Threads: 24 Member details
Posts: 2,270
Threads: 24
Thanks Received: 1,711 in 1,043 posts
Thanks Given: 2512
Joined: Oct 2017
Reputation:
5
Country:
19-02-2026, 01:29 PM
(This post was last modified: 19-02-2026, 01:56 PM by nablator.)
Register or login to view the content
Posts: 489Threads: 34 Member details
Posts: 489
Threads: 34
Thanks Received: 375 in 184 posts
Thanks Given: 169
Joined: May 2024
Reputation:
3
Location: Barcelona
Country:
19-02-2026, 01:52 PM
(This post was last modified: 19-02-2026, 02:01 PM by quimqu.)
Register or login to view the content
Posts: 17Threads: 2 Member details
Posts: 17
Threads: 2
Thanks Received: 2 in 1 posts
Thanks Given: 3
Joined: Feb 2026
Reputation:
0
Location: United States
Register or login to view the content
Posts: 399Threads: 8 Member details
Posts: 399
Threads: 8
Thanks Received: 200 in 138 posts
Thanks Given: 1108
Joined: Nov 2024
Reputation:
1
Location: Italy
19-02-2026, 02:07 PM
(This post was last modified: 19-02-2026, 02:09 PM by Mauro.)
Register or login to view the content
Posts: 489Threads: 34 Member details
Posts: 489
Threads: 34
Thanks Received: 375 in 184 posts
Thanks Given: 169
Joined: May 2024
Reputation:
3
Location: Barcelona
Country:
19-02-2026, 03:26 PM
(This post was last modified: 19-02-2026, 03:32 PM by quimqu.)
Register or login to view the content
Posts: 489Threads: 34 Member details
Posts: 489
Threads: 34
Thanks Received: 375 in 184 posts
Thanks Given: 169
Joined: May 2024
Reputation:
3
Location: Barcelona
Country:
Register or login to view the content
Posts: 2,270Threads: 24 Member details
Posts: 2,270
Threads: 24
Thanks Received: 1,711 in 1,043 posts
Thanks Given: 2512
Joined: Oct 2017
Reputation:
5
Country:
19-02-2026, 05:01 PM
(This post was last modified: 19-02-2026, 05:36 PM by nablator.)
Register or login to view the content
Posts: 489Threads: 34 Member details
Posts: 489
Threads: 34
Thanks Received: 375 in 184 posts
Thanks Given: 169
Joined: May 2024
Reputation:
3
Location: Barcelona
Country:
Register or login to view the content
The following 1 user says Thank You to quimqu for this post:1 user says Thank You to quimqu for this post
• nablator
Posts: 2,270Threads: 24 Member details
Posts: 2,270
Threads: 24
Thanks Received: 1,711 in 1,043 posts
Thanks Given: 2512
Joined: Oct 2017
Reputation:
5
Country:
Register or login to view the content
|