Class Feature<T extends FeatureInput>
- Type Parameters:
T- input-type from which a measurement is calculated.
- Direct Known Subclasses:
FeatureBinary,FeatureFromList,FeatureGeneric,FeatureResults,FeatureUnary
This is a key base class in the Anchor framework,
and many algorithms and procedures use a Feature on particular input-types to calculate
measurements in a flexible way, and often to use these measurements in a machine-learning
algorithm.
See Feature (Machine learning) on Wikipedia for general background on the concept of a feature in Machine Learning.
- Author:
- Owen Feehan
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedFeature()Creates with the default initializer.protectedFeature(BeanInitializer<FeatureInitialization> propertyInitializer) Creates with a custom initializer. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidassignTo(Feature<FeatureInput> target) Copies fields in this (base) class totarget.protected voidbeforeCalc(FeatureInitialization initialization) Dummy method, that children can optionally override.protected abstract doublecalculate(FeatureCalculationInput<T> input) Calculates a value for some input.doubleCalculates the result of a feature and throws an exception if the feature has not been initialized.castAs()Casts the feature to having a different input-type.final FeatureList<FeatureInput> Returns a list of Features that exist as bean-properties of this feature, either directly or in lists.final StringA human-readable description of the parameterization of the bean.A long human-readable description of the feature and some or all of its parameterization.duplicateChangeName(String customName) Duplicates the feature as perAnchorBean.duplicateBean()but sets a particular custom-name.An optional additional name that be associated with the feature (defaults to an empty string).A user-friendly human-readable name for theFeature.abstract Class<? extends FeatureInput> The class corresponding to feature input-type.voidonInitialization(FeatureInitialization initialization) Called after initialization.voidsetCustomName(String customName) An optional additional name that be associated with the feature (defaults to an empty string).toString()Methods inherited from class org.anchoranalysis.bean.initializable.InitializableBean
getInitialization, getLogger, getPropertyInitializer, initialize, initializeRecursive, initRecursiveWithInitializer, isInitializedMethods inherited from class org.anchoranalysis.bean.AnchorBean
checkMisconfigured, describeChildren, duplicateBean, fields, findFieldsOfClass, getBeanName, getLocalPath, localise
-
Constructor Details
-
Feature
protected Feature()Creates with the default initializer. -
Feature
Creates with a custom initializer.- Parameters:
propertyInitializer- the custom initializer.
-
-
Method Details
-
onInitialization
Called after initialization.An empty implementation is provided, to be overridden as needed in the sub-classes.
- Overrides:
onInitializationin classInitializableBean<Feature<T extends FeatureInput>, FeatureInitialization>- Throws:
InitializeException
-
inputType
The class corresponding to feature input-type.i.e. corresponding to the
Ttemplate parameter.- Returns:
- the class.
-
describeBean
- Overrides:
describeBeanin classAnchorBean<Feature<T extends FeatureInput>>
-
descriptionLong
A long human-readable description of the feature and some or all of its parameterization.This can be overwritten to create an alternative description for features. By default string returned by
describeBean()is used.- Returns:
- the description.
-
duplicateChangeName
Duplicates the feature as perAnchorBean.duplicateBean()but sets a particular custom-name.- Parameters:
customName- the custom-name to set.- Returns:
- a duplicated (deep copy of bean attributes) feature, identical to current feature, but with the specified custom-name.
-
getFriendlyName
A user-friendly human-readable name for theFeature.If a custom-name has been assigned, this is returned, otherwise the
descriptionLong().- Returns:
- the user-friendly human-readable name.
-
createListChildFeatures
Returns a list of Features that exist as bean-properties of this feature, either directly or in lists.It does not recurse.
It ignores features that are referenced from elsewhere.
- Returns:
- the list of features.
- Throws:
BeanMisconfiguredException- if the feature-beans are not structured as expected.
-
describeParameters
A human-readable description of the parameterization of the bean.- Returns:
- the description.
-
toString
- Overrides:
toStringin classAnchorBean<Feature<T extends FeatureInput>>
-
castAs
Casts the feature to having a different input-type.Note that no active compile-type check occurs, so be careful that this is used appropriately.
- Type Parameters:
S- the type to cast to, which should be a sub-type of the existing-type.- Returns:
- the same instance, cast as having a different input-type.
-
calculateCheckInitialized
public double calculateCheckInitialized(FeatureCalculationInput<T> input) throws FeatureCalculationException Calculates the result of a feature and throws an exception if the feature has not been initialized.It is not recommended to directly use this method to calculate a feature's value, but rather to:
- Externally, for code outside a
Feature's implementation, please use the feature-session classes, who will perform the calculation using caching to reduce redundant computation. - Internally, for code inside a
Feature's implementation, please callFeatureCalculationInput.calculate(Feature)and similar methods, who will back-reference the session above, to take advantage of the caching.
- Parameters:
input- the input to the calculation.- Returns:
- the feature-value corresponding to
inputfor this feature. - Throws:
FeatureCalculationException- if the feature has not been initialized.
- Externally, for code outside a
-
beforeCalc
Dummy method, that children can optionally override.- Parameters:
initialization- initialization parameters.- Throws:
InitializeException- if initialization cannot complete successfully.
-
calculate
protected abstract double calculate(FeatureCalculationInput<T> input) throws FeatureCalculationException Calculates a value for some input.- Parameters:
input- the input to the calculation.- Returns:
- the result of the calculation.
- Throws:
FeatureCalculationException- if the calculation cannot successfully complete.
-
assignTo
Copies fields in this (base) class totarget.This is intended to be called by sub-classes to help when duplicating.
- Parameters:
target- the object fields are assigned to.
-
getCustomName
An optional additional name that be associated with the feature (defaults to an empty string). -
setCustomName
An optional additional name that be associated with the feature (defaults to an empty string).
-