Skip to content

Commit 676afb8

Browse files
0.32.2
1 parent bf5adae commit 676afb8

4 files changed

Lines changed: 5 additions & 179 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"
77

88
[project]
99
name = "spotpython"
10-
version = "0.32.1"
10+
version = "0.32.2"
1111
authors = [
1212
{ name="T. Bartz-Beielstein", email="tbb@bartzundbartz.de" }
1313
]

src/spotpython/surrogate/kriging.py

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -469,34 +469,6 @@ def build_Psi(self) -> None:
469469
print("Building Psi failed. Error: %s, Type: %s", err, type(err))
470470
raise
471471

472-
def _kernel(self, X: np.ndarray, theta: np.ndarray, p: float) -> np.ndarray:
473-
"""
474-
Computes the correlation matrix Psi using vectorized operations.
475-
476-
Args:
477-
X (np.ndarray): Input data of shape (n_samples, n_features).
478-
theta (np.ndarray): Theta parameters of shape (n_features,).
479-
p (float): Power exponent.
480-
481-
Returns:
482-
np.ndarray: The upper triangle of the correlation matrix Psi.
483-
"""
484-
n_samples, n_features = X.shape
485-
Psi = np.zeros((n_samples, n_samples), dtype=float)
486-
# Calculate all pairwise differences:
487-
# X_expanded_rows will have shape (n_samples, 1, n_features)
488-
# X_expanded_cols will have shape (1, n_samples, n_features)
489-
# diff will have shape (n_samples, n_samples, n_features)
490-
diff = np.abs(X[:, np.newaxis, :] - X[np.newaxis, :, :]) ** p
491-
# Apply theta and sum over features
492-
# dist_matrix will have shape (n_samples, n_samples)
493-
dist_matrix = np.sum(theta * diff, axis=2)
494-
# Compute Psi using the exponential kernel
495-
Psi = np.exp(-dist_matrix)
496-
# Return only the upper triangle, as the matrix is symmetric
497-
# and the diagonal will be handled later.
498-
return np.triu(Psi, k=1)
499-
500472
def likelihood(self, x: np.ndarray) -> Tuple[float, np.ndarray, np.ndarray]:
501473
"""
502474
Computes the negative of the concentrated log-likelihood for a given set
@@ -541,14 +513,6 @@ def likelihood(self, x: np.ndarray) -> Tuple[float, np.ndarray, np.ndarray]:
541513
n = X.shape[0]
542514
one = np.ones(n)
543515

544-
# Build the correlation matrix Psi (modified in 0.31.0)
545-
# theta = self.theta
546-
# theta is in log scale, so transform it back:
547-
# theta10 = 10.0**theta
548-
# p = self.p_val
549-
# Build correlation matrix (preparation for build_Psi())
550-
# Psi_upper_triangle = self._kernel(X, theta10, p)
551-
552516
Psi_upper_triangle = self.build_Psi()
553517

554518
Psi = Psi_upper_triangle + Psi_upper_triangle.T + np.eye(n) + np.eye(n) * lambda_
@@ -655,16 +619,13 @@ def _pred(self, x: np.ndarray) -> float:
655619
y = self.y_.flatten()
656620

657621
if (self.method == "regression") or (self.method == "reinterpolation"):
658-
# theta = x[:-1]
659622
self.theta = self.logtheta_lambda_[: self.n_theta]
660-
# lambda_ = x[-1]
661623
lambda_ = self.logtheta_lambda_[self.n_theta : self.n_theta + 1]
662624
# lambda is in log scale, so transform it back:
663625
lambda_ = 10.0**lambda_
664626
if self.optim_p:
665627
self.p_val = self.logtheta_lambda_[self.n_theta + 1 : self.n_theta + 1 + self.n_p]
666628
elif self.method == "interpolation":
667-
# theta = x
668629
self.theta = self.logtheta_lambda_[: self.n_theta]
669630
# use the original, untransformed eps:
670631
lambda_ = self.eps
@@ -688,17 +649,6 @@ def _pred(self, x: np.ndarray) -> float:
688649
resid_tilde = np.linalg.solve(U, resid)
689650
resid_tilde = np.linalg.solve(U.T, resid_tilde)
690651

691-
# Build psi (modified in 0.31.0)
692-
# X = self.X_
693-
# p = self.p_val
694-
# theta = self.theta
695-
# # theta is in log scale, so transform it back:
696-
# theta10 = 10.0**theta
697-
# psi = np.ones(n)
698-
# for i in range(n):
699-
# dist_vec = np.abs(X[i, :] - x) ** p
700-
# psi[i] = np.exp(-np.sum(theta10 * dist_vec))
701-
702652
psi = self.build_psi_vec(x)
703653

704654
# Compute SigmaSqr and SSqr

src/spotpython/utils/metrics.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
from scipy.stats import spearmanr
3131

3232

33-
3433
def apk(actual, predicted, k=10):
3534
"""
3635
Computes the average precision at k.
@@ -278,13 +277,14 @@ def calculate_xai_consistency_euclidean(attributions) -> float:
278277
print(result_xai)
279278
return result_xai
280279

280+
281281
def calculate_xai_consistency_spearman(attributions) -> float:
282282
"""
283283
Calculates the consistency of XAI methods using Spearman rank correlation.
284-
284+
285285
Args:
286286
attributions (np.ndarray): shape (n_methods, n_features)
287-
287+
288288
Returns:
289289
float: Mean of upper triangle of Spearman correlation matrix (excluding diagonal)
290290
"""
@@ -305,4 +305,4 @@ def calculate_xai_consistency_spearman(attributions) -> float:
305305

306306
print("XAI Consistency (mean of upper triangle of Spearman correlation matrix):")
307307
print(upper_triangle_values.mean())
308-
return upper_triangle_values.mean()
308+
return upper_triangle_values.mean()

test/test_kernel.py

Lines changed: 0 additions & 124 deletions
This file was deleted.

0 commit comments

Comments
 (0)