Ejemplo n.º 1
0
    def compute_score(self, score_type='association', dim='A'):
        """Compute a score, such as an index or normalization, of the co-occurrence data.

        Parameters
        ----------
        score_type : {'association', 'normalize'}, optional
            The type of score to apply to the co-occurrence data.
        dim : {'A', 'B'}, optional
            Which dimension of counts to use to normalize the co-occurence data by.
            Only used if 'score' is 'normalize'.
        """

        if score_type == 'association':
            if self.square:
                self.score = compute_association_index(self.counts,
                                                       self.terms['A'].counts,
                                                       self.terms['A'].counts)
            else:
                self.score = compute_association_index(self.counts,
                                                       self.terms['A'].counts,
                                                       self.terms['B'].counts)

        elif score_type == 'normalize':
            self.score = compute_normalization(self.counts,
                                               self.terms[dim].counts, dim)

        else:
            raise ValueError('Score type not understood.')
Ejemplo n.º 2
0
    def compute_score(self, score_type='association', dim='A'):
        """Compute a score, such as an index or normalization, of the co-occurrence data.

        Parameters
        ----------
        score_type : {'association', 'normalize'}, optional
            The type of score to apply to the co-occurrence data.
        dim : {'A', 'B'}, optional
            Which dimension of counts to use to normalize the co-occurrence data by.
            Only used if 'score' is 'normalize'.

        Examples
        --------
        Compute association scores of co-occurrence data collected for two lists of terms:

        >>> counts = Counts()
        >>> counts.add_terms(['frontal lobe', 'temporal lobe', 'parietal lobe', 'occipital lobe'])
        >>> counts.add_terms(['attention', 'perception'], dim='B')
        >>> counts.run_collection() # doctest: +SKIP
        >>> counts.compute_score() # doctest: +SKIP

        Once you have co-occurence scores calculated, you might want to plot this data.
        You can plot the results as a matrix, as a clustermap, and/or as a dendrogram:

        >>> from lisc.plts.counts import plot_matrix, plot_clustermap, plot_dendrogram  # doctest:+SKIP
        >>> plot_matrix(counts.score, counts.terms['B'].labels, counts.terms['A'].labels) # doctest:+SKIP
        >>> plot_clustermap(counts.score, counts.terms['B'].labels, counts.terms['A'].labels) # doctest:+SKIP
        >>> plot_dendrogram(counts.score, counts.terms['B'].labels) # doctest:+SKIP
        """

        if score_type == 'association':
            if self.square:
                self.score = compute_association_index(self.counts,
                                                       self.terms['A'].counts,
                                                       self.terms['A'].counts)
            else:
                self.score = compute_association_index(self.counts,
                                                       self.terms['A'].counts,
                                                       self.terms['B'].counts)

        elif score_type == 'normalize':
            self.score = compute_normalization(self.counts,
                                               self.terms[dim].counts, dim)

        else:
            raise ValueError('Score type not understood.')
Ejemplo n.º 3
0
# Once co-occurrence data has been collected, we often want to compute a normalization
# or transform of the data.
#
# The :func:`~.compute_normalization`, :func:`~.compute_association_index`
# and :func:`~.compute_similarity` functions take in co-occurrence data as returned
# by the :func:`~.collect_counts` function.
#
# More details on the measures available in LISC are available in the :class:`~.Counts`
# tutorial. When using the functions approach, all implemented scores and transforms
# are available in `lisc.analysis`.
#

###################################################################################################

# Calculate the normalized data measure, normalizing the co-occurrences by the term counts
normed_coocs = compute_normalization(coocs, term_counts[0], dim='A')

# Check the computed score measure for the co-occurrence collection
print(normed_coocs)

###################################################################################################

# Compute the association index score, calculating the Jaccard index from the co-occurrences
score = compute_association_index(coocs, term_counts[0], term_counts[1])

# Check the computed score measure for the co-occurrence collection
print(score)

###################################################################################################
#
# From here, further analysis of collected co-occurrence data depends on the goal of the analysis.
Ejemplo n.º 4
0
    def compute_score(self,
                      score_type='association',
                      dim='A',
                      return_result=False):
        """Compute a score, such as an index or normalization, of the co-occurrence data.

        Parameters
        ----------
        score_type : {'association', 'normalize', 'similarity'}, optional
            The type of score to apply to the co-occurrence data.
        dim : {'A', 'B'}, optional
            Which dimension of counts to use to normalize by or compute similarity across.
            Only used if 'score' is 'normalize' or 'similarity'.
        return_result : bool, optional, default: False
            Whether to return the computed result.

        Examples
        --------
        Compute association scores of co-occurrence data collected for two lists of terms:

        >>> counts = Counts()
        >>> counts.add_terms(['frontal lobe', 'temporal lobe', 'parietal lobe', 'occipital lobe'])
        >>> counts.add_terms(['attention', 'perception'], dim='B')
        >>> counts.run_collection() # doctest: +SKIP
        >>> counts.compute_score() # doctest: +SKIP

        Once you have co-occurrence scores calculated, you might want to plot this data.

        You can plot the results as a matrix:

        >>> from lisc.plts.counts import plot_matrix  # doctest:+SKIP
        >>> plot_matrix(counts)  # doctest:+SKIP

        And/or as a clustermap:

        >>> from lisc.plts.counts import plot_clustermap  # doctest:+SKIP
        >>> plot_clustermap(counts)  # doctest:+SKIP

        And/or as a dendrogram:

        >>> from lisc.plts.counts import plot_dendrogram  # doctest:+SKIP
        >>> plot_dendrogram(counts)  # doctest:+SKIP
        """

        if not self.has_data:
            raise ValueError('No data is available - cannot proceed.')

        if score_type == 'association':
            if self.square:
                self.score = compute_association_index(self.counts,
                                                       self.terms['A'].counts,
                                                       self.terms['A'].counts)
            else:
                self.score = compute_association_index(self.counts,
                                                       self.terms['A'].counts,
                                                       self.terms['B'].counts)

        elif score_type == 'normalize':
            self.score = compute_normalization(self.counts,
                                               self.terms[dim].counts, dim)

        elif score_type == 'similarity':
            self.score = compute_similarity(self.counts, dim=dim)

        else:
            raise ValueError('Score type not understood.')

        self.score_info['type'] = score_type
        if score_type in ['normalize', 'similarity']:
            self.score_info['dim'] = dim

        if return_result:
            return deepcopy(self.score)