예제 #1
0
def estimate_infcens(Y):
    res = {}
    params = np.array([[0, 0, 1, 0, 1]] * N).T
    for _ in range(100000):
        D = MultivariateNormal(params)
        S = MLE()
        grad = np.mean(S.grad(D, Y, natural=True).T, axis=1, keepdims=True)
        params = params - 1 * grad
        if np.linalg.norm(grad) < 1e-4:
            break

    print('Jointly Estimated E:', params[0, 0])
    res['joint'] = params[0, 0]

    params = np.array([[0, 0]] * N).T
    for _ in range(100000):
        D = LogNormal(params)
        S = MLE()
        grad = np.mean(S.grad(D, Y, natural=True).T, axis=1, keepdims=True)
        params = params - 0.005 * grad
        if np.linalg.norm(grad) < 1e-4:
            break

    print('Estimate E (assume non-inf):', params[0, 0])
    res['lognorm'] = params[0, 0]
    return res
예제 #2
0
def mvnorm_mle(Y, max_iter=1e4, lr=0.5, eps=1e-4):
    N = Y.shape[0]
    params = np.array([[0, 0, 1, 0, 1]] * N).T
    for _ in range(max_iter):
        D = MultivariateNormal(params)
        S = MLE()
        grad = np.mean(S.grad(D, Y, natural=True).T, axis=1, keepdims=True)
        params = params - lr * grad
        if np.linalg.norm(grad) < eps:
            break
예제 #3
0
def lognormal_mle(Y, max_iter=1e4, lr=0.05, eps=1e-4, verbose=False):
    N = Y.shape[0]
    params = np.array([[0, 0]] * N).T
    for i in range(int(max_iter)):
        if i % 500 == 1 and verbose:
            print('Param: ', params[:, :2])
            print('Grad: ', grad)
        D = LogNormal(params)
        S = MLE()

        grad = np.mean(S.grad(D, Y, natural=True).T, axis=1, keepdims=True)
        params = params - lr * grad
        if np.linalg.norm(grad) < eps:
            break

    mu = params[0, 0]
    sigma = params[1, 0]
    return mu, sigma
예제 #4
0
    col_event = 'Event'
    col_time = 'Time'
    y = np.empty(dtype=[(col_event, np.bool), (col_time, np.float64)],
                 shape=T.shape[0])
    y[col_event] = E
    y[col_time] = np.exp(T)
    return y


Y = Y_join(T, E)

params = np.array([[0, 0, 1, 0, 1]] * N).T
for _ in range(100000):
    D = MultivariateNormal(params)
    S = MLE()
    grad = np.mean(S.grad(D, Y, natural=True).T, axis=1, keepdims=True)
    params = params - 1 * grad
    if np.linalg.norm(grad) < 1e-4:
        break

print('Jointly Estimated E:', params[0, 0])

params = np.array([[0, 0]] * N).T
for _ in range(100000):
    D = LogNormal(params)
    S = MLE()
    grad = np.mean(S.grad(D, Y, natural=True).T, axis=1, keepdims=True)
    params = params - 0.1 * grad
    if np.linalg.norm(grad) < 1e-4:
        break