decargroup / pykoop Goto Github PK
View Code? Open in Web Editor NEWKoopman operator identification library in Python, compatible with `scikit-learn`
Home Page: https://pykoop.readthedocs.io/en/stable/
License: MIT License
Koopman operator identification library in Python, compatible with `scikit-learn`
Home Page: https://pykoop.readthedocs.io/en/stable/
License: MIT License
Binder can't run because scipy
1.9.0 is too new. Need to use 1.7.3.
Currently every subclass has to handle the episode feature itself. This is clunky.
Add EdmdMeta
to scikit-learn
estimator checks in test_regressors.py
.
Some unit tests are slow and require Mosek, so they can't be run server-side. Only a subset of the tests are currently run. Unit tests need to be reorganized so that the most possible tests can be run at each merge.
Scoring does not work correctly when X has NaN entries. Example to reproduce:
"""Example of how to use the Koopman pipeline."""
from sklearn.preprocessing import MaxAbsScaler, StandardScaler
import pykoop
import numpy as np
def example_pipeline_simple() -> None:
"""Demonstrate how to use the Koopman pipeline."""
# Get example mass-spring-damper data
eg = pykoop.example_data_msd()
# Create pipeline
kp = pykoop.KoopmanPipeline(
lifting_functions=[
('pl', pykoop.PolynomialLiftingFn(order=10)),
],
regressor=pykoop.Edmd(alpha=0),
)
# Fit the pipeline
kp.fit(
eg['X_train'],
n_inputs=eg['n_inputs'],
episode_feature=eg['episode_feature'],
)
# Predict using the pipeline
X_pred = kp.predict_trajectory(eg['x0_valid'], eg['u_valid'])
print(np.any(np.isnan(X_pred)))
# Score using the pipeline
score = kp.score(eg['X_valid'])
print(score)
if __name__ == '__main__':
example_pipeline_simple()
Solution is to implement the scikit-learn
convention:
error_score 'raise' or numeric, default=np.nan
Value to assign to the score if an error occurs in estimator
fitting. If set to ‘raise’, the error is raised. If a numeric value
is given, FitFailedWarning is raised. This parameter does not affect
the refit step, which will always raise the error.
Also delete useless doc/diagram/.gitignire
file
Despite the branch name, the PDF sources do not need to be added because they can be generated form the Python script.
When checking input dimensions, predict_trajectory()
forgets to account for the episode feature if U=None
.
Add diagram outlining Koopman pipeline.
Need to add sparse regression to docs... oops.
See https://packaging.python.org/en/latest/tutorials/packaging-projects/ and https://docs.pytest.org/en/7.1.x/explanation/goodpractices.html#tests-outside-application-code.
Need to make sure this does not negatively impact older versions of Python (3.7+).
Ever since numbers have been prefixed to the example file names, they are not correctly run by pytest
. Need to either edit the pytest.ini
pattern or rename the files.
The issue templates are too wordy.
error_score
should be the worst possible score returned by score_trajectory
.
If error_score=-1,
for example, a diverging trajectory could return a better score than a really bad bounded trajectory. This is problematic when pykoop
is paired with a hyperparameter optimizer like skopt.BayesSearchCV
.
Refactor PolynomialLiftingFn
to support products of other polynomials instead
of just monomials. For example, instead of x1^2 * x2
, allow H2(x1) * H1(x2)
where Hx
is the x
th Hermite polynomial.
This can be achieved by removing the wrapped scikit-learn
polynomial
transformer and using a custom one with similar functionality. Specifically the
powers_
matrix.
Add support for pykoop.DelayLiftingFn
in pykoop.SplitPipeline
.
pykoop.score_trajectory()
should always return a finite float (no np.inf
or np.nan
), return the error_score
, or raise a ValueError
.
If the inputs to pykoop.score_trajectory()
are finite, but overflow during the calculation of the score, then the function will return -np.inf
instead of error_score
. This can cause external hyperparameter optimizers to crash.
import numpy as np
import pykoop
X_predicted = np.array([
[1e-2, 1e-3],
]).T
X_expected = np.array([
[1e150, 1e250],
]).T
score = pykoop.score_trajectory(X_predicted, X_expected, episode_feature=False)
print(score)
test_regressors.py
is particularly messy
Automate plotting of common tasks like prediction error comparison.
Either my_pipeline.plot_whatever()
or pykoop.plot_whatever(my_pipeline)
. TBD.
DECAR Systems Group -> DECAR Group or just DECAR
Given a Koopman matrix U
, create a KoopmanRegressor
object that functions as if it was fit with pykoop
.
Along these lines:
class DataRegressor(KoopmanRegressor):
def __init__(self, U):
self.U = U
def fit(X, y):
self.n_features_in_ = ...
self.coef_ = U.copy()
This project has been using implicit optional so far, but that's deprecated now. Need to change
def f(x: np.ndarray = None)
to
def f(x: Optional[np.ndarray] = None)
While we're at it, consider changing np.ndarray
to ArrayLike
.
Allow keyword arguments like multioutput
to be passed to regression_metric
in KoopmanPipeline,make_scorer()
1.
Double-check GitHub action for release too, along with all URLS in docs.
Simply just allow bias in PolynomialLiftingFn
?
Makes user opt in to logging instead of opting out.
Add KoopmanPipeline.frequency_response()
to calculate Bode plot without actually plotting anything.
check_is_fitted
does not check for the right attributes all the time.
I forgot to bump the version in the source code from v1.1.0 to v1.1.1. PyPi rejected the release, but Zenodo accepted it. When fixing this, PyPi accepted the new package, but Zenodo rejected it. So I had to draft v1.1.2 to make everything consistent again.
I need to look into an automated check to prevent this from happening. If not that, then at least a written checklist to follow.
With the same input, relift_state=True
and relift_state=False
should have the same length outputs.
The lengths of the predictions differ. This indicates that something is wrong with the indexing.
Scale only lifted states without rescaling original states? Maybe the PolynomialLiftingFn
should handle its own scaling.
Either way, it's becoming more clear that normalizing and standardizing should be done outside of the KoopmanPipeline
, or within each lifting function as needed. But having a "normalizing" lifting function is a bit awkward since we want to keep the original state inside the lifted state unmodified.
sklearn.linear_model.Lasso
, sklearn.linear_model.ElasticNet
, sklearn.linear_model.SGDRegressor
, etc.
To implement in new Koopman regressor EdmdMeta
(because it's a meta-estimator).
https://scikit-learn.org/stable/modules/classes.html#module-sklearn.linear_model
Implement Total Least Squares DMD
Binder should load when clicking the link in the README.
Binder does not load because it requires Python 3.7.
KoopmanLiftingFn.transform()
can return non-finite outputs. I'm not sure if I should add a check before returning the transformed values, or if I should check for this elsewhere. Warnings are already raised by NumPy, so I think it's better to leave it alone for the time being.
predict_trajectory
checks if non-existent variables are finite.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.