import networkx as nx
# Disclosed customer-supplier linkages from SEC Form 10-K and direct procurement contracts
ground_truth_edges = [
('ASML', 'TSM', 'Lithography Equipment', 0.38),
('AMAT', 'TSM', 'Process Tools', 0.15),
('SNPS', 'NVDA', 'EDA Software & IP', 0.05),
('SNPS', 'AMD', 'EDA Software & IP', 0.05),
('TSM', 'NVDA', 'Foundry CoWoS', 0.11),
('TSM', 'AMD', 'Foundry 5nm/4nm', 0.08),
('AMKR', 'TSM', 'Packaging Partner', 0.12),
('AMKR', 'NVDA', 'OSAT Assembly', 0.10),
('NVDA', 'MSFT', 'H100/B200 Clusters', 0.15),
('AMD', 'MSFT', 'MI300 Accelerators', 0.06),
('ALB', 'TSLA', 'Lithium Hydroxide', 0.14),
('SQM', 'TSLA', 'Lithium Carbonate', 0.10),
('ALB', 'RIVN', 'Battery Materials', 0.08),
('TSLA', 'FLNC', 'Megapack Cells/Packs', 0.05)
]
edges_df = pd.DataFrame(ground_truth_edges, columns=[
'Supplier (Source)', 'Customer (Target)', 'Segment Relationship', 'Estimated Revenue Share'
])
# Build directed ground truth graph
G_gt = nx.DiGraph()
for _, row in edges_df.iterrows():
G_gt.add_edge(
row['Supplier (Source)'],
row['Customer (Target)'],
segment=row['Segment Relationship'],
weight=row['Estimated Revenue Share']
)
# Compute network centrality metrics for ground truth
centrality_df = pd.DataFrame({
'Ticker': list(G_gt.nodes()),
'In-Degree (Supplied By)': [G_gt.in_degree(n) for n in G_gt.nodes()],
'Out-Degree (Supplies To)': [G_gt.out_degree(n) for n in G_gt.nodes()],
'Degree Centrality': [nx.degree_centrality(G_gt)[n] for n in G_gt.nodes()]
}).sort_values(by=['In-Degree (Supplied By)', 'Out-Degree (Supplies To)'], ascending=False).reset_index(drop=True)
centrality_df