Loss does not reduce, EDMD

Hello all,

I hope that you are well.

I am facing some problems to converge a solution using algorithm 1 (see attached image). The algorithm comes from https://arxiv.org/pdf/1707.00225.pdf

The idea of the algorithm is that there are 2 steps:

• In the first step, K is calculated
• In the second step, the Adam algorithm is applied

The loss is always big and sometimes increases.
Not sure how to help the algorithm to converge.

I was wondering if you have any ideas

Loss values for some iterations:

``````7800

8000
8100
8200
8300
8400
8500
8600
8700
8800
``````

The code

``````
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Mar 28 10:08:00 2022

"""

import os
import argparse
import time
import numpy as np

import torch
import torch.nn as nn
import torch.optim as optim
import cloudpickle

import numpy as np
from scipy import linalg as la

from matplotlib import pyplot as plt
from scipy.stats import uniform
from statistics import mean

data_name = 'Duffing_oscillator'  # 'spectrum',  'Duffing_oscillator', 'Linear'，Discrete_Linear Duffing_oscillator spectrum-1

lambda_ = 1e-2

epsilon = 30

d = 2
l = 170
M = 22
I = torch.eye(M + 3, M + 3)

N = 10000
inv_N = 1/N  #0.1

net = nn.Sequential(
nn.Linear(d, l),
nn.Tanh(),
nn.Linear(l, l),
nn.Tanh(),
nn.Linear(l, l),
nn.Tanh(),
nn.Linear(l, M),
)

loss_fn = nn.MSELoss()

def data_Preprocessing(tr_val_te, cut):
data = np.loadtxt(('./data/%s_%s.csv' % (data_name, tr_val_te)), delimiter=',', dtype=np.float64)[:cut]
data = torch.tensor(data, dtype=torch.float32)
return data

def Frobenius_norm(X):
M = torch.mm(X, torch.transpose(X, 0, 1))

x = []
y = []
X = []
Y = []
K_tilde = []

#net input
x_data = data_Preprocessing("train_x", N)
y_data = data_Preprocessing("train_y", N)

count = 0
rotation = 50000

loss = float("INF")

while loss > epsilon  and count < rotation:
if count % 100 == 0:
print(count)

pred_sai = net(x_data)
y_pred_sai = net(y_data)

# combines the neural and auxiliary non-trainable dictionary

# Non-trainable dictionary
# Torch.Size([10000,3])

fixed_sai = torch.tensor([i + [0.1] for i in x_data.detach().tolist()], dtype=torch.float32)
y_fixed_sai = torch.tensor([i + [0.1] for i in y_data.detach().tolist()], dtype=torch.float32)

# Non-trainable dictionary + trainable dictionary

pred_sai = torch.cat([pred_sai, fixed_sai], dim=1)
y_pred_sai = torch.cat([y_pred_sai, y_fixed_sai], dim=1)

pred_sai_T = torch.transpose(pred_sai, 0, 1)

G = inv_N * torch.matmul(pred_sai_T, pred_sai)  #
A = inv_N * torch.matmul(pred_sai_T, y_pred_sai)

K_tilde = torch.mm(torch.pinverse(G + lambda_ * I), A)

Pred = torch.mm(K_tilde, pred_sai_T)

y_pred_sai_T = torch.transpose(y_pred_sai, 0, 1)

# loss calculation for the algorithm
res = lambda_ * Frobenius_norm(K_tilde)
MSE = (y_pred_sai_T - Pred)** 2

loss = torch.sum(MSE) + res

y.append(loss)
if count % 10 == 0:
print("loss", loss)

loss.backward()