def test_pruned_max(self): forward_max_weights = k2host.DoubleArray1.create_array_with_size( self.num_states) backward_max_weights = k2host.DoubleArray1.create_array_with_size( self.num_states) wfsa = k2host.WfsaWithFbWeights(self.fsa, k2host.FbWeightType.kMaxWeight, forward_max_weights, backward_max_weights) beam = 8.0 remover = k2host.EpsilonsRemoverPrunedMax(wfsa, beam) fsa_size = k2host.IntArray2Size() arc_derivs_size = k2host.IntArray2Size() remover.get_sizes(fsa_size, arc_derivs_size) fsa_out = k2host.Fsa.create_fsa_with_size(fsa_size) arc_derivs = k2host.IntArray2.create_array_with_size(arc_derivs_size) arc_weights_out = k2host.FloatArray1.create_array_with_size( fsa_size.size2) remover.get_output(fsa_out, arc_derivs) self.assertTrue(k2host.is_epsilon_free(fsa_out)) self.assertEqual(fsa_out.size1, 6) self.assertEqual(fsa_out.size2, 11) # TODO: fix this self.assertEqual(arc_derivs.size1, 11) # TODO: fix this self.assertEqual(arc_derivs.size2, 18) # TODO: fix this self.assertTrue( k2host.is_rand_equivalent_max_weight(self.fsa, fsa_out, beam))
def test_pruned_max(self): forward_max_weights = k2host.DoubleArray1.create_array_with_size( self.num_states) backward_max_weights = k2host.DoubleArray1.create_array_with_size( self.num_states) wfsa = k2host.WfsaWithFbWeights(self.fsa, k2host.FbWeightType.kMaxWeight, forward_max_weights, backward_max_weights) beam = 10.0 determinizer = k2host.DeterminizerPrunedMax( wfsa, beam, 100, k2host.FbWeightType.kNoWeight) fsa_size = k2host.IntArray2Size() arc_derivs_size = k2host.IntArray2Size() determinizer.get_sizes(fsa_size, arc_derivs_size) fsa_out = k2host.Fsa.create_fsa_with_size(fsa_size) arc_derivs = k2host.IntArray2.create_array_with_size(arc_derivs_size) arc_weights_out = k2host.FloatArray1.create_array_with_size( fsa_size.size2) determinizer.get_output(fsa_out, arc_derivs) self.assertTrue(k2host.is_deterministic(fsa_out)) self.assertEqual(fsa_out.size1, 7) self.assertEqual(fsa_out.size2, 9) self.assertEqual(arc_derivs.size1, 9) self.assertEqual(arc_derivs.size2, 12) self.assertTrue( k2host.is_rand_equivalent_max_weight(self.fsa, fsa_out, beam))
def test_with_beam(self): self.assertTrue( k2host.is_rand_equivalent_max_weight(self.fsa_a, self.fsa_b, 4.0)) self.assertFalse( k2host.is_rand_equivalent_max_weight(self.fsa_a, self.fsa_c, 6.0))
def test_max_weight(self): self.assertTrue( k2host.is_rand_equivalent_max_weight(self.fsa_a, self.fsa_b)) self.assertFalse( k2host.is_rand_equivalent_max_weight(self.fsa_a, self.fsa_c))