3 回答

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 軸需要移動。或者也許它畢竟是正確的。我明天會用新鮮的大腦來思考這個問題。
下圖顯示了兩種算法,其中包含計算出的指數數據,其中兩個位置設置為非遞增值。

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)

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)
添加回答
舉報