Пример #1
0
 def test_max_against_brute_force(self):
   maxes = [max_brute_force(self._weights[i])
            for i in range(self._weights.shape[0])]
   maxes2 = npy_ops.soft_sw_affine(self._toy_sub.numpy(),
                                   self._toy_gap_open.numpy(),
                                   self._toy_gap_extend.numpy(),
                                   temperature=0)
   self.assertAllClose(maxes, maxes2)
Пример #2
0
 def test_lse_against_brute_force(self):
   for temp in (1e-3, 1.0, 1e3):
     softmaxes = np.array([lse_brute_force(self._weights[i],
                                           temperature=temp)
                           for i in range(self._weights.shape[0])])
     softmaxes2 = npy_ops.soft_sw_affine(self._toy_sub.numpy(),
                                         self._toy_gap_open.numpy(),
                                         self._toy_gap_extend.numpy(),
                                         temperature=temp)
     self.assertAllClose(softmaxes, softmaxes2)
  def test_perturbation_friendly_version_against_numpy_version(self, decorator):
    smith_waterman_fn = tf_ops.hard_sw_affine
    if decorator is not None:
      smith_waterman_fn = decorator(smith_waterman_fn)

    maxes, _ = smith_waterman_fn(self._w)
    maxes2 = npy_ops.soft_sw_affine(self._toy_sub.numpy(),
                                    self._toy_gap_open.numpy(),
                                    self._toy_gap_extend.numpy(),
                                    temperature=0)

    self.assertAllClose(maxes, maxes2)
Пример #4
0
  def test_gradient_shape(self):
    toy_sub = self._toy_sub.numpy()
    toy_gap_open = self._toy_gap_open.numpy()
    toy_gap_extend = self._toy_gap_extend.numpy()

    values, g_sim_mat, g_gap_open, g_gap_extend = npy_ops.soft_sw_affine(
        sim_mat=toy_sub,
        gap_open=toy_gap_open,
        gap_extend=toy_gap_extend,
        ret_grads=True)
    self.assertEqual(values.shape[0], toy_sub.shape[0])
    self.assertAllEqual(g_sim_mat.shape, toy_sub.shape)
    self.assertAllEqual(g_gap_open.shape, toy_gap_open.shape)
    self.assertAllEqual(g_gap_extend.shape, toy_gap_extend.shape)
    def test_soft_version_against_numpy_version(self, decorator, temp):
        soft_version_fn = tf_ops.soft_sw_affine_fwd
        if decorator is not None:
            soft_version_fn = decorator(soft_version_fn)

            maxes = npy_ops.soft_sw_affine(self._toy_sub.numpy(),
                                           self._toy_gap_open.numpy(),
                                           self._toy_gap_extend.numpy(),
                                           temperature=temp)
            maxes2 = soft_version_fn(self._toy_sub,
                                     self._toy_gap_open,
                                     self._toy_gap_extend,
                                     temp=temp)

            self.assertAllClose(maxes, maxes2)
Пример #6
0
  def test_max_against_sw_general(self):
    def make_gap_func(gap_open, gap_extend):
      def gap_func(k):
        return gap_open + gap_extend * (k-1)
      return gap_func

    toy_sub = self._toy_sub.numpy()
    toy_gap_open = self._toy_gap_open.numpy()
    toy_gap_extend = self._toy_gap_extend.numpy()

    maxes = [_sw_general(toy_sub[i],
                         make_gap_func(toy_gap_open[i], toy_gap_extend[i]))
             for i in range(self._weights.shape[0])]
    maxes2 = npy_ops.soft_sw_affine(toy_sub, toy_gap_open, toy_gap_extend,
                                    temperature=0)
    self.assertAllClose(maxes, maxes2)