Exemplo n.º 1
0
    def test_PAA_Discretization_Difference(self):
        msg = ""
        res = True

        d = EqualWidth(2, 0, window_size=1)
        p2t = {1: []}
        p2t[1] = [
            TimeStamp(-75, 1, 1, 0),
            TimeStamp(-25, 2, 2, 0),
            TimeStamp(1, 3, 3, 0),
            TimeStamp(25, 4, 4, 0)
        ]  # min = -75, max = 25
        expected_cutpoints = {1: [-25]}
        d.discretize_property({}, {}, p2t, 1)
        real_cutpoints = d.bins_cutpoints
        t_res, t_msg = assert_almost_equality(expected_cutpoints,
                                              real_cutpoints)
        msg += t_msg
        res &= t_res

        no_paa_cutpoints = real_cutpoints

        d = EqualWidth(2, 0, window_size=2)
        p2t = {1: []}
        p2t[1] = [
            TimeStamp(-75, 1, 1, 0),
            TimeStamp(-25, 2, 2, 0),
            TimeStamp(1, 3, 3, 0),
            TimeStamp(25, 4, 4, 0)
        ]  # min = -50 max = 13
        expected_cutpoints = {1: [-50 + 63 / 2]}
        d.discretize_property({}, {}, p2t, 1)
        real_cutpoints = d.bins_cutpoints
        t_res, t_msg = assert_almost_equality(expected_cutpoints,
                                              real_cutpoints)
        if t_msg != "":
            t_msg = "\n" + t_msg
        msg += t_msg
        res &= t_res

        paa_cutpoints = real_cutpoints

        t_res, t_msg = assert_almost_equality({1: no_paa_cutpoints},
                                              {1: paa_cutpoints})
        if t_res:
            msg += "\nExpected different cutpoints with PAA! Got %s" % no_paa_cutpoints
            res = False

        self.assertTrue(res, msg)
Exemplo n.º 2
0
 def test_SAX_mechanics_PAA_identical(self):
     d = __SAX__(points_amount=3)
     vals = reduce(lambda x, y: x + y, [[i, i, i] for i in range(100)])
     expected = list(range(100))
     real, _ = d.to_paa(vals)
     res, msg = assert_almost_equality({1: expected}, {1: list(real)})
     self.assertTrue(res, msg)
Exemplo n.º 3
0
 def test_SAX_mechanics_normalize_std(self):
     d = __SAX__()
     vals = [i for i in range(100)]
     mean = 49.5
     std = 28.86607005
     normalized_vals = [(i - mean) / std for i in vals]
     real_vals = d.normalize(vals)
     res, msg = assert_almost_equality({1: normalized_vals}, {1: real_vals})
     self.assertTrue(res, msg)
Exemplo n.º 4
0
 def test_synthetic_EQF_5(self):
     d = EqualFrequency(5, 0)
     p2t = {1:[]}
     p2t[1] = [TimeStamp(-75,1,1,0),TimeStamp(25,1,1,0)] # min = -75, max = 25
     expected_cutpoints = {1:[-55,-35,-15,5]}
     d.discretize_property_without_abstracting({},{},p2t,1)
     real_cutpoints = d.bins_cutpoints
     res, msg = assert_almost_equality(expected_cutpoints,real_cutpoints)
     self.assertTrue(res,msg)
Exemplo n.º 5
0
 def test_synthetic_EQW_3(self):
     d = EqualWidth(3, 0)
     p2t = {1: []}
     p2t[1] = [TimeStamp(-75, 1, 1, 0), TimeStamp(25, 1, 1, 0)]  # min = -75, max = 25
     expected_cutpoints = {1: [-75 + 100/3, -75 + 200/3]}
     d.discretize_property_without_abstracting({}, {}, p2t, 1)
     real_cutpoints = d.bins_cutpoints
     res, msg = assert_almost_equality(expected_cutpoints, real_cutpoints)
     self.assertTrue(res, msg)
Exemplo n.º 6
0
 def test_synthetic_EQF_Stress_Big_Request_4(self):
     p2t = {1: [TimeStamp(i,1,1,0) for i in range(STRESS_VALUE_COUNT)]}
     max_index = STRESS_VALUE_COUNT - 1
     BIN_COUNT = 4
     d = EqualFrequency(BIN_COUNT, 0)
     d.discretize_property_without_abstracting({}, {}, p2t, 1)
     expected_res = {1:[i*max_index/BIN_COUNT for i in range(1,BIN_COUNT)]}
     res = d.bins_cutpoints
     res, msg = assert_almost_equality(expected_res,res)
     self.assertTrue(res,msg)
Exemplo n.º 7
0
def test_persist(PROPERTY_ID, expected, expected_scores):
    ACCURACY_MEASURE = 100
    res_bool = True
    msg = ""
    d = Persist(5, 0, 1, ACCURACY_MEASURE=ACCURACY_MEASURE)
    d.property_folder = PARTITIONS_PATH
    p2t = {}
    d.load_property_to_timestamps(p2t, PROPERTY_ID)
    d.discretize_property_without_abstracting({}, {}, p2t, PROPERTY_ID)
    res = d.cutoffs_according_to_order
    res_scores = d.chosen_scores
    t_res, t_msg = assert_almost_equality({PROPERTY_ID: expected}, res)
    if not t_res:
        msg += "\nCutoffs wrong!\n%s\n" % t_msg
        res_bool = False
    t_res, t_msg = assert_almost_equality({PROPERTY_ID: expected_scores}, res_scores)
    if not t_res:
        msg += "\nScores wrong!\n%s\n" % t_msg
        res_bool = False
    return msg, res_bool
Exemplo n.º 8
0
 def test_synthetic_stress_EQW_2(self):
     d = EqualWidth(2, 0)
     p2t = {1:[]}
     p2t[1] = [TimeStamp(3, 1, 1, 0)] * STRESS_VALUE_COUNT + [TimeStamp(-75, 1, 1, 0)] + [TimeStamp(3, 1, 1,
                                                                                                    0)] * STRESS_VALUE_COUNT + [
                  TimeStamp(25, 1, 1, 0)] + [TimeStamp(3, 1, 1, 0)] * STRESS_VALUE_COUNT  # min = -75, max = 25
     expected_cutpoints = {1:[-25]}
     d.discretize_property_without_abstracting({},{},p2t,1)
     real_cutpoints = d.bins_cutpoints
     res, msg = assert_almost_equality(expected_cutpoints,real_cutpoints)
     self.assertTrue(res,msg)
Exemplo n.º 9
0
    def test_real_EQF_FAAgeGroup_F3_Property_44(self):
        PROPERTY_ID = 44
        EXPECTED_RES = [0.71,0.84,0.95,1.1]

        d = EqualFrequency(5, 0)
        d.property_folder = PARTITIONS_PATH
        d.discretize_property_without_abstracting({}, {}, {}, PROPERTY_ID)
        real_cutpoints = d.bins_cutpoints
        expected_cutpoints = {PROPERTY_ID: EXPECTED_RES}
        res, msg = assert_almost_equality(expected_cutpoints, real_cutpoints)

        self.assertTrue(res,msg)
Exemplo n.º 10
0
 def test_synthetic_EQF_Stress_Many_Requests(self):
     res = True
     msg = ""
     p2t = {1: [TimeStamp(0,1,1,0),TimeStamp(1,1,1,0)]}
     for bin_count in range(2,10000):
         d = EqualFrequency(bin_count, 0)
         d.discretize_property_without_abstracting({},{},p2t,1)
         sum_real_cutpoints = sum(d.bins_cutpoints[1])
         expected_sum = (bin_count-1)/2
         t_res, t_msg = assert_almost_equality({1:[expected_sum]}, {1:[sum_real_cutpoints]})
         res &= t_res
         msg += t_msg
     self.assertTrue(res,msg)
Exemplo n.º 11
0
 def test_syntetic_cutpoint_generation(self):
     res = True
     msg = ""
     for c in range(2,1000):
         d = EqualWidth(c,0)
         p2t = {1: []}
         p2t[1] = [TimeStamp(-75, 1, 1, 0), TimeStamp(25, 1, 1, 0)]  # min = -75, max = 25
         interval = 100/c
         expected_cutpoints = {1: [-75+interval*i for i in range(1,c)]}
         d.discretize_property_without_abstracting({}, {}, p2t, 1)
         real_cutpoints = d.bins_cutpoints
         t_res, t_msg = assert_almost_equality(expected_cutpoints, real_cutpoints)
         res &= t_res
         msg += t_msg
     self.assertTrue(res, msg)
Exemplo n.º 12
0
def test_cutpoints(MAX, MIN, PROPERTY_ID):
    res = True
    msg = ""
    m1 = {}
    m2 = {}
    m3 = {}
    for c in range(2, 1000):
        d = EqualWidth(c, 0)
        d.property_folder = PARTITIONS_PATH
        expected_cutpoints = {PROPERTY_ID: generate_cutpoints(MIN, MAX, c)}
        d.discretize_property_without_abstracting(m1, m2, m3, PROPERTY_ID)
        real_cutpoints = d.bins_cutpoints
        t_res, t_msg = assert_almost_equality(expected_cutpoints, real_cutpoints)
        res &= t_res
        msg += t_msg
    return msg, res