コード例 #1
0
    def plot_contour(self, xv, yv, cost_grid):
        """
        Function constructs contour lines
        """
        contour = Contour(xv, yv, cost_grid)
        contour_lines = contour.contours(
            np.linspace(np.min(cost_grid), np.max(cost_grid), 20))

        series = []
        count = 0
        for key, value in contour_lines.items():
            for line in value:
                if len(line) > 3:
                    tck, u = splprep(np.array(line).T, u=None, s=0.0, per=0)
                    u_new = np.linspace(u.min(), u.max(), 100)
                    x_new, y_new = splev(u_new, tck, der=0)
                    interpol_line = np.c_[x_new, y_new]
                else:
                    interpol_line = line

                series.append(
                    dict(data=interpol_line,
                         color=self.contour_color,
                         type="spline",
                         lineWidth=0.5,
                         marker=dict(enabled=False),
                         name="%g" % round(key, 2),
                         enableMouseTracking=False))
                count += 1
        return series
コード例 #2
0
    def plot_contour(self, xv, yv, cost_grid):
        """
        Function constructs contour lines
        """
        contour = Contour(xv, yv, cost_grid)
        contour_lines = contour.contours(
            np.linspace(np.min(cost_grid), np.max(cost_grid), 20))

        series = []
        count = 0
        for key, value in contour_lines.items():
            for line in value:
                if len(line) > 3:
                    tck, u = splprep(np.array(line).T, u=None, s=0.0, per=0)
                    u_new = np.linspace(u.min(), u.max(), 100)
                    x_new, y_new = splev(u_new, tck, der=0)
                    interpol_line = np.c_[x_new, y_new]
                else:
                    interpol_line = line

                series.append(dict(data=interpol_line,
                                   color=self.contour_color,
                                   type="spline",
                                   lineWidth=0.5,
                                   showInLegend=False,
                                   marker=dict(enabled=False),
                                   name="%g" % round(key, 2),
                                   enableMouseTracking=False
                                   ))
                count += 1
        return series
コード例 #3
0
    def plot_contour(self):
        """
        Function constructs contour lines
        """
        self.scatter.remove_contours()
        if not self.data:
            return
        if self.contours_enabled:
            is_tree = type(self.learner) in [RandomForestLearner, TreeLearner]
            # tree does not need smoothing
            contour = Contour(
                self.xv, self.yv, self.probabilities_grid
                if is_tree else self.blur_grid(self.probabilities_grid))
            contour_lines = contour.contours(
                np.hstack(
                    (np.arange(0.5, 0, - self.contour_step)[::-1],
                     np.arange(0.5 + self.contour_step, 1, self.contour_step))))
            # we want to have contour for 0.5

            series = []
            count = 0
            for key, value in contour_lines.items():
                for line in value:
                    if (len(line) > self.degree and
                                type(self.learner) not in
                                [RandomForestLearner, TreeLearner]):
                        # if less than degree interpolation fails
                        tck, u = splprep(
                            [list(x) for x in zip(*reversed(line))],
                            s=0.001, k=self.degree,
                            per=(len(line)
                                 if np.allclose(line[0], line[-1])
                                 else 0))
                        new_int = np.arange(0, 1.01, 0.01)
                        interpol_line = np.array(splev(new_int, tck)).T.tolist()
                    else:
                        interpol_line = line

                    series.append(dict(data=self.labeled(interpol_line, count),
                                       color=self.contour_color,
                                       type="spline",
                                       lineWidth=0.5,
                                       showInLegend=False,
                                       marker=dict(enabled=False),
                                       name="%g" % round(key, 2),
                                       enableMouseTracking=False
                                       ))
                    count += 1
            self.scatter.add_series(series)
        self.scatter.redraw_series()
コード例 #4
0
    def plot_contour(self):
        """
        Function constructs contour lines
        """
        self.scatter.remove_contours()
        if not self.data:
            return
        if self.contours_enabled:
            is_tree = type(self.learner) in [RandomForestLearner, TreeLearner]
            # tree does not need smoothing
            contour = Contour(
                self.xv, self.yv, self.probabilities_grid
                if is_tree else self.blur_grid(self.probabilities_grid))
            contour_lines = contour.contours(
                np.hstack((np.arange(0.5, 0, -self.contour_step)[::-1],
                           np.arange(0.5 + self.contour_step, 1,
                                     self.contour_step))))
            # we want to have contour for 0.5

            series = []
            count = 0
            for key, value in contour_lines.items():
                for line in value:
                    if (len(line) > self.degree and type(self.learner)
                            not in [RandomForestLearner, TreeLearner]):
                        # if less than degree interpolation fails
                        tck, u = splprep(
                            [list(x) for x in zip(*reversed(line))],
                            s=0.001,
                            k=self.degree,
                            per=(len(line)
                                 if np.allclose(line[0], line[-1]) else 0))
                        new_int = np.arange(0, 1.01, 0.01)
                        interpol_line = np.array(splev(new_int,
                                                       tck)).T.tolist()
                    else:
                        interpol_line = line

                    series.append(
                        dict(data=self.labeled(interpol_line, count),
                             color=self.contour_color,
                             type="spline",
                             lineWidth=0.5,
                             showInLegend=False,
                             marker=dict(enabled=False),
                             name="%g" % round(key, 2),
                             enableMouseTracking=False))
                    count += 1
            self.scatter.add_series(series)
        self.scatter.redraw_series()
コード例 #5
0
    def test_contours(self):
        """
        Test if right amount of values
        """
        c = Contour(self.xv, self.yv, self.z_vertical_asc)
        c_lines = c.contours([1, 2, 3])

        # all line exists in particular data
        self.assertIn(1, c_lines.keys())
        self.assertIn(2, c_lines.keys())
        self.assertIn(3, c_lines.keys())

        # in particular data none line are in more peaces
        self.assertEqual(len(c_lines[1]), 1)
        self.assertEqual(len(c_lines[2]), 1)
        self.assertEqual(len(c_lines[3]), 1)

        c = Contour(self.xv, self.yv, self.z_vertical_desc)
        c_lines = c.contours([1, 2, 3])

        # all line exists in particular data
        self.assertIn(1, c_lines.keys())
        self.assertIn(2, c_lines.keys())
        self.assertIn(3, c_lines.keys())

        # in particular data none line are in more peaces
        self.assertEqual(len(c_lines[1]), 1)
        self.assertEqual(len(c_lines[2]), 1)
        self.assertEqual(len(c_lines[3]), 1)

        c = Contour(self.xv, self.yv, self.z_horizontal_asc)
        c_lines = c.contours([1, 2, 3])

        # all line exists in particular data
        self.assertIn(1, c_lines.keys())
        self.assertIn(2, c_lines.keys())
        self.assertIn(3, c_lines.keys())

        # in particular data none line are in more peaces
        self.assertEqual(len(c_lines[1]), 1)
        self.assertEqual(len(c_lines[2]), 1)
        self.assertEqual(len(c_lines[3]), 1)

        c = Contour(self.xv, self.yv, self.z_horizontal_desc)
        c_lines = c.contours([1, 2, 3])

        # all line exists in particular data
        self.assertIn(1, c_lines.keys())
        self.assertIn(2, c_lines.keys())
        self.assertIn(3, c_lines.keys())

        # in particular data none line are in more peaces
        self.assertEqual(len(c_lines[1]), 1)
        self.assertEqual(len(c_lines[2]), 1)
        self.assertEqual(len(c_lines[3]), 1)

        c = Contour(self.xv, self.yv, self.z_lt_rb_asc)
        c_lines = c.contours([1, 2, 3])

        # all line exists in particular data
        self.assertIn(1, c_lines.keys())
        self.assertIn(2, c_lines.keys())
        self.assertIn(3, c_lines.keys())

        # in particular data none line are in more peaces
        self.assertEqual(len(c_lines[1]), 1)
        self.assertEqual(len(c_lines[2]), 1)
        self.assertEqual(len(c_lines[3]), 1)

        c = Contour(self.xv, self.yv, self.z_lt_rb_desc)
        c_lines = c.contours([1, 2, 3])

        # all line exists in particular data
        self.assertIn(1, c_lines.keys())
        self.assertIn(2, c_lines.keys())
        self.assertIn(3, c_lines.keys())

        # in particular data none line are in more peaces
        self.assertEqual(len(c_lines[1]), 1)
        self.assertEqual(len(c_lines[2]), 1)
        self.assertEqual(len(c_lines[3]), 1)

        c = Contour(self.xv, self.yv, self.z_rt_lb_asc)
        c_lines = c.contours([1, 2, 3])

        # all line exists in particular data
        self.assertIn(1, c_lines.keys())
        self.assertIn(2, c_lines.keys())
        self.assertIn(3, c_lines.keys())

        # in particular data none line are in more peaces
        self.assertEqual(len(c_lines[1]), 1)
        self.assertEqual(len(c_lines[2]), 1)
        self.assertEqual(len(c_lines[3]), 1)

        c = Contour(self.xv, self.yv, self.z_rt_lb_desc)
        c_lines = c.contours([1, 2, 3])

        # all line exists in particular data
        self.assertIn(1, c_lines.keys())
        self.assertIn(2, c_lines.keys())
        self.assertIn(3, c_lines.keys())

        # in particular data none line are in more peaces
        self.assertEqual(len(c_lines[1]), 1)
        self.assertEqual(len(c_lines[2]), 1)
        self.assertEqual(len(c_lines[3]), 1)

        # test in cycle set
        c = Contour(self.xv_cycle, self.yv_cycle, self.cycle1)
        c_lines = c.contours([0.5])

        self.assertIn(0.5, c_lines.keys())
        self.assertEqual(len(c_lines[0.5]), 1)

        # test start with square 5, before only 10 was checked
        c = Contour(self.xv_cycle, self.yv_cycle, self.cycle2)
        c_lines = c.contours([0.5])

        self.assertIn(0.5, c_lines.keys())
        self.assertEqual(len(c_lines[0.5]), 1)

        # test no contours, then no key in dict
        c = Contour(self.xv_cycle, self.yv_cycle, self.cycle2)
        c_lines = c.contours([1.5])

        self.assertNotIn(1.5, c_lines.keys())
コード例 #6
0
    def test_contours(self):
        """
        Test if right amount of values
        """
        c = Contour(self.xv, self.yv, self.z_vertical_asc)
        c_lines = c.contours([1, 2, 3])

        # all line exists in particular data
        self.assertIn(1, c_lines.keys())
        self.assertIn(2, c_lines.keys())
        self.assertIn(3, c_lines.keys())

        # in particular data none line are in more peaces
        self.assertEqual(len(c_lines[1]), 1)
        self.assertEqual(len(c_lines[2]), 1)
        self.assertEqual(len(c_lines[3]), 1)

        c = Contour(self.xv, self.yv, self.z_vertical_desc)
        c_lines = c.contours([1, 2, 3])

        # all line exists in particular data
        self.assertIn(1, c_lines.keys())
        self.assertIn(2, c_lines.keys())
        self.assertIn(3, c_lines.keys())

        # in particular data none line are in more peaces
        self.assertEqual(len(c_lines[1]), 1)
        self.assertEqual(len(c_lines[2]), 1)
        self.assertEqual(len(c_lines[3]), 1)

        c = Contour(self.xv, self.yv, self.z_horizontal_asc)
        c_lines = c.contours([1, 2, 3])

        # all line exists in particular data
        self.assertIn(1, c_lines.keys())
        self.assertIn(2, c_lines.keys())
        self.assertIn(3, c_lines.keys())

        # in particular data none line are in more peaces
        self.assertEqual(len(c_lines[1]), 1)
        self.assertEqual(len(c_lines[2]), 1)
        self.assertEqual(len(c_lines[3]), 1)

        c = Contour(self.xv, self.yv, self.z_horizontal_desc)
        c_lines = c.contours([1, 2, 3])

        # all line exists in particular data
        self.assertIn(1, c_lines.keys())
        self.assertIn(2, c_lines.keys())
        self.assertIn(3, c_lines.keys())

        # in particular data none line are in more peaces
        self.assertEqual(len(c_lines[1]), 1)
        self.assertEqual(len(c_lines[2]), 1)
        self.assertEqual(len(c_lines[3]), 1)

        c = Contour(self.xv, self.yv, self.z_lt_rb_asc)
        c_lines = c.contours([1, 2, 3])

        # all line exists in particular data
        self.assertIn(1, c_lines.keys())
        self.assertIn(2, c_lines.keys())
        self.assertIn(3, c_lines.keys())

        # in particular data none line are in more peaces
        self.assertEqual(len(c_lines[1]), 1)
        self.assertEqual(len(c_lines[2]), 1)
        self.assertEqual(len(c_lines[3]), 1)

        c = Contour(self.xv, self.yv, self.z_lt_rb_desc)
        c_lines = c.contours([1, 2, 3])

        # all line exists in particular data
        self.assertIn(1, c_lines.keys())
        self.assertIn(2, c_lines.keys())
        self.assertIn(3, c_lines.keys())

        # in particular data none line are in more peaces
        self.assertEqual(len(c_lines[1]), 1)
        self.assertEqual(len(c_lines[2]), 1)
        self.assertEqual(len(c_lines[3]), 1)

        c = Contour(self.xv, self.yv, self.z_rt_lb_asc)
        c_lines = c.contours([1, 2, 3])

        # all line exists in particular data
        self.assertIn(1, c_lines.keys())
        self.assertIn(2, c_lines.keys())
        self.assertIn(3, c_lines.keys())

        # in particular data none line are in more peaces
        self.assertEqual(len(c_lines[1]), 1)
        self.assertEqual(len(c_lines[2]), 1)
        self.assertEqual(len(c_lines[3]), 1)

        c = Contour(self.xv, self.yv, self.z_rt_lb_desc)
        c_lines = c.contours([1, 2, 3])

        # all line exists in particular data
        self.assertIn(1, c_lines.keys())
        self.assertIn(2, c_lines.keys())
        self.assertIn(3, c_lines.keys())

        # in particular data none line are in more peaces
        self.assertEqual(len(c_lines[1]), 1)
        self.assertEqual(len(c_lines[2]), 1)
        self.assertEqual(len(c_lines[3]), 1)

        # test in cycle set
        c = Contour(self.xv_cycle, self.yv_cycle, self.cycle1)
        c_lines = c.contours([0.5])

        self.assertIn(0.5, c_lines.keys())
        self.assertEqual(len(c_lines[0.5]), 1)

        # test start with square 5, before only 10 was checked
        c = Contour(self.xv_cycle, self.yv_cycle, self.cycle2)
        c_lines = c.contours([0.5])

        self.assertIn(0.5, c_lines.keys())
        self.assertEqual(len(c_lines[0.5]), 1)

        # test no contours, then no key in dict
        c = Contour(self.xv_cycle, self.yv_cycle, self.cycle2)
        c_lines = c.contours([1.5])

        self.assertNotIn(1.5, c_lines.keys())