Levenberg Marquardt algorithm

"""

import numpy as np
from scipy.optimize import least_squares
import matplotlib.pyplot as plt

def y(theta, t):
return theta[0] / (1 + np.exp(- theta[1] * (t - theta[2])))

ts = np.linspace(0, 1, 100)
K = 1; r = 10; t0 = 0.5; noise = 0.1
ys = y([K, r, t0], ts) + noise * np.random.rand(ts.shape[0])

def fun(theta):
return y(theta, ts) - ys

theta0 = [1,2,3]
res1 = least_squares(fun, theta0, method = "lm")

plt.plot(ts, y(res1.x, ts), color = "blue")
plt.scatter(ts, ys, color = "red", s = 1)
print(res1.x)
plt.show()

"""

scipy で非線形フィッティングをする。

こちら

Levenberg Marquardt 法は、反復法で、

 (J^T J + \lambda I) \delta = J^T (y - f(\beta))という式に従って、更新していく。

ここで、λは非負の減衰係数で、徐々に調整されるらしい。