de.fu_berlin.ties.classify.winnow
Class WinnowStore

java.lang.Object
  extended by de.fu_berlin.ties.classify.winnow.WinnowStore
All Implemented Interfaces:
XMLStorable, Pruner, RemoveCallback
Direct Known Subclasses:
DefaultWinnowStore, SharedWinnowStore

public abstract class WinnowStore
extends Object
implements Pruner, RemoveCallback, XMLStorable

Feature store used by Winnow. Controls the number of stored features and implements pruning based on the LRU (least recently used) principle.

Instances of this class are synchronized externally by Winnow.

Version:
$Revision: 1.33 $, $Date: 2006/10/21 16:03:59 $, $Author: siefkes $
Author:
Christian Siefkes

Field Summary
protected static QName ATTRIB_HASH
          Name of the attribute used to store feature hashes for XML serialization.
protected static QName ATTRIB_IGNORE_IRRELEVANT
          Attribute name used for XML serialization.
protected static QName ATTRIB_INIT_WEIGHTS
          Name of the attribute used to store the initial weight for XML serialization.
protected static QName ATTRIB_MAX_SIZE
          Name of the attribute used to store the maximum number of features for XML serialization.
protected static QName ATTRIB_PRUNE_CANDIDATES
          Name of the XML attribute used to store number of candidates to consider for pruning.
protected static QName ATTRIB_PRUNE_NUMBER
          Name of the XML attribute used to store number of elements to remove by each pruning operation.
protected static QName ATTRIB_WEIGHTS
          Name of the attribute used to store feature weight arrays for XML serialization.
protected static String CONFIG_IGNORE_IRRELEVANT
          Configuration parameter: whether "irrelevant" keys should be ignored.
static String CONFIG_SHARED_STORE
          Configuration parameter: Whether a shared feature store is used for all Winnow instances.
protected static QName ELEMENT_FEATURE
          Name of the element used to store features for XML serialization.
static QName ELEMENT_MAIN
          Name of the main element used for XML serialization.
 
Constructor Summary
WinnowStore(boolean ignoreIrrelevant)
          Creates a new instance.
WinnowStore(TiesConfiguration config, String configSuffix)
          Creates a new instance.
 
Method Summary
static WinnowStore create(float initialWeight, TiesConfiguration config, String configSuffix)
          Factory method that creates and configures a new instance.
 void destroy()
          Destroys the store if it will never be used again.
abstract  float[] getWeights(Feature feature)
          Returns the weights of a feature.
protected  AdaptableLRUMap initStore(int featureNum, int candidates, int pruneNum)
          Helper method that initializes the internal store.
protected  AdaptableLRUMap initStore(TiesConfiguration config, String configSuffix)
          Helper method that initializes the internal store.
 boolean isIgnoringIrrelevant()
          Whether features within a certain range around the default weight are ignored during classification.
 boolean isRelevant(Feature feature)
          Whether a feature is considered relevant for classification.
 int maxSize()
          Returns the maximum number of features that can be stored by this instance.
abstract  void putWeights(Feature feature, float[] weights)
          Stores new weights for a feature.
protected  void removeFromRelevantKeys(Long key)
          Helper method that removes a key from the set of relevant keys.
 void reset()
          Resets the store, completely deleting the prediction model.
 void setRelevant(Feature feature, boolean relevant)
          Marks a feature as relevant or irrelevant for classification.
 int size()
          Returns the number of features currently stored by this instance.
protected abstract  AdaptableLRUMap store()
          Allows raw access to the internal store.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface de.fu_berlin.ties.util.Pruner
sortForPruning
 
Methods inherited from interface de.fu_berlin.ties.util.RemoveCallback
removed
 
Methods inherited from interface de.fu_berlin.ties.io.XMLStorable
toElement
 

Field Detail

CONFIG_IGNORE_IRRELEVANT

protected static final String CONFIG_IGNORE_IRRELEVANT
Configuration parameter: whether "irrelevant" keys should be ignored.

See Also:
Constant Field Values

CONFIG_SHARED_STORE

public static final String CONFIG_SHARED_STORE
Configuration parameter: Whether a shared feature store is used for all Winnow instances.

See Also:
Constant Field Values

ELEMENT_MAIN

public static final QName ELEMENT_MAIN
Name of the main element used for XML serialization.


ELEMENT_FEATURE

protected static final QName ELEMENT_FEATURE
Name of the element used to store features for XML serialization.


ATTRIB_HASH

protected static final QName ATTRIB_HASH
Name of the attribute used to store feature hashes for XML serialization.


ATTRIB_WEIGHTS

protected static final QName ATTRIB_WEIGHTS
Name of the attribute used to store feature weight arrays for XML serialization.


ATTRIB_INIT_WEIGHTS

protected static final QName ATTRIB_INIT_WEIGHTS
Name of the attribute used to store the initial weight for XML serialization.


ATTRIB_IGNORE_IRRELEVANT

protected static final QName ATTRIB_IGNORE_IRRELEVANT
Attribute name used for XML serialization.


ATTRIB_PRUNE_NUMBER

protected static final QName ATTRIB_PRUNE_NUMBER
Name of the XML attribute used to store number of elements to remove by each pruning operation.


ATTRIB_PRUNE_CANDIDATES

protected static final QName ATTRIB_PRUNE_CANDIDATES
Name of the XML attribute used to store number of candidates to consider for pruning.


ATTRIB_MAX_SIZE

protected static final QName ATTRIB_MAX_SIZE
Name of the attribute used to store the maximum number of features for XML serialization.

Constructor Detail

WinnowStore

public WinnowStore(TiesConfiguration config,
                   String configSuffix)
Creates a new instance.

Parameters:
config - Used to configure this instance
configSuffix - Optional suffix appended to the configuration keys when configuring this instance; might be null

WinnowStore

public WinnowStore(boolean ignoreIrrelevant)
Creates a new instance.

Parameters:
ignoreIrrelevant - whether features within a certain range around the default weight are ignored during classification
Method Detail

create

public static WinnowStore create(float initialWeight,
                                 TiesConfiguration config,
                                 String configSuffix)
Factory method that creates and configures a new instance.

Parameters:
initialWeight - The initial weight of each feature -- this implementation prunes features whose weights deviate least from this initial weight
config - Used to configure this instance
configSuffix - Optional suffix appended to the configuration keys when configuring this instance; might be null
Returns:
the created store

store

protected abstract AdaptableLRUMap store()
Allows raw access to the internal store. Used by the maxSize(), size() and reset() methods.

Returns:
the value of the attribute

destroy

public void destroy()
Destroys the store if it will never be used again. The default implementation delegates to reset(), but subclasses can overwrite this behaviour if appropriate.


getWeights

public abstract float[] getWeights(Feature feature)
Returns the weights of a feature.

Parameters:
feature - the feature to look up
Returns:
The weights of this feature

initStore

protected AdaptableLRUMap initStore(int featureNum,
                                    int candidates,
                                    int pruneNum)
Helper method that initializes the internal store.

Parameters:
featureNum - The number of features to store
candidates - The number of candidates to consider for each pruning operation
pruneNum - The number of elements to remove by each pruning operation, must not be larger than candidates
Returns:
the store to use

initStore

protected AdaptableLRUMap initStore(TiesConfiguration config,
                                    String configSuffix)
Helper method that initializes the internal store.

Parameters:
config - Used to configure this instance
configSuffix - Optional suffix appended to the configuration keys when configuring this instance; might be null
Returns:
the store to use

isIgnoringIrrelevant

public boolean isIgnoringIrrelevant()
Whether features within a certain range around the default weight are ignored during classification.

Returns:
the value of the attribute

isRelevant

public boolean isRelevant(Feature feature)
Whether a feature is considered relevant for classification.

Parameters:
feature - the feature to look up
Returns:
whether the specified feature is relevant for classification

maxSize

public int maxSize()
Returns the maximum number of features that can be stored by this instance.

Returns:
the value of the attribute

putWeights

public abstract void putWeights(Feature feature,
                                float[] weights)
Stores new weights for a feature.

Parameters:
feature - the feature to use
weights - The new weights of this feature

removeFromRelevantKeys

protected void removeFromRelevantKeys(Long key)
Helper method that removes a key from the set of relevant keys. If no relevant keys are used, this method does nothing.

Parameters:
key - the key to remove

reset

public void reset()
Resets the store, completely deleting the prediction model.


setRelevant

public void setRelevant(Feature feature,
                        boolean relevant)
Marks a feature as relevant or irrelevant for classification. Initially all features are considered irrelevant.

Parameters:
feature - the feature to mark
relevant - whether or not the feature is relevant

size

public int size()
Returns the number of features currently stored by this instance.

Returns:
the value of the attribute


Copyright © 2003-2007 Christian Siefkes. All Rights Reserved.