示例#1
0
    def test_merge_fifty_fifty_same_doms(self):
        dom = {0:2, 1:1}        
        dim = {0:{0:1, 1:1}, 1:{2:3, 3:2.0}}
        w = Weights(dom, dim)

        dom2 = {0:1, 1:1}        
        dim2 = {0:{0:0.5, 1:0.5}, 1:{2:0.5, 3:0.5}}
        w2 = Weights(dom2, dim2)
        
        dom_res = {0:(7.0/6.0), 1:(5.0/6.0)}
        dim_res = {0:{0:0.5, 1:0.5}, 1:{2:0.55, 3:0.45}}
        w_res = Weights(dom_res, dim_res)

        self.assertEqual(w.merge_with(w2), w_res)
        self.assertEqual(w.merge_with(w2), w2.merge_with(w))        
示例#2
0
    def test_merge_overlapping_doms(self):
        dom = {0:2, 1:1}        
        dim = {0:{0:1, 1:1}, 1:{2:3, 3:2.0}}
        w = Weights(dom, dim)

        dom2 = {1:1, 2:2}        
        dim2 = {1:{2:0.5, 3:0.5}, 2:{4:1, 5:1, 6:2}}
        w2 = Weights(dom2, dim2)
        
        dom_res = {0:(4.0)/3, 1:(2.0)/3, 2:4.0/3}
        dim_res = {0:{0:0.5, 1:0.5}, 1:{2:0.55, 3:0.45}, 2:{4:0.25, 5:0.25, 6:0.5}}
        w_res = Weights(dom_res, dim_res)

        self.assertEqual(w.merge_with(w2), w_res)
        self.assertEqual(w.merge_with(w2), w2.merge_with(w))        
示例#3
0
    def test_merge_different_doms(self):
        dom = {1:1}        
        dim = {1:{2:3, 3:2.0}}
        w = Weights(dom, dim)

        dom2 = {0:1}        
        dim2 = {0:{0:0.5, 1:0.5}}
        w2 = Weights(dom2, dim2)
        
        dom_res = {0:1, 1:1}
        dim_res = {0:{0:0.5, 1:0.5}, 1:{2:0.6, 3:0.4}}
        w_res = Weights(dom_res, dim_res)

        self.assertEqual(w.merge_with(w2), w_res)
        self.assertEqual(w.merge_with(w2), w2.merge_with(w))        
示例#4
0
    def test_merge_three_to_one_same_doms(self):
        dom = {0:2, 1:1}        
        dim = {0:{0:1, 1:1}, 1:{2:3, 3:2.0}}
        w = Weights(dom, dim)

        dom2 = {0:1, 1:1}        
        dim2 = {0:{0:0.5, 1:0.5}, 1:{2:0.5, 3:0.5}}
        w2 = Weights(dom2, dim2)
        
        dom_res = {0:1.25, 1:0.75}
        dim_res = {0:{0:0.5, 1:0.5}, 1:{2:0.575, 3:0.42500000000000004}} # weird rounding error in python!
        w_res = Weights(dom_res, dim_res)
        
        self.assertEqual(w.merge_with(w2, 0.75, 0.75), w_res)
        self.assertEqual(w.merge_with(w2, 0.75, 0.75), w2.merge_with(w, 0.25, 0.25))        
示例#5
0
    def test_merge_identity(self):
        dom = {0:2, 1:1}        
        dim = {0:{0:1, 1:1}, 1:{2:3, 3:2.0}}

        w = Weights(dom, dim)
        self.assertEqual(w.merge_with(w), w)