Class Feature<T extends FeatureInput>
- Type Parameters:
T
- input-type from which a measurement is calculated.
- Direct Known Subclasses:
FeatureAllMemo
,FeatureBinary
,FeatureEnergy
,FeatureFromList
,FeatureGeneric
,FeatureHistogram
,FeatureImageMetadata
,FeatureObjectCollection
,FeaturePairMemo
,FeaturePairObjects
,FeatureResults
,FeatureSingleMemo
,FeatureSingleObject
,FeatureStack
,FeatureUnary
,FromDimensionsBase
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
ConstructorsModifierConstructorDescriptionprotected
Feature()
Creates with the default initializer.protected
Feature
(BeanInitializer<FeatureInitialization> propertyInitializer) Creates with a custom initializer. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
assignTo
(Feature<FeatureInput> target) Copies fields in this (base) class totarget
.protected void
beforeCalc
(FeatureInitialization initialization) Dummy method, that children can optionally override.protected abstract double
calculate
(FeatureCalculationInput<T> input) Calculates a value for some input.double
Calculates 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 String
A (maybe longer) description identifying the bean and perhaps its key parameters.A 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.void
onInitialization
(FeatureInitialization initialization) Called after initialization.void
setCustomName
(String customName) An optional additional name that be associated with the feature (defaults to an empty string).toString()
By default, we useAnchorBean.describeBean()
as the string representation of the bean.Methods inherited from class org.anchoranalysis.bean.initializable.InitializableBean
getInitialization, getLogger, getPropertyInitializer, initialize, initializeRecursive, initRecursiveWithInitializer, isInitialized
Methods 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:
onInitialization
in classInitializableBean<Feature<T extends FeatureInput>,
FeatureInitialization> - Parameters:
initialization
- parameters used for initialization.- Throws:
InitializeException
- if initialization does not successfully complete.
-
inputType
The class corresponding to feature input-type.i.e. corresponding to the
T
template parameter.- Returns:
- the class.
-
describeBean
Description copied from class:AnchorBean
A (maybe longer) description identifying the bean and perhaps its key parameters.By default, it returns the same as
AnchorBean.getBeanName()
but beans can optionally override it- Overrides:
describeBean
in classAnchorBean<Feature<T extends FeatureInput>>
- Returns:
- either the short-name of the bean, or a longer description
-
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
Description copied from class:AnchorBean
By default, we useAnchorBean.describeBean()
as the string representation of the bean.- Overrides:
toString
in classAnchorBean<Feature<T extends FeatureInput>>
- Returns:
- the string representation
-
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
input
for 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).
-