T
- input-type from which a measurement is calculated.public abstract class Feature<T extends FeatureInput> extends InitializableBean<Feature<T>,FeatureInitialization>
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.
Modifier | Constructor and Description |
---|---|
protected |
Feature()
Creates with the default initializer.
|
protected |
Feature(BeanInitializer<FeatureInitialization> propertyInitializer)
Creates with a custom initializer.
|
Modifier and Type | Method and Description |
---|---|
protected void |
assignTo(Feature<FeatureInput> target)
Copies fields in this (base) class to
target . |
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 |
calculateCheckInitialized(FeatureCalculationInput<T> input)
Calculates the result of a feature and throws an exception if the feature has not been
initialized.
|
<S extends T> |
castAs()
Casts the feature to having a different input-type.
|
FeatureList<FeatureInput> |
createListChildFeatures()
Returns a list of Features that exist as bean-properties of this feature, either directly or
in lists.
|
String |
describeBean()
A (maybe longer) description identifying the bean and perhaps its key parameters.
|
String |
describeParameters()
A human-readable description of the parameterization of the bean.
|
String |
descriptionLong()
A long human-readable description of the feature and some or all of its parameterization.
|
Feature<T> |
duplicateChangeName(String customName)
Duplicates the feature as per
AnchorBean.duplicateBean() but sets a particular custom-name. |
String |
getCustomName()
An optional additional name that be associated with the feature (defaults to an empty
string).
|
String |
getFriendlyName()
A user-friendly human-readable name for the
Feature . |
abstract Class<? extends FeatureInput> |
inputType()
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).
|
String |
toString()
By default, we use
AnchorBean.describeBean() as the string representation of the bean. |
getInitialization, getLogger, getPropertyInitializer, initialize, initializeRecursive, initRecursiveWithInitializer, isInitialized
checkMisconfigured, describeChildren, duplicateBean, fields, findFieldsOfClass, getBeanName, getLocalPath, localise
protected Feature()
protected Feature(BeanInitializer<FeatureInitialization> propertyInitializer)
propertyInitializer
- the custom initializer.public void onInitialization(FeatureInitialization initialization) throws InitializeException
An empty implementation is provided, to be overridden as needed in the sub-classes.
onInitialization
in class InitializableBean<Feature<T extends FeatureInput>,FeatureInitialization>
initialization
- parameters used for initialization.InitializeException
- if initialization does not successfully complete.public abstract Class<? extends FeatureInput> inputType()
i.e. corresponding to the T
template parameter.
public final String describeBean()
AnchorBean
By default, it returns the same as AnchorBean.getBeanName()
but beans can optionally override
it
describeBean
in class AnchorBean<Feature<T extends FeatureInput>>
public String descriptionLong()
This can be overwritten to create an alternative description for features. By default
string returned by describeBean()
is used.
public Feature<T> duplicateChangeName(String customName)
AnchorBean.duplicateBean()
but sets a particular custom-name.customName
- the custom-name to set.public String getFriendlyName()
Feature
.
If a custom-name has been assigned, this is returned, otherwise the descriptionLong()
.
public final FeatureList<FeatureInput> createListChildFeatures() throws BeanMisconfiguredException
It does not recurse.
It ignores features that are referenced from elsewhere.
BeanMisconfiguredException
- if the feature-beans are not structured as expected.public String describeParameters()
public String toString()
AnchorBean
AnchorBean.describeBean()
as the string representation of the bean.toString
in class AnchorBean<Feature<T extends FeatureInput>>
public <S extends T> Feature<S> castAs()
Note that no active compile-type check occurs, so be careful that this is used appropriately.
S
- the type to cast to, which should be a sub-type of the existing-type.public double calculateCheckInitialized(FeatureCalculationInput<T> input) throws FeatureCalculationException
It is not recommended to directly use this method to calculate a feature's value, but rather to:
Feature
's implementation, please use the
feature-session classes, who will perform the calculation using caching to
reduce redundant computation.
Feature
's implementation, please call
FeatureCalculationInput.calculate(Feature)
and similar methods, who will
back-reference the session above, to take advantage of the caching.
input
- the input to the calculation.input
for this feature.FeatureCalculationException
- if the feature has not been initialized.protected void beforeCalc(FeatureInitialization initialization) throws InitializeException
initialization
- initialization parameters.InitializeException
- if initialization cannot complete successfully.protected abstract double calculate(FeatureCalculationInput<T> input) throws FeatureCalculationException
input
- the input to the calculation.FeatureCalculationException
- if the calculation cannot successfully complete.protected void assignTo(Feature<FeatureInput> target)
target
.
This is intended to be called by sub-classes to help when duplicating.
target
- the object fields are assigned to.public String getCustomName()
public void setCustomName(String customName)
Copyright © 2010–2023 Owen Feehan, ETH Zurich, University of Zurich, Hoffmann-La Roche. All rights reserved.