<｜begin▁of▁sentence｜>### Instruction:
Given a graph with an edge set [(1, 2), (2, 3), (3, 4), (4, 5)], how can we compute the Katz centrality for the nodes using NetworkX, taking into account that the attenuation factor should be slightly less than the inverse largest eigenvalue of the graph's adjacency matrix?
### Response:
import networkx as nx
import math

# Create a graph
G = nx.Graph()
G.add_edges_from([(1, 2), (2, 3), (3, 4), (4, 5)])

# Calculate the largest eigenvalue for the adjacency matrix of G
eigenvalue = max(nx.adjacency_spectrum(G))
alpha = 1/eigenvalue - 0.01  # Attenuation factor
beta = 1.0  # Weight attributed to the immediate neighborhood
max_iter = 1000  # Maximum iterations

# Compute the Katz centrality
katz_centrality = nx.katz_centrality(G, alpha=alpha, beta=beta, max_iter=max_iter)

# Print the Katz centrality for each node
for node, centrality in sorted(katz_centrality.items()):
    print(f"Node {node}: {centrality:.4f}")
<|EOT|>
