亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使用熊貓或Numpy計算離散時間序列的“倍增時間”?

如何使用熊貓或Numpy計算離散時間序列的“倍增時間”?

慕萊塢森 2022-09-27 09:48:34
下面是一個數據集。每一行都是一個時間片。第一列是讀數。第二個是多少個時間段前的讀數是它的50%。我通過盯著它來手工計算它,所以數字并不完全正確。197 218 256 328     4413     4525     4646     4777     51159    41838    22417    23240    2.54257    34955    45752    5.56620    57738    5.58966    4.510402   5因此,假設我有一個數據幀,如下所示:df = pd.DataFrame({'val': [197,218,256,328,413,525,646,777,1159,1838,2417,3240,4257,4955,5752,6620,7738,8966,10402]})如何計算 df.倍增?我可以想象從最后開始,向后工作,每次掃描一個值的50%。但是有更好的方法。我認為這與Log2有關,但不知道該怎么做!
查看完整描述

3 回答

?
MM們

TA貢獻1886條經驗 獲得超2個贊

您是否正在將Covid-19感染時間加倍?


請仔細檢查結果。


我忘了你正在使用熊貓,所以你可能需要這個:


y = df['val'].to_numpy()

這是第一次拍攝:


import numpy as np

from scipy.interpolate import interp1d


y = np.array([197, 218, 256, 328, 413,525, 646, 646, 777,

              1159, 1838, 2417, 3240, 4257, 4955, 4955,

              5752, 6620, 7738, 8966, 10402],

              dtype=float)


# get the deltas to check if there was no increase

# between two consecutive data points        

dy = np.diff(y)


# these are the places without increase

idx = np.argwhere(dy) #could also be np.where(dy == 0.0)[0]


y_fixed = y.copy()


# create the x axis, probably days 

x = np.arange(y.shape[0])


# Hack: increase the second identical value be a

# small amount so the interpolation works

# increase the indices by one to increment the second value

y_fixed[idx + 1] += 0.001


# you need scipy > 0.17 for extrapolation to work

f = interp1d(y_fixed, x, fill_value="extrapolate")


# there are the values you need?

y_half = y / 2.0


# get the according x values by interpolation

x_interp = f(y_half)


# delta between the current day and the date when

# the value was half

dbl = x - x_interp


# this already looks quite good, but double check!

print(dbl)

也許 x 軸需要移動。或者也許它畢竟是正確的。我明天會用新鮮的大腦來思考這個問題。

http://img1.sycdn.imooc.com//6332569a0001d58906220464.jpg

下圖顯示了兩種算法,其中包含計算出的指數數據,其中兩個位置設置為非遞增值。

http://img1.sycdn.imooc.com//633256a400014f9706220469.jpg

查看完整回答
反對 回復 2022-09-27
?
不負相思意

TA貢獻1777條經驗 獲得超10個贊

可能最終會看起來像這樣。


ACCURACY = 0


cases = [197, 218, 256, 328, 413,525, 646, 646, 777,

          1159, 1838, 2417, 3240, 4257, 4955, 4955,

          5752, 6620, 7738, 8966, 10402]

doubling = []


for t in range(len(cases)):

    found = False

    for t_2 in range(t):

        if cases[t_2] - (cases[t] // 2) > ACCURACY:

            doubling.append(t - t_2)

            found = True

            break


    # Append nothing if value not found

    if not found:

        doubling.append(None)


查看完整回答
反對 回復 2022-09-27
?
拉丁的傳說

TA貢獻1789條經驗 獲得超8個贊

我正在處理這些數據。這是一個老派的解決方案。我跟蹤了您的解決方案,但無法完全遵循它。但是我的不是那么優雅,但我認為這是正確的...而且圖表看起來與您的圖表非常相似...!


import numpy as np

readings = np.array([197, 218, 256, 328, 413,525, 646, 646, 777,

          1159, 1838, 2417, 3240, 4257, 4955, 4955,

          5752, 6620, 7738, 8966, 10402],

          dtype=float)   


readingsLength = len(readings)

double = np.zeros(readingsLength)

for i in range( readingsLength - 1, -1, -1):

    target = readings[i]

    count = 0

    for j in range(i, -1, -1):

        diffsofar = target-readings[j]

        exact = target / 2

        if diffsofar  > exact:

            f = (exact - readings[j]) / (readings[j]-readings[j+1]) + count

            double[i] = f

            break

        else:

            count = count+1

print(double)  

http://img1.sycdn.imooc.com//633256bc000161d406580451.jpg

查看完整回答
反對 回復 2022-09-27
  • 3 回答
  • 0 關注
  • 74 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號