Wednesday, 5 June 2019

Autofilter for Time Series in Python/Keras using Conv1d

It may looks like a lot of code, but most of the code is comments or formatting to make it more readable.

Given:
If I define my variable of interest, "sequence", as follows:

# define input sequence
np.random.seed(988) 

#make numbers 1 to 100
sequence = np.arange(0,10, dtype=np.float16)

#shuffle the numbers
sequence = sequence[np.random.permutation(len(sequence))]

#augment the sequence with itself
sequence = np.tile(sequence,[15]).flatten().transpose()

#scale for Relu
sequence = (sequence - sequence.min()) / (sequence.max()-sequence.min())

sequence

# reshape input into [samples, timesteps, features]
n_in = len(sequence)
sequence = sequence.reshape((1, n_in, 1))

Question:
How do I use the conv1d in an autoencoder in Keras to estimate this sequence with a reasonable level of accuracy?

If conv1d is not appropriate for this problem, can you tell me what the more appropriate layer-type for the encoder-decoder might be?

More information:
Points about the data:

  • it is a repeating sequence of 10 distinct values
  • a single lag of 10 steps should perfectly predict the sequence
  • a dictionary of 10 elements should give a "predict the next given this"

I had tried other layers the encoder and decoder portions (LSTM, Dense, multilayer dense) to predict, and they kept hitting a "wall" at around mse of 0.0833... which is the variance of a uniform distribution ranged between 0 and 1. To me, a good autoencoder on this simple of a problem should be able to get at least 99.9% accurate, so a 'mse' substantially below 1%.

I haven't been able to get the conv1d to work because I am messing up the inputs. There seem to be no really great examples of how to make it work, and I am new enough to this overall architecture that it isn't being apparent to me.

Links:



from Autofilter for Time Series in Python/Keras using Conv1d

No comments:

Post a Comment