コード例 #1
0
ファイル: krg_mgp.py プロジェクト: Witekklim/smt
    def _componentwise_distance(self, dx, small=False, opt=0):
        """
        Compute the componentwise distance with respect to the correlation kernel
        

        Parameters
        ----------
        dx : numpy.ndarray
            Distance matrix.
        small : bool, optional
            Compute the componentwise distance in small (n_components) dimension 
            or in initial dimension. The default is False.
        opt : int, optional
            useless for MGP

        Returns
        -------
        d : numpy.ndarray
            Component wise distance.

        """
        if small:
            d = componentwise_distance(dx, self.options["corr"], self.options["n_comp"])
        else:
            d = componentwise_distance(dx, self.options["corr"], self.nx)
        return d
コード例 #2
0
    def test_corr_derivatives(self):
        for ind, corr in enumerate(self.corr_def):  # For every kernel
            self.corr_str[ind] = self.corr_def[ind]
            D = componentwise_distance(self.D, self.corr_str, self.X.shape[1])

            k = corr(self.theta, D)
            K = np.eye(self.X.shape[0])
            K[self.ij[:, 0], self.ij[:, 1]] = k[:, 0]
            K[self.ij[:, 1], self.ij[:, 0]] = k[:, 0]
            grad_norm_all = []
            diff_norm_all = []
            ind_theta = []
            for i, theta_i in enumerate(self.theta):
                eps_theta = np.zeros(self.theta.shape)
                eps_theta[i] = self.eps

                k_dk = corr(self.theta + eps_theta, D)

                K_dk = np.eye(self.X.shape[0])
                K_dk[self.ij[:, 0], self.ij[:, 1]] = k_dk[:, 0]
                K_dk[self.ij[:, 1], self.ij[:, 0]] = k_dk[:, 0]

                grad_eps = (K_dk - K) / self.eps

                dk = corr(self.theta, D, grad_ind=i)
                dK = np.zeros((self.X.shape[0], self.X.shape[0]))
                dK[self.ij[:, 0], self.ij[:, 1]] = dk[:, 0]
                dK[self.ij[:, 1], self.ij[:, 0]] = dk[:, 0]
                grad_norm_all.append(np.linalg.norm(dK))
                diff_norm_all.append(np.linalg.norm(grad_eps))
                ind_theta.append(r"$x_%d$" % i)
            self.assert_error(np.array(grad_norm_all), np.array(diff_norm_all),
                              1e-5, 1e-5)  # from utils/smt_test_case.py
コード例 #3
0
ファイル: kplsk.py プロジェクト: vishalbelsare/smt
 def _componentwise_distance(self,
                             dx,
                             opt=0,
                             theta=None,
                             return_derivative=False):
     if opt == 0:
         # Kriging step
         d = componentwise_distance(
             dx,
             self.options["corr"],
             self.nx,
             theta=theta,
             return_derivative=return_derivative,
         )
     else:
         # KPLS step
         d = componentwise_distance_PLS(
             dx,
             self.options["corr"],
             self.options["n_comp"],
             self.coeff_pls,
             theta=theta,
             return_derivative=return_derivative,
         )
     return d
コード例 #4
0
ファイル: kplsk.py プロジェクト: friedenhe/smt
 def _componentwise_distance(self,dx,opt=0):
     if opt == 0:
         # Kriging step
         d = componentwise_distance(dx,self.options['corr'],self.nx)
     else:
         # KPLS step
         d = componentwise_distance_PLS(dx,self.options['corr'],
                                             self.options['n_comp'],self.coeff_pls)
     return d
コード例 #5
0
ファイル: mfkplsk.py プロジェクト: vishalbelsare/smt
    def _componentwise_distance(self, dx, opt=0):
        # Modif for KPLSK model
        if opt == 0:
            # Kriging step
            d = componentwise_distance(dx, self.options["corr"], self.nx)
        else:
            # KPLS step
            d = super(MFKPLSK, self)._componentwise_distance(dx, opt)

        return d
コード例 #6
0
 def _componentwise_distance(self,
                             dx,
                             opt=0,
                             theta=None,
                             return_derivative=False):
     d = componentwise_distance(
         dx,
         self.options["corr"],
         self.nx,
         theta=theta,
         return_derivative=return_derivative,
     )
     return d
コード例 #7
0
ファイル: mfk.py プロジェクト: udemirezen/smt
 def _componentwise_distance(self, dx, opt=0):
     d = componentwise_distance(dx, self.options["corr"], self.nx)
     return d
コード例 #8
0
ファイル: krg.py プロジェクト: haojia632/smt
 def _componentwise_distance(self,dx,opt=0):
     d = componentwise_distance(dx,self.options['corr'].__name__,
                                self.nx)
     return d