Example #1
0
    def Dfun(x):
        Xs, ys, ts = destructure_x(x, return_ts=True)
        aHs, omaHs, adHs = [], [], []
        for i in xrange(N):
            shard = Shard(Xs[i], k)
            H, dX = shard(domain, return_dX=True, epsilon=epsilon)
            aH = alpha * H
            aHs.append(aH)
            omaHs.append(1.0 - aH)
            adHs.append(alpha * dX)

        I = np.ones_like(aHs[0])
        JXs, Jts = [], []
        for l in xrange(N):
            JXl = J0 * prod(I, omaHs, 0, l)[..., np.newaxis]
            for i in xrange(l):
                JXli = aHs[i] * prod(I, omaHs, i + 1, l)
                JXl += ys[i] * JXli[..., np.newaxis]
            prod_lp1 = prod(I, omaHs, l + 1)
            JXl -= ys[l] * prod_lp1[..., np.newaxis]
            JXl_T = adHs[l][..., np.newaxis] * JXl
            JXs.append(JXl_T.reshape(X_size, -1))

            neg_aH_prod_lp1 = -(aHs[l] * prod_lp1)
            dy = sigmoid_dt(ts[l])
            Jt = np.zeros(((y_size,) + I.shape + (y_size,)),
                          dtype=np.float64)
            for i in xrange(y_size):
                Jt[i, ..., i] = dy[i] * neg_aH_prod_lp1
            Jts.append(Jt.reshape(y_size, -1))
        return np.vstack(JXs + Jts).T
Example #2
0
 def Dfun(x):
     X_, y_, t_ = destructure_x(x, return_t=True)
     shard = Shard(X_, k)
     H, dX = shard(domain, return_dX=True, epsilon=epsilon)
     d = alpha * (J - y_)
     JX = dX[..., np.newaxis] * d
     aH = -alpha * H
     dy = sigmoid_dt(t_)
     n = y.size
     Jy = np.zeros(((n,) + H.shape + (n,)), dtype=np.float64)
     for i in xrange(n):
         Jy[i, ..., i] = dy[i] * aH
     return np.c_[JX.reshape(X.size, -1).T, Jy.reshape(n, -1).T]