日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python日期加减源码_Python 时间序列的时间延迟计算

發布時間:2025/3/19 python 48 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python日期加减源码_Python 时间序列的时间延迟计算 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

時間:2018-12-08

概述:隨機數 時間序列 延遲 自相關法

Python自相關法求時間延遲,混沌時間序列分析源程序,時間序列的時間延遲計算,用戶輸入時間序列以及最大時間延遲,可返回所求時間序列的時間延遲,在測試的過程中,生成隨機數字序列用于測試具體實現方法請看如下的代碼段:

import numpy as np

import matplotlib.pyplot as plt

import random

import matplotlib as mpl

import warnings

#混沌時間序列分析源程序

#download by http://www.codesc.net

#時間序列的時間延遲計算

def autocorrelation(data,tau_max):

"""#data:輸入的時間序列

#tau_max:最大時間延遲

#Tau:返回所求時間序列的時間延遲"""

N=len(data)

#時間序列長度

x_mean=np.mean(data)

#時間序列的平均值

data=data-x_mean

SSd=np.dot(data,data)

R_xx=np.zeros((1,tau_max))[0]#=zeros(1,tau_max)

#自相關函數初始化

for tau in range(0,tau_max):#1:tau_max

#計算自相關函數

for ii in range(0,N-tau):#1:N-tau

#print(tau,ii,ii+tau,N)

R_xx[tau] = R_xx[tau]+data[ii]*data[ii+tau]#

R_xx[tau]=R_xx[tau]/SSd

##end

#print(len(R_xx))

print(R_xx)

#print(np.arange(1,tau_max+1))

plt.plot(np.arange(1,tau_max+1),R_xx) #plot(1:tau_max,R_xx);

#plt.show()##hold on

#作自相關函數圖

plt.plot([1,tau_max],[0,0])#line([1,tau_max],[0,0])

plt.title('自相關法求時間延遲')

plt.ylabel('自相關函數')

plt.xlabel('時間延遲') ;plt.show()#

Tau=0

#求時間序列的時間延遲

R_tau = list(map(lambda x:x>=0,R_xx))

#print(R_tau)

jj = 0;R_jj =R_tau[0]

while jj < tau_max:

jj = jj+1

if R_jj!=R_tau[jj]:

break

tau = jj

#print('tau jj:',tau)

if abs(R_xx[jj-1])>abs(R_xx[jj]):

Tau=Tau+1

#print('tau ok:',tau)

'''jj = 0

while jj < tau_max:#for jj in range(1,tau_max):#2:tau_max

jj = jj+1#print(jj)

Tau=jj;print(Tau)

print(R_xx[jj-1],R_xx[jj],R_xx[jj-1]*R_xx[jj])

if R_xx[jj-1]*R_xx[jj]<=0:

print(jj)

if abs(R_xx[jj-1])>abs(R_xx[jj]):

pass#Tau=jj;print('tau1:',tau) #break

else:

Tau=Tau-1#Tau=jj-1;print('tau2:',tau)#break

print('tau:',tau);break'''

#end

#end

#end

print('tau:',tau)

return tau

#生成隨機數字序列用于測試

def gen_series(n):

result = []

for i in range(n):

t = random.randint(0,99)#random.uniform(1, 10)#random.random()#random.randint(0,50)#uniform(1, 3)

#隨機浮點數random.random() #random.uniform(1, 10)

#隨機字符:random.choice('abcdefg#^*f')#多個字符中選取特定數量的字符:random.sample('abcdefghij',3)

#隨機整數:random.randint(0,99)#隨機選取0到100間的偶數:random.randrange(0, 101, 2)

result.append(t)

print(result)

return result

if __name__ == "__main__":

#解決中文的問題

mpl.use('TkAgg')

mpl.rcParams['font.sans-serif'] = ['SimHei']

mpl.rcParams['font.family']='sans-serif'

#解決負號'-'顯示為方塊的問題

mpl.rcParams['axes.unicode_minus'] = False

x = gen_series(100)

print('autocorrelation:')

print(autocorrelation(x,20))

總結

以上是生活随笔為你收集整理的python日期加减源码_Python 时间序列的时间延迟计算的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。