Commit 261d77a0 authored by Adam Paquette's avatar Adam Paquette
Browse files

final edits to outlier detector

parent 9b07b36c
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -138,7 +138,7 @@ class SpatialSuppression(Observable):

    """

    def __init__(self, df, domain, min_radius=1, k=250, error_k=0.1):
    def __init__(self, df, domain, min_radius=1.5, k=250, error_k=0.1):
        columns = df.columns
        for i in ['x', 'y', 'strength']:
            if i not in columns:
@@ -182,7 +182,7 @@ class SpatialSuppression(Observable):
            self.k = len(self.df)
            result = self.df.index
            process = False
        search_space = np.linspace(self.min_radius, self.max_radius, 250)
        search_space = np.linspace(self.min_radius, self.max_radius, 100)
        cell_sizes = search_space / math.sqrt(2)
        min_idx = 0
        max_idx = len(search_space) - 1
@@ -242,6 +242,7 @@ class SpatialSuppression(Observable):
                    grid[y_min: y_max,
                         x_min: x_max] = True


            #  Check break conditions
            if self.k - self.k * self.error_k <= len(result) <= self.k + self.k * self.error_k:
                process = False
@@ -251,6 +252,7 @@ class SpatialSuppression(Observable):
                if max_idx == 0:
                    warnings.warn('Unable to retrieve {} points. Consider reducing the amount of points you request(k)'
                                  .format(self.k))
                    process = False
                if min_idx == max_idx:
                    process = False
            elif min_idx == mid_idx or mid_idx == max_idx:
+4 −4
Original line number Diff line number Diff line
@@ -104,13 +104,13 @@ class TestSpatialSuppression(unittest.TestCase):

        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)
        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)
        df2 = pd.DataFrame(r.uniform(0,25,(500, 3)), columns=['x', 'y', 'strength'])
        sup2 = SpatialSuppression(df2, (25,25), k = 25)
        sup2.suppress()
        self.assertEqual(len(df2[sup2.mask]), 4)
        self.assertEqual(len(df2[sup2.mask]), 25)

        df3 = pd.DataFrame(r.uniform(0,100,(500, 3)), columns=['x', 'y', 'strength'])
        sup3 = SpatialSuppression(df3, (100,100), k = 15)
+132 −93

File changed.

Preview size limit exceeded, changes collapsed.