FaultDiagnosis

FaultDiagnosis module

FaultDiagnosis

Class FaultDiagnosis.

FaultDiagnosis.check_input_with_gephi

Write list of nodes and list of edges CSV format files, to visualize the input with Gephi.

FaultDiagnosis.fitness_iteration_parallel

Parallel iteration for fitness evaluation.

FaultDiagnosis.fitness_evaluation_parallel

Wrapper for fitness evaluation.

FaultDiagnosis.fitness_evaluation

Evaluation of fitness on individual.

FaultDiagnosis.optimizer

Genetic algorithm to optimize switches conditions, using DEAP.

FaultDiagnosis.check_paths_and_measures

Describe the topology of the graph.

FaultDiagnosis.rm_nodes

Remove nodes from the graph in a depth first search way to propagate the perturbation.

FaultDiagnosis.update_output

Update columns output DataFrame with attributes in attribute_list.

FaultDiagnosis.update_status_areas

FaultDiagnosis.delete_a_node

Delete a node in the graph.

FaultDiagnosis.apply_perturbation

Perturbation simulator, actually applying the perturbation to all the nodes.

FaultDiagnosis.simulate_element_perturbation

Simulate a perturbation of one or multiple nodes.

FaultDiagnosis.simulate_area_perturbation

FaultDiagnosis.graph_characterization_to_file

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
  • filename (str) – input file in CSV format.

  • parallel (bool, optional) – flag for parallel graph creation, default to False.

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.

Parameters
  • node (str) – the id of the node to remove.

  • graph (nx.DiGraph) – graph on which to apply the node deletion

  • visited (set, optional) – nodes already visited, default to None.

  • broken_nodes (list, optional) – nodes that got broken along the perturbation, default to None.

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

update_output(attribute_list, prefix='')[source]

Update columns output DataFrame with attributes in attribute_list.

Parameters
  • attribute_list (list) – list of attributes to be updated to the output DataFrame.

  • prefix (str, optional) – prefix to be added to column name, default to empty string.