Skip to content
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

Checks on the data sets array dimensions #82

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions dso/dso/task/regression/regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@ def __init__(self, function_set, dataset, metric="inv_nrmse",
self.y_test = self.y_train
self.y_test_noiseless = self.y_test

# Check that y training and testing data arrays are one dimensional numpy arrays
# Problems when they are not and almost exclusively seen with sklearn-like (X,y) data
if self.y_train.ndim!=1:
raise ValueError(f"The array containing the data set\'s function values at the training points, \'y_train', needs to be a one dimensional Numpy array and nothing else. The given array is a {self.y_train.ndim} dimensional.")
if self.y_test.ndim!=1:
raise ValueError(f"The array containing the data set\'s function values at the testing points, \'y_test', needs to be a one dimensional Numpy array and nothing else. The given array is a {self.y_test.ndim} dimensional.")

# Save time by only computing data variances once
self.var_y_test = np.var(self.y_test)
self.var_y_test_noiseless = np.var(self.y_test_noiseless)
Expand Down
9 changes: 9 additions & 0 deletions dso/dso/task/regression/sklearn.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from sklearn.base import BaseEstimator, RegressorMixin
from sklearn.utils.validation import check_is_fitted
from numpy import ndarray

from dso import DeepSymbolicOptimizer

Expand All @@ -21,6 +22,14 @@ def __init__(self, config=None):

def fit(self, X, y):

# Do some various input argument checking.
if not(isinstance(X, ndarray) and isinstance(y, ndarray)):
raise TypeError(f"Both functional arguments (X, y) are to be Numpy ndarray class objects. The given function objects where "+type(X).__name__ + " and "+type(y).__name__ +" class objects respectively.")
if X.ndim!=2:
raise ValueError(f"The first function argument, \'X', needs to be a two dimensional Numpy array and nothing else. The given argument is a {X.ndim} dimensional array.")
if y.ndim!=1:
raise ValueError(f"The second function arguement, \'y', needs to be a one dimensional Numpy array and nothing else. The given array is a {y.ndim} dimensional array.")

# Update the Task
config = deepcopy(self.config)
config["task"]["dataset"] = (X, y)
Expand Down