گراف چیست؟

graph-matrix
شبکه عصبی شبکه عصبی گرافی هوش مصنوعي

گراف چیست؟

گراف

$$ \color{black} \large L_{i,j} := \begin{cases} \deg(v_i) & \text{if } i = j \\ -1 & \text{if } i \neq j \text{ and } v_i \text{ is adjacent to } v_j \\ 0 & \text{otherwise} \end{cases} $$
$$ \color{black} M_{i,k} = \begin{cases} -1 & \text{if } v_i \text{ is the source of } e_k \\ 1 & \text{if } v_i \text{ is the target of } e_k \\ 0 & \text{otherwise} \end{cases} $$
$$ \color{black} X = \begin{bmatrix} 25 & 50000 \\ 30 & 60000 \\ 45 & 80000 \end{bmatrix} $$
pip install networkx numpy matplotlib
import networkx as nx
import numpy as np
import matplotlib.pyplot as plt

# ایجاد گراف بدون جهت
G = nx.Graph()
G.add_nodes_from([1, 2, 3, 4])
G.add_edges_from([(1, 2), (2, 3), (3, 4), (4, 1), (2, 4)])

# استخراج ماتریس مجاورت
A = nx.adjacency_matrix(G).toarray()
print("ماتریس مجاورت:\n", A)

# نمایش گراف
nx.draw(G, with_labels=True)
plt.title("گراف نمونه")
plt.show()
\begin{bmatrix} 0 & 1 & 0 & 1 \\ 1 & 0 & 1 & 1 \\ 0 & 1 & 0 & 1 \\ 1 & 1 & 1 & 0 \end{bmatrix}​​​
# ماتریس درجه
degrees = np.sum(A, axis=1)
D = np.diag(degrees)
print("ماتریس درجه:\n", D)

# ماتریس لاپلاسین
L = D - A
print("ماتریس لاپلاسین:\n", L)
\begin{bmatrix} 2 & 0 & 0 & 0 \\ 0 & 3 & 0 & 0 \\ 0 & 0 & 2 & 0 \\ 0 & 0 & 0 & 3 \end{bmatrix}​​
\begin{bmatrix} 2 & -1 & 0 & -1 \\ -1 & 3 & -1 & -1 \\ 0 & -1 & 2 & -1 \\ -1 & -1 & -1 & 3 \end{bmatrix}​​​

فکر خود را اینجا بگذارید

نشانی ایمیل شما منتشر نخواهد شد. بخش‌های موردنیاز علامت‌گذاری شده‌اند *