Hi
The LSTM has been trained to take a sequence of length _n_seq_in and provide a prediction of length _n_seq_out. As such, the known, initial data of length _n_seq_in would need to be provided to the model, and for the subsequent inference steps, the prediction in the previous inference step is appended to the input sequence. I would expect that for real application, this makes sense as the data in the prediction window is unknown.
However, the inference in the code test_emulation.py calls a function in neural_nets.py where the input data data_in is passed to the model for prediction, instead of using input sequence where the model output output_state is appended:
| coeffs_tmp=emulation.model_inference(data_in=data_test, idx=idx) |
| states[:,:] =np.copy(np.transpose(data_in[:,idx_x[cnt]])) |
I've modified the inference (not tested) to make it use coeffs which is updated with the model output, instead of data_in:
## initialization of variables and vectorsinput_batch=np.zeros([1, n_seq_in, n_features])
prediction=np.zeros([n_seq_out, n_features])
states=np.zeros([n_seq_in, n_features] , dtype=complex)
coeffs=np.zeros([n_features, nt] , dtype=complex)
idx_x=np.empty([nt-n_seq_in, n_seq_in] , int)
## compute real partname_tmp='real'+str(idx)
name_real=os.path.join(self._savedir, name_tmp+'.weights.h5')
self.model.load_weights(name_real)
coeffs[:,:n_seq_in] =data_in[:,:n_seq_in]
cnt=0fortintqdm(range(n_seq_in,nt,n_seq_out), desc='inference_real'):
idx_x[cnt,...] =np.arange(t-n_seq_in, t)
states[:,:] =np.transpose(coeffs[:,idx_x[cnt]])
input_batch[0,:,:] =states[None,:,:].realoutput_state=self.model.predict(input_batch, verbose=0)
coeffs_tmp=np.reshape(output_state[:], [n_seq_out, n_features])
lb= (n_seq_out*cnt) +n_seq_inub= (n_seq_out* (cnt+1)) +n_seq_incoeffs[:,lb:ub] =np.transpose(coeffs_tmp)
cnt=cnt+1
It would be nice to know which approach has been used in the article Lario et al., 2022.
Thanks in advance.
Hi
The LSTM has been trained to take a sequence of length
_n_seq_inand provide a prediction of length_n_seq_out. As such, the known, initial data of length_n_seq_inwould need to be provided to the model, and for the subsequent inference steps, the prediction in the previous inference step is appended to the input sequence. I would expect that for real application, this makes sense as the data in the prediction window is unknown.However, the inference in the code
test_emulation.pycalls a function inneural_nets.pywhere the input datadata_inis passed to the model for prediction, instead of using input sequence where the model outputoutput_stateis appended:PySPOD/tests/test_emulation.py
Line 272 in 9d69ac0
PySPOD/pyspod/emulation/neural_nets.py
Line 175 in 9d69ac0
I've modified the inference (not tested) to make it use
coeffswhich is updated with the model output, instead ofdata_in:It would be nice to know which approach has been used in the article Lario et al., 2022.
Thanks in advance.