next up previous contents
Next: Integrated Methods Up: Labelings Previous: Retrieving information   Contents

Global vs Local Labelings

In so far we've only dealt with local Labeling classes. That is the Labeling is only available to the Dataset or View that it was attached to upon instantiation. Often it is desirable to be able to work with labels that are persistent across all View of a Dataset. MLX provides a Labeling for this purpose and it's behavior is identical to that of a Labeling with the exception that it requires a view context as the first argument to all method calls that either retrieve or attach labels.

>>> #
... # Create a dataset and labeling
... #
...
>>> from compClust.mlx.datasets import Dataset
>>> from compClust.mlx.labelings import GlobalLabeling
>>> from compClust.mlx.views import *
>>> ds = Dataset(MLab.rand(5,3))
>>> ds.setName('Test Dataset')
>>> glab = GlobalLabeling(ds)
>>> glab.setName('First Global Labeling')
>>> # now we'll label all the rows 1,2,3 - remember it requires the context as first parameter
>>> glab.labelRows(ds, [0,1,2,3,4])
>>> glab
GlobalLabeling: First Global Labeling,  5 unique labels
>>> glab.getLabelByRows(ds)
[0, 1, 2, 3, 4]
>>> # Now we'll look at this labeling in a different view
>>> v1 = RowSubsetView(ds, [1,3]) 
>>> # Now if we look at all the row labels we should only see the label for rows 1 and 3
>>> glab.getLabelByRows(v1)
[1, 3]

Although often you will want to use a Labeling to attach labels to your data, often, once you've created a Labeling, you'll want it to ``look and act'' identically to a local Labeling, that is expose the same interface. This is accomplished useing a Labelings which can be thought of as a local shell around a Labeling. A Labelings is a Labeling and behaves exactly the same except method calls to the Labelings act through a Labeling. A Labelings can be obtained in two ways: 1) through its constructer requireing a Labeling and a View. 2) From a View or Dataset's getLabelings() or getLabeling() methods. This is best explained through demonstration.

>>> from compClust.mlx.labelings import GlobalWrapper
>>> # This contiues from the previous example
>>> # We'll start by directly instantiating a GlobalWrapper
>>> gwrap = GlobalWrapper(v1, glabeling=glab)
>>> gwrap
GlobalWrapper: First Global Labeling,  5 unique labels
>>> gwrap.getLabelByRows() 
[1, 3]
>>> # Now we'll get a GlobalWrapper using the datasets's getLabeling method
>>> gwrap = ds.getLabeling('First Global Labeling')
>>> gwrap.getLabelByRows()
[1, 2, 3, 4, 5]

And this concludes our quick example on basic Labeling usage. Remember also that View are conceptually identical to Dataset, so all of the Labeling techniques apply to View as well. Next we'll look at some of the sophisticated methods which leverage Dataset, View, and Labeling simultaneously.


next up previous contents
Next: Integrated Methods Up: Labelings Previous: Retrieving information   Contents
Lucas Scharenbroich 2003-08-27