com.aliasi.features
Class InteractionFeatureExtractor<E>

java.lang.Object
  extended by com.aliasi.features.InteractionFeatureExtractor<E>
All Implemented Interfaces:
FeatureExtractor<E>, Serializable

public class InteractionFeatureExtractor<E>
extends Object
implements FeatureExtractor<E>, Serializable

An InteractionFeatureExtractor produces interaction features between two feature extractors. The value of an interaction feature is the product of the values of the individual features. The feature itself will be prefixed with a specific string and the features for the interaction are separated by a specific string.

If the two feature extractors are the same, then only one feature extraction is performed on an input and redundant features are removed.

Two Extractor Example

If we have feature maps {"a"->1.5, "b"->2.0, "c"->3.0} and {"d"->1.0, "e"-> 0.25}, with prefix I: and separator *, then the interaction features are {"I:a*d"->1.5, "I:a*e"->0.375, "I:b*d"->2.0, "I:b*e"->0.5, "I:c*d"->3.0, "I:c*e"->0.75}.

One Extractor Example

If only one extractor is involved, symmetry is applied and the features are not generated twice. For instance, if we have the single feature map {"x"->-1.5, "y"->2.0, "z"->1.0}, the interaction feature map is {"I:x*x"->2.25, "I:x*y"->-3.0, "I:x*z"->-1.5, "I:y*y"->4.0, "I:y*z"->2.0, "I:z*z"->1.0}.

In order to preserve uniqueness of the feature output in the one-extractor case, we need to sort the features. So we make sure that the features are in sorted order in the combination (as determined by the natural sort order defined for String by its compareTo(String) method. Specifically, we get "I:x*z", but not "I:z*x" in the case above. This is not an issue for the two-extractor case, as you get all pairs, with the first extractor's feature always coming first in the resulting feature.

Serialization

An interaction feature extractor may be serialized if its component extractors are serializable.

Thread Safety

An interaction feature structure is thread safe if the component feature extractor(s) are thread safe.

Since:
LingPipe3.9.2
Version:
3.9.2
Author:
Bob Carpenter
See Also:
Serialized Form

Constructor Summary
InteractionFeatureExtractor(String prefix, String separator, FeatureExtractor<E> extractor)
          Construct a feature extractor for interactions between the features extracted by the specified extractor, creating new features with the specified prefix and separator.
InteractionFeatureExtractor(String prefix, String separator, FeatureExtractor<E> extractor1, FeatureExtractor<E> extractor2)
          Construct a feature extractor for interactions between the features extracted by the specified extractors, creating new features with the specified prefix and separator.
 
Method Summary
 Map<String,Double> features(E in)
          Return the interaction feature map for the specified input.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InteractionFeatureExtractor

public InteractionFeatureExtractor(String prefix,
                                   String separator,
                                   FeatureExtractor<E> extractor1,
                                   FeatureExtractor<E> extractor2)
Construct a feature extractor for interactions between the features extracted by the specified extractors, creating new features with the specified prefix and separator.

Parameters:
prefix - Prefix to prepend to interaction features.
separator - Separator between features in interaction features.
extractor1 - First feature extractor.
extractor2 - Second feature extractor.

InteractionFeatureExtractor

public InteractionFeatureExtractor(String prefix,
                                   String separator,
                                   FeatureExtractor<E> extractor)
Construct a feature extractor for interactions between the features extracted by the specified extractor, creating new features with the specified prefix and separator.

Parameters:
prefix - Prefix to prepend to interaction features.
separator - Separator between features in interaction features.
extractor - Feature extractor.
Method Detail

features

public Map<String,Double> features(E in)
Return the interaction feature map for the specified input.

Specified by:
features in interface FeatureExtractor<E>
Parameters:
in - Input whose features are extracted.
Returns:
The interaction feature map for the input.