def fit(self, X, y, 
            initial_range=INITIAL_RANGE_DEFAULT, tol=TOLERANCE_DEFAULT):
        # Run input checks
        # Transforms floats and arrays in lists to have a multifidelity structure
        self._check_list_structure(X, y)
        # Checks if all parameters are structured as required
        self._check_params()

        X = self.X
        y = self.y
        nlevel = self.nlevel
        n_samples = self.n_samples

        # initialize lists
        self.beta = nlevel*[0]
        self.beta_rho = nlevel*[None]
        self.beta_regr = nlevel*[None]
        self.C = nlevel*[0]
        self.D = nlevel*[0]
        self.F = nlevel*[0]
        self.p = nlevel*[0]
        self.q = nlevel*[0]
        self.G = nlevel*[0]
        self.sigma2 = nlevel*[0]
        self._R_adj = nlevel*[None]
        
        y_best = y[nlevel-1]
        for i in range(nlevel-1)[::-1]:
            y_best = np.concatenate((y[i][:-n_samples[i+1]],y_best))
        self.y_best = y_best
            
        self.y_mean = np.zeros(1)
        self.y_std  = np.ones(1)
        self.X_mean = np.zeros(1)
        self.X_std  = np.ones(1)
        
        for lvl in range(nlevel):
            
            # Calculate matrix of distances D between samples
            self.D[lvl] = l1_cross_distances(X[lvl])
            if (np.min(np.sum(self.D[lvl], axis=1)) == 0.):
                raise Exception("Multiple input features cannot have the same"
                                " value.")
                                
            # Regression matrix and parameters
            self.F[lvl] = self.regr(X[lvl])
            self.p[lvl] = self.F[lvl].shape[1]
                
            # Concatenate the autoregressive part for levels > 0
            if lvl > 0:
                F_rho = self.rho_regr(X[lvl])
                self.q[lvl] = F_rho.shape[1]
                self.F[lvl] = np.hstack((F_rho*np.dot((self.y[lvl-1])[-n_samples[lvl]:],
                                              np.ones((1,self.q[lvl]))), self.F[lvl]))
            else:
                self.q[lvl] = 0
            
            n_samples_F_i = self.F[lvl].shape[0]

            if n_samples_F_i != n_samples[lvl]:
                raise Exception("Number of rows in F and X do not match. Most "
                                "likely something is going wrong with the "
                                "regression model.")

            if int(self.p[lvl] + self.q[lvl]) >= n_samples_F_i:
                raise Exception(("Ordinary least squares problem is undetermined "
                                 "n_samples=%d must be greater than the regression"
                                 " model size p+q=%d.")
                                 % (n_samples[i], self.p[lvl]+self.q[lvl]))

        # Set attributes
        self.X = X
        self.y = y              

        self.rlf_value = np.zeros(nlevel)
        
        for lvl in range(nlevel):
            # Determine Gaussian Process model parameters
            if self.theta[lvl] is None:
                # Maximum Likelihood Estimation of the parameters                             
                sol = self._max_rlf(lvl=lvl, initial_range=initial_range, tol=tol)
                self.theta[lvl] = sol['theta']
                self.rlf_value[lvl] = sol['rlf_value']
                
                if np.isinf(self.rlf_value[lvl]):
                    raise Exception("Bad parameter region. "
                                    "Try increasing upper bound")          
            else:
                self.rlf_value[lvl] = self.rlf(lvl=lvl)
                if np.isinf(self.rlf_value[lvl]):
                    raise Exception("Bad point. Try increasing theta0.")
            
        return
The Multi-Fidelity co-kriging model fitting method.
dataset/ETHPy150Open OpenMDAO/OpenMDAO-Framework/openmdao.lib/src/openmdao/lib/surrogatemodels/multifi_cokriging_surrogate.py/MultiFiCoKriging.fit