Browse Source

fix the subsequence segmentation

master
lhenry15 4 years ago
parent
commit
a942786c91
3 changed files with 100 additions and 0 deletions
  1. +1
    -0
      tods/resources/.entry_points.ini
  2. +98
    -0
      tods/tests/timeseries_processing/test_SubsequenceSegmentation.py
  3. +1
    -0
      tods/timeseries_processing/SubsequenceSegmentation.py

+ 1
- 0
tods/resources/.entry_points.ini View File

@@ -20,6 +20,7 @@ tods.timeseries_processing.transformation.simple_exponential_smoothing = tods.ti
tods.timeseries_processing.transformation.holt_smoothing = tods.timeseries_processing.HoltSmoothing:HoltSmoothingPrimitive tods.timeseries_processing.transformation.holt_smoothing = tods.timeseries_processing.HoltSmoothing:HoltSmoothingPrimitive
tods.timeseries_processing.transformation.holt_winters_exponential_smoothing= tods.timeseries_processing.HoltWintersExponentialSmoothing:HoltWintersExponentialSmoothingPrimitive tods.timeseries_processing.transformation.holt_winters_exponential_smoothing= tods.timeseries_processing.HoltWintersExponentialSmoothing:HoltWintersExponentialSmoothingPrimitive
tods.timeseries_processing.decomposition.time_series_seasonality_trend_decomposition = tods.timeseries_processing.TimeSeriesSeasonalityTrendDecomposition:TimeSeriesSeasonalityTrendDecompositionPrimitive tods.timeseries_processing.decomposition.time_series_seasonality_trend_decomposition = tods.timeseries_processing.TimeSeriesSeasonalityTrendDecomposition:TimeSeriesSeasonalityTrendDecompositionPrimitive
tods.timeseries_processing.subsequence_segmentation = tods.timeseries_processing.SubsequenceSegmentation:SubsequenceSegmentationPrimitive




tods.feature_analysis.auto_correlation = tods.feature_analysis.AutoCorrelation:AutoCorrelationPrimitive tods.feature_analysis.auto_correlation = tods.feature_analysis.AutoCorrelation:AutoCorrelationPrimitive


+ 98
- 0
tods/tests/timeseries_processing/test_SubsequenceSegmentation.py View File

@@ -0,0 +1,98 @@
import unittest

from d3m import container, utils
from d3m.metadata import base as metadata_base
from tods.timeseries_processing import SubsequenceSegmentation


class SubsequenceSegmentationTest(unittest.TestCase):
def test_basic(self):
self.maxDiff = None
main = container.DataFrame({'a': [1., 2., 3.], 'b': [2., 3., 4.], 'c': [3., 4., 5.],},
# columns=['a', 'b', 'c'],
generate_metadata=True)

print(main)


self.assertEqual(utils.to_json_structure(main.metadata.to_internal_simple_structure()), [{
'selector': [],
'metadata': {
# 'top_level': 'main',
'schema': metadata_base.CONTAINER_SCHEMA_VERSION,
'structural_type': 'd3m.container.pandas.DataFrame',
'semantic_types': ['https://metadata.datadrivendiscovery.org/types/Table'],
'dimension': {
'name': 'rows',
'semantic_types': ['https://metadata.datadrivendiscovery.org/types/TabularRow'],
'length': 3,
},
},
}, {
'selector': ['__ALL_ELEMENTS__'],
'metadata': {
'dimension': {
'name': 'columns',
'semantic_types': ['https://metadata.datadrivendiscovery.org/types/TabularColumn'],
'length': 3,
},
},
}, {
'selector': ['__ALL_ELEMENTS__', 0],
'metadata': {'structural_type': 'numpy.float64', 'name': 'a'},
}, {
'selector': ['__ALL_ELEMENTS__', 1],
'metadata': {'structural_type': 'numpy.float64', 'name': 'b'},
}, {
'selector': ['__ALL_ELEMENTS__', 2],
'metadata': {'structural_type': 'numpy.float64', 'name': 'c'}
}])


self.assertIsInstance(main, container.DataFrame)


hyperparams_class = SubsequenceSegmentation.SubsequenceSegmentationPrimitive.metadata.get_hyperparams()
primitive = SubsequenceSegmentation.SubsequenceSegmentationPrimitive(hyperparams=hyperparams_class.defaults())
new_main = primitive.produce(inputs=main).value
print(new_main)
print(new_main.shape)


self.assertEqual(utils.to_json_structure(main.metadata.to_internal_simple_structure()), [{
'selector': [],
'metadata': {
# 'top_level': 'main',
'schema': metadata_base.CONTAINER_SCHEMA_VERSION,
'structural_type': 'd3m.container.pandas.DataFrame',
'semantic_types': ['https://metadata.datadrivendiscovery.org/types/Table'],
'dimension': {
'name': 'rows',
'semantic_types': ['https://metadata.datadrivendiscovery.org/types/TabularRow'],
'length': 3,
},
},
}, {
'selector': ['__ALL_ELEMENTS__'],
'metadata': {
'dimension': {
'name': 'columns',
'semantic_types': ['https://metadata.datadrivendiscovery.org/types/TabularColumn'],
'length': 3,
},
},
}, {
'selector': ['__ALL_ELEMENTS__', 0],
'metadata': {'structural_type': 'numpy.float64', 'name': 'a'},
}, {
'selector': ['__ALL_ELEMENTS__', 1],
'metadata': {'structural_type': 'numpy.float64', 'name': 'b'},
}, {
'selector': ['__ALL_ELEMENTS__', 2],
'metadata': {'structural_type': 'numpy.float64', 'name': 'c'}
}])



if __name__ == '__main__':
unittest.main()

+ 1
- 0
tods/timeseries_processing/SubsequenceSegmentation.py View File

@@ -7,6 +7,7 @@ import numpy as np
import typing import typing
import time import time
import pandas as pd import pandas as pd
import uuid


from d3m import container from d3m import container
from d3m.primitive_interfaces import base, transformer from d3m.primitive_interfaces import base, transformer


Loading…
Cancel
Save