示例#1
0
    def _update_stats_view(self):
        if self.statistics_name in GLOBAL_STATS:
            stat_func = GLOBAL_STATS[self.statistics_name]

            try:
                res = stat_func(self.annotations, nclasses=self.nclasses)
            except PyannoValueError as e:
                logger.info(e)
                res = np.nan

            self.stats_view = _SingleStatView(value=res,
                                              name=self.statistics_name)

        else:
            stat_func = PAIRWISE_STATS[self.statistics_name]

            try:
                res = measures.pairwise_matrix(stat_func,
                                               self.annotations,
                                               nclasses=self.nclasses)
            except PyannoValueError as e:
                logger.info(e)
                nannotators = self.annotations.shape[1]
                res = np.empty((nannotators, nannotators))
                res.fill(np.nan)

            self.stats_view = MatrixPlot(matrix=res,
                                         colormap_low=-1.0,
                                         colormap_high=1.0,
                                         title=self.statistics_name)
    def _update_stats_view(self):
        if self.statistics_name in GLOBAL_STATS:
            stat_func = GLOBAL_STATS[self.statistics_name]

            try:
                res = stat_func(self.annotations, nclasses=self.nclasses)
            except PyannoValueError as e:
                logger.info(e)
                res = np.nan

            self.stats_view = _SingleStatView(value=res,
                                              name=self.statistics_name)

        else:
            stat_func = PAIRWISE_STATS[self.statistics_name]

            try:
                res = measures.pairwise_matrix(stat_func, self.annotations,
                                               nclasses=self.nclasses)
            except PyannoValueError as e:
                logger.info(e)
                nannotators = self.annotations.shape[1]
                res = np.empty((nannotators, nannotators))
                res.fill(np.nan)

            self.stats_view = MatrixPlot(matrix=res,
                                              colormap_low=-1.0,
                                              colormap_high=1.0,
                                              title=self.statistics_name)
示例#3
0
def plot_pairwise_statistics(stat_func, annotations, nclasses=None, **kwargs):
    """Plot a matrix representation of a statistical function of annotations.

    The function `stat_func` is applied to the annotations of all pairs of
    annotators, and the resulting matrix is displayed in a window.

    Example: :::

       >>> plot_pairwise_statistics(pyanno.measures.cohens_kappa, annotations)

    See also :func:`pyanno.measures.helpers.pairwise_matrix`,
    :func:`~pyanno.plots.matrix_plot.plot_square_matrix`.

    Arguments
    ---------
    stat_func : function
        Function accepting as first two arguments two 1D array of
        annotations, and returning a single scalar measuring some annotations
        statistics.

    annotations : ndarray, shape = (n_items, n_annotators)
        Array of annotations for multiple annotators. Missing values should be
        indicated by :attr:`pyanno.util.MISSING_VALUE`

    nclasses : int
        Number of annotation classes. If None, `nclasses` is inferred from the
        values in the annotations

    kwargs : dictionary
        Additional keyword arguments passed to the plot. The argument 'title'
        sets the title of the plot.
    """

    if nclasses is None:
        measures.helpers.compute_nclasses(annotations)

    matrix = measures.pairwise_matrix(stat_func, annotations,
                                      nclasses=nclasses)

    kwargs_local = {'colormap_low': -1.0,
                    'colormap_high': 1.0}
    # add user kwargs, allowing for overwrite
    kwargs_local.update(kwargs)

    matrix_view = plot_square_matrix(matrix, **kwargs_local)
    return matrix_view