FaultDiagnosis¶
FaultDiagnosis module
Class FaultDiagnosis. |
|
Write list of nodes and list of edges CSV format files, to visualize the input with Gephi. |
|
Parallel iteration for fitness evaluation. |
|
Wrapper for fitness evaluation. |
|
Evaluation of fitness on individual. |
|
Genetic algorithm to optimize switches conditions, using DEAP. |
|
Describe the topology of the graph. |
|
Remove nodes from the graph in a depth first search way to propagate the perturbation. |
|
Update columns output DataFrame with attributes in attribute_list. |
|
|
|
Delete a node in the graph. |
|
Perturbation simulator, actually applying the perturbation to all the nodes. |
|
Simulate a perturbation of one or multiple nodes. |
|
|
|
Write to file graph characterization after the perturbation. |
-
class
FaultDiagnosis
(filename, parallel=False)[source] Bases:
object
Class FaultDiagnosis.
Perturbation of a GeneralGraph object. Perturbation can be simulated on a list of elements. From one element, the perturbation propagates in all directions, unless an isolating element is present.
Create an input graph, with the structure contained in the input file.
- Parameters
-
apply_perturbation
(perturbed_nodes, params, weights, parallel, verbose, kind='element')[source] Perturbation simulator, actually applying the perturbation to all the nodes. The optimizer is run if any switch is present, and edges connecting its predecessors are removed if the switch state is set to ‘False’.
- Parameters
perturbed_nodes (list) – nodes(s) involved in the perturbing event.
params (dict) – values for the optimizer evolutionary algorithm. Dict of: {str: int, str: int, str: float, str: float, str: int}: - ‘npop’: number of individuals for each population (default to 300) - ‘ngen’: total number of generations (default to 100) - ‘indpb’: independent probability for attributes to be changed (default to 0.6) - ‘tresh’: threshold for applying crossover/mutation (default to 0.5) - ‘nsel’: number of individuals to select (default to 5)
weights (dict) –
weights for fitness evaluation on individuals. Dict of: {str: float, str: float, str: float}: - ‘w1’: weight multiplying number of switch flips (default to 1.0) - ‘w2’: weight multiplying total final service (default to -1.0) - ‘w3’: weight multiplying final graph size (default to -1.0) - ‘w4’: weight multiplying number of users with non-zero service
(default to -1.0)
’w5’: weight for service balance over users (default to 2.0)
parallel (bool) – flag for parallel fitness evaluation of initial population.
verbose (bool) – flag for verbose printing.
kind (str) – type of simulation, used to label output files, default to ‘element’.
Note
A perturbation, depending on the considered system, may spread in all directions starting from the damaged component(s) and may be affect nearby elements.
-
check_input_with_gephi
()[source] Write list of nodes and list of edges CSV format files, to visualize the input with Gephi.
-
check_paths_and_measures
(prefix=None)[source] Describe the topology of the graph. Compute efficiency measures for the whole graph and its nodes. Check the availability of paths between source and target nodes.
- Parameters
prefix (str, optional) – prefix to be added to column name, default to None.
-
delete_a_node
(node)[source] Delete a node in the graph.
- Parameters
node (str) – the id of the node to remove.
Warning
the node id must be contained in the graph. No check is done within this function.
-
fitness_evaluation
(individual, perturbed_nodes, initial_condition)[source] Evaluation of fitness on individual. The individual is a list of conditions for the graph switches (True or False). Edges connecting its predecessors are removed if the switch state is set to ‘False’.
- Parameters
individual (list) – element on which to compute the fitness.
perturbed_nodes (list) – nodes(s) involved in the perturbing event.
initial_condition (dict) – initial status (boolean) for the graph switches.
-
fitness_evaluation_parallel
(pop, perturbed_nodes, initial_condition)[source] Wrapper for fitness evaluation. This methods spawns the processes for fitness evaluation and collects the results.
- Parameters
pop (list) – list of individuals.
perturbed_nodes (list) – nodes(s) involved in the perturbing event.
initial_condition (dict) – initial status (boolean) for the graph switches.
- Returns
list of tuples constituted by the index of the individual, the individual itself, and its fitness.
- Return type
list
-
fitness_iteration_parallel
(out_queue, ichunk, chunk_length, individuals, perturbed_nodes, initial_condition)[source] Parallel iteration for fitness evaluation. We append to the multiprocessing queue a tuple constituted by constituted by the index of the individual, the individual itself, and its fitness.
- Parameters
out_queue (multiprocessing.queues.Queue) – multiprocessing queue
ichunk (int) – index of the chunk under consideration.
chunk_length (int) – lengths of the chunks (the last chunk may be shorter due to non-even division of the number of generations by the number of processors).
individuals (list) – list of individuals on which to perform fitness evaluation.
perturbed_nodes (list) – nodes(s) involved in the perturbing event.
initial_condition (dict) – initial status (boolean) for the graph switches.
-
graph_characterization_to_file
(filename)[source] Write to file graph characterization after the perturbation. File is written in CSV format.
- Parameters
filename (str) – output file name where to write the graph characterization.
-
optimizer
(perturbed_nodes, initial_condition, params, weights, parallel)[source] Genetic algorithm to optimize switches conditions, using DEAP.
- Parameters
perturbed_nodes (list) – nodes(s) involved in the perturbing event.
initial_condition (dict) – initial status (boolean) for the graph switches.
params (dict) – values for the optimizer evolutionary algorithm. Dict of: {str: int, str: int, str: float, str: float, str: int}. - ‘npop’: number of individuals for each population (default to 300) - ‘ngen’: total number of generations (default to 100) - ‘indpb’: independent probability for attributes to be changed (default to 0.6) - ‘tresh’: threshold for applying crossover/mutation (default to 0.5) - ‘nsel’: number of individuals to select (default to 5)
weights (dict) –
weights for fitness evaluation on individuals. Dict of: {str: float, str: float, str: float}: - ‘w1’: weight multiplying number of switch flips (default to 1.0) - ‘w2’: weight multiplying total final service (default to -1.0) - ‘w3’: weight multiplying final graph size (default to -1.0) - ‘w4’: weight multiplying number of users with non-zero service
(default to -1.0)
’w5’: weight for service balance over users (default to 2.0)
parallel (bool) – flag for parallel fitness evaluation of initial populations.
-
rm_nodes
(node, graph, visited=None, broken_nodes=None)[source] Remove nodes from the graph in a depth first search way to propagate the perturbation.
-
simulate_element_perturbation
(perturbed_nodes, params={'indpb': 0.6, 'ngen': 100, 'npop': 300, 'nsel': 5, 'tresh': 0.5}, weights={'w1': 1.0, 'w2': -1.0, 'w3': -1.0, 'w4': -1.0, 'w5': 2.0}, parallel=False, verbose=True)[source] Simulate a perturbation of one or multiple nodes.
- Parameters
perturbed_nodes (list) – nodes(s) involved in the perturbing event.
params (dict, optional) – values for the optimizer evolutionary algorithm. Dict of: {str: int, str: int, str: float, str: float, str: int}: - ‘npop’: number of individuals for each population (default to 300) - ‘ngen’: total number of generations (default to 100) - ‘indpb’: independent probability for attributes to be changed (default to 0.6) - ‘tresh’: threshold for applying crossover/mutation (default to 0.5) - ‘nsel’: number of individuals to select (default to 5)
weights (dict, optional) –
weights for fitness evaluation on individuals. Dict of: {str: float, str: float, str: float}: - ‘w1’: weight multiplying number of switch flips (default to 1.0) - ‘w2’: weight multiplying total final service (default to -1.0) - ‘w3’: weight multiplying final graph size (default to -1.0) - ‘w4’: weight multiplying number of users with non-zero service
(default to -1.0)
’w5’: weight for service balance over users (default to 2.0)
parallel (bool, optional) – flag for parallel fitness evaluation of initial population, default to False.
verbose (bool, optional different kinds of perturbations, default to None.) – flag for verbose output, default to True.
Note
A perturbation, depending on the considered system, may spread in all directions starting from the damaged component(s) and may be affect nearby elements.
- Raises
SystemExit