以下のためにニュートン・ラプソン、はい、私たちは持っています
π1=π0−u(π0)/J(π0).
πI(π)I(π)=−E(J(π))=E[u(π)u′(π)]
I^(π0)=∑inui(π0)u′i(π0),
ui(π)=xiπ−1−xi1−πxiπ1=π0+u(π0)/I^(π0).
n
I_hat(pi)
@ihadannyのPython
コードを修正しました。現在、Newton-RaphsonとFisherのスコアリングは同じ結果を提供します。
import random
import numpy as np
pi_t = random.random()
n = 1000
draws = [1 if x < pi_t else 0 for x in np.random.rand(n)]
x_bar = np.mean(draws)
def u(pi):
return n*x_bar/pi - n*(1-x_bar)/(1-pi)
def J(pi):
return -n*x_bar/pi**2 - n*(1-x_bar)/((1-pi)**2)
def I_hat(pi):
x = 0
for i in range(0, n):
x = x + (draws[i]/pi - (1-draws[i])/(1-pi))**2
return x
def Newton(pi):
return pi - u(pi)/J(pi)
def Fisher(pi):
return pi + u(pi)/I_hat(pi)
def dance(method_name, method):
print("starting iterations for: " + method_name)
pi, prev_pi, i = 0.5, None, 0
while i == 0 or (abs(pi-pi_t) > 0.001 and abs(pi-prev_pi) > 0.001 and i < 10):
prev_pi, pi = pi, method(pi)
i += 1
print(method_name, i, "delta: ", abs(pi-pi_t))
dance("Newton", Newton)
dance("Fisher", Fisher)
Log Message
starting iterations for: Newton
Newton 1 delta: 0.00899203081545
Newton 2 delta: 0.00899203081545
starting iterations for: Fisher
Fisher 1 delta: 0.00899203081545
Fisher 2 delta: 0.00899203081545
更新
I^(π)=∑in(xiπ−1−xi1−π)2=∑nixiπ2+(n−∑nixi)(1−π)2=−J(π),