-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
45 changed files
with
9,738 additions
and
9,755 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,23 @@ | ||
from __future__ import annotations | ||
|
||
from pkg_resources import DistributionNotFound | ||
from pkg_resources import get_distribution | ||
|
||
try: | ||
__version__ = get_distribution(__name__).version | ||
except DistributionNotFound: | ||
pass | ||
|
||
from .koopman import Koopman | ||
from .koopman_continuous import KoopmanContinuous | ||
|
||
|
||
__all__ = [ | ||
"Koopman", | ||
"KoopmanContinuous", | ||
"common", | ||
"differentiation", | ||
"observables", | ||
"regression", | ||
"analytics", | ||
] | ||
from __future__ import annotations | ||
|
||
from pkg_resources import DistributionNotFound | ||
from pkg_resources import get_distribution | ||
|
||
try: | ||
__version__ = get_distribution(__name__).version | ||
except DistributionNotFound: | ||
pass | ||
|
||
from .koopman import Koopman | ||
from .koopman_continuous import KoopmanContinuous | ||
|
||
|
||
__all__ = [ | ||
"Koopman", | ||
"KoopmanContinuous", | ||
"common", | ||
"differentiation", | ||
"observables", | ||
"regression", | ||
"analytics", | ||
] |
14 changes: 7 additions & 7 deletions
14
pykoopman/analytics/__init__.py → src/pykoopman/analytics/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
from __future__ import annotations | ||
|
||
from ._base_analyzer import BaseAnalyzer | ||
from ._ms_pd21 import ModesSelectionPAD21 | ||
from ._pruned_koopman import PrunedKoopman | ||
|
||
__all__ = ["BaseAnalyzer", "ModesSelectionPAD21", "PrunedKoopman"] | ||
from __future__ import annotations | ||
|
||
from ._base_analyzer import BaseAnalyzer | ||
from ._ms_pd21 import ModesSelectionPAD21 | ||
from ._pruned_koopman import PrunedKoopman | ||
|
||
__all__ = ["BaseAnalyzer", "ModesSelectionPAD21", "PrunedKoopman"] |
178 changes: 89 additions & 89 deletions
178
pykoopman/analytics/_base_analyzer.py → src/pykoopman/analytics/_base_analyzer.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,89 +1,89 @@ | ||
"""module for implement modes analyzer for Koopman approximation""" | ||
from __future__ import annotations | ||
|
||
import abc | ||
|
||
import numpy as np | ||
|
||
|
||
class BaseAnalyzer(object): | ||
"""Base class for Koopman model analyzer. | ||
Attributes: | ||
model (Koopman): An instance of `pykoopman.koopman.Koopman`. | ||
eigenfunction (Koopman.compute_eigenfunction): A function that evaluates Koopman | ||
psi. | ||
eigenvalues_cont (numpy.ndarray): Koopman lamda in continuous-time. | ||
eigenvalues_discrete (numpy.ndarray): Koopman lamda in discrete-time. | ||
""" | ||
|
||
def __init__(self, model): | ||
"""Initialize the BaseAnalyzer object. | ||
Args: | ||
model (Koopman): An instance of `pykoopman.koopman.Koopman`. | ||
""" | ||
self.model = model | ||
self.eigenfunction = self.model.psi | ||
self.eigenvalues_cont = self.model.continuous_lamda_array | ||
self.eigenvalues_discrete = self.model.lamda_array | ||
|
||
def _compute_phi_minus_phi_evolved(self, t, validate_data_one_traj): | ||
"""Compute the difference between psi evolved and psi observed. | ||
Args: | ||
t (numpy.ndarray): Time stamp of this validation trajectory. | ||
validate_data_one_traj (numpy.ndarray): Data matrix of this validation | ||
trajectory. | ||
Returns: | ||
list: Linear residual for each mode. | ||
""" | ||
|
||
# shape of phi = (num_samples, num_modes) | ||
psi = self.eigenfunction(validate_data_one_traj.T).T | ||
|
||
linear_residual_list = [] | ||
for i in range(len(self.eigenvalues_cont)): | ||
linear_residual_list.append( | ||
psi[:, i] - np.exp(self.eigenvalues_cont[i] * t) * psi[0:1, i] | ||
) | ||
return linear_residual_list | ||
|
||
def validate(self, t, validate_data_one_traj): | ||
"""Validate Koopman psi. | ||
Given a single trajectory, compute the norm of the difference | ||
between observed psi and evolved psi for each mode. | ||
Args: | ||
t (numpy.ndarray): Time stamp of this validation trajectory. | ||
validate_data_one_traj (numpy.ndarray): Data matrix of this validation | ||
trajectory. | ||
Returns: | ||
list: Difference in norm for each mode. | ||
""" | ||
|
||
linear_residual_list = self._compute_phi_minus_phi_evolved( | ||
t, validate_data_one_traj | ||
) | ||
linear_residual_norm_list = [ | ||
np.linalg.norm(tmp) for tmp in linear_residual_list | ||
] | ||
return linear_residual_norm_list | ||
|
||
@abc.abstractmethod | ||
def prune_model(self, *params, **kwargs): | ||
"""Prune the model. | ||
This method should be implemented by the derived classes. | ||
Args: | ||
*params: Variable length argument list. | ||
**kwargs: Arbitrary keyword arguments. | ||
Raises: | ||
NotImplementedError: If the method is not implemented by the derived class. | ||
""" | ||
raise NotImplementedError | ||
"""module for implement modes analyzer for Koopman approximation""" | ||
from __future__ import annotations | ||
|
||
import abc | ||
|
||
import numpy as np | ||
|
||
|
||
class BaseAnalyzer(object): | ||
"""Base class for Koopman model analyzer. | ||
Attributes: | ||
model (Koopman): An instance of `pykoopman.koopman.Koopman`. | ||
eigenfunction (Koopman.compute_eigenfunction): A function that evaluates Koopman | ||
psi. | ||
eigenvalues_cont (numpy.ndarray): Koopman lamda in continuous-time. | ||
eigenvalues_discrete (numpy.ndarray): Koopman lamda in discrete-time. | ||
""" | ||
|
||
def __init__(self, model): | ||
"""Initialize the BaseAnalyzer object. | ||
Args: | ||
model (Koopman): An instance of `pykoopman.koopman.Koopman`. | ||
""" | ||
self.model = model | ||
self.eigenfunction = self.model.psi | ||
self.eigenvalues_cont = self.model.continuous_lamda_array | ||
self.eigenvalues_discrete = self.model.lamda_array | ||
|
||
def _compute_phi_minus_phi_evolved(self, t, validate_data_one_traj): | ||
"""Compute the difference between psi evolved and psi observed. | ||
Args: | ||
t (numpy.ndarray): Time stamp of this validation trajectory. | ||
validate_data_one_traj (numpy.ndarray): Data matrix of this validation | ||
trajectory. | ||
Returns: | ||
list: Linear residual for each mode. | ||
""" | ||
|
||
# shape of phi = (num_samples, num_modes) | ||
psi = self.eigenfunction(validate_data_one_traj.T).T | ||
|
||
linear_residual_list = [] | ||
for i in range(len(self.eigenvalues_cont)): | ||
linear_residual_list.append( | ||
psi[:, i] - np.exp(self.eigenvalues_cont[i] * t) * psi[0:1, i] | ||
) | ||
return linear_residual_list | ||
|
||
def validate(self, t, validate_data_one_traj): | ||
"""Validate Koopman psi. | ||
Given a single trajectory, compute the norm of the difference | ||
between observed psi and evolved psi for each mode. | ||
Args: | ||
t (numpy.ndarray): Time stamp of this validation trajectory. | ||
validate_data_one_traj (numpy.ndarray): Data matrix of this validation | ||
trajectory. | ||
Returns: | ||
list: Difference in norm for each mode. | ||
""" | ||
|
||
linear_residual_list = self._compute_phi_minus_phi_evolved( | ||
t, validate_data_one_traj | ||
) | ||
linear_residual_norm_list = [ | ||
np.linalg.norm(tmp) for tmp in linear_residual_list | ||
] | ||
return linear_residual_norm_list | ||
|
||
@abc.abstractmethod | ||
def prune_model(self, *params, **kwargs): | ||
"""Prune the model. | ||
This method should be implemented by the derived classes. | ||
Args: | ||
*params: Variable length argument list. | ||
**kwargs: Arbitrary keyword arguments. | ||
Raises: | ||
NotImplementedError: If the method is not implemented by the derived class. | ||
""" | ||
raise NotImplementedError |
Oops, something went wrong.