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

Expose the optimal spline in SplineCV #219

Merged
merged 1 commit into from
Jan 20, 2020
Merged
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
21 changes: 12 additions & 9 deletions verde/spline.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ class SplineCV(BaseGridder):
The optimal value for the *mindist* parameter.
damping_ : float
The optimal value for the *damping* parameter.
spline_ : :class:`verde.Spline`
A fitted :class:`~verde.Spline` with the optimal configuration
parameters.

See also
--------
Expand Down Expand Up @@ -182,34 +185,34 @@ def fit(self, coordinates, data, weights=None):
scores = [score.result() for score in scores]
self.scores_ = np.mean(scores, axis=1)
best = np.argmax(self.scores_)
self._best = Spline(**parameter_sets[best])
self._best.fit(coordinates, data, weights=weights)
self.spline_ = Spline(**parameter_sets[best])
self.spline_.fit(coordinates, data, weights=weights)
return self

@property
def force_(self):
"The estimated forces that fit the data."
return self._best.force_
return self.spline_.force_

@property
def region_(self):
"The bounding region of the data used to fit the spline"
return self._best.region_
return self.spline_.region_

@property
def damping_(self):
"The optimal damping parameter"
return self._best.damping
return self.spline_.damping

@property
def mindist_(self):
"The optimal mindist parameter"
return self._best.mindist
return self.spline_.mindist

@property
def force_coords_(self):
"The optimal force locations"
return self._best.force_coords_
return self.spline_.force_coords_

def predict(self, coordinates):
"""
Expand All @@ -231,8 +234,8 @@ def predict(self, coordinates):
The data values evaluated on the given points.

"""
check_is_fitted(self, ["_best"])
return self._best.predict(coordinates)
check_is_fitted(self, ["spline_"])
return self.spline_.predict(coordinates)


class Spline(BaseGridder):
Expand Down