Exemplo n.º 1
0
def histogram_bottom_up_ll(node, data=None, dtype=np.float64):
    probs = histogram_likelihood(node, data=data, dtype=dtype)
    mpe_ids = np.isnan(data[:, node.scope[0]])
    mode_data = np.ones((1, data.shape[1])) * histogram_mode(node)
    probs[mpe_ids] = histogram_likelihood(node, data=mode_data, dtype=dtype)

    return probs
Exemplo n.º 2
0
def histogram_to_tf_graph(node,
                          data_placeholder=None,
                          log_space=True,
                          variable_dict=None,
                          dtype=np.float32):
    with tf.variable_scope("%s_%s" % (node.__class__.__name__, node.id)):
        inps = np.arange(int(max(node.breaks))).reshape((-1, 1))
        tmpscope = node.scope[0]
        node.scope[0] = 0
        hll = histogram_likelihood(node, inps)
        node.scope[0] = tmpscope
        if log_space:
            hll = np.log(hll)

        lls = tf.constant(hll.astype(dtype))

        col = data_placeholder[:, node.scope[0]]

        return tf.squeeze(tf.gather(lls, col))