Willcox-Research-Group / rom-operator-inference-Python3

Operator Inference for data-driven, non-intrusive model reduction of dynamical systems.
https://willcox-research-group.github.io/rom-operator-inference-Python3
MIT License
67 stars 30 forks source link

Receive `Required step size is less than spacing between numbers` when using `cAH` mode. #32

Closed minhtriet closed 1 year ago

minhtriet commented 2 years ago

The objective I tried to run the code with cA mode. After that I include model form H mode to cA to improve performance. However, I receive the error IntegrationWarning: Required step size is less than spacing between numbers from rom_operator_inference/core/nonparametric/_public.py

Already tried tests

def prepare_data_and_train(data_to_train, r, regularizer=1e-2):
  train_data_derivative = opinf.pre.ddt(data_to_train, DELTA_T, order=6)        # Calculate the time derivative matrix.
  Vr, _ = opinf.pre.pod_basis(data_to_train, r=r)    
  rom = opinf.ContinuousOpInfROM(modelform="cAH")  
  rom.fit(Vr, data_to_train, train_data_derivative, regularizer=regularizer)
  return rom

During my simulation, I took care to not let the Courant strays far from 1.0

How could I debug this error?

minhtriet commented 2 years ago

This happened when I tried to increase r from _pre.podbasis from 3 to 4, 5, 6 etc. Also, if I change the mode from cAH to cAHG, then the integration error doesn't happen at _podbasis=4

minhtriet commented 2 years ago

A grid search shows some insights, the first column is number of basis, 2nd is regularizer

4 10000.0
4 100000.0
4 1000000.0
4 10000000.0
5 10000.0
5 100000.0
5 1000000.0
5 10000000.0
6 10000.0
6 100000.0
6 1000000.0
6 10000000.0
7 10000.0
With r=7, regularizer=10000.0, integration error happens
7 100000.0
7 1000000.0
7 10000000.0
8 10000.0
8 100000.0
8 1000000.0
8 10000000.0
9 10000.0
9 100000.0
9 1000000.0
9 10000000.0
10 10000.0
10 100000.0
10 1000000.0
10 10000000.0
11 10000.0
11 100000.0
11 1000000.0
11 10000000.0
12 10000.0
12 100000.0
12 1000000.0
12 10000000.0
With r=13, regularizer=10000.0, unterdetermined system
With r=13, regularizer=100000.0, unterdetermined system
With r=13, regularizer=1000000.0, unterdetermined system
With r=13, regularizer=10000000.0, unterdetermined system
With r=14, regularizer=10000.0, unterdetermined system
With r=14, regularizer=100000.0, unterdetermined system
With r=14, regularizer=1000000.0, unterdetermined system
With r=14, regularizer=10000000.0, unterdetermined system
With r=15, regularizer=10000.0, unterdetermined system
With r=15, regularizer=100000.0, unterdetermined system
With r=15, regularizer=1000000.0, unterdetermined system
With r=15, regularizer=10000000.0, unterdetermined system
minhtriet commented 2 years ago

By setting regularization to very large number (in comparison to machine learning normal range) like 3000 or 4000, I was able to solve the issue, but I do not know why

shanemcq18 commented 2 years ago

@minhtriet, the appropriate range for the regularizer is highly problem dependent. In relatively simple problems, we've had success with small regularization values. In others, such as in this paper, we've needed larger regularization values like the ones you are seeing. So this is normal. Hope that helps.

minhtriet commented 2 years ago

I see. Thank you. Currently I am doing a grid search with equal spacing from e-5 to e6. Perhaps I should change to grid search in log scale. Do you know of a way to find that regularization value quicker?

On 13. Aug 2022, at 20:35, Shane A. McQuarrie @.***> wrote:

 @minhtriet, the appropriate range for the regularizer is highly problem dependent. In relatively simple problems, we've had success with small regularization values. In others, such as in this paper, we've needed larger regularization values like the ones you are seeing. So this is normal. Hope that helps.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.

shanemcq18 commented 2 years ago

@minhtriet yes, I recommend searching for the regularizer on a log scale, np.logspace() might be helpful. This repository might also be helpful to look at (specifically step3_train.py, though it uses an older version of the package).