Esempio n. 1
0
 def test_reshape_class1(self):
     # 3 instances, each having 2 features
     batch1 = [[[11, 12], 1], [[21, 22], 2], [[31, 32], 3]]
     batch1_reshape = Dataset.reshape_batch_helper(batch1,
                                                   n_features=2,
                                                   is_sequence=False)
     # print("DEBUG: reshape_class_1: batch1_reshape=", batch1_reshape, file=sys.stderr)
     assert batch1_reshape == ([[11, 21, 31], [12, 22, 32]], [1, 2, 3])
     batch1_reshape_np = Dataset.reshape_batch_helper(batch1,
                                                      as_numpy=True,
                                                      n_features=2,
                                                      is_sequence=False)
Esempio n. 2
0
    def test_reshape_seq1(self):
        # test reshaping sequence learning batches
        # a simple tiny batch of 3 sequences of feature vectors, each having 2 features and a target
        # the sequence lengths are 1,4,2
        batch1 = [[[[111, 112]], [-11]],
                  [[[211, 212], [221, 222], [231, 232], [241, 242]],
                   [-21, -22, -23, -23]], [[[311, 312], [321, 322]],
                                           [-31, -32]]]
        # print("DEBUG: reshape_seq1: batch1=", batch1, file=sys.stderr)
        batch1_reshape = Dataset.reshape_batch_helper(
            batch1, feature_types=["index", "index"], is_sequence=True)
        # print("DEBUG: reshape_seq1: batch1_reshape=\n", batch1_reshape, file=sys.stderr)
        # print("DEBUG: expected: \n",
        #       [
        #           [[111, 0, 0, 0], [211, 221, 231, 241], [311, 321, 0, 0]],
        #           [[112, 0, 0, 0], [212, 222, 232, 242], [312, 322, 0, 0]]
        #       ],
        #       [
        #           [-11, -1, -1, -1], [-21, -22, -23, -23], [-31, -32, -1, -1]
        #       ], file=sys.stderr)

        assert batch1_reshape == ([[[111, 0, 0, 0], [211, 221, 231, 241],
                                    [311, 321, 0, 0]],
                                   [[112, 0, 0, 0], [212, 222, 232, 242],
                                    [312, 322, 0, 0]]], [[-11, -1, -1, -1],
                                                         [-21, -22, -23, -23],
                                                         [-31, -32, -1, -1]])
Esempio n. 3
0
 def test_reshape_class1a(self):
     # 3 instances, each having 2 features, this time indep only
     batch1 = [
         [11, 12],
         [21, 22],
         [31, 32],
     ]
     batch1_reshape = Dataset.reshape_batch_helper(batch1,
                                                   n_features=2,
                                                   is_sequence=False,
                                                   indep_only=True)
     # print("DEBUG: reshape_class_1a: batch1_reshape=", batch1_reshape, file=sys.stderr)
     assert batch1_reshape == [[11, 21, 31], [12, 22, 32]]
     batch1_reshape_np = Dataset.reshape_batch_helper(batch1,
                                                      as_numpy=True,
                                                      n_features=2,
                                                      is_sequence=False,
                                                      indep_only=True)
Esempio n. 4
0
 def test_reshape_class2(self):
     # 3 instances, each having 2 features, both features are sequences
     # feature value numbers indicate: instance, feature number, sequence element
     # Sequence lengths of first feature: 3, 2, 1,
     # Sequence lengths of second feature: 1, 4, 2
     batch1 = [[[[111, 112, 113], [121]], 1],
               [[[211, 212], [221, 222, 223, 224]], 2],
               [[[311], [321, 322]], 3]]
     batch1_reshape = Dataset.reshape_batch_helper(batch1,
                                                   n_features=2,
                                                   is_sequence=False)
     # print("DEBUG: reshape_class_2: batch1_reshape=", batch1_reshape, file=sys.stderr)
     assert batch1_reshape == ([[[111, 112, 113], [211, 212, 0],
                                 [311, 0, 0]],
                                [[121, 0, 0, 0], [221, 222, 223, 224],
                                 [321, 322, 0, 0]]], [1, 2, 3])
     batch1_reshape_np = Dataset.reshape_batch_helper(batch1,
                                                      as_numpy=True,
                                                      n_features=2,
                                                      is_sequence=False)