equinor / equinor/graphite-maps

Precision matrix estimates are non zero at zero locations

Open
#159 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
Python
Stars
8
Forks
3
PR merge metrics
No merged PRs in 30d

Description

The function `fit_precision_cholesky` returns non-zero precision estimates in locations where the sparsity graph G say precision should be zero. From what I understand this is a bug. I have not figured out where the bug is yet. Small reproducible example:

```python3
import networkx as nx
import numpy as np

rng = np.random.default_rng(8)
n = 4 # Size
density = 0.4 # Density

# Create G indicating sparsity pattern
G = rng.uniform(size=(n, n)) < (density / 2)
G = G.T + G
np.fill_diagonal(G, np.ones(n))
G_mat = (G > 0).astype(int)
print("Sparsity pattern")
print(G_mat)
assert np.all(np.linalg.svd(G_mat).S > 0)
G = nx.from_scipy_sparse_array(sp.csc_array(G_mat))

# Create data U
U = rng.normal(size=(999, n))

# Estimate precision
Prec_est, *_ = fit_precision_cholesky(U=U, Graph_u=G, use_tqdm=False)
Prec_est = Prec_est.todense()
print("Estimated precision matrix")
print(Prec_est.round(4)) # Estimated precision matrix

# Look for non-zero precision where the sparsity pattern say the should be zero
entries_at_zero = Prec_est[G_mat == 0]
print("Entries at zero:")
entr= entries_at_zero[~np.isclose(entries_at_zero, 0.0)]
print(entr)
print(f"Number of entries at zero: {len(entr)}")
```

```text
Sparsity pattern
[[1 0 1 1]
[0 1 0 1]
[1 0 1 0]
[1 1 0 1]]
Estimated precision matrix
[[ 0.9576 0.0352 -0.0156 -0.0098]
[ 0.0352 0.9629 0. 0.0131]
[-0.0156 0. 0.9723 0. ]
[-0.0098 0.0131 0. 0.9614]]
Entries at zero:
[0.03518255 0.03518255]
Number of entries at zero: 2
```

Contributor guide

Open the contributing guide

Research direction

Start by locating `fit_precision_cholesky` and run the reproducible example from the issue to inspect how the graph sparsity pattern is applied. Trace the precision estimate at entries where `G_mat == 0`; done means those entries remain zero while the existing estimation behavior is preserved.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.