示例#1
0
    def testMegaComplexRecursion(self):
        #pass
        '''         
             0                            1                      2
             +----------------------------+----------------------+
             |            0.5             |         1.5          |
             | +-----------+------------+ | +--------+---------+ |
             | |    0.25   |            | | |        |         | |
             | | +---+---+ |            | | |        |         | |
             | | | 1 | 2 | |     0      | | |   3    |    4    | |
             | | +---+---+ |            | | |        |         | |
             | +-----------+------------+ | +--------+---------+ |
             +---------------------------------------------------+    
        '''
        outer_mapper = FuncBinMapper(self.fn1, 2)
        middle_mapper1 = FuncBinMapper(self.fn2, 2)
        middle_mapper2 = FuncBinMapper(self.fn4, 2)
        inner_mapper = FuncBinMapper(self.fn3, 2)

        rmapper = RecursiveBinMapper(outer_mapper)
        rmapper.add_mapper(middle_mapper1, [0.5])
        rmapper.add_mapper(inner_mapper, [0.25])
        rmapper.add_mapper(middle_mapper2, [1.5])

        assert rmapper.nbins == 5
        coords = numpy.array([[0.1], [0.2], [0.3], [0.4], [0.6], [1.1], [1.6]])
        output = rmapper.assign(coords)
        assert list(output) == [1, 1, 2, 2, 0, 3, 4]
示例#2
0
    def testDeepRecursion(self):
        #pass
        '''
         0                            1                      2
         +----------------------------+----------------------+
         |            0.5             |                      |
         | +-----------+------------+ |                      |
         | |    0.25   |            | |                      |
         | | +---+---+ |            | |           0          |
         | | | 2 | 3 | |     1      | |                      |
         | | +---+---+ |            | |                      |
         | +-----------+------------+ |                      |
         +---------------------------------------------------+    
        '''

        outer_mapper = FuncBinMapper(self.fn1, 2)
        middle_mapper = FuncBinMapper(self.fn2, 2)
        inner_mapper = FuncBinMapper(self.fn3, 2)

        rmapper = RecursiveBinMapper(outer_mapper)
        rmapper.add_mapper(middle_mapper, [0.5])
        rmapper.add_mapper(inner_mapper, [0.25])

        assert rmapper.nbins == 4
        coords = numpy.array([[0.1], [0.2], [0.3], [0.4], [0.6], [1.1]])
        output = rmapper.assign(coords)
        assert list(output) == [2, 2, 3, 3, 1, 0]
示例#3
0
    def testSideBySideRecursion(self):
        #pass
        '''         
             0                            1                      2
             +----------------------------+----------------------+
             |            0.5             |         1.5          |
             | +-----------+------------+ | +--------+---------+ |
             | |           |            | | |        |         | |
             | |     0     |     1      | | |   2    |    3    | |
             | |           |            | | |        |         | |
             | |           |            | | |        |         | |
             | +-----------+------------+ | +--------+---------+ |
             +---------------------------------------------------+    
        '''
        outer_mapper = FuncBinMapper(self.fn1, 2)
        middle_mapper2 = FuncBinMapper(self.fn2, 2)
        middle_mapper1 = FuncBinMapper(self.fn4, 2)

        rmapper = RecursiveBinMapper(outer_mapper)
        rmapper.add_mapper(middle_mapper1, [1.5])
        rmapper.add_mapper(middle_mapper2, [0.5])

        assert rmapper.nbins == 4
        coords = numpy.array([[0.1], [0.2], [0.3], [0.4], [0.6], [1.1], [1.6]])
        output = rmapper.assign(coords)
        assert list(output) == [0, 0, 0, 0, 1, 2, 3]
示例#4
0
 def testMegaComplexRecursion(self):
     #pass
     '''         
          0                            1                      2
          +----------------------------+----------------------+
          |            0.5             |         1.5          |
          | +-----------+------------+ | +--------+---------+ |
          | |    0.25   |            | | |        |         | |
          | | +---+---+ |            | | |        |         | |
          | | | 1 | 2 | |     0      | | |   3    |    4    | |
          | | +---+---+ |            | | |        |         | |
          | +-----------+------------+ | +--------+---------+ |
          +---------------------------------------------------+    
     '''
     outer_mapper = FuncBinMapper(self.fn1,2)
     middle_mapper1 = FuncBinMapper(self.fn2,2)
     middle_mapper2 = FuncBinMapper(self.fn4,2)
     inner_mapper = FuncBinMapper(self.fn3,2)
     
     rmapper = RecursiveBinMapper(outer_mapper)
     rmapper.add_mapper(middle_mapper1, [0.5])
     rmapper.add_mapper(inner_mapper, [0.25])        
     rmapper.add_mapper(middle_mapper2, [1.5])
     
     
     assert rmapper.nbins == 5
     coords = numpy.array([[0.1], [0.2], [0.3], [0.4], [0.6], [1.1], [1.6]])
     output = rmapper.assign(coords)
     assert list(output) == [1,1,2,2,0,3,4]
示例#5
0
    def testSideBySideRecursion(self):
        #pass
        '''         
             0                            1                      2
             +----------------------------+----------------------+
             |            0.5             |         1.5          |
             | +-----------+------------+ | +--------+---------+ |
             | |           |            | | |        |         | |
             | |     0     |     1      | | |   2    |    3    | |
             | |           |            | | |        |         | |
             | |           |            | | |        |         | |
             | +-----------+------------+ | +--------+---------+ |
             +---------------------------------------------------+    
        '''
        outer_mapper = FuncBinMapper(self.fn1,2)
        middle_mapper2 = FuncBinMapper(self.fn2,2)
        middle_mapper1 = FuncBinMapper(self.fn4,2)

        
        rmapper = RecursiveBinMapper(outer_mapper)
        rmapper.add_mapper(middle_mapper1, [1.5])
        rmapper.add_mapper(middle_mapper2, [0.5])
        
        assert rmapper.nbins == 4
        coords = numpy.array([[0.1], [0.2], [0.3], [0.4], [0.6], [1.1], [1.6]])
        output = rmapper.assign(coords)
        assert list(output) == [0,0,0,0,1,2,3]
示例#6
0
 def testDeepRecursion(self):
     #pass
 
     '''
      0                            1                      2
      +----------------------------+----------------------+
      |            0.5             |                      |
      | +-----------+------------+ |                      |
      | |    0.25   |            | |                      |
      | | +---+---+ |            | |           0          |
      | | | 2 | 3 | |     1      | |                      |
      | | +---+---+ |            | |                      |
      | +-----------+------------+ |                      |
      +---------------------------------------------------+    
     '''
     
     outer_mapper = FuncBinMapper(self.fn1,2)
     middle_mapper = FuncBinMapper(self.fn2,2)
     inner_mapper  = FuncBinMapper(self.fn3,2)
     
     rmapper = RecursiveBinMapper(outer_mapper)
     rmapper.add_mapper(middle_mapper, [0.5])
     rmapper.add_mapper(inner_mapper, [0.25])
     
     assert rmapper.nbins == 4
     coords = numpy.array([[0.1], [0.2], [0.3], [0.4], [0.6], [1.1]])
     output = rmapper.assign(coords)
     assert list(output) == [2, 2, 3, 3, 1, 0]
示例#7
0
    def testOuterMapperWithOffset(self):
        #pass
        '''         
             0                            1                      2
             +----------------------------+----------------------+
             |              1             |          2           |
             +---------------------------------------------------+    
        '''

        mapper = FuncBinMapper(self.fn1, 2)
        rmapper = RecursiveBinMapper(mapper, 1)
        coords = numpy.array([[0.1], [0.2], [0.3], [0.4], [0.6], [1.1]])
        output = rmapper.assign(coords)
        assert list(output) == [1, 1, 1, 1, 1, 2]
示例#8
0
    def testOuterMapperWithOffset(self):
        #pass
        '''         
             0                            1                      2
             +----------------------------+----------------------+
             |              1             |          2           |
             +---------------------------------------------------+    
        '''

        mapper = FuncBinMapper(self.fn1,2)
        rmapper = RecursiveBinMapper(mapper,1)
        coords = numpy.array([[0.1], [0.2], [0.3], [0.4], [0.6], [1.1]])
        output = rmapper.assign(coords)
        assert list(output) == [1,1,1,1,1,2]
示例#9
0
    def test2dRectilinearRecursion(self):
        '''
             0                            1                      2
             +----------------------------+----------------------+
             |                            |         1.5          |
             |                            | +--------+---------+ |
             |                            | |        |         | |
             |             0              | |   3    |   4     | |
             |                            | |        |         | |
             |                            | |        |         | |
             |                            | +--------+---------+ |
            1+---------------------------------------------------+
             |            0.5             |                      |
             | +-----------+------------+ |                      |
             | |           |            | |                      |
             | |    1      |     2      | |           5          |
             | |           |            | |                      |
             | |           |            | |                      |
             | +-----------+------------+ |                      |
            2+---------------------------------------------------+

        '''

        outer_mapper = RectilinearBinMapper([[0, 1, 2], [0, 1, 2]])

        upper_right_mapper = RectilinearBinMapper([[1, 1.5, 2], [0, 1]])
        lower_left_mapper = RectilinearBinMapper([[0, 0.5, 1], [1, 2]])

        rmapper = RecursiveBinMapper(outer_mapper)
        rmapper.add_mapper(upper_right_mapper, [1.5, 0.5])
        rmapper.add_mapper(lower_left_mapper, [0.5, 1.5])

        pairs = [(0.5, 0.5), (1.25, 0.5), (1.75, 0.5), (0.25, 1.5),
                 (0.75, 1.5), (1.5, 1.5)]

        assert rmapper.nbins == 6
        assignments = rmapper.assign(pairs)
        expected = [0, 3, 4, 1, 2, 5]
        print('PAIRS', pairs)
        print('LABELS', list(rmapper.labels))
        print('EXPECTED', expected)
        print('OUTPUT  ', assignments)
        assert (assignments == expected).all()
示例#10
0
    def test2dRectilinearRecursion(self):
        '''
             0                            1                      2
             +----------------------------+----------------------+
             |                            |         1.5          |
             |                            | +--------+---------+ |
             |                            | |        |         | |
             |             0              | |   4    |   5     | |
             |                            | |        |         | |
             |                            | |        |         | |
             |                            | +--------+---------+ |
            1+---------------------------------------------------+
             |            0.5             |                      |
             | +-----------+------------+ |                      |
             | |           |            | |                      |
             | |    2      |     3      | |           1          |
             | |           |            | |                      |
             | |           |            | |                      |
             | +-----------+------------+ |                      |
            2+---------------------------------------------------+

        '''

        outer_mapper = RectilinearBinMapper([[0,1,2],[0,1,2]])

        upper_right_mapper = RectilinearBinMapper([[1,1.5,2],[0,2]])
        lower_left_mapper = RectilinearBinMapper([[0,0.5,1], [0,2]])

        rmapper = RecursiveBinMapper(outer_mapper)
        rmapper.add_mapper(upper_right_mapper, [1.5,0.5])
        rmapper.add_mapper(lower_left_mapper, [0.5, 1.5])


        pairs = [(0.5, 0.5), (1.25, 0.5), (1.75, 0.5),
                 (0.25, 1.5), (0.75, 1.5), (1.5, 1.5)]

        assert rmapper.nbins == 6
        assert (rmapper.assign(pairs) == [0,4,5,2,3,1]).all()
示例#11
0
    def testSingleRecursion(self):
        #pass
        '''         
             0                            1                      2
             +----------------------------+----------------------+
             |            0.5             |                      |
             | +-----------+------------+ |                      |
             | |           |            | |                      |
             | |     1     |     2      | |          0           |
             | |           |            | |                      |
             | |           |            | |                      |
             | +-----------+------------+ |                      |
             +---------------------------------------------------+    
        '''

        outer_mapper = FuncBinMapper(self.fn1, 2)
        inner_mapper = FuncBinMapper(self.fn2, 2)
        rmapper = RecursiveBinMapper(outer_mapper)
        rmapper.add_mapper(inner_mapper, [0.5])
        assert rmapper.nbins == 3
        coords = numpy.array([[0.1], [0.2], [0.3], [0.4], [0.6], [1.1]])
        output = rmapper.assign(coords)
        assert list(output) == [1, 1, 1, 1, 2, 0]
示例#12
0
    def testSingleRecursion(self):
        #pass
    
        '''         
             0                            1                      2
             +----------------------------+----------------------+
             |            0.5             |                      |
             | +-----------+------------+ |                      |
             | |           |            | |                      |
             | |     1     |     2      | |          0           |
             | |           |            | |                      |
             | |           |            | |                      |
             | +-----------+------------+ |                      |
             +---------------------------------------------------+    
        '''

        outer_mapper = FuncBinMapper(self.fn1,2)
        inner_mapper = FuncBinMapper(self.fn2,2)
        rmapper = RecursiveBinMapper(outer_mapper)
        rmapper.add_mapper(inner_mapper, [0.5])
        assert rmapper.nbins == 3
        coords = numpy.array([[0.1], [0.2], [0.3], [0.4], [0.6], [1.1]])
        output = rmapper.assign(coords)
        assert list(output) == [1, 1, 1, 1, 2, 0]