You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

已知周期的时间序列:如何定位周期性起始位置与周期序列

Solutions for Hidden Periodic Time Series (Known Cycle Length)

Alright, let's tackle your two core problems head-on—since you already know the exact cycle length (like 60 or 100 minutes), we can skip the cycle detection step and dive straight into pinpointing starts and mid-cycle periodic segments.

1. Determining the Periodicity Start Position

Here are three practical, actionable methods:

  • Sliding Window Cycle Similarity Matching
    The idea is to test every possible starting offset (from 0 to cycle_length-1) and pick the one where consecutive cycles have the highest similarity. For each offset:

    1. Extract all points that fall into the same "position" within the cycle (e.g., for cycle length 60, offset 5 would take points at indices 5, 65, 125, ...)
    2. Calculate the correlation (Pearson, Spearman) or mean squared error (MSE) between consecutive cycles in this subset
    3. The offset with the highest correlation (or lowest MSE) is your optimal start position. This works because a true periodic start will align all repeating patterns perfectly.
  • Autocorrelation Phase Calibration

    1. Compute the autocorrelation function (ACF) of your time series. You'll see a strong peak at lag = cycle_length (since you already confirmed the cycle exists)
    2. Iterate over possible start offsets, shift the series by each offset, and recalculate the ACF peak at lag cycle_length
    3. The offset that maximizes this ACF peak is the correct start—this aligns the periodic components so their autocorrelation is maximized.
  • FFT Phase Extraction

    1. Convert the time series to the frequency domain using Fast Fourier Transform (FFT)
    2. Isolate the frequency component corresponding to your known cycle length (frequency = 1/cycle_length)
    3. Extract the phase angle of this component, then convert it back to the time domain to find the exact starting point where the periodic pattern begins.

Quick Code Example (Sliding Window Method)

import numpy as np
from scipy.stats import pearsonr

def find_optimal_cycle_start(time_series, cycle_length):
    max_correlation = -1.0
    best_start_idx = 0
    
    # Only check offsets 0 to cycle_length-1 (beyond that repeats the same pattern)
    for start in range(cycle_length):
        # Extract all points at this cycle position
        cycle_segment = time_series[start::cycle_length]
        # Need at least 2 full cycles to compare
        if len(cycle_segment) < 2:
            continue
        # Correlate consecutive cycles
        corr, _ = pearsonr(cycle_segment[:-1], cycle_segment[1:])
        if corr > max_correlation:
            max_correlation = corr
            best_start_idx = start
    return best_start_idx

2. Locating Periodic Segments That Start Mid-Series

If the periodicity kicks in halfway through your data, these methods will help you spot the transition:

  • Segmented Cycle Consistency Check

    1. Split the entire series into non-overlapping chunks of length cycle_length
    2. For each consecutive pair of chunks, calculate their similarity (correlation, MSE)
    3. Set a similarity threshold (e.g., Pearson correlation > 0.8) and look for a run of 3-5 consecutive chunk pairs that meet this threshold. The start of the first chunk in this run is where the periodicity begins.
  • Rolling Window Period Validation

    1. Use a rolling window of size k * cycle_length (where k ≥ 2, e.g., 2*60=120 minutes)
    2. For each window, split it into k equal sub-windows (each of length cycle_length) and compute the average similarity between all sub-window pairs
    3. When this average similarity jumps above your threshold and stays there, the start of the window marks the beginning of the periodic segment.
  • Residual Variance Drop Detection

    1. First, fit a simple periodic model using the known cycle length (e.g., take the mean of each cycle position once you have a candidate segment)
    2. Calculate the residual (actual value - model prediction) for every point in the series
    3. Track the rolling variance of these residuals. A sharp, sustained drop in variance indicates the point where the data starts following the periodic pattern consistently.

Key Notes for Success

  • De-trend First: If your time series has an underlying trend (linear, exponential), remove it first (via differencing or fitting a trend line and subtracting it) — trends can skew similarity and correlation calculations.
  • Adjust Thresholds: Tune similarity thresholds based on your data's noise level. Noisy data will need lower thresholds, while clean data can use stricter ones.
  • Validate with Visualization: Always plot the detected periodic segments alongside the original data to confirm the results—nothing beats a visual check for edge cases.

内容的提问来源于stack exchange,提问作者Hen Tzaban

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 11:57:44