# Path: Utility.py
# def l2(x):
# def apply_scale(w, a, b):
# def logabsdiffexp(x, y):
#     def f(x, y):
# def logit_mean(x):
# def digest(x):
# def tree():
# def lift_tree(src, dst):
# def init_latex_rendering():
# def draw_confidence(a, m, S, levels = [0.95]):


import numpy as np
from Utility import logsumexp
        print 'X: t_min = %.2f, t_max = %.2f' % (t_X.min(), t_X.max())
        
    # Statistics for the samples from the proposal distribution only
    # need to be calculated once...
    t_Y = np.empty((L, K+1))
    t_Y[:,K] = 0.0
    for k in range(K):
        t_Y[:,k] = t(Y[k])
        if verbose:
            print 'Y_%d: t_min = %.2f, t_max = %.2f' % \
                (k, t_Y[:,k].min(), t_Y[:,k].max())
    if two_sided:
        I_t_Y_plus = t_Y >= t_X
        I_t_Y_plus[:,K] = True
    I_t_Y_minus = -t_Y >= -t_X
    I_t_Y_minus[:,K] = True

    # Probabilities under each component of the proposal distribution
    # only need to be calculated once...
    log_Q_X = np.empty(L)
    log_Q_Y = np.empty((L,K))
    for l in range(L):
        theta_l = theta_grid[l]

        log_Q_X[l] = log_likelihood(X, theta_l)
        for k in range(K):
            log_Q_Y[l,k] = log_likelihood(Y[k], theta_l)
        if verbose:
            print '%.2f: %.2g, %.2g' % \
              (theta_l, np.exp(log_Q_X[l]), np.exp(log_Q_Y[l].max()))

# Path: Utility.py
# def l2(x):
# def apply_scale(w, a, b):
# def logabsdiffexp(x, y):
#     def f(x, y):
# def logit_mean(x):
# def digest(x):
# def tree():
# def lift_tree(src, dst):
# def init_latex_rendering():
# def draw_confidence(a, m, S, levels = [0.95]):


# Path: Confidence.py
import numpy as np
from Utility import logsumexp

        print 'X: t_min = %.2f, t_max = %.2f' % (t_X.min(), t_X.max())
        
    # Statistics for the samples from the proposal distribution only
    # need to be calculated once...
    t_Y = np.empty((L, K+1))
    t_Y[:,K] = 0.0
    for k in range(K):
        t_Y[:,k] = t(Y[k])
        if verbose:
            print 'Y_%d: t_min = %.2f, t_max = %.2f' % \
                (k, t_Y[:,k].min(), t_Y[:,k].max())
    if two_sided:
        I_t_Y_plus = t_Y >= t_X
        I_t_Y_plus[:,K] = True
    I_t_Y_minus = -t_Y >= -t_X
    I_t_Y_minus[:,K] = True

    # Probabilities under each component of the proposal distribution
    # only need to be calculated once...
    log_Q_X = np.empty(L)
    log_Q_Y = np.empty((L,K))
    for l in range(L):
        theta_l = theta_grid[l]

        log_Q_X[l] = log_likelihood(X, theta_l)
        for k in range(K):
            log_Q_Y[l,k] = log_likelihood(Y[k], theta_l)
        if verbose:
            print '%.2f: %.2g, %.2g' % \
              (theta_l, np.exp(log_Q_X[l]), np.exp(log_Q_Y[l].max()))

    log_Q_sum_X = logsumexp(log_Q_X)