Skip to content

Commit

Permalink
Merge pull request #176 from sebasmos/main
Browse files Browse the repository at this point in the history
adding RSS and RMS
  • Loading branch information
mmaelicke authored Jan 20, 2024
2 parents 60a6ea5 + 6308149 commit 871eb45
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 10 deletions.
46 changes: 36 additions & 10 deletions skgstat/Variogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -2220,6 +2220,7 @@ def residuals(self):
)
return self.model_residuals


@property
def model_residuals(self) -> np.ndarray:
"""
Expand Down Expand Up @@ -2277,19 +2278,11 @@ def rmse(self):
RMSE = \sqrt{\frac{\sum_{i=0}^{i=N(x)} (x-y)^2}{N(x)}}
"""
# get the deviations
experimental, model = self.model_deviations()

# get the sum of squares
rsum = np.nansum(np.fromiter(
map(lambda x, y: (x - y)**2, experimental, model), float)
)

return np.sqrt(rsum / len(model))
return self.root_mean_square

@property
def mse(self):
r"""RMSE
r"""MSE
Calculate the Mean squared error between the experimental
variogram and the theoretical model values at corresponding lags.
Expand Down Expand Up @@ -2383,6 +2376,39 @@ def nrmse(self):
"""
return self.rmse / np.nanmean(self.experimental)

@property
def root_mean_square(self):
"""Root Mean Square (RMS) of the residuals
Calculates the square root of the mean of squared residuals.
Returns
-------
float
Root Mean Square of the residuals.
"""
return np.sqrt(np.nanmean(np.square(self.model_residuals)))

@property
def residual_sum_of_squares(self):
"""Residual Sum of Squares (RSS)
Calculates the sum of squared differences between the experimental
variogram and theoretical model values.
Returns
-------
float
Residual sum of squares (RSS), a measure of the overall model fit
representing the sum of squared deviations between the observed
experimental variogram and the corresponding theoretical model values.
"""
return np.nansum(np.square(self.model_residuals))

@property
def rss(self):
return self.residual_sum_of_squares

@property
def nrmse_r(self):
r"""NRMSE
Expand Down
5 changes: 5 additions & 0 deletions skgstat/tests/test_variogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -1197,6 +1197,11 @@ def test_mse(self):

self.assertAlmostEqual(np.sqrt(V.mse), V.rmse, places=6)

def test_rss(self):
V = Variogram(self.c, self.v, n_lags=15)

self.assertAlmostEqual(V.rss, 357.76, places=2)

def test_update_kwargs(self):
V = Variogram(self.c, self.v, percentile=.3)

Expand Down

0 comments on commit 871eb45

Please sign in to comment.