def f(cls, x, params, do_alter, do_shift_x=True):
     w1, w2, b = params
     if do_alter:
         b *= 2.
         w1 += 5.
         w2 /= 0.9
     if do_shift_x:
         x = x * 2 + 1.
     return 0.5 * np.dot(np.dot(x.T, w1), x) + np.dot(w2, x) + b
 def f_lin_exact(cls, x0, x, params, do_alter, do_shift_x=True):
     w1, w2, b = params
     f0 = EmpiricalTest.f(x0, params, do_alter, do_shift_x)
     if do_shift_x:
         x0 = x0 * 2 + 1.
         x = x * 2 + 1.
     dx = x - x0
     if do_alter:
         b *= 2.
         w1 += 5.
         w2 /= 0.9
     return f0 + np.dot(np.dot(x0.T, w1) + w2, dx)
 def f_2_exact(x0, x, params, do_alter, do_shift_x=True):
     w1, w2, b = params
     f_lin = EmpiricalTest.f_lin_exact(x0, x, params, do_alter,
                                       do_shift_x)
     if do_shift_x:
         x0 = x0 * 2 + 1.
         x = x * 2 + 1.
     if do_alter:
         b *= 2.
         w1 += 5.
         w2 /= 0.9
     dx = x - x0
     return f_lin + 0.5 * np.dot(np.dot(dx.T, w1), dx)
示例#4
0
    def forward(self, x):
        """Performs the forward pass.

        Args:
            x: 2-d array of size batch_size x image_size.

        Returns:
            A 2-d array of size batch_size x num_classes.
        """
        for l in self.layers:
            w = l.weights
            b = l.biases
            x = self.sigmoid(np.dot(x, w) + b)
        return x
示例#5
0
 def apply_fun(params, inputs, **kwargs):
     W, b = params
     return tfnp.dot(inputs, W) + b