Example #1
0
    def test_prep_row_priors(self):
        """prepare row priors."""

        # let ref universe have two annotations and one null
        refA = Representation(data=dict(a=1), name="refA")
        refA.defaults(zerovals)
        refB = Representation(data=dict(a=1, b=0.8), name="refB")
        refB.defaults(zerovals)
        rs = ReferenceSet(dict(refA=0.5, refB=0.5), ids=zerovals.keys())
        rs.add(refA).add(refB)
        # compute feature priors
        rs.prep()
        # row_priors should gain key/values for all features
        expected_features = set(zerovals.keys())
        self.assertEqual(set(rs.row_names), expected_features)
        # features declared in representations should get reasonable priors
        a_index = rs.rows["a"]
        b_index = rs.rows["b"]
        d_index = rs.rows["d"]
        self.assertEqual(rs.row_priors[a_index], 1,
                         "refA and refB both have a")
        self.assertEqual(rs.row_priors[b_index], 0.4,
                         "only refB has b, so 0.8/2")
        self.assertEqual(rs.row_priors[d_index], 0.2,
                         "value is 1/num features")
Example #2
0
    def test_keys(self):
        """setting and getting from a generic representation."""

        rr = Representation(dict(xyz=0.2))
        rr.set("bob", 0.4)
        rr.set("xyz", 0.3)
        rr.defaults(self.defaults)
        self.assertEqual(rr.keys(), ["abc", "xyz", "bob"],
                         "keys should have defaults and non-defaults")
Example #3
0
    def setUp(self):
        """prepare a reference set with some data."""

        # let ref universe have two annotations and one null
        refA = Representation(data=dict(a=1, b=0.8), name="refA")
        refA.defaults(zerovals)
        refB = Representation(data=dict(a=1, d=0.2), name="refB")
        refB.defaults(zerovals)
        self.rs = ReferenceSet(dict(null=0.7, refA=0.15, refB=0.15),
                               ids=zerovals.keys())
        self.rs.add(refA).add(refB)
        self.rs.prep()
Example #4
0
    def test_general_representation_get(self):
        """setting and getting from a generic representation."""

        rr = Representation(dict(xyz=0.2))
        rr.set("bob", 0.4)
        rr.set("xyz", 0.3)
        rr.defaults(self.defaults)
        self.assertEqual(rr.get("bob"), 0.4,
                         "value should come from manual input")
        self.assertEqual(rr.get("abc"), 0.1,
                         "value should come from defaults dict")
        self.assertEqual(rr.get("xyz"), 0.3,
                         "value should come from manual override")
Example #5
0
    def test_general_representation_get2(self):
        """setting and getting from a generic representation."""

        # Similar to previous, but setting defaults before the specifics
        rr = Representation(dict(abc=0.1, xyz=0.2))
        rr.defaults(self.defaults)
        rr.set("bob", 0.4)
        rr.set("xyz", 0.3)
        self.assertEqual(rr.get("bob"), 0.4,
                         "value should come from manual input")
        self.assertEqual(rr.get("abc"), 0.1,
                         "value should come from defaults dict")
        self.assertEqual(rr.get("xyz"), 0.3,
                         "value should come from manual override")