2
$\begingroup$

I have a Neural Network (an autoencoder) that gets as the input a time-window of length M from a time series of length N, (M << N), and transforms it to another same dimensional time-window.

In purpose of visualization, I want to make a video that shows input of the NN in the top of the frame and the corresponding output in the bottom of the frame, runnig the NN on consecutive windows.

I was wondering if you could introduce me some tools or give me some hints on this.

$\endgroup$
0
1
$\begingroup$

Using this, I've written a script for it.

%matplotlib notebook

import numpy as np
import matplotlib.pyplot as plt
import time

plt.ion() 
size_x = 128
def pltts(ts1, ts2, ax, colors, lbl):
    x = np.linspace(0,2.5,size_x)
    if ax.lines:
        ax.lines[0].set_xdata(x)
        ax.lines[1].set_xdata(x)

        ax.lines[0].set_ydata(ts1)
        ax.lines[1].set_ydata(ts2)
    else:
        l1, l2 = ax.plot(x, ts1, colors[0], x, ts2, colors[1])
        fig.legend((l1, l2), ("BLUE", "RED"), loc='center', fontsize=fnt_siz-2)
        ax.set_title(lbl, fontsize=fnt_siz-2)
    fig.canvas.draw()

fnt_siz = 16

fig,ax = plt.subplots(2,1, figsize=(10,10))
fig.suptitle('Data', fontsize=fnt_siz)
ax[0].set_xlabel('Time', fontsize=fnt_siz-4)
ax[0].set_ylabel('Magnitude', fontsize=fnt_siz-4)
ax[1].set_xlabel('Time', fontsize=fnt_siz-4)
ax[1].set_ylabel('Magnitude', fontsize=fnt_siz-4)
plt.subplots_adjust(hspace=0.75)
# ax[0].grid(True)
# ax[1].grid(True)
for f in range(50):
    ts1 = np.random.normal(0, 4, size=(size_x,1))
    ts2 = np.random.normal(1, 1, size=(size_x,1))
    pltts(ts1, ts2, ax[0], ['b', 'r'], "ORGINAL")
    ts1 = 2*ts1
    ts2 = -3*ts2
    pltts(ts1, ts2, ax[1], ['b', 'r'], "TRANSFORMED")
    time.sleep(1)

This is a sample output:

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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