Class TimeSeriesTreeLearningAlgorithm
- 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,TimeSeriesTreeClassifier>
-
- ai.libs.jaicore.ml.weka.classification.singlelabel.timeseries.learner.trees.TimeSeriesTreeLearningAlgorithm
-
- All Implemented Interfaces:
java.lang.Iterable<org.api4.java.algorithm.events.IAlgorithmEvent>,java.util.concurrent.Callable<TimeSeriesTreeClassifier>,java.util.Iterator<org.api4.java.algorithm.events.IAlgorithmEvent>,org.api4.java.algorithm.IAlgorithm<ai.libs.jaicore.ml.classification.singlelabel.timeseries.dataset.TimeSeriesDataset2,TimeSeriesTreeClassifier>,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 TimeSeriesTreeLearningAlgorithm extends ai.libs.jaicore.ml.classification.singlelabel.timeseries.learner.ASimplifiedTSCLearningAlgorithm<java.lang.Integer,TimeSeriesTreeClassifier>
Algorithm to build a time series tree as described in Deng, Houtao et al. "A Time Series Forest for Classification and Feature Extraction." Inf. Sci. 239 (2013): 142-153.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceTimeSeriesTreeLearningAlgorithm.ITimeSeriesTreeConfig
-
Field Summary
Fields Modifier and Type Field Description static doubleENTROPY_APLHAAlpha parameter used to weight the importance of the feature's margins to the threshold candidates.static intNUM_THRESH_CANDIDATESNumber of threshold candidates created in each tree recursion step.static booleanUSE_BIAS_CORRECTIONIndicator that the bias (Bessel's) correction should be used for the calculation of the standard deviation.
-
Constructor Summary
Constructors Constructor Description TimeSeriesTreeLearningAlgorithm(TimeSeriesTreeLearningAlgorithm.ITimeSeriesTreeConfig config, TimeSeriesTreeClassifier tree, ai.libs.jaicore.ml.classification.singlelabel.timeseries.dataset.TimeSeriesDataset2 data)Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static doublecalculateDeltaEntropy(double[] dataValues, int[] targets, double thresholdCandidate, java.util.List<java.lang.Integer> classes, double parentEntropy)Function calculating the delta entropy for a giventhresholdCandidateandparentEntropy.static doublecalculateEntrance(double deltaEntropy, double margin)Calculates the entrance gain specified by Deng et. al. in the paper's chapter 4.1.static doublecalculateMargin(double[] dataValues, double thresholdCandidate)Function calculating the margin between the giventhresholdCandidateand the nearest feature value from the givendataValues.TimeSeriesTreeClassifiercall()Training procedure construction a time series tree using the given input data.voidcancel()static java.util.List<java.util.List<java.lang.Double>>generateThresholdCandidates(ai.libs.jaicore.basic.sets.Pair<java.util.List<java.lang.Integer>,java.util.List<java.lang.Integer>> pairOfIntervalLists, int numOfCandidates, double[][][] transformedFeatures)Function generating threshold candidates for each feature type.intgetBestSplitIndex(double[] deltaEntropyStarPerFeatureType)Function returning feature type used for the split based on given the deltaEntropy star values.static ai.libs.jaicore.basic.sets.Pair<java.util.List<java.lang.Integer>,java.util.List<java.lang.Integer>>getChildDataIndices(double[][][] transformedData, int n, int fType, int t1t2, double threshold)Function returning the data indices assigned to the left and the right child of a binary tree based on the splitting criterion given by the feature typefType, the intervals indext1t2in the transformed data settransformedDataand thethreshold.intgetNumCPUs()org.api4.java.algorithm.TimeoutgetTimeout()booleanhasNext()java.util.Iterator<org.api4.java.algorithm.events.IAlgorithmEvent>iterator()org.api4.java.algorithm.events.IAlgorithmEventnext()org.api4.java.algorithm.events.IAlgorithmEventnextWithException()static java.util.List<java.lang.Integer>randomlySampleNoReplacement(java.util.List<java.lang.Integer> list, int sampleSize, long seed)Function sampling a givenlistrandomly without replacement using the givenseed.voidregisterListener(java.lang.Object listener)static ai.libs.jaicore.basic.sets.Pair<java.util.List<java.lang.Integer>,java.util.List<java.lang.Integer>>sampleIntervals(int m, long seed)Function sampling intervals based on the length of the time seriesmand the givenseed.voidsetNumCPUs(int numberOfCPUs)voidsetTimeout(org.api4.java.algorithm.Timeout timeout)double[][][]transformInstances(double[][] dataset, ai.libs.jaicore.basic.sets.Pair<java.util.List<java.lang.Integer>,java.util.List<java.lang.Integer>> pairOfItervalLists)Method transforming the givendatasetusing the interval pairs specified inT1T2by calculating eachTimeSeriesFeature.FeatureTypefor every instance and interval pair.voidtree(double[][] data, int[] targets, double parentEntropy, ai.libs.jaicore.graph.TreeNode<ai.libs.jaicore.ml.weka.classification.singlelabel.timeseries.learner.trees.TimeSeriesTreeClassifier.TimeSeriesTreeNodeDecisionFunction> nodeToBeFilled, int depth)Tree generation (cf.-
Methods inherited from class ai.libs.jaicore.ml.classification.singlelabel.timeseries.learner.ASimplifiedTSCLearningAlgorithm
getClassifier
-
Methods inherited from class ai.libs.jaicore.basic.algorithm.AAlgorithm
activate, announceTimeoutDetected, avoidReinterruptionOnShutdownOnCurrentThread, checkAndConductTermination, checkTermination, computeTimeoutAware, getActivationTime, getConfig, getDeadline, getId, getInput, getListeners, getLoggerName, getRemainingTimeToDeadline, getState, getTimeoutPrecautionOffset, hasThreadBeenInterruptedDuringShutdown, interruptThreadAsPartOfShutdown, isCanceled, isShutdownInitialized, isStopCriterionSatisfied, isTimeoutDefined, isTimeouted, post, registerActiveThread, resolveShutdownInterruptOnCurrentThread, setConfig, setDeadline, setLoggerName, setMaxNumThreads, setState, setTimeout, setTimeoutPrecautionOffset, shutdown, terminate, unregisterActiveThread, unregisterThreadAndShutdown
-
-
-
-
Field Detail
-
NUM_THRESH_CANDIDATES
public static final int NUM_THRESH_CANDIDATES
Number of threshold candidates created in each tree recursion step.- See Also:
- Constant Field Values
-
ENTROPY_APLHA
public static final double ENTROPY_APLHA
Alpha parameter used to weight the importance of the feature's margins to the threshold candidates.- See Also:
- Constant Field Values
-
USE_BIAS_CORRECTION
public static final boolean USE_BIAS_CORRECTION
Indicator that the bias (Bessel's) correction should be used for the calculation of the standard deviation.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
TimeSeriesTreeLearningAlgorithm
public TimeSeriesTreeLearningAlgorithm(TimeSeriesTreeLearningAlgorithm.ITimeSeriesTreeConfig config, TimeSeriesTreeClassifier tree, ai.libs.jaicore.ml.classification.singlelabel.timeseries.dataset.TimeSeriesDataset2 data)
Constructor.- Parameters:
maxDepth- Maximal depth of the tree to be trainedseed- Seed used for randomized operationsuseFeatureCaching- Indicator whether feature caching should be used. Since feature generation is very efficient, this should be only used if the time series is very long
-
-
Method Detail
-
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,TimeSeriesTreeClassifier>- 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,TimeSeriesTreeClassifier>
-
getNumCPUs
public int getNumCPUs()
- Specified by:
getNumCPUsin interfaceorg.api4.java.algorithm.IAlgorithm<ai.libs.jaicore.ml.classification.singlelabel.timeseries.dataset.TimeSeriesDataset2,TimeSeriesTreeClassifier>- Overrides:
getNumCPUsin classai.libs.jaicore.basic.algorithm.AAlgorithm<ai.libs.jaicore.ml.classification.singlelabel.timeseries.dataset.TimeSeriesDataset2,TimeSeriesTreeClassifier>
-
setNumCPUs
public void setNumCPUs(int numberOfCPUs)
- Specified by:
setNumCPUsin interfaceorg.api4.java.algorithm.IAlgorithm<ai.libs.jaicore.ml.classification.singlelabel.timeseries.dataset.TimeSeriesDataset2,TimeSeriesTreeClassifier>- Overrides:
setNumCPUsin classai.libs.jaicore.basic.algorithm.AAlgorithm<ai.libs.jaicore.ml.classification.singlelabel.timeseries.dataset.TimeSeriesDataset2,TimeSeriesTreeClassifier>
-
setTimeout
public void setTimeout(org.api4.java.algorithm.Timeout timeout)
- Specified by:
setTimeoutin interfaceorg.api4.java.algorithm.IAlgorithm<ai.libs.jaicore.ml.classification.singlelabel.timeseries.dataset.TimeSeriesDataset2,TimeSeriesTreeClassifier>- Overrides:
setTimeoutin classai.libs.jaicore.basic.algorithm.AAlgorithm<ai.libs.jaicore.ml.classification.singlelabel.timeseries.dataset.TimeSeriesDataset2,TimeSeriesTreeClassifier>
-
getTimeout
public org.api4.java.algorithm.Timeout getTimeout()
- Specified by:
getTimeoutin interfaceorg.api4.java.algorithm.IAlgorithm<ai.libs.jaicore.ml.classification.singlelabel.timeseries.dataset.TimeSeriesDataset2,TimeSeriesTreeClassifier>- Overrides:
getTimeoutin classai.libs.jaicore.basic.algorithm.AAlgorithm<ai.libs.jaicore.ml.classification.singlelabel.timeseries.dataset.TimeSeriesDataset2,TimeSeriesTreeClassifier>
-
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,TimeSeriesTreeClassifier>- Overrides:
nextWithExceptionin classai.libs.jaicore.ml.classification.singlelabel.timeseries.learner.ASimplifiedTSCLearningAlgorithm<java.lang.Integer,TimeSeriesTreeClassifier>
-
call
public TimeSeriesTreeClassifier call()
Training procedure construction a time series tree using the given input data.
-
iterator
public java.util.Iterator<org.api4.java.algorithm.events.IAlgorithmEvent> iterator()
- Specified by:
iteratorin interfacejava.lang.Iterable<org.api4.java.algorithm.events.IAlgorithmEvent>- Overrides:
iteratorin classai.libs.jaicore.ml.classification.singlelabel.timeseries.learner.ASimplifiedTSCLearningAlgorithm<java.lang.Integer,TimeSeriesTreeClassifier>
-
hasNext
public boolean hasNext()
- Specified by:
hasNextin interfacejava.util.Iterator<org.api4.java.algorithm.events.IAlgorithmEvent>- Overrides:
hasNextin classai.libs.jaicore.ml.classification.singlelabel.timeseries.learner.ASimplifiedTSCLearningAlgorithm<java.lang.Integer,TimeSeriesTreeClassifier>
-
next
public org.api4.java.algorithm.events.IAlgorithmEvent next()
- Specified by:
nextin interfacejava.util.Iterator<org.api4.java.algorithm.events.IAlgorithmEvent>- Overrides:
nextin classai.libs.jaicore.ml.classification.singlelabel.timeseries.learner.ASimplifiedTSCLearningAlgorithm<java.lang.Integer,TimeSeriesTreeClassifier>
-
cancel
public void cancel()
- Specified by:
cancelin interfaceorg.api4.java.common.control.ICancelable- Overrides:
cancelin classai.libs.jaicore.ml.classification.singlelabel.timeseries.learner.ASimplifiedTSCLearningAlgorithm<java.lang.Integer,TimeSeriesTreeClassifier>
-
tree
public void tree(double[][] data, int[] targets, double parentEntropy, ai.libs.jaicore.graph.TreeNode<ai.libs.jaicore.ml.weka.classification.singlelabel.timeseries.learner.trees.TimeSeriesTreeClassifier.TimeSeriesTreeNodeDecisionFunction> nodeToBeFilled, int depth)Tree generation (cf. Algorithm 2 of original paper). Samples the intervals in each recursion step and calculates the features (using caches ifTimeSeriesTreeLearningAlgorithm#useFeatureCachingwas set true). It then searches for an optimal split regarding several threshold candidates for feature splits. The splitting criterion is based on a metric called Entrance gain which is a combination of the entropy induced by the class proportions and the feature margins to the threshold (cf. chapter 4.1 in the paper). The tree's recursion is stopped at a leaf node if there is no entropy gain, themaxDepthhas been reached or the local entropy is zero.- Parameters:
data- The untransformed data which will be used for the split in the transformed feature representationtargets- The targets of the instancesparentEntropy- The parent entropy calculated in the recursion's previous stepnodeToBeFilled- The tree node which should be filled with the splitting information to use it for predictionsdepth- The current depth to be compared to theTimeSeriesTreeLearningAlgorithm#maxDepth
-
getChildDataIndices
public static ai.libs.jaicore.basic.sets.Pair<java.util.List<java.lang.Integer>,java.util.List<java.lang.Integer>> getChildDataIndices(double[][][] transformedData, int n, int fType, int t1t2, double threshold)Function returning the data indices assigned to the left and the right child of a binary tree based on the splitting criterion given by the feature typefType, the intervals indext1t2in the transformed data settransformedDataand thethreshold.- Parameters:
transformedData- Transformed data on which the split is calculatedn- The number of instancesfType- The feature type to be used for the splitt1t2- The interval's index in thetransformedDatato be used for the splitthreshold- The threshold to be used for the split- Returns:
- Returns a pair of two lists, storing the data indices for the data points assigned to the left child of the current node (X) and the data indices assigned to the right child (Y)
-
getBestSplitIndex
public int getBestSplitIndex(double[] deltaEntropyStarPerFeatureType)
Function returning feature type used for the split based on given the deltaEntropy star values. If multiple feature types have generated the same deltaEntropy value, a random decision is taken.- Parameters:
deltaEntropyStarPerFeatureType- The delta entropy star value per feature- Returns:
- Returns the feature type index which has been chosen
-
calculateDeltaEntropy
public static double calculateDeltaEntropy(double[] dataValues, int[] targets, double thresholdCandidate, java.util.List<java.lang.Integer> classes, double parentEntropy)Function calculating the delta entropy for a giventhresholdCandidateandparentEntropy. The values of the data are the feature type's values for each instance. The delta entropy is formed of the difference between the parent entropy and the weighted sum of the entropy values of the children and their instance assignments based on the split.- Parameters:
dataValues- The transformed feature type values for each instancetargets- The targets of each instancethresholdCandidate- The threshold candidate to be evaluatedclasses- List storing the classes whose indices can be looked upparentEntropy- The parent entropy used for the delta calculation- Returns:
- Returns the delta entropy for the threshold candidate of the current feature type
-
calculateEntrance
public static double calculateEntrance(double deltaEntropy, double margin)Calculates the entrance gain specified by Deng et. al. in the paper's chapter 4.1.- Parameters:
deltaEntropy- The delta entropymargin- The features margin- Returns:
- Returns the entrance gain
-
calculateMargin
public static double calculateMargin(double[] dataValues, double thresholdCandidate)Function calculating the margin between the giventhresholdCandidateand the nearest feature value from the givendataValues.- Parameters:
dataValues- The feature values compared to the candidatethresholdCandidate- The threshold candidate which is assessed- Returns:
- Returns the minimum distance among the feature values and the threshold candidate
-
transformInstances
public double[][][] transformInstances(double[][] dataset, ai.libs.jaicore.basic.sets.Pair<java.util.List<java.lang.Integer>,java.util.List<java.lang.Integer>> pairOfItervalLists)Method transforming the givendatasetusing the interval pairs specified inT1T2by calculating eachTimeSeriesFeature.FeatureTypefor every instance and interval pair.- Parameters:
dataset- The dataset which should be transformedpairOfItervalLists- The start and end interval pairs (seeTimeSeriesTreeLearningAlgorithm#sampleIntervals(int, int))- Returns:
- Returns the transformed instances (shape: number of feature types x number of interval pairs x number of instances)
-
generateThresholdCandidates
public static java.util.List<java.util.List<java.lang.Double>> generateThresholdCandidates(ai.libs.jaicore.basic.sets.Pair<java.util.List<java.lang.Integer>,java.util.List<java.lang.Integer>> pairOfIntervalLists, int numOfCandidates, double[][][] transformedFeatures)Function generating threshold candidates for each feature type. It calculates the interval [min f_k(t1,t2), max f_k(t1,t2)] among all instances for every feature type and every possible interval and generatesnumberOfCandidatescandidates using equal-width intervals.- Parameters:
pairOfIntervalLists- The pair of start and end interval pairs (seeTimeSeriesTreeLearningAlgorithm#sampleIntervals(int, int))numOfCandidates- The number of candidates to be generated per feature typetransformedFeatures- The transformed data instances- Returns:
- Returns a list consisting of a list for each feature type storing the threshold candidates
-
sampleIntervals
public static ai.libs.jaicore.basic.sets.Pair<java.util.List<java.lang.Integer>,java.util.List<java.lang.Integer>> sampleIntervals(int m, long seed)Function sampling intervals based on the length of the time seriesmand the givenseed. Refers to algorithm 1 of the paper. The sampled intervals are stored in a pair of lists where each index of the first list is related to the same index in the second list. Sampling is done without replacement.- Parameters:
m- Number of time series attributes (steps)seed- The seed used for the randomized sampling- Returns:
- Returns a pair of lists consisting of the start indices (X) and the end indices (Y)
-
randomlySampleNoReplacement
public static java.util.List<java.lang.Integer> randomlySampleNoReplacement(java.util.List<java.lang.Integer> list, int sampleSize, long seed)Function sampling a givenlistrandomly without replacement using the givenseed.sampleSizemany elements are sampled and returned.- Parameters:
list- List to be sampled from without replacementsampleSize- Number of elements to be sampled (must be <= list.size())seed- The seed used for the randomized sampling- Returns:
- Returns a list of elements which have been sampled
-
-