Commit 42d11aa5 authored by Adam Paquette's avatar Adam Paquette
Browse files

fixed up outlier_detector, wrote a few tests for suppression

parent ade893e1
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -224,6 +224,7 @@ class SpatialSuppression(Observable):

                if cell == False:
                    result.append(idx)
                    x = len(result)
                    pts.append((p[['x', 'y']]))
                    if len(result) > self.k + self.k * self.error_k:
                        # Too many points, break
@@ -256,10 +257,17 @@ class SpatialSuppression(Observable):
            elif len(result) < self.k:
                # The radius is too large
                max_idx = mid_idx
                if max_idx == 0:
                    warnings.warn('Unable to retrieve {} points. Consider reducing the amount of points you request(k)'
                                  .format(self.k))
                    break
            elif min_idx == mid_idx or mid_idx == max_idx:
                warnings.warn('Unable to optimally solve.  Returning with {} points'.format(len(result)))
                break

            if len(result) == self.k:
                x = 0

        self.mask = pd.Series(False, self.df.index)
        self.mask.loc[list(result)] = True
        state_package = {'mask':self.mask,
+20 −5
Original line number Diff line number Diff line
@@ -94,12 +94,27 @@ class TestSpatialSuppression(unittest.TestCase):
        self.suppression_obj.suppress()
        self.assertIn(self.suppression_obj.mask.sum(), list(range(27, 34)))

    def spatial_suppression_testing(self):
    def spatial_suppression_edge_testing(self):
        r = np.random.RandomState(12345)
        df = pd.DataFrame(r.uniform(0,4,(500, 3)), columns=['x', 'y', 'strength'])
        minimum = SpatialSuppression(df, (4,4), k = 1)

        minimum.suppress()
        df.plot(kind = 'scatter', x = 'x', y = 'y')
        df1 = pd.DataFrame(r.uniform(0,1,(500, 3)), columns=['x', 'y', 'strength'])
        sup1 = SpatialSuppression(df1, (1,1), k = 1)
        self.assertRaises(ValueError, sup1.suppress)


        df2 = pd.DataFrame(r.uniform(0,6,(500, 3)), columns=['x', 'y', 'strength'])
        sup2 = SpatialSuppression(df2, (6,6), k = 4)
        sup2.suppress()
        self.assertEqual(len(df2[sup2.mask]), 4)

        df3 = pd.DataFrame(r.uniform(0,100,(500, 3)), columns=['x', 'y', 'strength'])
        sup3 = SpatialSuppression(df3, (100,100), k = 15)
        sup3.suppress()
        self.assertEqual(len(df3[sup3.mask]), 17)

        df4 = pd.DataFrame(r.uniform(0,100,(500, 3)), columns=['x', 'y', 'strength'])
        sup4 = SpatialSuppression(df4, (100,100), k = 100)
        sup4.suppress()
        self.assertEqual(len(df4[sup4.mask]), 111)

+508 −90

File changed.

Preview size limit exceeded, changes collapsed.