File size: 1,587 Bytes
b265364
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
def generate_agent_actions(fig, feature_map, red_nodes, central_node, scores, threshold=0.7):
    """
    Suggests actions based on node anomaly scores and graph structure.

    Args:
        fig (matplotlib.Figure): The plotted graph figure.
        feature_map (list): List mapping node indices to feature names.
        red_nodes (list): Indices of detected anomalous nodes.
        central_node (int): The node with highest anomaly score.
        scores (np.ndarray): Anomaly score array per node.
        threshold (float): Minimum score to trigger an action.

    Returns:
        list of str: Recommended actions for inspection.
    """
    actions = []

    # Get name of central node
    try:
        central_name = feature_map[central_node]
    except IndexError:
        central_name = f"Node {central_node}"

    central_score = scores[central_node]
    actions.append(f"🔍 Investigate central anomaly node: {central_name} (score: {central_score:.2f})")

    for node in red_nodes:
        if node == central_node:
            continue

        try:
            node_name = feature_map[node]
        except IndexError:
            node_name = f"Node {node}"

        node_score = scores[node]
        if node_score > threshold:
            actions.append(f"🔧 Inspect connected node: {node_name} (score: {node_score:.2f})")
        else:
            actions.append(f"ℹ️ Monitor node: {node_name} (score: {node_score:.2f})")

    # Sort actions by score
    actions.sort(key=lambda x: float(x.split("score:")[-1].rstrip(")").strip()), reverse=True)
    return actions