python 회색 예측 Verhulst 모델 구현

8926 단어 수학 모범
//Verhulst
import numpy as np
import math


def predict(data):
    x1 = data.cumsum()
    z = (x1[:len(x1) - 1] + x1[1:]) / 2.0
    B = np.array([-z, z*z]).T
    Y = data[1:]
    u = np.dot(np.dot(np.linalg.inv(np.dot(B.T, B)), B.T), Y)
    a, b = u[0], u[1]
    return [a*data[0]/(b*data[0]+(a-b*data[0])*math.exp(a*i)) for i in range(len(data))]


if __name__ == '__main__':
    data = np.array([4.93, 2.33, 3.87, 4.35, 6.63, 7.15, 5.37, 6.39, 7.81, 8.35])
    predict_data = predict(data)  #  x1
    result = np.ediff1d(predict_data)  #  
    print(' :', data[1:])
    print(' :', result)
    print(' :', (np.array(result[:len(data)]) - np.array(data[1:len(data)])) / np.array(data[1:len(data)]))

좋은 웹페이지 즐겨찾기