def test_normal_logEI_elemwise():
    rng = np.random.RandomState(123)

    N = 2000
    thresh = np.linspace(-50, 500, N)
    #N = 100
    #thresh = np.linspace(37, 38, N)
    mean = thresh * 0
    var = 1e-1 + rng.rand(N)
    sigma = np.sqrt(var)

    s_t, s_m, s_v = theano.tensor.dvectors('tmv')

    fn = theano.function([s_t, s_m, s_v],
                         normal_logEI_diff_sigma_elemwise(
                             s_t - s_m,
                             theano.tensor.sqrt(s_v)))

    my = fn(thresh, mean, var)
    ref = logEI_gaussian(mean, var, thresh)
    for xi, myv, spv in zip(thresh, my, ref):
        print xi, 'my', myv, 'sp', spv, 'diff', (myv - spv)

    assert np.any(thresh / sigma > 34)
    assert np.all(np.isfinite(my))
    assert np.allclose(my[thresh/sigma < 34], ref[thresh/sigma < 34])
    assert np.allclose(my, ref, rtol=.1)
 def f_arg1(x):
     return normal_logEI_diff_sigma_elemwise(
         np.ones(N) * 100,
         x)
 def f_arg0(x):
     return normal_logEI_diff_sigma_elemwise(x, np.ones(N))