AVt天堂网 手机版,亚洲va久久久噜噜噜久久4399,天天综合亚洲色在线精品,亚洲一级Av无码毛片久久精品

當前位置:首頁 > 科技  > 軟件

使用遞歸圖 recurrence plot 表征時間序列

來源: 責編: 時間:2023-11-10 17:07:16 295觀看
導讀在本文中,我將展示如何使用遞歸圖 Recurrence Plots 來描述不同類型的時間序列。我們將查看具有500個數據點的各種模擬時間序列。我們可以通過可視化時間序列的遞歸圖并將其與其他已知的不同時間序列的遞歸圖進行比較,

在本文中,我將展示如何使用遞歸圖 Recurrence Plots 來描述不同類型的時間序列。我們將查看具有500個數據點的各種模擬時間序列。我們可以通過可視化時間序列的遞歸圖并將其與其他已知的不同時間序列的遞歸圖進行比較,從而直觀地表征時間序列。N3Z28資訊網——每日最新資訊28at.com

N3Z28資訊網——每日最新資訊28at.com

遞歸圖

Recurrence  Plots(RP)是一種用于可視化和分析時間序列或動態系統的方法。它將時間序列轉化為圖形化的表示形式,以便分析時間序列中的重復模式和結構。Recurrence Plots 是非常有用的,尤其是在時間序列數據中存在周期性、重復事件或關聯結構時。N3Z28資訊網——每日最新資訊28at.com

Recurrence Plots 的基本原理是測量時間序列中各點之間的相似性。如果兩個時間點之間的距離小于某個給定的閾值,就會在 Recurrence Plot 中繪制一個點,表示這兩個時間點之間存在重復性。這些點在二維平面上組成了一種圖像。N3Z28資訊網——每日最新資訊28at.com

import numpy as np import matplotlib.pyplot as plt  def recurrence_plot(data, threshold=0.1):    """    Generate a recurrence plot from a time series.     :param data: Time series data    :param threshold: Threshold to determine recurrence    :return: Recurrence plot    """    # Calculate the distance matrix    N = len(data)    distance_matrix = np.zeros((N, N))    for i in range(N):        for j in range(N):            distance_matrix[i, j] = np.abs(data[i] - data[j])     # Create the recurrence plot    recurrence_plot = np.where(distance_matrix <= threshold, 1, 0)     return recurrence_plot

上面的代碼創建了一個二進制距離矩陣,如果時間序列i和j的值相差在0.1以內(閾值),則它們的值為1,否則為0。得到的矩陣可以看作是一幅圖像。N3Z28資訊網——每日最新資訊28at.com

白噪聲

接下來我們將可視化白噪聲。首先,我們需要創建一系列模擬的白噪聲:N3Z28資訊網——每日最新資訊28at.com

# Set a seed for reproducibility np.random.seed(0)  # Generate 500 data points of white noise white_noise = np.random.normal(size=500)  # Plot the white noise time series plt.figure(figsize=(10, 6)) plt.plot(white_noise, label='White Noise') plt.title('White Noise Time Series') plt.xlabel('Time') plt.ylabel('Value') plt.legend() plt.grid(True) plt.show()

圖片N3Z28資訊網——每日最新資訊28at.com

遞歸圖為這種白噪聲提供了有趣的可視化效果。對于任何一種白噪聲,圖看起來都是一樣的:N3Z28資訊網——每日最新資訊28at.com

# Generate and plot the recurrence plot recurrence = recurrence_plot(white_noise, threshold=0.1)  plt.figure(figsize=(8, 8)) plt.imshow(recurrence, cmap='binary', origin='lower') plt.title('Recurrence Plot') plt.xlabel('Time') plt.ylabel('Time') plt.colorbar(label='Recurrence') plt.show()

N3Z28資訊網——每日最新資訊28at.com

可以直觀地看到一個嘈雜的過程。可以看到圖中對角線總是黑色的。N3Z28資訊網——每日最新資訊28at.com

隨機游走

接下來讓我們看看隨機游走(Random Walk)是什么樣子的:N3Z28資訊網——每日最新資訊28at.com

# Generate 500 data points of a random walk steps = np.random.choice([-1, 1], size=500) # Generate random steps: -1 or 1 random_walk = np.cumsum(steps) # Cumulative sum to generate the random walk  # Plot the random walk time series plt.figure(figsize=(10, 6)) plt.plot(random_walk, label='Random Walk') plt.title('Random Walk Time Series') plt.xlabel('Time') plt.ylabel('Value') plt.legend() plt.grid(True) plt.show()

N3Z28資訊網——每日最新資訊28at.com

# Generate and plot the recurrence plot recurrence = recurrence_plot(random_walk, threshold=0.1)  plt.figure(figsize=(8, 8)) plt.imshow(recurrence, cmap='binary', origin='lower') plt.title('Recurrence Plot') plt.xlabel('Time') plt.ylabel('Time') plt.colorbar(label='Recurrence') plt.show()

N3Z28資訊網——每日最新資訊28at.com

SARIMA

SARIMA(4,1,4)(1,0,0,12)的模擬數據N3Z28資訊網——每日最新資訊28at.com

from statsmodels.tsa.statespace.sarimax import SARIMAX  # Define SARIMA parameters p, d, q = 4, 1, 4 # Non-seasonal order P, D, Q, s = 1, 0, 0, 12 # Seasonal order  # Simulate data model = SARIMAX(np.random.randn(100), order=(p, d, q), seasonal_order=(P, D, Q, s), trend='ct') fit = model.fit(disp=False) # Fit the model to random data to get parameters simulated_data = fit.simulate(nsimulatinotallow=500)  # Plot the simulated time series plt.figure(figsize=(10, 6)) plt.plot(simulated_data, label=f'SARIMA({p},asoweqmqs,{q})({P},{D},{Q},{s})') plt.title('Simulated Time Series from SARIMA Model') plt.xlabel('Time') plt.ylabel('Value') plt.legend() plt.grid(True) plt.show()

N3Z28資訊網——每日最新資訊28at.com

recurrence = recurrence_plot(simulated_data, threshold=0.1)  plt.figure(figsize=(8, 8)) plt.imshow(recurrence, cmap='binary', origin='lower') plt.title('Recurrence Plot') plt.xlabel('Time') plt.ylabel('Time') plt.colorbar(label='Recurrence') plt.show()

N3Z28資訊網——每日最新資訊28at.com

混沌的數據

def logistic_map(x, r):    """Logistic map function."""    return r * x * (1 - x)  # Initialize parameters N = 500         # Number of data points r = 3.9         # Parameter r, set to a value that causes chaotic behavior x0 = np.random.rand() # Initial value  # Generate chaotic time series data chaotic_data = [x0] for _ in range(1, N):    x_next = logistic_map(chaotic_data[-1], r)    chaotic_data.append(x_next)  # Plot the chaotic time series plt.figure(figsize=(10, 6)) plt.plot(chaotic_data, label=f'Logistic Map (r={r})') plt.title('Chaotic Time Series') plt.xlabel('Time') plt.ylabel('Value') plt.legend() plt.grid(True) plt.show()

N3Z28資訊網——每日最新資訊28at.com

recurrence = recurrence_plot(chaotic_data, threshold=0.1)  plt.figure(figsize=(8, 8)) plt.imshow(recurrence, cmap='binary', origin='lower') plt.title('Recurrence Plot') plt.xlabel('Time') plt.ylabel('Time') plt.colorbar(label='Recurrence') plt.show()

N3Z28資訊網——每日最新資訊28at.com

標準普爾500指數

作為最后一個例子,讓我們看看從2013年10月28日至2023年10月27日的標準普爾500指數真實數據:N3Z28資訊網——每日最新資訊28at.com

import pandas as pd  df = pd.read_csv('standard_and_poors_500_idx.csv', parse_dates=True) df['Date'] = pd.to_datetime(df['Date']) df.set_index('Date', inplace = True) df.drop(columns = ['Open', 'High', 'Low'], inplace = True)  df.plot() plt.title('S&P 500 Index - 10/28/2013 to 10/27/2023') plt.ylabel('S&P 500 Index') plt.xlabel('Date');

N3Z28資訊網——每日最新資訊28at.com

recurrence = recurrence_plot(df['Close/Last'], threshold=10)  plt.figure(figsize=(8, 8)) plt.imshow(recurrence, cmap='binary', origin='lower') plt.title('Recurrence Plot') plt.xlabel('Time') plt.ylabel('Time') plt.colorbar(label='Recurrence') plt.show()

N3Z28資訊網——每日最新資訊28at.com

選擇合適的相似性閾值是 遞歸圖分析的一個關鍵步驟。較小的閾值會導致更多的重復模式,而較大的閾值會導致更少的重復模式。閾值的選擇通常需要根據數據的特性和分析目標進行調整。N3Z28資訊網——每日最新資訊28at.com

這里我們不得不調整閾值,最終確得到的結果為10,這樣可以獲得更大的對比度。上面的遞歸圖看起來很像隨機游走遞歸圖和無規則的混沌數據的混合體。N3Z28資訊網——每日最新資訊28at.com

總結

在本文中,我們介紹了遞歸圖以及如何使用Python創建遞歸圖。遞歸圖給了我們一種直觀表征時間序列圖的方法。遞歸圖是一種強大的工具,用于揭示時間序列中的結構和模式,特別適用于那些具有周期性、重復性或復雜結構的數據。通過可視化和特征提取,研究人員可以更好地理解時間序列數據并進行進一步的分析。N3Z28資訊網——每日最新資訊28at.com

從遞歸圖中可以提取各種特征,以用于進一步的分析。這些特征可以包括重復點的分布、Lempel-Ziv復雜度、最長對角線長度等。N3Z28資訊網——每日最新資訊28at.com

遞歸圖在多個領域中得到了廣泛應用,包括時間序列分析、振動分析、地震學、生態學、金融分析、生物醫學等。它可用于檢測周期性、異常事件、相位同步等。N3Z28資訊網——每日最新資訊28at.com

本文鏈接:http://www.tebozhan.com/showinfo-26-19948-0.html使用遞歸圖 recurrence plot 表征時間序列

聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。郵件:2376512515@qq.com

上一篇: 系統架構七個非功能性需求

下一篇: 線性回歸,核技巧和線性核

標簽:
  • 熱門焦點
  • 6月安卓手機好評榜:魅族20 Pro蟬聯冠軍

    性能榜和性價比榜之后,我們來看最后的安卓手機好評榜,數據來源安兔兔評測,收集時間2023年6月1日至6月30日,僅限國內市場。第一名:魅族20 Pro好評率:95%5月份的時候魅族20 Pro就是
  • 摸魚心法第一章——和配置文件說拜拜

    為了能摸魚我們團隊做了容器化,但是帶來的問題是服務配置文件很麻煩,然后大家在群里進行了“親切友好”的溝通圖片圖片圖片圖片對比就對比,簡單對比下獨立配置中心和k8s作為配
  • 三分鐘白話RocketMQ系列—— 如何發送消息

    我們知道RocketMQ主要分為消息 生產、存儲(消息堆積)、消費 三大塊領域。那接下來,我們白話一下,RocketMQ是如何發送消息的,揭秘消息生產全過程。注意,如果白話中不小心提到相關代
  • 從零到英雄:高并發與性能優化的神奇之旅

    作者 | 波哥審校 | 重樓作為公司的架構師或者程序員,你是否曾經為公司的系統在面對高并發和性能瓶頸時感到手足無措或者焦頭爛額呢?筆者在出道那會為此是吃盡了苦頭的,不過也得
  • 一文搞定Java NIO,以及各種奇葩流

    大家好,我是哪吒。很多朋友問我,如何才能學好IO流,對各種流的概念,云里霧里的,不求甚解。用到的時候,現百度,功能雖然實現了,但是為什么用這個?不知道。更別說效率問題了~下次再遇到,
  • 破圈是B站頭上的緊箍咒

    來源 | 光子星球撰文 | 吳坤諺編輯 | 吳先之每年的暑期檔都少不了瞄準追劇女孩們的古偶劇集,2021年有優酷的《山河令》,2022年有愛奇藝的《蒼蘭訣》,今年卻輪到小破站抓住了追
  • 回歸OPPO兩年,一加贏了銷量,輸了品牌

    成為OPPO旗下主打性能的先鋒品牌后,一加屢創佳績。今年618期間,一加手機全渠道銷量同比增長362%,憑借一加 11、一加 Ace 2、一加 Ace 2V三款爆品,一加
  • 上海舉辦人工智能大會活動,建設人工智能新高地

    人工智能大會在上海浦江兩岸隆重拉開帷幕,人工智能新技術、新產品、新應用、新理念集中亮相。8月30日晚,作為大會的特色活動之一的上海人工智能發展盛典人工
  • “買真退假” 這種“羊毛”不能薅

    □ 法治日報 記者 王春   □ 本報通訊員 胡佳麗  2020年初,還在上大學的小東加入了一個大學生兼職QQ群。群主&ldquo;七王&rdquo;在群里介紹一些刷單賺
Top