messif.pivotselection
Class AbstractPivotChooser

java.lang.Object
  extended by messif.pivotselection.AbstractPivotChooser
Direct Known Subclasses:
ClusterPivotChooser, CoveragePivotChooser, IncrementalIDistanceChooser, IncrementalPivotChooser, KMeansPivotChooser, OutlierPivotChooser, RandomPivotChooser, StreamSequencePivotChooser, TwoDistantIncrementalPivotChooser

public abstract class AbstractPivotChooser
extends java.lang.Object

Abstract class for pivot selection algorithms hierarchy This class provides basic methods for selecting and accessing pivots and automatically registers statistic DistanceComputations.PivotChooser, i.e. number of distance computations spent in choosing pivots. Pivots are automatically selected if additional pivots are required by pivot getter methods. Pivot selection also supports transactions - if a transaction is initialized, the actual state of the list of selected objects is remember. The transaction ends by either commiting all changes made to the list or by rolling back all the changes.


Field Summary
protected static StatisticRefCounter counterBucketReadBuckets
          Global bucket accesses refcounter statistic
protected static StatisticCounter counterObjectDistComp
          Global distance computations statistic counter
protected static StatisticCounter counterPivotDistComp
          Statistic counter for pivot chooser distance computations
protected static StatisticRefCounter counterPivotReadBuckets
          Statistic refcounter for pivot chooser accesses to bucket
protected  java.util.List<LocalAbstractObject> preselectedPivots
          List of selected pivots
protected  java.util.Set<ObjectProvider<? extends LocalAbstractObject>> sampleProviders
          Registered sample providers
 
Constructor Summary
AbstractPivotChooser()
           
 
Method Summary
 void addPivot(LocalAbstractObject pivot)
          This method appends a new pivot to the currently existing list.
 void clear()
          Clears the list of preselected pivots.
 void deregisterSampleProvider(ObjectProvider<? extends LocalAbstractObject> provider)
          Removes registration of a sample set provider that was previously registered (others are silently ignored).
 LocalAbstractObject getLastPivot()
          Access to the last selected pivot.
 LocalAbstractObject getNextPivot()
          Returns a new pivot that is freshly selected.
 LocalAbstractObject getPivot()
          Access to the first selected pivot (even if more pivots are available).
 LocalAbstractObject getPivot(int position)
          Returns a reference to a preselected pivot at the desired position.
 java.util.Iterator<LocalAbstractObject> iterator()
          Provides a read-only iterator over the collection of currently selected pivots
 void registerSampleProvider(ObjectProvider<? extends LocalAbstractObject> provider)
          Registers a new sample set provider used by this pivot chooser to select pivots.
 LocalAbstractObject removeLastPivot()
          Deletes the last pivot from the list of current pivots and returns it.
 void selectPivot()
          Selects one pivot and appends it to the list of pivots.
 void selectPivot(int count)
          Method for selecting pivots and appending them to the list of pivots.
protected abstract  void selectPivot(int count, AbstractObjectIterator<? extends LocalAbstractObject> sampleSetIterator)
          This method carries out the actual pivot selection and must be implemented by subclasses.
 int size()
          The number of currently selected pivots.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

preselectedPivots

protected final java.util.List<LocalAbstractObject> preselectedPivots
List of selected pivots


sampleProviders

protected final java.util.Set<ObjectProvider<? extends LocalAbstractObject>> sampleProviders
Registered sample providers


counterPivotDistComp

protected static final StatisticCounter counterPivotDistComp
Statistic counter for pivot chooser distance computations


counterObjectDistComp

protected static final StatisticCounter counterObjectDistComp
Global distance computations statistic counter


counterPivotReadBuckets

protected static final StatisticRefCounter counterPivotReadBuckets
Statistic refcounter for pivot chooser accesses to bucket


counterBucketReadBuckets

protected static final StatisticRefCounter counterBucketReadBuckets
Global bucket accesses refcounter statistic

Constructor Detail

AbstractPivotChooser

public AbstractPivotChooser()
Method Detail

clear

public void clear()
Clears the list of preselected pivots.


size

public int size()
The number of currently selected pivots. If a transaction is running, it returns the current state not the state before the transaction has been initiated.

Returns:
Returns the number of currently selected pivots

iterator

public java.util.Iterator<LocalAbstractObject> iterator()
Provides a read-only iterator over the collection of currently selected pivots

Returns:
Returns iterator over a collection of currently selected pivots

getPivot

public LocalAbstractObject getPivot()
Access to the first selected pivot (even if more pivots are available). The pivot selection is automatically called if necessary.

Returns:
Returns the first pivot

getLastPivot

public LocalAbstractObject getLastPivot()
Access to the last selected pivot. Null is returned if there are no selected pivots yet, i.e. no automatic selection is issued.

Returns:
Returns the last pivot from the list of selected pivots.

getNextPivot

public LocalAbstractObject getNextPivot()
Returns a new pivot that is freshly selected. The pivot selection is always called to choose additional pivot.

Returns:
Returns a new pivot

getPivot

public LocalAbstractObject getPivot(int position)
                             throws java.lang.IndexOutOfBoundsException
Returns a reference to a preselected pivot at the desired position. If the list does not contain enough pivots, the remaining ones are newly selected. Moreover, if the position is still out of range, method throws IndexOutOfBoundsException.

Parameters:
position - The possition (number) of the requested pivot
Returns:
Returns the pivot at requested position
Throws:
java.lang.IndexOutOfBoundsException - Thrown if the pivot selection cannot select enough additional pivots

removeLastPivot

public LocalAbstractObject removeLastPivot()
Deletes the last pivot from the list of current pivots and returns it.

Returns:
Returns an instance of AbstractObject which is the pivot that got deleted. Returns null if there are no more pivots to delete.

addPivot

public void addPivot(LocalAbstractObject pivot)
This method appends a new pivot to the currently existing list.

Parameters:
pivot - The pivot added to the preselected list

selectPivot

public final void selectPivot()
Selects one pivot and appends it to the list of pivots. This method internally calls selectPivot(1).


selectPivot

public final void selectPivot(int count)
Method for selecting pivots and appending them to the list of pivots. It is called from getPivot() automatically.

Parameters:
count - Number of pivots to generate

selectPivot

protected abstract void selectPivot(int count,
                                    AbstractObjectIterator<? extends LocalAbstractObject> sampleSetIterator)
This method carries out the actual pivot selection and must be implemented by subclasses. The implementation must select at least count pitvots and add them by addPivot method.

Parameters:
count - Number of pivots to generate
sampleSetIterator - Iterator over the sample set of objects to choose new pivots from

registerSampleProvider

public void registerSampleProvider(ObjectProvider<? extends LocalAbstractObject> provider)
Registers a new sample set provider used by this pivot chooser to select pivots.

Parameters:
provider - the sample set provider

deregisterSampleProvider

public void deregisterSampleProvider(ObjectProvider<? extends LocalAbstractObject> provider)
Removes registration of a sample set provider that was previously registered (others are silently ignored).

Parameters:
provider - the previously registered sample set provider