Exemplo n.º 1
0
    def test_set_gold(self):
        swap = SWAP()
        labels = {0: 1, 1: 1, 2: 0, 3: 0}
        swap.set_gold_labels(labels)

        b = swap.subjects
        for i, g in labels.items():
            assert i in b
            assert b.get(i).gold == g
Exemplo n.º 2
0
    def test_set_gold_negates(self):
        swap = SWAP()
        subject = Subject(0)
        subject._gold = 1
        swap.subjects.add(subject)

        swap.set_gold_labels({})

        print(type(subject.gold))
        print(subject.gold)
        assert subject.gold == -1
Exemplo n.º 3
0
    def test_manifest(self):
        swap = SWAP()
        golds = {0: 1, 1: 1, 2: 0, 3: 0}
        swap.set_gold_labels(golds)

        for x in range(10):
            for y in range(10):
                swap.classify(Classification(x, y, 0))
        swap.process_changes()

        print(swap.manifest())
Exemplo n.º 4
0
    def test_init(self):
        swap = SWAP()

        assert type(swap.users) is Bureau
        assert type(swap.subjects) is Bureau
        assert swap.users.agent_type is User
        assert swap.subjects.agent_type is Subject
Exemplo n.º 5
0
    def test_classify_subject(self):
        swap = SWAP()
        u = User(1)
        s = Subject(2)
        s._gold = 1

        u.classify = MagicMock()
        s.classify = MagicMock()

        swap.users.add(u)
        swap.subjects.add(s)

        cl = Classification(1, 2, 0, 0)
        swap.classify(cl, subject=True, user=False)

        u.classify.assert_not_called()
        s.classify.assert_called_with(cl, u)
Exemplo n.º 6
0
    def test_stats(self):
        swap = SWAP()
        golds = {0: 1, 1: 1, 2: 0, 3: 0}
        swap.set_gold_labels(golds)

        for x in range(10):
            for y in range(10):
                swap.classify(Classification(x, y, 0))
        swap.process_changes()

        stats = swap.stats
        print(stats)
        assert type(stats) is Stats
Exemplo n.º 7
0
    def test_doesnt_override_golds(self):
        swap = SWAP()
        golds = {1: 1, 2: 0, 3: 0}
        swap.set_gold_labels(golds)

        bureau = swap.subjects
        print(bureau)

        cl = Classification(0, 2, 0)
        cl.gold = 1
        swap.classify(cl)
        swap.process_changes()
        print(bureau.get(1))
        assert bureau.get(2).gold == 0
Exemplo n.º 8
0
def main():

    client = MongoClient()
    db = client.SNHunters

    mjd_limits = get_date_limits_from_manifest("../data/20160725.txt")
    min_mjd = mjd_limits[0]
    mjd_limits = get_date_limits_from_manifest("../data/20160829.txt")
    max_mjd = mjd_limits[1]
    mjd_limits = (min_mjd, max_mjd)
    print mjd_limits
    #subjects = get_subjects_by_date_limits(db, mjd_limits)

    subjects = np.squeeze(
        sio.loadmat("swap_20160725-20160829.mat")["subjects"]).tolist()
    ids = np.squeeze(sio.loadmat("swap_20160725-20160829.mat")["ids"]).tolist()

    mag_bin_to_subjects_map = split_subjects_on_magnitude(db, subjects)

    out = open("mag_bin_to_subjects_map_20160725-20160829.pkl", "wb")
    pickle.dump(mag_bin_to_subjects_map, out)
    out.close()

    mag_bin_to_subjects_map = \
        pickle.load(open("mag_bin_to_subjects_map_20160725-20160829.pkl","rb"))

    #Run separate swap instances for each magnitude bin.

    #### 13 <= mag < 19
    subjects = mag_bin_to_subjects_map[13] + mag_bin_to_subjects_map[14] + \
               mag_bin_to_subjects_map[15] + mag_bin_to_subjects_map[16] + \
               mag_bin_to_subjects_map[17] + mag_bin_to_subjects_map[18]

    swap = SWAP(db, subjects, p0=0.1, epsilon=0.5)
    swap.process()
    swap.save("swap_20160725-20160829_13-18.mat")

    #### 19 <= mag < 20
    subjects = mag_bin_to_subjects_map[19]

    swap = SWAP(db, subjects, p0=0.1, epsilon=0.5)
    swap.process()
    swap.save("swap_20160725-20160829_19.mat")

    #### 20 <= mag < 21
    subjects = mag_bin_to_subjects_map[20]

    swap = SWAP(db, subjects, p0=0.1, epsilon=0.5)
    swap.process()
    swap.save("swap_20160725-20160829_20.mat")

    #### 21 <= mag < 23
    subjects = mag_bin_to_subjects_map[21] + mag_bin_to_subjects_map[22]

    swap = SWAP(db, subjects, p0=0.1, epsilon=0.5)
    swap.process()
    swap.save("swap_20160725-20160829_21-22.mat")
Exemplo n.º 9
0
 def test_stats_empty(self):
     swap = SWAP()
     swap.stats
Exemplo n.º 10
0
    def test_get_gold(self):
        swap = SWAP()
        labels = {0: 1, 1: 1, 2: 0, 3: 0}
        swap.set_gold_labels(labels)

        assert swap.golds == labels