Returns log of (weighted) mean of exp(v). 

       Parameters
       ----------
       v: ndarray 
           data, should be such that v.shape[0] = N 

       W: (N,) ndarray, optional  
            normalised weights (>=0, sum to one)

       Returns
       -------
       ndarray 
           mean (or weighted mean, if W is provided) of vector exp(v) 

       See also
       --------
       log_sum_exp

def log_mean_exp(v, W=None):
    """Returns log of (weighted) mean of exp(v). 

       Parameters
       ----------
       v: ndarray 
           data, should be such that v.shape[0] = N 

       W: (N,) ndarray, optional  
            normalised weights (>=0, sum to one)

       Returns
       -------
       ndarray 
           mean (or weighted mean, if W is provided) of vector exp(v) 

       See also
       --------
       log_sum_exp

    """
    m = v.max()
    V = np.exp(v - m)
    if W is None:
        return m + np.log(np.mean(V))
    else:
        return m + np.log(np.average(V, weights=W))