Coverage for src/papierstat/datasets/graph.py: 100%
6 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-30 06:49 +0200
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-30 06:49 +0200
1# -*- coding: utf-8 -*-
2"""
3@file
4@brief Fonctions retournant des jeux de données liés aux graphes.
5"""
6import numpy
9def create_tiny_graph():
10 """
11 Graphe très petit. La fonction retourne une matrice
12 dans laquelle chaque élément représente la probabilité
13 de passer du noeud *i* au noeud *j*.
14 Notebooks associés à ce jeu de données :
16 .. runpython::
17 :rst:
19 from papierstat.datasets.documentation import list_notebooks_rst_links
20 links = list_notebooks_rst_links('lectures', 'tinygraph')
21 links = [' * %s' % s for s in links]
22 print('\\n'.join(links))
24 @return :epkg:`pandas:DataFrame`
26 .. runpython::
27 :showcode:
29 from papierstat.datasets import create_tiny_graph
30 print(create_tiny_graph())
32 .. plot::
34 from papierstat.datasets import create_tiny_graph
35 P = create_tiny_graph()
37 import networkx as nx
38 G = nx.Graph()
39 for i in range(0, max(P.shape)):
40 G.add_node(i)
41 for i in range(0, P.shape[0]):
42 for j in range(0, P.shape[1]):
43 if P[i,j] !=0 :
44 G.add_edge(i,j, weight=int(P[i,j] * 100)/100)
46 import matplotlib.pyplot as plt
47 fig, ax = plt.subplots(1, 1, figsize=(3,3))
48 pos = nx.shell_layout(G)
49 nx.draw(G, with_labels=True, font_weight='bold', ax=ax, pos=pos)
50 nx.draw_networkx_edge_labels(G, pos=pos)
51 plt.show()
52 """
53 r3 = 1. / 3
54 P = numpy.matrix([[0, 0.5, 0, 0.5], [0.5, 0, 0.5, 0],
55 [r3, r3, 0, r3], [0.1, 0.9, 0, 0]])
56 return P