0
$\begingroup$

Can you please tell me how to build an autoencoder with a single matrix(4,4) with integer numbers? I want to build an autoencoder for the below-mentioned data. I don't know whether I should convert the decimal numbers to binary first using one-hot encoding or a neural network will recognize integer numbers. e.g,

input data = array([[ 4,  3,  8,  6],
                    [ 1,  1,  2,  2],
                    [24, 18, 32, 24],
                    [ 6,  6,  8,  8]])
autoencoder(data)
output data= array([[ 4,  3,  8,  6],
                    [ 1,  1,  2,  2],
                    [24, 18, 32, 24]
                    [ 6,  6,  8,  8]])
$\endgroup$
0

1 Answer 1

0
$\begingroup$

You can convert your data to float32 and feed it to an stack of LSTM Autoencoder with linear activation function.

The following architecture works, but you an fine tune it:

input_data = np.array([[[4, 3, 8, 6], [1, 1, 2, 2], [24, 18, 32, 24], [6, 6, 8, 8]]]).astype(np.float32)

model = tf.keras.Sequential([
    tf.keras.layers.LSTM(4, return_sequences=True, activation="linear"),
    tf.keras.layers.LSTM(2, return_sequences=True, activation="linear"),
    tf.keras.layers.LSTM(1, return_sequences=True, activation="linear"),
    tf.keras.layers.LSTM(2, return_sequences=True, activation="linear"),
    tf.keras.layers.LSTM(4, return_sequences=True, activation="linear"),
])

model.compile(optimizer="Adam", loss="MAE", metrics=["MSE"])
model.fit(input_data, input_data, epochs=200000)

What I have got after 200,000 epochs!:

[[[ 3.9911306   2.9956746   7.989547    5.9939675 ]
  [ 0.9976706   0.99182177  2.0006196   1.9999651 ]
  [23.9897     17.996624   31.995388   24.006733  ]
  [ 6.0549197   5.9584255   8.023056    8.003849  ]]]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.