SciPy

tethne.model.managers.tap module

Classes and methods related to the TAPModelManager.

class tethne.model.managers.tap.TAPModelManager(D=None, G=None, model=None, **kwargs)[source]

Bases: tethne.model.managers.SocialModelManager

Generates a time-sensitive set of TAPModels from a Corpus, a corpus model, and a coauthorship GraphCollection.

The standard TAPModel is not sensitive to time, in that influence among authors is estimated without regard to the sequence in which those authors adopt features in their papers. The TAPModelManager generates TAPModels sequentially, using the posterior influence values from one time-period as priors for the next time-period. The TAPModel for the latest time-period, therefore, should reflect both the structure of the network in that time-period as well as the evolution of that network and the sequence in which authors adopt features in their work.

author_theta Generates distributions over topics for authors, based on distributions over topics for their papers.
graph_collection Generate a GraphCollection from the set of TapModel instances, for topic k.
Parameters:

D : Corpus

G : GraphCollection

model : LDAModel

Examples

Starting with some JSTOR DfR data, a typical workflow might look something like this:

>>> from tethne.readers import dfr                  # 1. Create a Corpus.
>>> from nltk.corpus import stopwords
>>> C = dfr.read_corpus('/path/to/dataset/', 'uni', stopwords.word())
>>> C.slice('date', 'time_period', window_size=5)

>>> from tethne import GraphCollection          # 2. Coauthorship graphs.
>>> G = GraphCollection().build(C, 'date', 'authors', 'coauthors')
>>> G.graphs

>>> from tethne.model import MALLETModelManager        # 3. Corpus model.
>>> outpath = '/path/to/my/working/directory'
>>> mallet = '/Applications/mallet-2.0.7'
>>> M = MALLETModelManager(C, 'wc_filtered', outpath, mallet_path=mallet)
>>> model = M.build(Z=50, max_iter=300)

>>> from tethne.model import TAPModelManager        # 4. Build TAPModels.
>>> T = TAPModelManager(C, G, model)
>>> T.build()

To visualize the TAPModels, use TAPModelManager.graph_collection() to generate a GraphCollection of influence graphs for a particular topic. For example:

>>> IG = T.graph_collection(0)

You can then use a method from writers to export a network datafile for visualization in Cytoscape or Gephi.

_images/tap_topic0.png
author_theta(papers, authors=None, indexed_by='doi')[source]

Generates distributions over topics for authors, based on distributions over topics for their papers.

Parameters:

papers : list

Contains Paper instances.

authors : dict

Maps author names (LAST F) onto coauthor Graph indices.

indexed_by : str

Key in Paper used to index Corpus.

Returns:

a_theta : dict

Maps author indices (from coauthor Graph) onto arrays describing distribution over topics (normalized to 1).

graph_collection(k)[source]

Generate a GraphCollection from the set of TapModel instances, for topic k.

Parameters:

k : int

Topic index.

Returns:

C : GraphCollection