-
Notifications
You must be signed in to change notification settings - Fork 0
[WIP] Refactor forecast #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…ing number of components, predict with skforecast
…gnature for get_component Creates a setter method to pass neccessary variables from simulation class to the decompostion class Corrects method signature for get_component in forecast.py and dimensionality_reduction.py
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors the forecasting code by separating dimensionality reduction and forecasting techniques into dedicated classes, updating configuration files, and modifying related scripts for consistency. Key changes include updating function signatures (e.g. adding a filename parameter to prepare), refactoring PCA/decomposition routines to leverage strategy classes, and adjusting forecast prediction reconstruction and error evaluation.
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
techniques_config.yaml | Added configuration entries to specify DR and forecast techniques. |
ocean_terms.yaml | Introduced a YAML file to map ocean term names for flexible usage. |
main_forecast.py | Updated function signatures, logging, and file handling logic. |
lib/restart.py | Added YAML loading for ocean terms in restart functions. |
lib/forecast_technique.py | Refactored forecast techniques including direct and recursive approaches. |
lib/forecast.py | Modified simulation loading, decomposition, reconstruction and forecasting logic. |
lib/dimensionality_reduction.py | Updated PCA and KernelPCA implementations with new methods for reconstruction. |
Comments suppressed due to low confidence (3)
main_forecast.py:557
- The revised logic for generating x_pred may not cover the full intended time range; please verify that the prediction array handles the simulation length and forecast steps as expected.
x_pred = np.arange(1 + pas, 1 + steps * pas, pas).reshape(-1, 1)
lib/forecast.py:156
- The comparison 'if self.len < self.end' may lead to errors if self.end is None; ensure that self.end is always set to a valid integer value or introduce a conditional branch to handle the None case.
array = [self.loadFile(file) for file in self.files if self.len < self.end]
main_forecast.py:85
- [nitpick] Minor typo: 'forcasted' should be corrected to 'forecasted'.
print(f"{term} time series forcasted")
if ( | ||
hasattr(self.regressor, "predict") | ||
and "return_std" in self.regressor.predict.__code__.co_varnames | ||
): | ||
y_hat, y_hat_std = self.regressor.predict(x_pred, return_std=True) | ||
return y_hat, y_hat_std | ||
else: | ||
y_hat = self.regressor.predict(x_pred) | ||
return y_hat, None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using code to check for the 'return_std' parameter may fail for built-in or compiled functions; consider using a more robust approach (e.g. try/except) to detect if standard deviation can be returned.
if ( | |
hasattr(self.regressor, "predict") | |
and "return_std" in self.regressor.predict.__code__.co_varnames | |
): | |
y_hat, y_hat_std = self.regressor.predict(x_pred, return_std=True) | |
return y_hat, y_hat_std | |
else: | |
y_hat = self.regressor.predict(x_pred) | |
return y_hat, None | |
if hasattr(self.regressor, "predict"): | |
try: | |
# Attempt to call predict with return_std=True | |
y_hat, y_hat_std = self.regressor.predict(x_pred, return_std=True) | |
return y_hat, y_hat_std | |
except TypeError: | |
# If TypeError is raised, fall back to predict without return_std | |
y_hat = self.regressor.predict(x_pred) | |
return y_hat, None | |
else: | |
raise AttributeError("The regressor does not have a 'predict' method.") |
Copilot uses AI. Check for mistakes.
The aim is to refactor the forecast.py code to make it easier to swap between different dimensionality reduction and forecasting techniques.
Refactored jupyter notebook, main_forecast and main to reflect changes to the refactored libraries. The jumper notebook is specific to using normal PCA (not Kernal PCA)
Separated code into forecasting technique classes and dimensionality reduction classes
Forecast.py calls the methods defined in the above two classes
The DR and forecasting techniques created are imported and stored in a dictionary
The DR and forecasting techniques the user wants to use can be specified by setting the name within "techniques_config.yaml"
Ocean_terms.yaml defines the names of the terms stored in the NEMO grid files, e.g. different configurations of nemo use different names for temperature, ssh and salinity. You can specify which names are used in the yaml file. Restart.py will then be able to read the correct keys.
Tested that the refactored code runs end-to-end
Test written against the non-refactored code need to be written.