

def EM(init_params, data, callback=None):

    def EM_update(params):
        natural_params = map(np.log, params)
        (loglike, E_stats) = vgrad(log_partition_function)(natural_params, data)
        if callback:
            callback(loglike, params)
        return map(normalize, E_stats)

    def fixed_point(f, x0):
        x1 = f(x0)
        while different(x0, x1):
            (x0, x1) = (x1, f(x1))
        return x1

    def different(params1, params2):
        allclose = partial(np.allclose, atol=0.001, rtol=0.001)
        return (not all(map(allclose, params1, params2)))
    return fixed_point(EM_update, data)

dataset/ETHPy150Open HIPS/autograd/examples/hmm_em.py EM/VarMisuse@172/204 `init_params`->`data`