ロジスティック曲線への近似

2017/02/08

# -*- coding: utf-8 -*-
import math
import numpy as np
import matplotlib.pyplot as plt

def main():

    X = [1,2,3,4,5,6,7,8,9]
    Y = [0.2, 0.1, 0.3, 0.3, 0.5, 0.8, 0.9,0.8, 0.9]

    K = 1.0
    LY = []
    for y in Y:
        LY.append(math.log(K/y-1))

    A = np.array([X,np.ones(len(X))])
    A = A.T
    Q,P = np.linalg.lstsq(A,LY)[0]

    b = math.exp(P)
    c = -Q

    LA = []
    for x in X:
        LA.append(K/(1.0+b*math.exp(-c*x)))

    plt.plot(X,Y,"ro")
    plt.plot(X,LA,"g--")
    plt.grid()
    plt.show()

if __name__ == '__main__':
    main()


成長曲線(ゴンペルツ曲線とロジスティック曲線)
http://www.kogures.com/hitoshi/webtext/stat-seicho-kyokusen/

NumPyと最小二乗法で線形近似
http://tokeigaku.blog.jp/python/numpy/%E6%9C%80%E5%B0%8F%E4%BA%8C%E4%B9%97%E6%B3%95