相空间重构python
- 格式:docx
- 大小:15.34 KB
- 文档页数:7
相空间重构matlab
相空间重构是一个非常重要的信号处理方法,在信号分析和数据挖掘中得到了广泛应用。
在Matlab中,相空间重构可以通过一些常见的函数和工具来实现。
相空间重构的第一步是准备数据,通常是一个时间序列。
可以使用Matlab中的load函数从文件中加载数据,也可以从Web服务或其他数据源中实时获取数据。
一旦获取了数据,就可以使用工具箱中的函数进行进一步的处理。
在进行相空间重构之前,需要先选择合适的参数,如嵌入维度、延迟时间等。
这些参数对相空间重构的效果和准确度影响很大,需要根据具体情况进行调整。
可以使用Matlab中的自动调参工具或手动调整来选择最佳参数。
一旦选择了合适的参数,就可以开始进行相空间重构。
可以使用Matlab中的takens函数进行初步的相空间重构,或编写自己的代码来实现更复杂的重构算法。
重构完成后,可以使用Matlab中的其他函数来进行信号分析和可视化。
总之,相空间重构是一个非常有用的信号处理工具,在Matlab 中可以轻松实现。
通过合适的参数选择和重构算法,可以从时间序列中获取更多有用的信息,并为进一步的分析和挖掘奠定基础。
python数字信号处理—采样与重构第⼀章步骤⼆:信号抽样和重构(tu1_3_sinsmpling.py)import numpy as npimport pylab as plimport scipy.signal as signalimport matplotlib.pyplot as pltfrom pylab import *mpl.rcParams['font.sans-serif'] = ['SimHei'] #图形中正确显⽰汉字import matplotlibmatplotlib.rcParams['axes.unicode_minus']=False #坐标轴正确显⽰负数# 产⽣50Hz的模拟信号# 较⾼的采样频率2000Hz模拟f0 = 50 # 50HzFs = 2000 # 模拟信号采样频率为2000Hzt = np.arange(-0.1, 0.1, 1/Fs) # 产⽣-0.1s-0.1s范围的信号xat = np.sin(2*np.pi*f0*t + np.pi/8) #产⽣f0=50Hz信号# 抽样频率200Hz产⽣信号# ⽅法⼀:⽤函数重新⽣成# ⽅法⼆:对步骤⼀模拟信号进⾏抽样fs = 200 # sampling rate 200HzTs = 1/fs # sampling peridon = np.arange(-0.1/Ts, 0.1/Ts) #对应的时间轴# xn = np.sin(2*np.pi*f0/fs*n + np.pi/8) #⽅法⼀tmpn = np.arange(-0.1*Fs, 0.1*Fs, Fs/fs) #⽅法⼆抽样tmpn = list(map(int, tmpn+200)) #矩阵下标平移xn = xat[tmpn] #抽取对应采样点的数据# 利⽤采样重构公式进⾏重构xat = []xatt = 0for ti in t:for nj in n:#xskt = np.cos(2*np.pi*f0/fs*nj + pi/8);xskt = xn[int(nj+20)] #下标移位if (ti == nj*Ts):piRt = 1 # 在采样点时,系数为1,以免造成分母为0的情况else: #构建插值函数piRt = (np.sin(np.pi / Ts * (ti - nj * Ts))) / (np.pi / Ts * (ti - nj * Ts))xatt = xatt + xskt * piRt #与插值函数相乘xat = np.append(xat, xatt) #序列追加xatt = 0pl.figure(1, figsize=(7,6))pl.subplot(3,1,1)pl.plot(t, xat)pl.title('continunous wave')#pl.xlabel('Time (s)')pl.xlim(-0.1,0.1)pl.ylim(-1,1)pl.grid(1)pl.subplot(3,1,2)pl.stem(n, xn)pl.title('Sample Wave')plt.subplots_adjust(top=1, wspace=0.2, hspace=0.5) # 调整视图pl.subplot(3,1,3)pl.plot(t, xat)pl.title('reconstructed signal')pl.xlabel('Time (s)')pl.xlim(-0.1,0.1)pl.ylim(-1,1)pl.grid(1)plt.subplots_adjust(top=1, wspace=0.2, hspace=0.4) # 调整视图plt.savefig('figure1_3.jpg', bbox_inches='tight', dpi=300, pad_inches=0.1) #保存⽂件,300dpi pl.show()图2 信号的采样与重构。
相空间重构互信息法1.引言1.1 概述概述相空间重构是一种重要的数据分析技术,通过将高维数据映射到低维子空间中,可以提取出数据中隐藏的关系和结构。
互信息法则是相空间重构中常用的方法之一,它利用互信息的度量来判断数据之间的依赖关系,从而帮助我们在进行相空间重构时选择合适的参数。
本文将重点介绍相空间重构和互信息法的原理以及它们在实际应用中的意义。
我们将首先介绍相空间重构的基本概念和意义,包括什么是相空间重构以及它的应用领域。
然后,我们将详细解释互信息法的原理,包括互信息的计算方法和其在数据分析中的作用。
在正文部分,我们将进一步探讨相空间重构的具体方法和技巧,包括如何选择适当的相空间重构算法和参数。
同时,我们将介绍互信息法在相空间重构中的应用,并举例说明其在实际问题中的效果和意义。
最后,在结论部分,我们将总结相空间重构的重要性和互信息法在相空间重构中的应用价值。
我们希望通过本文的阐述可以使读者对相空间重构和互信息法有更深入的理解,并能将其应用于自己的研究或实际工作中。
文章结构部分的内容应包括文章的组织结构和各个部分的内容概述,以帮助读者了解文章的整体框架和各部分的关系。
在这篇文章中,我们将按照以下结构来呈现内容:1. 引言1.1 概述1.2 文章结构1.3 目的2. 正文2.1 相空间重构2.1.1 什么是相空间重构2.1.2 相空间重构的应用2.2 互信息法2.2.1 互信息法的原理2.2.2 互信息法在相空间重构中的应用3. 结论3.1 总结相空间重构的重要性3.2 总结互信息法在相空间重构中的应用引言部分将对文章的主题进行概述,并介绍文章的结构和目的。
正文将重点讨论相空间重构和互信息法这两个主要内容。
在相空间重构部分,我们将首先介绍相空间重构的基本概念和原理,然后探讨其在实际应用中的具体作用。
在互信息法部分,我们将详细解释互信息法的原理,并说明其在相空间重构中的应用方法。
最后,结论部分将对相空间重构的重要性和互信息法的应用进行总结和归纳。
相空间重构matlab代码相空间重构是一种用于非线性动力系统分析的方法,它可以将高维数据重构成低维空间中的轨迹,从而更好地理解和描述系统的行为特征。
在这里,我们提供一个相空间重构的Matlab代码,帮助大家进行数据分析和可视化。
首先,我们需要导入数据。
可以使用Matlab中的load命令将数据从文件中读取到Matlab中。
这里以一个二维数据为例:load data.txtx = data(:,1);y = data(:,2);接下来,我们需要确定嵌入维数和延迟时间。
嵌入维数表示我们将数据嵌入到低维空间的维数,延迟时间表示我们将数据点在时间上延迟的步数。
我们可以使用Matlab中的corr命令计算数据的自相关函数,来确定延迟时间。
具体代码如下:[R,lags] = xcorr(x,'coeff');plot(lags,R)xlabel('lags')ylabel('correlation')然后,我们可以通过视觉判断自相关函数中的首个过零点来确定延迟时间。
在这个例子中,延迟时间为3个时间步长。
接下来,我们可以使用Matlab中的embeddelay函数来进行相空间重构。
具体代码如下:m = 2; %嵌入维数tau = 3; %延迟时间X = embeddelay([x,y],m,tau);现在,我们可以使用Matlab中的plot3函数来可视化重构后的数据。
具体代码如下:figureplot3(X(:,1),X(:,2),X(:,3))xlabel('X_1')ylabel('X_2')zlabel('X_3')我们可以通过改变嵌入维数m的值来观察不同维数下的重构效果。
最后,我们可以使用Matlab中的phaseplane函数来绘制相空间轨迹图。
具体代码如下:figurephaseplane(X(:,1),X(:,2))在这个例子中,我们使用了二维数据进行相空间重构,并绘制了相空间轨迹图。
相空间重构方法相空间重构是物理学和工程学中一个重要的概念,尤其在非线性动力学和时间序列分析中具有广泛应用。
本文将详细介绍相空间重构的方法及其在数据分析中的应用。
在研究复杂系统的动力学行为时,相空间重构提供了一种将时间序列数据转换到高维状态空间的方法。
通过这种方法,我们可以更深入地理解系统的演化轨迹和内在结构。
以下是相空间重构的主要方法及其原理。
### 相空间重构的原理相空间重构的基础是假设系统的动力学行为可以由一组变量的演化轨迹来描述。
这些变量可以是原始系统的状态变量,也可以是通过某种方式构造的代理变量。
在重构过程中,我们试图通过时间序列数据恢复出这些状态变量在相空间中的轨迹。
### 相空间重构的主要方法#### 延迟坐标法(Time Delay Embedding)延迟坐标法是最常用的相空间重构方法。
它基于时间序列的自身历史信息来构造相空间的坐标。
具体步骤如下:1.选择适当的时间延迟(τ),这是重构过程中的关键参数。
2.选择嵌入维数(m),它决定了相空间的维度。
3.利用时间序列数据{x(t)},构造相空间中的点:X(t) = [x(t), x(t+τ),x(t+2τ), ..., x(t+(m-1)τ)]。
#### 窗口法(Phase Space Windowing)窗口法通过在不同时间尺度上观察时间序列,以确定合适的延迟时间和嵌入维数。
这种方法适用于确定时间序列的局部预测误差,以此来确定最优的相空间重构参数。
#### 线性预测法(Linear Predictive Method)线性预测法通过最小化时间序列的线性预测误差来确定延迟时间和嵌入维数。
这种方法对噪声较为敏感,但在处理实际数据时仍有一定的应用价值。
### 应用相空间重构方法在许多领域都有广泛应用,例如:- 预测复杂系统的未来行为。
- 识别混沌吸引子及其性质。
- 分析时间序列的混沌特性,如李雅普诺夫指数和分岔。
- 生物医学信号处理,如心率变异性和脑电图分析。
python fbp重建算法摘要:1.引言2.Python FBP重建算法简介3.FBP算法原理4.Python实现FBP算法5.应用案例6.总结正文:1.引言在医学图像处理领域,计算机断层扫描(CT)是一种常用的成像技术。
通过CT扫描得到的原始数据,需要经过一系列的图像重建算法处理,才能得到高质量的医学图像。
FBP(Filtered Backprojection)算法是CT图像重建中最常用的算法之一。
本文将介绍如何使用Python实现FBP重建算法。
2.Python FBP重建算法简介Python是一种广泛应用于科学计算和数据分析的编程语言。
利用Python 丰富的库和易于学习的特点,可以方便地实现FBP重建算法。
本文将使用Python的NumPy和SciPy库来实现FBP算法。
3.FBP算法原理FBP算法是基于CT扫描数据的线性变换和滤波过程。
首先,将原始的CT 数据进行线性变换,得到投影数据。
然后,对投影数据进行滤波,去除噪声和干扰。
最后,利用逆变换将滤波后的投影数据恢复为重建图像。
4.Python实现FBP算法以下是使用Python实现FBP算法的示例代码:```pythonimport numpy as npfrom scipy.special import gammadef fbp_reconstruction(data, angles, distance, filter_width=3): """FBP重建算法实现:param data: CT数据,形状为(num_rows, num_cols, num_angles):param angles: 扫描角度,形状为(num_angles,):param distance: 探测器到物体的距离,形状为(num_rows,num_cols):param filter_width: 滤波器宽度,默认值为3:return: 重建图像,形状为(num_rows, num_cols)"""# 计算滤波器filter_data = np.zeros((data.shape[0], data.shape[1],filter_width))for i in range(filter_width):angle = angles[i]filter_data[:, :, i] = gamma(0.5 * (filter_width - i)) * (distance** (filter_width - i))# 计算逆滤波器inverse_filter_data = np.zeros((data.shape[0], data.shape[1], filter_width))for i in range(filter_width):angle = angles[i]inverse_filter_data[:, :, i] = gamma(0.5 * i) * (distance ** i) # FBP重建num_angles = data.shape[2]reconstruction = np.zeros((data.shape[0], data.shape[1]))for i in range(num_angles):projection = data[:, :, i]filtered_projection = np.convolve(projection, filter_data[:, :, i], mode="valid")inverse_filtered_projection =np.convolve(filtered_projection, inverse_filter_data[:, :, i], mode="valid") reconstruction += inverse_filtered_projectionreturn reconstruction```5.应用案例以下是一个使用上述FBP重建算法实现的Python脚本示例:```python# 加载CT数据ct_data = np.load("ct_data.npy")# 设置参数angles = np.load("angles.npy")distance = 1000 # 物体到探测器的距离,单位为毫米filter_width = 3# 重建图像reconstruction = fbp_reconstruction(ct_data, angles, distance, filter_width)# 显示图像import matplotlib.pyplot as pltplt.imshow(reconstruction, cmap="gray")plt.show()```6.总结本文介绍了如何使用Python实现FBP重建算法。
相空间重构预测混沌序列你有没有想过,生活中那些看似乱七八糟、毫无规律的事情,背后其实都藏着某种规律呢?比如股票市场的波动,天气的变化,甚至我们大脑里的思绪奔腾,都是那种你抓不住又不明不白的“混沌”。
嗯,这就是我们说的混沌现象。
要是你稍微有点数学基础,可能听说过“相空间重构”这个词。
哎,别紧张,不是啥天书,只不过是用一个简单的办法,把这些看似乱成一团的事物,拉出来给你一个“长眼睛”的机会,好让你看清楚其中的奥秘。
想象一下,如果你在海边散步,看到浪花一阵阵拍打岸边,波动不定,时而温柔,时而汹涌,甚至你都开始怀疑,海到底在想什么。
你要是把这场景记录下来,就能得到一系列数字,也就是“时间序列”。
听起来很枯燥?别着急,接下来你就知道,这些数字不是什么没用的玩意儿,而是能给你揭开一段混沌故事的钥匙。
你想过没有,咱们生活中的那些“无序”背后,可能就是深藏着某种“规律”呢!只不过,我们看不清楚,抓不住。
这时候,你就需要用到一个绝妙的“魔法”:相空间重构。
哎,听起来是不是很神秘?其实这就是一种将复杂的时间序列通过某种方式“变形”,让它变得容易看懂的技术。
比如说,你看海浪拍打的节奏,总觉得不那么规律,心里嘀咕:它不是有规律的吗?那就试着把这些“浪花”拉出来,放到一个多维空间里。
别被“多维空间”吓着,其实就相当于你用一张二维的画纸,突然画上几条三维的线条,弄得这张纸的“维度”一下子就多了。
通过这种方式,你就能看到那些隐藏在混沌背后的小秘密。
说得更具体一点,相空间重构的一个关键就是选定一个合适的延迟时间。
想象你在大海边看浪花,不可能一次看清楚所有的波动,你得给自己一些时间,等下一波浪花过来,这才有可能看清楚全貌。
这就是延迟时间的作用:给你时间去捕捉波动,才能让你更好地理解整个海洋的节奏。
然后你再做个“维度扩展”,把这些波动在更高维度里“摆放”一下,这样就能让混沌的景象变得不那么让你摸不着头脑了。
相空间重构的好处就是让我们能用数学的工具,去预测未来的波动。
python 重构多重if else的方法Python重构多重if else语句的方法在编写Python程序的过程中,我们经常会遇到需要对不同的条件进行判断并执行相应的代码块。
最常见的实现方式是使用if else语句来实现条件逻辑的控制。
然而,当条件逻辑比较复杂时,使用多层嵌套的if else语句会使代码变得难以理解和维护。
为了改善这种情况,我们可以采用重构的方法来简化多重if else语句。
本文将介绍几种常见的重构方法,并示范其实际应用。
1. 提取函数当一个条件逻辑比较复杂时,我们可以考虑将其提取成一个独立的函数。
这样可以使代码更加模块化,同时可以减少主代码的复杂性。
例如,假设我们要根据不同的成绩等级返回相应的评价信息,可以将评价信息的判断逻辑提取成一个函数,如下所示:pythondef get_evaluation(score):if score >= 90:return '优秀'elif score >= 80:return '良好'elif score >= 60:return '及格'else:return '不及格'使用提取函数的方式,我们将复杂的判断逻辑封装在一个函数中,然后在主代码中通过调用该函数来获取评价信息。
这样不仅使代码更加清晰简洁,还方便了其他部分的复用。
2. 使用字典映射在某些情况下,我们可以使用字典映射来替代多重if else语句。
字典映射是一种将一个数据对应到另一个数据的方式,可以用来简化判断逻辑。
例如,假设我们需要根据用户的角色来判断其对应的权限等级,可以使用字典映射来实现:pythondef get_permission_level(role):permission_mapping = {'admin': '最高权限','manager': '中等权限','user': '最低权限'}return permission_mapping.get(role, '未知权限')在上述代码中,我们使用字典映射来将不同的角色映射到相应的权限等级。
from operator import subimport numpy as npfrom sklearn import metricsfrom sklearn.neighbors import NearestNeighborsfrom toolz import currydef global_false_nearest_neighbors(x, lag, min_dims=1, max_dims=10, **cutoffs):"""Across a range of embedding dimensions $d$, embeds $x(t)$ with lag $\tau$, finds all nearest neighbors,and computes the percentage of neighbors that that remain neighbors when an additional dimension is unfolded.See [1] for more information.Parameters----------x : array-likeOriginal signal $x(t).lag : intTime lag $\tau$ in units of the sampling time $h$ of $x(t)$.min_dims : int, optionalThe smallest embedding dimension $d$ to test.max_dims : int, optionalThe largest embedding dimension $d$ to test.relative_distance_cutoff : float, optionalThe cutoff for determining neighborliness,in distance increase relative to the original distance between neighboring points.The default, 15, is suggested in [1] (p. 41).relative_radius_cutoff : float, optionalThe cutoff for determining neighborliness,in distance increase relative to the radius of the attractor.The default, 2, is suggested in [1] (p. 42).Returns-------dims : ndarrayThe tested dimensions $d$.gfnn : ndarrayThe percentage of nearest neighbors that are false neighbors at each dimension.See Also--------reconstructReferences----------[1] Arbanel, H. D. (1996). *Analysis of Observed Chaotic Data* (pp. 40-43). New York: Springer."""x = _vector(x)dimensions = np.arange(min_dims, max_dims + 1)false_neighbor_pcts = np.array([_gfnn(x, lag, n_dims, **cutoffs) for n_dims in dimensions]) return dimensions, false_neighbor_pctsdef _gfnn(x, lag, n_dims, **cutoffs):# Global false nearest neighbors at a particular dimension.# Returns percent of all nearest neighbors that are still neighbors when the next dimension is unfolded.# Neighbors that can't be embedded due to lack of data are not counted in the denominator.offset = lag*n_dimsis_true_neighbor = _is_true_neighbor(x, _radius(x), offset)return np.mean([not is_true_neighbor(indices, distance, **cutoffs)for indices, distance in _nearest_neighbors(reconstruct(x, lag, n_dims))if (indices + offset < x.size).all()])def _radius(x):# Per Arbanel (p. 42):# "the nominal 'radius' of the attractor defined as the RMS value of the data about its mean."return np.sqrt(((x - x.mean())**2).mean())@currydef _is_true_neighbor(x, attractor_radius, offset, indices, distance,relative_distance_cutoff=15,relative_radius_cutoff=2):distance_increase = np.abs(sub(*x[indices + offset]))return (distance_increase / distance < relative_distance_cutoff anddistance_increase / attractor_radius < relative_radius_cutoff)def _nearest_neighbors(y):"""Wrapper for sklearn.neighbors.NearestNeighbors.Yields the indices of the neighboring points, and the distance between them."""distances, indices = NearestNeighbors(n_neighbors=2, algorithm='kd_tree').fit(y).kneighbors(y)for distance, index in zip(distances, indices):yield index, distance[1]def reconstruct(x, lag, n_dims):"""Phase-space reconstruction.Given a signal $x(t)$, dimensionality $d$, and lag $\tau$, return the reconstructed signal \[\mathbf{y}(t) = [x(t), x(t + \tau), \ldots, x(t + (d - 1)\tau)].\]Parameters----------x : array-likeOriginal signal $x(t)$.lag : intTime lag $\tau$ in units of the sampling time $h$ of $x(t)$.n_dims : intEmbedding dimension $d$.Returns-------ndarray$\mathbf{y}(t)$ as an array with $d$ columns."""x = _vector(x)if lag * (n_dims - 1) >= x.shape[0] // 2:raise ValueError('longest lag cannot be longer than half the length of x(t)')lags = lag * np.arange(n_dims)return np.vstack(x[lag:lag - lags[-1] or None] for lag in lags).transpose()def ami(x, y=None, n_bins=10):"""Calculate the average mutual information between $x(t)$ and $y(t)$.Parameters----------x : array-likey : array-like, optional$x(t)$ and $y(t)$.If only `x` is passed, it must have two columns;the first column defines $x(t)$ and the second $y(t)$.n_bins : intThe number of bins to use when computing the joint histogram.Returns-------scalarAverage mutual information between $x(t)$ and $y(t)$, in nats (natural log equivalent of bits).See Also--------lagged_amiReferences----------Arbanel, H. D. (1996). *Analysis of Observed Chaotic Data* (p. 28). New York: Springer. """x, y = _vector_pair(x, y)if x.shape[0] != y.shape[0]:raise ValueError('timeseries must have the same length')return metrics.mutual_info_score(None, None, contingency=np.histogram2d(x, y, bins=n_bins)[0])def lagged_ami(x, min_lag=0, max_lag=None, lag_step=1, n_bins=10):"""Calculate the average mutual information between $x(t)$ and $x(t + \tau)$, at multiple values of $\tau$.Parameters----------x : array-like$x(t)$.min_lag : int, optionalThe shortest lag to evaluate, in units of the sampling period $h$ of $x(t)$.max_lag : int, optionalThe longest lag to evaluate, in units of $h$.lag_step : int, optionalThe step between lags to evaluate, in units of $h$.n_bins : intThe number of bins to use when computing the joint histogram in order to calculate mutual information.See |ami|.Returns-------lags : ndarrayThe evaluated lags $\tau_i$, in units of $h$.amis : ndarrayThe average mutual information between $x(t)$ and $x(t + \tau_i)$.See Also--------ami"""if max_lag is None:max_lag = x.shape[0]//2lags = np.arange(min_lag, max_lag, lag_step)amis = [ami(reconstruct(x, lag, 2), n_bins=n_bins) for lag in lags]return lags, np.array(amis)def _vector_pair(a, b):a = np.squeeze(a)if b is None:if a.ndim != 2 or a.shape[1] != 2:raise ValueError('with one input, array must have be 2D with two columns') a, b = a[:, 0], a[:, 1]return a, np.squeeze(b)def _vector(x):x = np.squeeze(x)if x.ndim != 1:raise ValueError('x(t) must be a 1-dimensional signal')return xTEXTimport numpy as npimport pytestimport pypsrdef test_ami():a = np.arange(100)assert np.isclose(np.exp(pypsr.ami(a, a)), 10)assert np.isclose(pypsr.ami(a, np.ones_like(a)), 0)def test_ami_two_column_input():a = np.arange(100)assert np.isclose(np.exp(pypsr.ami(np.vstack((a, a)).transpose())), 10)def test_ami_different_length_signals():a = np.arange(10)with pytest.raises(ValueError):pypsr.ami(a, a[:-1])def test_ami_only_one_signal():with pytest.raises(ValueError):pypsr.ami(np.arange(10))def test_lagged_ami():lags, ami = gged_ami(np.arange(10), min_lag=0, max_lag=5)assert lags.dtype == 'int64'assert ami.dtype == 'float64'assert np.all(lags == np.arange(5))assert np.all(np.isclose(np.exp(ami), np.arange(10, 5, -1)))def test_ami_unsqueezed_vector():a = np.arange(10)[:, np.newaxis]assert np.isclose(np.exp(pypsr.ami(a, a)), 10)assert np.isclose(pypsr.ami(a, np.ones_like(a)), 0)def test_lagged_ami_unsqueezed_vector():a = np.arange(10)[:, np.newaxis]lags, ami = gged_ami(a)assert np.all(lags == np.arange(5))assert np.all(np.isclose(np.exp(ami), np.arange(10, 5, -1)))def test_reconstruction():assert np.all(pypsr.reconstruct(np.arange(10), 1, 2) == np.vstack((np.arange(9), np.arange(1, 10))).transpose())assert np.all(pypsr.reconstruct(np.arange(10), 2, 3)== np.vstack((np.arange(6), np.arange(2, 8), np.arange(4, 10))).transpose())def test_reconstruction_wrong_dimension_input():with pytest.raises(ValueError):pypsr.reconstruct(np.ones((10, 10)), 1, 2)def test_reconstruction_too_long_lag():with pytest.raises(ValueError):pypsr.reconstruct(np.ones(10), 5, 2)with pytest.raises(ValueError):pypsr.reconstruct(np.ones(10), 2, 5)def test_gfnn():test_data = np.loadtxt('gfnn_test_data.csv', delimiter=',')known_gfnn = np.loadtxt('test_data_lag_30_gfnn.csv', delimiter=',')lags, gfnn = pypsr.global_false_nearest_neighbors(test_data, 30, max_dims=known_gfnn.size)assert (lags == np.arange(1, known_gfnn.size + 1)).all()assert np.isclose(gfnn, known_gfnn).all()def test_gfnn_wrong_dimension_input():with pytest.raises(ValueError):pypsr.global_false_nearest_neighbors(np.ones((10, 10)), 30)。