Manual small-graph tests
This document explains the manually verifiable link prediction tests used in the unit test suite.
The goal is to validate simple graph configurations where expected values can be derived by hand before adding broader validation against R linkprediction::proxfun.
Scope
The current manual tests focus on local and semi-local metrics:
common_neighborsjaccardadamic_adarresource_allocationpreferential_attachmentsaltonsorensenhub_promotedhub_depressedlhn_localdegreeshortest_pathlocal_path
Global metrics such as katz, rwr, and act are better suited for tolerance-based tests because they depend on matrix conventions, graph connectivity assumptions, and numerical precision.
Path graph
0 -- 1 -- 2For pair (0, 2):
Expected values:
| Metric | Expected value |
|---|---|
common_neighbors | 1 |
jaccard | 1.0 |
adamic_adar | |
resource_allocation | |
preferential_attachment | 1 |
salton | 1.0 |
sorensen | 1.0 |
hub_promoted | 1.0 |
hub_depressed | 1.0 |
lhn_local | 1.0 |
shortest_path | 2.0 |
Unequal-degree graph
3
|
0 -- 2 -- 1 -- 4
| \
5 6For pair (0, 1):
Expected values:
| Metric | Expected value |
|---|---|
common_neighbors | 1 |
preferential_attachment | 8 |
jaccard | |
salton | |
sorensen | |
hub_promoted | |
hub_depressed | |
lhn_local |
Local path graph
0 -- 1 -- 2 -- 3For pair (0, 3):
- there are no walks of length 2;
- there is one walk of length 3;
- with the default
, the expected score is 0.01.
The local path formula is:
Disconnected graph
0 -- 1 2 -- 3For pair (0, 2), shortest_path should be infinite because the nodes are in different connected components.
Isolated nodes
0 1For pair (0, 1), both nodes have degree zero. Similarity scores whose denominator would be zero should return 0.0, not NaN or an uninitialized numeric value.
This validates the package zero-division policy for:
jaccardsaltonsorensenhub_promotedhub_depressedlhn_local
Test command
pytest tests/unit/test_linkprediction.py tests/unit/test_linkprediction_manual_graphs.py -qRelationship to R validation
These tests are Python-side manual checks. They are not a replacement for R validation fixtures.
Future R validation should compare selected metrics against linkprediction::proxfun using aligned:
- node ordering;
- graph direction;
- pair selection;
- parameter values;
- disconnected-pair handling;
- floating-point tolerance.