Esempio n. 1
0
def test_bms_verbose():
    X = np.random.uniform(0, 200, size=(100, 10))
    pxp, xp, bor, q_m, alpha, f0, f1, niter = bms(X, verbose=True)
    assert np.equal(pxp.sum().round(5), 1)
    assert np.equal(xp.sum().round(5), 1)
    assert (0 <= bor <= 1)
    assert np.all(np.equal(q_m.sum(1).round(5), 1))
    assert np.all(np.greater(alpha, 0))
    assert np.greater_equal(f0, 0)
    assert np.greater_equal(f1, 0)
    assert np.greater(niter, 0)
Esempio n. 2
0
    def update_target(self):
        if not self.sink:
            neighbors = self.neighbors
            np.random.shuffle(neighbors)
            local_dists = [self.dist(e) for e in neighbors]

            # if limit_checks is not None:  # shorten neighbors list
            #     if len(neighbors) > limit_checks:
            #         sorted = np.argsort(local_dists)
            #         neighbors = [neighbors[i] for i in sorted[:limit_checks]]
            #         local_dists = [local_dists[i] for i in
            #                        sorted[:limit_checks]]

            local_dPs = [e.dP for e in neighbors]
            # TODO optimize this: precompute/estimate the gradient
            gradients = [self.grad_loss(l)(float(self.I) + 1e-20)
                         for l in local_dists]
            local_dPs = [local_dPs[i] - g for i, g in enumerate(gradients)]

            if any(np.greater(local_dPs, 0)):
                self.target = neighbors[np.argmax(local_dPs)]
            else:
                self.target = None
                self.dP = 0
                self.I = 0
                self.debt = 0
Esempio n. 3
0
def relu(x, a_max=None):
    """ Rectified linearity

    $$
    \mathbf x' = \max (x_i, 0)_{i=1}^{|\mathbf x|}
    $$

    Arguments:

        x: Vector of inputs
        a_max: Upper bound at which to clip values of `x`

    Returns:

        Exponentiated values of `x`.

    """
    if a_max is None: a_max = np.inf
    x = x.clip(max=a_max)
    return np.greater(x, 0) * x
Esempio n. 4
0
def gt(a: Numeric, b: Numeric):
    return anp.greater(a, b)
Esempio n. 5
0
 def calc_u(self, x):
     u = np.greater(self.params['x_J'] - x, 0.0) * self.calc_u_l(x)
     u += np.greater_equal(x - self.params['x_J'], 0.0) * self.calc_u_r(x)
     return u