def _plot_samples(self, plot, plot_data):
        nclasses = self.theta.shape[0]
        nsamples = self.theta_samples.shape[0]

        for k in range(nclasses):
            samples = np.sort(self.theta_samples[:,k,:], axis=0)
            perc5 = samples[int(nsamples*0.05),:]
            perc95 = samples[int(nsamples*0.95),:]
            avg = samples.mean(0)

            # build polygon
            index_name = self._label_name(k) + '_confint_index'
            value_name = self._label_name(k) + '_confint_value'
            index_coord = []
            value_coord = []
            # bottom part
            for i in range(nclasses):
                index_coord.append(i)
                value_coord.append(perc5[i])
            # top part
            for i in range(nclasses-1, -1, -1):
                index_coord.append(i)
                value_coord.append(perc95[i])

            plot_data.set_data(index_name, np.array(index_coord,
                                                    dtype=float))
            plot_data.set_data(value_name, np.array(value_coord,
                                                    dtype=float))

            # make color lighter and more transparent
            color = get_class_color(k)
            for i in range(3):
                color[i] = min(1.0, sigmoid(color[i]*5.))
            color[-1] = 0.3

            plot.plot(
                (index_name, value_name),
                type = 'polygon',
                face_color = color,
                edge_color = 'black',
                edge_width = 0.5
            )

            # add average
            avg_name = self._label_name(k) + '_avg_value'
            plot_data.set_data(avg_name, avg)
            plot.plot(
                ('classes', avg_name),
                color = get_class_color(k),
                line_style = 'dash'
            )
Example #2
0
    def _plot_samples(self, plot, plot_data):
        nclasses = self.theta.shape[0]
        nsamples = self.theta_samples.shape[0]

        for k in range(nclasses):
            samples = np.sort(self.theta_samples[:, k, :], axis=0)
            perc5 = samples[int(nsamples * 0.05), :]
            perc95 = samples[int(nsamples * 0.95), :]
            avg = samples.mean(0)

            # build polygon
            index_name = self._label_name(k) + '_confint_index'
            value_name = self._label_name(k) + '_confint_value'
            index_coord = []
            value_coord = []
            # bottom part
            for i in range(nclasses):
                index_coord.append(i)
                value_coord.append(perc5[i])
            # top part
            for i in range(nclasses - 1, -1, -1):
                index_coord.append(i)
                value_coord.append(perc95[i])

            plot_data.set_data(index_name, np.array(index_coord, dtype=float))
            plot_data.set_data(value_name, np.array(value_coord, dtype=float))

            # make color lighter and more transparent
            color = get_class_color(k)
            for i in range(3):
                color[i] = min(1.0, sigmoid(color[i] * 5.))
            color[-1] = 0.3

            plot.plot((index_name, value_name),
                      type='polygon',
                      face_color=color,
                      edge_color='black',
                      edge_width=0.5)

            # add average
            avg_name = self._label_name(k) + '_avg_value'
            plot_data.set_data(avg_name, avg)
            plot.plot(('classes', avg_name),
                      color=get_class_color(k),
                      line_style='dash')
Example #3
0
    def _plot_theta_values(self, plot, plot_data):
        theta = self.theta
        nclasses = theta.shape[0]

        data_names = ['classes']
        for k in range(nclasses):
            name = self._label_name(k)
            plot_data.set_data(name, theta[k, :])
            data_names.append(name)

        plots = {}
        for k in range(nclasses):
            name = self._label_name(k)
            line_plot = plot.plot(['classes', name],
                                  line_width=2.,
                                  color=get_class_color(k),
                                  name=name)
            plots[name] = line_plot

        return plots
Example #4
0
    def _plot_default(self):
        distr_len = len(self.data)

        # PolygonPlot holding the circles of the Hinton diagram
        polyplot = Plot(self.plot_data)
        for idx in range(distr_len):
            p = polyplot.plot(('x%d' % idx, 'y%d' % idx),
                              type="polygon",
                              face_color=get_class_color(idx),
                              edge_color='black')

        self._set_title(polyplot)
        self._remove_grid_and_axes(polyplot)

        # create x axis for labels
        axis = self._create_increment_one_axis(polyplot, 1., distr_len,
                                               'bottom')
        self._add_index_axis(polyplot, axis)

        # create y axis for probability density
        #prob_axis = self._create_probability_axis(polyplot)
        #polyplot.value_axis = prob_axis
        #polyplot.underlays.append(prob_axis)

        # tweak some of the plot properties
        range2d = DataRange2D(low=(0.5, 0.), high=(distr_len + 0.5, 1.))
        polyplot.range2d = range2d
        polyplot.aspect_ratio = ((range2d.x_range.high - range2d.x_range.low) /
                                 (range2d.y_range.high - range2d.y_range.low))

        polyplot.border_visible = False
        polyplot.padding = [0, 0, 25, 25]

        # create a container to position the plot and the colorbar side-by-side
        container = HPlotContainer(use_backbuffer=True, valign='center')
        container.add(polyplot)
        container.bgcolor = 0xFFFFFF  # light gray: 0xEEEEEE

        self.decorate_plot(container, self.data)
        return container
    def _plot_theta_values(self, plot, plot_data):
        theta = self.theta
        nclasses = theta.shape[0]

        data_names = ['classes']
        for k in range(nclasses):
            name = self._label_name(k)
            plot_data.set_data(name, theta[k,:])
            data_names.append(name)

        plots = {}
        for k in range(nclasses):
            name = self._label_name(k)
            line_plot = plot.plot(
                ['classes', name],
                line_width=2.,
                color = get_class_color(k),
                name=name
            )
            plots[name] = line_plot

        return plots
Example #6
0
    def _plot_default(self):
        distr_len = len(self.data)

        # PolygonPlot holding the circles of the Hinton diagram
        polyplot = Plot(self.plot_data)
        for idx in range(distr_len):
            p = polyplot.plot(('x%d' % idx, 'y%d' % idx),
                          type="polygon",
                          face_color=get_class_color(idx),
                          edge_color='black')

        self._set_title(polyplot)
        self._remove_grid_and_axes(polyplot)

        # create x axis for labels
        axis = self._create_increment_one_axis(polyplot, 1., distr_len, 'bottom')
        self._add_index_axis(polyplot, axis)

        # create y axis for probability density
        #prob_axis = self._create_probability_axis(polyplot)
        #polyplot.value_axis = prob_axis
        #polyplot.underlays.append(prob_axis)

        # tweak some of the plot properties
        range2d = DataRange2D(low=(0.5, 0.), high=(distr_len+0.5, 1.))
        polyplot.range2d = range2d
        polyplot.aspect_ratio = ((range2d.x_range.high - range2d.x_range.low)
                                 / (range2d.y_range.high - range2d.y_range.low))

        polyplot.border_visible = False
        polyplot.padding = [0, 0, 25, 25]

        # create a container to position the plot and the colorbar side-by-side
        container = HPlotContainer(use_backbuffer=True, valign='center')
        container.add(polyplot)
        container.bgcolor = 0xFFFFFF # light gray: 0xEEEEEE

        self.decorate_plot(container, self.data)
        return container