Download docs/deviation-direction.md from DecodeMarketing/Correlation-network: direct link, hf CLI and curl.
- Browser
- Download file 3.45 kB
-
https://huggingface.co/spaces/DecodeMarketing/Correlation-network/resolve/main/docs/deviation-direction.md
- Command line
-
hf download hf://spaces/DecodeMarketing/Correlation-network/docs/deviation-direction.md
-
curl -L -o deviation-direction.md https://huggingface.co/spaces/DecodeMarketing/Correlation-network/resolve/main/docs/deviation-direction.md
A newer version of the Streamlit SDK is available: 1.67.0
Reading direction of the deviation matrix
The matrix is asymmetric
The block the app reads from Results Correls is a deviation matrix, not a
correlation matrix. Rows are attributes (column C), columns are the same attributes
repeated as headers in row 5. Every pair therefore appears twice — once on each side
of the diagonal — and the two cells hold different numbers.
Measured on a real client file (P&G FemCare, 78 attributes, block AG92:DF169):
- mean gap between
[A,B]and[B,A]: 1.37, maximum 13.02 - all 78 blank cells fall exactly on the diagonal, zero blanks off it
That last point matters: the blanks are precisely the self-pairs, which proves the row and column labels are correctly aligned. The asymmetry is real data, not a parsing error.
The rule
An attribute's associations are read down its own column. For attribute X,
locate its column via the row-5 header and read down the attribute rows. In code:
value_for(source, target) == corr_df.loc[target, source]
Confirmed against the client's own expectation: for newness (column BI), the
expected top 5 matches the column reading exactly, and matches the row reading for
none of the five.
Why the previous behaviour was wrong
build_network.py sorts attribute names alphabetically to assign index numbers, then
used to store only the upper triangle, taking the cell whose row was the
alphabetically later of the two names. So which of the two values reached the graph
depended on where the English label fell in the alphabet. On the file above, 121 of
3003 pairs (4.0%) appeared or vanished by that accident, affecting 74 of 78
attributes, and a single attribute's edge list mixed both readings.
newness was the reported symptom: mid-alphabet, so 43 partners were read across its
row and 34 down its column. contains safe materials looked fine only because it sorts
early and none of its pairs happened to straddle the threshold.
Consequence for the data structure
The sparse map is directed: keys are "source,target", and both directions are
stored. The same pair legitimately shows different values depending on which node is
selected — selecting newness shows its column value for makes life easier (28.3),
selecting makes life easier shows its own column value for newness (32.9).
getCorr(i, j) in the generated JavaScript takes i as the source and j as the
target and looks the key up directly. Both call sites already pass the source first:
level 1 uses the selected node, level 2 uses the level-1 node.
Open questions
Deliberately deferred, to revisit with the codeowner:
- Level 2 currently follows the same rule (each level-1 node's own column). This is consistent, but was not independently confirmed against an expected result.
- Undirected framing. The UI calls this an "association network", which implies one value per pair. Averaging the two directions would restore that at the cost of showing neither measured value. Directional was chosen because the underlying statistic is directional and the UI is already ego-centric.
Related known behaviour
Blank cells in column D (Category Index) become 0, which renders as the smallest node
labelled (0) and sorts last. This is expected: some attributes are not asked in
the category modules the index is derived from, so no value exists. Left as-is by
decision, not oversight.