Defense¶

class
graph_tiger.defenses.
Defense
(graph, runs=10, steps=50, attack='id_node', defense=None, k_d=0, **kwargs)¶ Bases:
graph_tiger.simulations.Simulation
This class simulates a variety of defense techniques on an undirected NetworkX graph
 Parameters
graph – an undirected NetworkX graph
runs – an integer number of times to run the simulation
steps – an integer number of steps to run a single simulation
attack – a string representing the attack strategy to run
defense – a string representing the defense strategy to run
k_d – an integer number of nodes to defend
**kwargs –
see parent class Simulation for additional options

reset_simulation
()¶ Resets the simulation between each run

run_single_sim
()¶ Run the defense simulation

track_simulation
(step)¶ Keeps track of important simulation information at each step of the simulation
 Parameters
step – current simulation iteration

graph_tiger.defenses.
add_edge_degree
(graph, k=3)¶ Add k edges to defend based on top edge degree centrality entries [16].
 Parameters
graph – an undirected NetworkX graph
k – number of edges to add
 Returns
a list of edges to add

graph_tiger.defenses.
add_edge_eig
(graph, k=3)¶ Get k edges to defend based on top edge eigenvector centrality entries [16].
 Parameters
graph – an undirected NetworkX graph
k – number of edges to add
 Returns
a dictionary of the edges to be ‘added’

graph_tiger.defenses.
add_edge_pr
(graph, k=3)¶ Get k edges to defend based on top edge PageRank entries [16].
 Parameters
graph – an undirected NetworkX graph
k – number of edges to add
 Returns
a dictionary of the edges to be ‘added’

graph_tiger.defenses.
add_edge_pref
(graph, k=3)¶ Adds an edge connecting two nodes with the lowest degrees [2].
 Parameters
graph – an undirected NetworkX graph
k – number of edges to add
 Returns
a dictionary of the edges to be ‘added’

graph_tiger.defenses.
add_edge_rnd
(graph, k=3)¶ Add k random edges to the graph
 Parameters
graph – an undirected NetworkX graph
k – number of edges to add
 Returns
a dictionary of the edges to be ‘added’

graph_tiger.defenses.
get_central_edges
(graph, k, method='eig')¶ Internal function to compute edge PageRank, eigenvector centrality and degree centrality
 Parameters
graph – undirected NetworkX graph
k – int number of nodes to defend
method – string representing defense method
 Returns
list of edges to add

graph_tiger.defenses.
get_defense_category
(method)¶ Gets the defense category e.g., ‘node’, ‘edge’ defense.
 Parameters
method – a string representing the defense method
 Returns
a string representing the defense type (‘node’ or ‘edge’)

graph_tiger.defenses.
get_defense_methods
()¶ Gets a list of available defense methods as a list of functions.
 Returns
a list of all defense functions

graph_tiger.defenses.
get_node_eig
(graph, k=3)¶ Get k nodes to defend based on top eigenvector centrality entries
 Parameters
graph – an undirected NetworkX graph
k – number of nodes to defend
 Returns
a list of nodes to defend

graph_tiger.defenses.
get_node_ib
(graph, k=3, approx=inf)¶ Get k nodes to defend based on Initial Betweenness (IB) Removal [13].
 Parameters
graph – an undirected NetworkX graph
k – number of nodes to defend
approx – number of nodes to approximate the betweenness centrality, k=0.1n is a good approximation, where n
is the number of nodes in the graph
 Returns
a list of nodes to defend

graph_tiger.defenses.
get_node_id
(graph, k=3)¶ Get k nodes to defend based on Initial Degree (ID) Removal [13].
 Parameters
graph – an undirected NetworkX graph
k – number of nodes to defend
 Returns
a list of nodes to defend

graph_tiger.defenses.
get_node_ns
(graph, k=3)¶ Get k nodes to defend based on the Netshield algorithm [17].
 Parameters
graph – an undirected NetworkX graph
k – number of nodes to defend
 Returns
a list of nodes to defend

graph_tiger.defenses.
get_node_pr
(graph, k=3)¶ Get k nodes to defend based on top PageRank entries [15].
 Parameters
graph – an undirected NetworkX graph
k – number of nodes to defend
 Returns
a list of nodes to defend

graph_tiger.defenses.
get_node_rb
(graph, k=3, approx=inf)¶ Get k nodes to defend based on Recalculated Betweenness (RB) Removal [13]
 Parameters
graph – an undirected NetworkX graph
k – number of nodes to defend
approx – number of nodes to approximate the betweenness centrality, k=0.1n is a good approximation, where n
is the number of nodes in the graph
 Returns
a list of nodes to defend

graph_tiger.defenses.
get_node_rd
(graph, k=3)¶ Get k nodes to defend based on Recalculated Degree (RD) Removal [13].
 Parameters
graph – an undirected NetworkX graph
k – number of nodes to defend
 Returns
a list of nodes to defend

graph_tiger.defenses.
get_node_rnd
(graph, k=3)¶ Randomly select k distinct nodes to defend
 Parameters
graph – an undirected NetworkX graph
k – number of nodes to defend
 Returns
a list of nodes to defend

graph_tiger.defenses.
main
()¶

graph_tiger.defenses.
rewire_edge_pref
(graph, k=3)¶ Selects node with highest degree, randomly removes a neighbor; adds edge to random node in graph [2].
 Parameters
graph – an undirected NetworkX graph
k – number of edges to rewire
 Returns
a dictionary of the edges to be ‘removed’ and edges to be ‘added’

graph_tiger.defenses.
rewire_edge_pref_rnd
(graph, k=3)¶ Selects an edge, disconnects the higher degree node, and reconnects to a random one [2].
 Parameters
graph – an undirected NetworkX graph
k – number of edges to rewire
 Returns
a dictionary of the edges to be ‘removed’ and edges to be ‘added’

graph_tiger.defenses.
rewire_edge_rnd
(graph, k=3)¶ Removes a random edge and adds one randomly [2].
 Parameters
graph – an undirected NetworkX graph
k – number of edges to rewire
 Returns
a dictionary of the edges to be ‘removed’ and edges to be ‘added’

graph_tiger.defenses.
rewire_edge_rnd_neighbor
(graph, k=3)¶ Randomly selects a neighbor of a node and removes the edge; then adds a random edge [2].
 Parameters
graph – an undirected NetworkX graph
k – number of edges to rewire
 Returns
a dictionary of the edges to be ‘removed’ and edges to be ‘added’

graph_tiger.defenses.
run_defense_method
(graph, method, k=3, seed=None)¶ Runs a specified defense on an undirected graph, returning a list of nodes to defend.
 Parameters
graph – an undirected NetworkX graph
method – a string representing one of the attack methods
k – number of nodes or edges to attack
seed – sets the seed in order to obtain reproducible defense runs
 Returns
a list of nodes or edge tuples to defend