I have two biosignals recording the same phenomenon with different methods.
Target signal is a reference signal and I would like to find some non-linear mapping from the original signal to the target signal.
I generated attractors from these two signals (see figures), and I would like to know what kind of algorithm you suggest to find the non-linear mapping from the original signal to the target signal.
Would Growing Neural Gas (GNG) or some type of Self-Organizing Map (SOM) algorithm work in that sense?
Thanks for your time!
This is a very basic attempt to build a functional relationship between input and output data. Follows a basic python scrip which configures a LSTM with a hidden layer and 10 delays. This script can be enhanced by considering more hidden layers and more delays. This script is a mixture of cut and paste over existing code accessible via internet.
import pandas as pd import matplotlib.pyplot as plt from numpy import array from keras.models import Sequential from keras.layers import LSTM from keras.layers import Densedatain = pd.read_pickle('signal1.pkl') dataout = pd.read_pickle('signal2.pkl')""" discarding the 200 first values """ din = list(datain.values)[200:] dout = list(dataout.values)[200:]def media(data): s = 0; for dato in data: s += dato return s/len(data)def translate(data,media): data_translated = [] for dato in data: data_translated.append(dato-media) return data_translated"""univariate data preparation """ """ split a univariate sequence into samples """ def split_sequence(sequence_in, sequence_out, n_steps): (X, y) = (list(), list()) for i in range(len(sequence_in)): # find the end of this pattern end_ix = i + n_steps # check if we are beyond the sequence if end_ix > len(sequence_in)-1: break # gather input and output parts of the pattern (seq_x, seq_y) = (sequence_in[i:end_ix], sequence_out[end_ix]) X.append(seq_x) y.append(seq_y) return (array(X), array(y))
""" define input sequence """ seq_in = translate(din,media(din)) seq_out = translate(dout,media(dout))fig = plt.figure() ax = fig.gca() ax.plot(seq_in,seq_out) plt.title('Raw data') plt.show()""" choose a number of time steps """ n_steps = 10 """ split into samples """ (X, y) = split_sequence(seq_in, seq_out, n_steps) """ define model """ n_features = 1 X = X.reshape((X.shape[0], X.shape[1], n_features)) """ define model """ model = Sequential() model.add(LSTM(50, activation = 'relu', input_shape = (n_steps, n_features))) model.add(Dense(1)) model.compile(optimizer = 'adam', loss = 'mse') """ fit model """ model.fit(X, y, epochs = 800, verbose = 0) """ demonstrate prediction """ rec = [] for i in range(X.shape[0]): x_input = X[i] x_input = x_input.reshape((1, n_steps, n_features)) x_input = x_input.reshape((1, n_steps, n_features)) yhat = model.predict(x_input, verbose = 0) rec.append(yhat[0][0])pd.DataFrame(seq_in).plot.line() pd.DataFrame(seq_out).plot.line() pd.DataFrame(rec).plot.line()fig = plt.figure() ax = fig.gca() ax.plot(seq_in[n_steps:],rec) plt.title('Adjusted data') plt.show()