コード例 #1
0
 def test_encode_char(self):
     encoder = OneHotMatrixEncoder(1)
     sequences = np.array([[1], [4], [0]])
     encoded_vectors = encoder.encode_sequences(sequences)
     expected_vectors = np.array([[[0, 1, 0, 0, 0]], [[0, 0, 0, 0, 1]],
                                  [[1, 0, 0, 0, 0]]])
     np.testing.assert_array_equal(encoded_vectors, expected_vectors)
コード例 #2
0
 def test_encode_sequences(self):
     encoder = OneHotMatrixEncoder(4)
     sequences = np.array([[2, 1, 4, 3], [1, 4, 3, 2], [1, 4, 0, 2]])
     encoded_vectors = encoder.encode_sequences(sequences)
     expected_vectors = np.array([[[0, 0, 1, 0, 0], [0, 1, 0, 0, 0],
                                   [0, 0, 0, 0, 1], [0, 0, 0, 1, 0]],
                                  [[0, 1, 0, 0, 0], [0, 0, 0, 0, 1],
                                   [0, 0, 0, 1, 0], [0, 0, 1, 0, 0]],
                                  [[0, 1, 0, 0, 0], [0, 0, 0, 0, 1],
                                   [1, 0, 0, 0, 0], [0, 0, 1, 0, 0]]])
     np.testing.assert_array_equal(encoded_vectors, expected_vectors)
コード例 #3
0
 def test_encode_bad_prediction_length(self):
     try:
         encoder = OneHotMatrixEncoder(1, -1)
     except NegativePredictionLengthException as e:
         pass
     except Exception as e:
         self.fail()
コード例 #4
0
 def test_encode_bad_length(self):
     try:
         encoder = OneHotMatrixEncoder(0)
     except NonpositiveLengthException as e:
         pass
     except Exception as e:
         self.fail()
コード例 #5
0
ファイル: OneHotVector.py プロジェクト: bcgsc/GapPredict
class OneHotVectorEncoder(_OneHotVectorUtil):
    def __init__(self, sequence_length, encoding_constants=CONSTANTS):
        super().__init__(sequence_length,
                         encoding_constants=encoding_constants)
        self.encoder = OneHotMatrixEncoder(
            sequence_length, encoding_constants=self.encoding_constants)

    def encode_sequences(self, integer_encoding):
        if len(integer_encoding) == 0:
            return np.array([])

        cube = self.encoder.encode_sequences(integer_encoding)
        encoding_length = len(self.encoding_constants.ONE_HOT_ENCODING)
        dimensions = (len(cube), encoding_length * self.sequence_length)
        encoded_matrix = cube.reshape(dimensions)

        return encoded_matrix
コード例 #6
0
ファイル: OneHotVector.py プロジェクト: bcgsc/GapPredict
 def __init__(self, sequence_length, encoding_constants=CONSTANTS):
     super().__init__(sequence_length,
                      encoding_constants=encoding_constants)
     self.encoder = OneHotMatrixEncoder(
         sequence_length, encoding_constants=self.encoding_constants)
コード例 #7
0
 def test_encode_empty_array(self):
     encoder = OneHotMatrixEncoder(4)
     sequences = np.array([])
     encoded_vectors = encoder.encode_sequences(sequences)
     expected_vectors = np.array([])
     np.testing.assert_array_equal(encoded_vectors, expected_vectors)