Esempio n. 1
0
    def test_can_invert_pipeline_that_takes_frequency_adaptive_transform(self):
        td = TimeDimension(frequency=Seconds(1))
        scale = GeometricScale(20, 5000, 0.05, 10)
        arrs = [np.zeros((10, x)) for x in range(1, 11)]
        fa = FrequencyAdaptive(arrs, td, scale)

        @simple_in_memory_settings
        class Model(featureflow.BaseModel):
            log = featureflow.PickleFeature(
                Log,
                store=False)

            meanstd = featureflow.PickleFeature(
                MeanStdNormalization,
                needs=log,
                store=False)

            pipeline = featureflow.PickleFeature(
                PreprocessingPipeline,
                needs=(log, meanstd),
                store=True)

        _id = Model.process(log=fa)
        model = Model(_id)
        result = model.pipeline.transform(fa)
        recon = result.inverse_transform()
        self.assertIsInstance(recon, FrequencyAdaptive)
        self.assertEqual(fa.shape, recon.shape)
Esempio n. 2
0
 def test_can_roundtrip_frequency_adaptive_transform(self):
     td = TimeDimension(duration=Seconds(1), frequency=Milliseconds(500))
     scale = GeometricScale(20, 5000, 0.05, 120)
     arrs = [np.zeros((10, x)) for x in range(1, 121)]
     fa = FrequencyAdaptive(arrs, td, scale)
     decoded = self._roundtrip(fa, decoder=FrequencyAdaptiveDecoder())
     self.assertIsInstance(decoded, FrequencyAdaptive)
     self.assertEqual(fa.dimensions, decoded.dimensions)
Esempio n. 3
0
    def test_can_apply_weighting_to_frequency_adaptive_transform(self):
        @simple_in_memory_settings
        class Model(ff.BaseModel):
            weighted = ff.PickleFeature(
                Weighted,
                weighting=AWeighting(),
                store=False)

            scaled = ff.PickleFeature(
                InstanceScaling,
                needs=weighted,
                store=False)

            pipeline = ff.PickleFeature(
                PreprocessingPipeline,
                needs=(weighted, scaled),
                store=True)

        scale = GeometricScale(100, 1000, 0.1, 15)

        training = FrequencyAdaptive(
            [np.ones((100, x)) for x in xrange(1, len(scale) + 1)],
            time_dimension=TimeDimension(Seconds(1)),
            scale=scale)

        _id = Model.process(weighted=training)
        model = Model(_id)

        test = FrequencyAdaptive(
            [np.ones((10, x)) for x in xrange(1, len(scale) + 1)],
            time_dimension=TimeDimension(Seconds(1)),
            scale=scale)

        result = model.pipeline.transform(test)
        inverted = result.inverse_transform()

        self.assertIsInstance(inverted, FrequencyAdaptive)
        np.testing.assert_allclose(test, inverted)
Esempio n. 4
0
 def __call__(self, flo):
     raw = super(FrequencyAdaptiveDecoder, self).__call__(flo)
     return FrequencyAdaptive.from_array_with_units(raw)
Esempio n. 5
0
 def __call__(self, flo):
     raw = super(FrequencyAdaptiveDecoder, self).__call__(flo)
     return FrequencyAdaptive.from_array_with_units(raw)