def estimate_from_weights(log_ais_w):
    # Utility function for safely computing log-mean of the ais weights
    ais_w = T.vector()
    max_ais_w = T.max(ais_w)
    dlogz = T.log(T.mean(T.exp(ais_w - max_ais_w))) + max_ais_w
    log_mean = theano.function([ais_w], dlogz, allow_input_downcast=False)

    # Estimate the log-mean of the AIS weights
    dlogz = log_mean(log_ais_w)

    # Estimate log-variance of the AIS weights
    # VAR(log(X)) \approx VAR(X) / E(X)^2 = E(X^2)/E(X)^2 - 1
    m = numpy.max(log_ais_w)
    var_dlogz = (log_ais_w.shape[0] *
                 numpy.sum(numpy.exp(2 * (log_ais_w - m))) /
                 numpy.sum(numpy.exp(log_ais_w - m)) ** 2 - 1.)

    return dlogz, var_dlogz
Safely compute the log-average of the ais-weights
dataset/ETHPy150Open lisa-lab/pylearn2/pylearn2/scripts/dbm/dbm_metrics.py/estimate_from_weights