Class ShapeletTransformLearningAlgorithm
- java.lang.Object
-
- ai.libs.jaicore.basic.algorithm.AAlgorithm<ai.libs.jaicore.ml.classification.singlelabel.timeseries.dataset.TimeSeriesDataset2,C>
-
- ai.libs.jaicore.ml.classification.singlelabel.timeseries.learner.ASimplifiedTSCLearningAlgorithm<java.lang.Integer,ShapeletTransformTSClassifier>
-
- ai.libs.jaicore.ml.weka.classification.timeseries.learner.shapelets.ShapeletTransformLearningAlgorithm
-
- All Implemented Interfaces:
java.lang.Iterable<org.api4.java.algorithm.events.IAlgorithmEvent>,java.util.concurrent.Callable<ShapeletTransformTSClassifier>,java.util.Iterator<org.api4.java.algorithm.events.IAlgorithmEvent>,org.api4.java.algorithm.IAlgorithm<ai.libs.jaicore.ml.classification.singlelabel.timeseries.dataset.TimeSeriesDataset2,ShapeletTransformTSClassifier>,org.api4.java.common.control.ICancelable,org.api4.java.common.control.ILoggingCustomizable,org.api4.java.common.event.IEventEmitter<java.lang.Object>,org.api4.java.common.event.IRelaxedEventEmitter
public class ShapeletTransformLearningAlgorithm extends ai.libs.jaicore.ml.classification.singlelabel.timeseries.learner.ASimplifiedTSCLearningAlgorithm<java.lang.Integer,ShapeletTransformTSClassifier>
Algorithm training a ShapeletTransform classifier as described in Jason Lines, Luke M. Davis, Jon Hills, and Anthony Bagnall. 2012. A shapelet transform for time series classification. In Proceedings of the 18th ACM SIGKDD international conference on Knowledge discovery and data mining (KDD '12). ACM, New York, NY, USA, 289-297.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceShapeletTransformLearningAlgorithm.IShapeletTransformLearningAlgorithmConfig
-
Constructor Summary
Constructors Constructor Description ShapeletTransformLearningAlgorithm(ShapeletTransformLearningAlgorithm.IShapeletTransformLearningAlgorithmConfig config, ShapeletTransformTSClassifier classifier, ai.libs.jaicore.ml.classification.singlelabel.timeseries.dataset.TimeSeriesDataset2 dataset, ai.libs.jaicore.ml.classification.singlelabel.timeseries.quality.IQualityMeasure qualityMeasure)Constructs a training algorithm for theShapeletTransformTSClassifierclassifier specified by the given parameters.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ShapeletTransformTSClassifiercall()Training procedure forShapeletTransformTSClassifierusing the training algorithm described in the paper.java.util.List<ai.libs.jaicore.ml.classification.singlelabel.timeseries.shapelets.Shapelet>clusterShapelets(java.util.List<ai.libs.jaicore.ml.classification.singlelabel.timeseries.shapelets.Shapelet> shapelets, int noClusters, long beginTime)Clusters the givenshapeletsintonoClustersclusters (cf. algorithm 6 of the original paper).java.util.List<java.lang.Double>findDistances(ai.libs.jaicore.ml.classification.singlelabel.timeseries.shapelets.Shapelet s, double[][] matrix)Function finding the minimum single squared Euclidean distance for each instance among all of its subsequences compared to the shapelets.static java.util.Set<ai.libs.jaicore.ml.classification.singlelabel.timeseries.shapelets.Shapelet>generateCandidates(double[] data, int l, int candidateIndex)Function generation shapelet candidates for a given instance vectordata, the lengthland the candidate index which is used to identify the source of the shapelet's data.ShapeletTransformLearningAlgorithm.IShapeletTransformLearningAlgorithmConfiggetConfig()ai.libs.jaicore.ml.classification.singlelabel.timeseries.shapelets.search.AMinimumDistanceSearchStrategygetMinDistanceSearchStrategy()Getter forminDistanceSearchStrategy.static java.util.List<java.util.Map.Entry<ai.libs.jaicore.ml.classification.singlelabel.timeseries.shapelets.Shapelet,java.lang.Double>>merge(int k, java.util.List<java.util.Map.Entry<ai.libs.jaicore.ml.classification.singlelabel.timeseries.shapelets.Shapelet,java.lang.Double>> kShapelets, java.util.List<java.util.Map.Entry<ai.libs.jaicore.ml.classification.singlelabel.timeseries.shapelets.Shapelet,java.lang.Double>> shapelets)Function merging shapelet lists based on their quality scores.org.api4.java.algorithm.events.IAlgorithmEventnextWithException()voidregisterListener(java.lang.Object listener)static java.util.List<java.util.Map.Entry<ai.libs.jaicore.ml.classification.singlelabel.timeseries.shapelets.Shapelet,java.lang.Double>>removeSelfSimilar(java.util.List<java.util.Map.Entry<ai.libs.jaicore.ml.classification.singlelabel.timeseries.shapelets.Shapelet,java.lang.Double>> shapelets)Function removing self-similar shapelets from a list storing shapelet and their quality entries.voidsetMinDistanceSearchStrategy(ai.libs.jaicore.ml.classification.singlelabel.timeseries.shapelets.search.AMinimumDistanceSearchStrategy minDistanceSearchStrategy)Setter forminDistanceSearchStrategy.static double[]shapeletTransform(double[] instance, java.util.List<ai.libs.jaicore.ml.classification.singlelabel.timeseries.shapelets.Shapelet> shapelets, ai.libs.jaicore.ml.classification.singlelabel.timeseries.shapelets.search.AMinimumDistanceSearchStrategy searchStrategy)Function transforming the giveninstanceinto the new feature space spanned by the shapelets.static ai.libs.jaicore.ml.classification.singlelabel.timeseries.dataset.TimeSeriesDataset2shapeletTransform(ai.libs.jaicore.ml.classification.singlelabel.timeseries.dataset.TimeSeriesDataset2 dataSet, java.util.List<ai.libs.jaicore.ml.classification.singlelabel.timeseries.shapelets.Shapelet> shapelets, org.api4.java.algorithm.Timeout timeout, long beginTime, ai.libs.jaicore.ml.classification.singlelabel.timeseries.shapelets.search.AMinimumDistanceSearchStrategy searchStrategy)Performs a shapelet transform on a completedataSet.-
Methods inherited from class ai.libs.jaicore.ml.classification.singlelabel.timeseries.learner.ASimplifiedTSCLearningAlgorithm
cancel, getClassifier, hasNext, iterator, next
-
Methods inherited from class ai.libs.jaicore.basic.algorithm.AAlgorithm
activate, announceTimeoutDetected, avoidReinterruptionOnShutdownOnCurrentThread, checkAndConductTermination, checkTermination, computeTimeoutAware, getActivationTime, getDeadline, getId, getInput, getListeners, getLoggerName, getNumCPUs, getRemainingTimeToDeadline, getState, getTimeout, getTimeoutPrecautionOffset, hasThreadBeenInterruptedDuringShutdown, interruptThreadAsPartOfShutdown, isCanceled, isShutdownInitialized, isStopCriterionSatisfied, isTimeoutDefined, isTimeouted, post, registerActiveThread, resolveShutdownInterruptOnCurrentThread, setConfig, setDeadline, setLoggerName, setMaxNumThreads, setNumCPUs, setState, setTimeout, setTimeout, setTimeoutPrecautionOffset, shutdown, terminate, unregisterActiveThread, unregisterThreadAndShutdown
-
-
-
-
Constructor Detail
-
ShapeletTransformLearningAlgorithm
public ShapeletTransformLearningAlgorithm(ShapeletTransformLearningAlgorithm.IShapeletTransformLearningAlgorithmConfig config, ShapeletTransformTSClassifier classifier, ai.libs.jaicore.ml.classification.singlelabel.timeseries.dataset.TimeSeriesDataset2 dataset, ai.libs.jaicore.ml.classification.singlelabel.timeseries.quality.IQualityMeasure qualityMeasure)
Constructs a training algorithm for theShapeletTransformTSClassifierclassifier specified by the given parameters.- Parameters:
qualityMeasure- Quality measure used to assess the shapelets
-
-
Method Detail
-
call
public ShapeletTransformTSClassifier call() throws org.api4.java.algorithm.exceptions.AlgorithmException, java.lang.InterruptedException
Training procedure forShapeletTransformTSClassifierusing the training algorithm described in the paper.- Returns:
- Returns the trained model
- Throws:
org.api4.java.algorithm.exceptions.AlgorithmException- Thrown if the training could not be finishedjava.lang.InterruptedException
-
clusterShapelets
public java.util.List<ai.libs.jaicore.ml.classification.singlelabel.timeseries.shapelets.Shapelet> clusterShapelets(java.util.List<ai.libs.jaicore.ml.classification.singlelabel.timeseries.shapelets.Shapelet> shapelets, int noClusters, long beginTime) throws java.lang.InterruptedExceptionClusters the givenshapeletsintonoClustersclusters (cf. algorithm 6 of the original paper).- Parameters:
shapelets- Shapelets to be clustered.noClusters- Number of clusters to be used, i. e. the size of the output listbeginTime- Begin time of the training execution used for the timeout checks- Returns:
- Returns the clustered shapelets
- Throws:
java.lang.InterruptedException- Thrown when a timeout occurred
-
merge
public static java.util.List<java.util.Map.Entry<ai.libs.jaicore.ml.classification.singlelabel.timeseries.shapelets.Shapelet,java.lang.Double>> merge(int k, java.util.List<java.util.Map.Entry<ai.libs.jaicore.ml.classification.singlelabel.timeseries.shapelets.Shapelet,java.lang.Double>> kShapelets, java.util.List<java.util.Map.Entry<ai.libs.jaicore.ml.classification.singlelabel.timeseries.shapelets.Shapelet,java.lang.Double>> shapelets)Function merging shapelet lists based on their quality scores. Only the k best shapelets of the union of both lists are retained.- Parameters:
k- Number of elements to be retainedkShapelets- The previous best shapeletsshapelets- The new shapelets to be added to the top-k list- Returns:
- Returns the list containing the k best shapelets only
-
removeSelfSimilar
public static java.util.List<java.util.Map.Entry<ai.libs.jaicore.ml.classification.singlelabel.timeseries.shapelets.Shapelet,java.lang.Double>> removeSelfSimilar(java.util.List<java.util.Map.Entry<ai.libs.jaicore.ml.classification.singlelabel.timeseries.shapelets.Shapelet,java.lang.Double>> shapelets)
Function removing self-similar shapelets from a list storing shapelet and their quality entries. SeeisSelfSimilar(Shapelet, Shapelet).- Parameters:
shapelets- Shapelets to be compared- Returns:
- A sublist from the given
shapeletslist which does not contain any self-similar shapelets
-
findDistances
public java.util.List<java.lang.Double> findDistances(ai.libs.jaicore.ml.classification.singlelabel.timeseries.shapelets.Shapelet s, double[][] matrix)Function finding the minimum single squared Euclidean distance for each instance among all of its subsequences compared to the shapelets.- Parameters:
s- Shapelet which is compared to the instancesmatrix- Matrix storing the data instance vectors- Returns:
- Returns the list of all minimum distances of the shapelet and all the instances
-
generateCandidates
public static java.util.Set<ai.libs.jaicore.ml.classification.singlelabel.timeseries.shapelets.Shapelet> generateCandidates(double[] data, int l, int candidateIndex)Function generation shapelet candidates for a given instance vectordata, the lengthland the candidate index which is used to identify the source of the shapelet's data.- Parameters:
data- Data vector from which the values are extractedl- The length of the generated candidate shapeletcandidateIndex- Instance index which is used to identify the generated shapelets- Returns:
- Returns a set of shapelet candidates with the length
l
-
shapeletTransform
public static ai.libs.jaicore.ml.classification.singlelabel.timeseries.dataset.TimeSeriesDataset2 shapeletTransform(ai.libs.jaicore.ml.classification.singlelabel.timeseries.dataset.TimeSeriesDataset2 dataSet, java.util.List<ai.libs.jaicore.ml.classification.singlelabel.timeseries.shapelets.Shapelet> shapelets, org.api4.java.algorithm.Timeout timeout, long beginTime, ai.libs.jaicore.ml.classification.singlelabel.timeseries.shapelets.search.AMinimumDistanceSearchStrategy searchStrategy) throws java.lang.InterruptedExceptionPerforms a shapelet transform on a completedataSet. SeeShapeletTransformLearningAlgorithm#shapeletTransform(double[], List).- Parameters:
dataSet- Data set to be transformedshapelets- Shapelets used as new feature dimensionstimeout- Timeout compared to the current time difference to thebeginTimebeginTime- System time in ms when the training algorithm has startedsearchStrategy- Search strategy used to find the minimum distance from a shapelet to the time series- Returns:
- Returns the transformed data set
- Throws:
java.lang.InterruptedException- Thrown if there was a timeout
-
shapeletTransform
public static double[] shapeletTransform(double[] instance, java.util.List<ai.libs.jaicore.ml.classification.singlelabel.timeseries.shapelets.Shapelet> shapelets, ai.libs.jaicore.ml.classification.singlelabel.timeseries.shapelets.search.AMinimumDistanceSearchStrategy searchStrategy)Function transforming the giveninstanceinto the new feature space spanned by the shapelets. Uses the minimum squared Euclidean distance of the corresponding shapelets to the instance as feature values.- Parameters:
instance- The instance to be transformedshapelets- The shapelets to be used as new feature dimensionssearchStrategy- Search strategy used to find the minimum distance from a shapelet to the time series- Returns:
- Returns the transformed instance feature vector
-
getMinDistanceSearchStrategy
public ai.libs.jaicore.ml.classification.singlelabel.timeseries.shapelets.search.AMinimumDistanceSearchStrategy getMinDistanceSearchStrategy()
Getter forminDistanceSearchStrategy.- Returns:
- the minDistanceSearchStrategy
-
setMinDistanceSearchStrategy
public void setMinDistanceSearchStrategy(ai.libs.jaicore.ml.classification.singlelabel.timeseries.shapelets.search.AMinimumDistanceSearchStrategy minDistanceSearchStrategy)
Setter forminDistanceSearchStrategy.- Parameters:
minDistanceSearchStrategy- the minDistanceSearchStrategy to set
-
registerListener
public void registerListener(java.lang.Object listener)
- Specified by:
registerListenerin interfaceorg.api4.java.algorithm.IAlgorithm<ai.libs.jaicore.ml.classification.singlelabel.timeseries.dataset.TimeSeriesDataset2,ShapeletTransformTSClassifier>- Specified by:
registerListenerin interfaceorg.api4.java.common.event.IEventEmitter<java.lang.Object>- Overrides:
registerListenerin classai.libs.jaicore.ml.classification.singlelabel.timeseries.learner.ASimplifiedTSCLearningAlgorithm<java.lang.Integer,ShapeletTransformTSClassifier>
-
nextWithException
public org.api4.java.algorithm.events.IAlgorithmEvent nextWithException()
- Specified by:
nextWithExceptionin interfaceorg.api4.java.algorithm.IAlgorithm<ai.libs.jaicore.ml.classification.singlelabel.timeseries.dataset.TimeSeriesDataset2,ShapeletTransformTSClassifier>- Overrides:
nextWithExceptionin classai.libs.jaicore.ml.classification.singlelabel.timeseries.learner.ASimplifiedTSCLearningAlgorithm<java.lang.Integer,ShapeletTransformTSClassifier>
-
getConfig
public ShapeletTransformLearningAlgorithm.IShapeletTransformLearningAlgorithmConfig getConfig()
- Specified by:
getConfigin interfaceorg.api4.java.algorithm.IAlgorithm<ai.libs.jaicore.ml.classification.singlelabel.timeseries.dataset.TimeSeriesDataset2,ShapeletTransformTSClassifier>- Overrides:
getConfigin classai.libs.jaicore.basic.algorithm.AAlgorithm<ai.libs.jaicore.ml.classification.singlelabel.timeseries.dataset.TimeSeriesDataset2,ShapeletTransformTSClassifier>
-
-