EthanJamesLew / AutoKoopman

AutoKoopman - automated Koopman operator methods for data-driven dynamical systems analysis and control.
GNU General Public License v3.0
53 stars 10 forks source link

Feature: State Weighted eDMD (SW-eDMD) #88

Closed EthanJamesLew closed 3 months ago

EthanJamesLew commented 4 months ago

Summary

This is an implementation of our novel eDMD algorithm that allows states and snapshots to be weighted. A conversion is done in the objective to translate weights on state to weights on observables.

CC @Abdu-Hekal

Abdu-Hekal commented 4 months ago

Great, Thank you! @EthanJamesLew There seems to be an issue when only 1 trajectory is used, an error is thrown. The issue seems to be due to the size of weights being 1. The computed Atilde in this case in sw-edmdc is None. You can recreate the issue by setting the number of training trajectories in the weighted-cost-func.ipynb notebook to 1.

Abdu-Hekal commented 4 months ago

It seems the issue isn't just for a low number of trajectories, but in general when sw-edmdc fails to find a solution, which may be related to limited data. @EthanJamesLew

EthanJamesLew commented 4 months ago

@Abdu-Hekal I can certainly present an error for that. However, would it be better to present a warning and switch to unweighted eDMD?

Abdu-Hekal commented 4 months ago

@EthanJamesLew Yes I agree! Is this issue simply inherent due to the approach, where it just fails to find a reasonable solution due to limited data?

EthanJamesLew commented 4 months ago

@Abdu-Hekal I will investigate...

Also, I have another idea for reweighting--to move some of the reweighting to the RFFs in addition to the DMD stage. I will attend to this and then play with reweighting the observables directly (data-adaptive).

Abdu-Hekal commented 4 months ago

Perfect! @EthanJamesLew I will revert back to testing with previous weighting method in the meantime

EthanJamesLew commented 4 months ago

@Abdu-Hekal added regularization for the sparse data case. I think it's ready to try now.

Abdu-Hekal commented 4 months ago

@EthanJamesLew Great! No errors now. The fit for the weighted approach though seems to be much worse. For reference I am attaching two images, one with weighting and one without for learning the Automatic transmission model with 1 training trajectory. I am using a weight of one for all point so the result is expected to be the same. default weighted

The poorly learnt model with weighting reminds of issues with normalization, is there something similar going on here?

EthanJamesLew commented 4 months ago

@Abdu-Hekal I can guess what's going on (large state values cause numerical instability during optimization). However, to avoid wasting your time, can you please see me a couple of those trajectories so that I can test them on my machine. A simple CSV or mat file will do. Thanks

Abdu-Hekal commented 4 months ago

@EthanJamesLew Sent them, Thank you!

Abdu-Hekal commented 4 months ago

@EthanJamesLew Maybe we should investigate the discrepancy when using different weights, where weights are the same for all points and all trajectories. We should ideally expect the same results if all weights are equal. Whilst using a weight of 1e-4 no explosion in values occurs, falsification results are much worse for the majority of benchmarks. Using a weight of 1 seems to give comparable results to non-weighted, despite very bad learning for a trainset of 1-2 trajectories, as it stabilizes later on. Maybe we could investigate different solvers as well, which might also help reduce runtime.

EthanJamesLew commented 4 months ago

@Abdu-Hekal I changed SW-eDMD to use rank adaptation. It now performs better on the sparsity examples that I tested

full_rank.pdf rank_adapted.pdf