解读math_graph.py_图处理工具

  • scaled_laplacian函数:
  • cheb_poly_approx函数:
  • first_approx()函数:
  • weight_matrix()函数:
import numpy as np
import pandas as pd
from scipy.sparse.linalg import eigs


scaled_laplacian函数:

def scaled_laplacian(W):'''Normalized graph Laplacian function. 标准化拉普拉斯矩阵:param W: np.ndarray, [n_route, n_route], weighted adjacency matrix of G.:return: np.matrix, [n_route, n_route].'''# d ->  diagonal degree matrix 度矩阵n, d = np.shape(W)[0], np.sum(W, axis=1)      #1.取出矩阵W的维度 2.将矩阵W的列向量相加’‘’举例:c = np.array([[0, 2, 1], [3, 5, 6], [0, 1, 1]])print c.sum()print c.sum(axis=0)print c.sum(axis=1)结果分别是:19, [3 8 8], [ 3 14  2]‘’‘# L -> graph LaplacianL = -WL[np.diag_indices_from(L)] = d  #返回索引以访问n维数组L的主对角线for i in range(n):for j in range(n):if (d[i] > 0) and (d[j] > 0):L[i, j] = L[i, j] / np.sqrt(d[i] * d[j])# lambda_max \approx(大约) 2.0, the largest eigenvalues(特征值) of L.lambda_max = eigs(L, k=1, which='LR')[0][0].real  # 1. k:int, 可选参数所需的特征值和特征向量的数量。 2.‘LR’:largest real part 3. x.real取得xd的实部#eigs()全称为scipy.sparse.linalg.eigs()用于求平方矩阵A的k个特征值和特征向量。return np.mat(2 * L / lambda_max - np.identity(n))     #np.identity(n)生成一个n行n列的单位矩阵

np.identity()函数详解
scipy.sparse.linalg.eigs()函数详解~

cheb_poly_approx函数:

def cheb_poly_approx(L, Ks, n):'''Chebyshev(切比雪夫) polynomials(多项式) approximation(逼近、近似) function.:param L: np.matrix, [n_route, n_route], graph Laplacian(拉普拉斯算子).:param Ks: int, kernel size of spatial convolution(空间卷积核大小).:param n: int, number of routes / size of graph.(图的大小):return: np.ndarray, [n_route, Ks*n_route]. 返回一个np.ndarray的多维数组'''L0, L1 = np.mat(np.identity(n)), np.mat(np.copy(L))   #np.copy():返回给定对象的数组副本if Ks > 1:L_list = [np.copy(L0), np.copy(L1)]for i in range(Ks - 2):Ln = np.mat(2 * L * L1 - L0)L_list.append(np.copy(Ln))L0, L1 = np.matrix(np.copy(L1)), np.matrix(np.copy(Ln))# L_lsit [Ks, n*n], Lk [n, Ks*n]return np.concatenate(L_list, axis=-1)elif Ks == 1:return np.asarray(L0)    #将输入转换为数组else:raise ValueError(f'ERROR: the size of spatial kernel must be greater than 1, but received "{Ks}".')

np.copy()函数详解
np.concatenate()函数详解
numpy.asarray()函数详解

first_approx()函数:

def first_approx(W, n):'''1st-order approximation function.:param W: np.ndarray, [n_route, n_route], weighted adjacency matrix of G.:param n: int, number of routes / size of graph.:return: np.ndarray, [n_route, n_route].'''A = W + np.identity(n)d = np.sum(A, axis=1)sinvD = np.sqrt(np.mat(np.diag(d)).I)# refer to Eq.5return np.mat(np.identity(n) + sinvD * A * sinvD)

weight_matrix()函数:

def weight_matrix(file_path, sigma2=0.1, epsilon=0.5, scaling=True):'''Load weight matrix function.:param file_path: str, the path of saved weight matrix file.:param sigma2: float, scalar of matrix W.:param epsilon: float, thresholds to control the sparsity of matrix W.:param scaling: bool, whether applies numerical scaling on W.:return: np.ndarray, [n_route, n_route].'''try:W = pd.read_csv(file_path, header=None).valuesexcept FileNotFoundError:print(f'ERROR: input file was not found in {file_path}.')# check whether W is a 0/1 matrix.if set(np.unique(W)) == {0, 1}:print('The input graph is a 0/1 matrix; set "scaling" to False.')scaling = Falseif scaling:n = W.shape[0]W = W / 10000.W2, W_mask = W * W, np.ones([n, n]) - np.identity(n)# refer to Eq.10return np.exp(-W2 / sigma2) * (np.exp(-W2 / sigma2) >= epsilon) * W_maskelse:return W

STGCN复现第三弹:解读math_graph.py相关推荐

  1. ST-GCN复现以及配置环境遇到的问题(Colab)

    ST-GCN复现以及配置环境遇到的问题(Colab) ST-GCN介绍:解读:基于动态骨骼的动作识别方法ST-GCN(时空图卷积网络模型)_浪浪的博客-CSDN博客 这里我就不多介绍了,大家可以别的地 ...

  2. win10 ST-GCN复现

    win10 ST-GCN复现 下载源码 https://github.com/yysijie/st-gcn 安装requirements 1.anaconda切换python环境 命令为 conda ...

  3. 爬虫第三弹:图灵社区书籍信息爬取

    爬虫第三弹:图灵社区书籍信息爬取 一.目的:将图灵社区所有书籍的网址.书籍名称,作者,译者,阅读数,标签,出版日期,定价,页数,印刷方式,出版状态全部爬取下来存入mysql数据库,并导出xml格式,最 ...

  4. YOLOv5:解读yolo.py

    YOLOv5:解读yolo.py 前言 前提条件 相关介绍 yolo.py parse_model()函数 Detect类 Model类 参考 前言 记录一下自己阅读yolo.py代码的一些重要点,方 ...

  5. 他是第一个到达学校的人英语_日本留学:不需要英语成绩的大学盘点·私立学部篇(第三弹)...

    今日知识点:日本留学也是需要英语成绩的. 很多同学左脚刚要迈进日本留学大门,右脚就被英语成绩给吓回去了.嗯?我就是因为英语不好,才来日本的呀??? 连载篇来啦~大圣历时168小时整理出来不需要提交英语 ...

  6. MaxCompute - ODPS重装上阵 第三弹 - 复杂类型

    摘要: MaxCompute(原ODPS)是阿里云自主研发的具有业界领先水平的分布式大数据处理平台, 尤其在集团内部得到广泛应用,支撑了多个BU的核心业务. MaxCompute除了持续优化性能外,也 ...

  7. 面试基础算法及编程 第三弹(树(二叉树)相关:主要考察指针相关的操作)

    // # -*- coding:utf-8 -*- // # @Author: Mr.chen(ai-chen2050@qq.com) // # @Date: 2018-08-17 16:32:55 ...

  8. 触发器_触发器第三弹

    触发器第三弹 接上文继续探讨余下的主从触发器和边沿触发器,这里主要探讨他们波形图的画法以及需要注意的点. 1 主从触发器 前文我们介绍说同步JK触发器已经实现了全部的功能,并通过引入时钟信号CP解决了 ...

  9. as it exceeds the max of 500KB._我的英雄学院The “Ultra” Stage角色介绍第三弹!

    上周,小奈陆续为大家介绍了<我的英雄学院>The "Ultra" Stage 中10位角色,评论区里许多小伙伴纷纷给出"满分!"其实不止大家,原作者 ...

最新文章

  1. oracle跨库 导库,Oracle 用dblink 跨库导数据
  2. Mysql数据库表内外键关联的问题
  3. JS判断页面加载完毕
  4. UA MATH571B 试验设计III 单因素试验设计2
  5. 可以用JAVA编程的物联网开发板,了解一下?
  6. [UOJ #167]【UR #11】元旦老人与汉诺塔
  7. Ubuntu使用U盘把从互联网上下载的安装包及其依赖更新到内部机
  8. python findall_Python 正则表达式:findall
  9. EM算法的形式化推导
  10. SPD软件(医用耗材管理系统)应用效果分析
  11. pdf图片怎么转换成word文档?
  12. python是高级语言还是低级语言_python学习之高级语言和低级语言
  13. 什么是缓存雪崩、击穿、穿透?
  14. 超人气思维导图XMind新年新版本,这6个新功能你一定要看
  15. Bootstrap Method
  16. Python编程:itertools库排列组合
  17. WC2015 滚粗记
  18. 三角形已知三个点坐标,求外心坐标的公式
  19. 2021-10-22Pupu的问题记录|1
  20. HTTP 代理原理及实现(一)

热门文章

  1. AKABEiSOFT2经典作品推荐 車輪の国、向日葵の少女( 攻略、汉化、特典、PSP转换器)...
  2. 2021用友YonSuite与创新企业共舞
  3. java使用ftp上传文件
  4. 手机扫一扫ocr识别技术
  5. WPF中的渐变色动画
  6. vue的生命周期函数
  7. 三合一剪弦器怎么用_吉他换弦时多余的弦用什么工具剪掉?
  8. 说一下数据库有哪些索引类型,有什么优缺点?
  9. AI 算法是如何改变智能风控的 | 文末赠书
  10. Wrong namespace. Expected ‘com.baizhi.mapper.UserMapper‘ but found ‘com.com.baizhi.mapper.UserMappe