@@ -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
0 commit comments