def incremental_fit(self, train_x, train_y):
        """ Incrementally fit the regressor. """
        if not self._first_fitted:
            raise ValueError("The first_fit function needs to be called first.")

        train_x, train_y = np.array(train_x), np.array(train_y)

        # Incrementally compute K
        up_right_k = edit_distance_matrix(self._x, train_x)
        down_left_k = np.transpose(up_right_k)
        down_right_k = edit_distance_matrix(train_x)
        up_k = np.concatenate((self._distance_matrix, up_right_k), axis=1)
        down_k = np.concatenate((down_left_k, down_right_k), axis=1)
        temp_distance_matrix = np.concatenate((up_k, down_k), axis=0)
        k_matrix = bourgain_embedding_matrix(temp_distance_matrix)
        diagonal = np.diag_indices_from(k_matrix)
        diagonal = (diagonal[0][-len(train_x) :], diagonal[1][-len(train_x) :])
        k_matrix[diagonal] += self.alpha

        try:
            self._l_matrix = cholesky(k_matrix, lower=True)  # Line 2
        except LinAlgError:
            return self

        self._x = np.concatenate((self._x, train_x), axis=0)
        self._y = np.concatenate((self._y, train_y), axis=0)
        self._distance_matrix = temp_distance_matrix

        self._alpha_vector = cho_solve((self._l_matrix, True), self._y)  # Line 3

        return self
def incremental_fit ( self , train_x , train_y ) : if not self . _first_fitted : raise ValueError ( "The first_fit function needs to be called first." ) train_x , train_y = np . array ( train_x ) , np . array ( train_y ) up_right_k = edit_distance_matrix ( self . _x , train_x ) down_left_k = np . transpose ( up_right_k ) down_right_k = edit_distance_matrix ( train_x ) up_k = np . concatenate ( ( self . _distance_matrix , up_right_k ) , axis = 1 ) down_k = np . concatenate ( ( down_left_k , down_right_k ) , axis = 1 ) temp_distance_matrix = np . concatenate ( ( up_k , down_k ) , axis = 0 ) k_matrix = bourgain_embedding_matrix ( temp_distance_matrix ) diagonal = np . diag_indices_from ( k_matrix ) diagonal = ( diagonal [ 0 ] [ - len ( train_x ) : ] , diagonal [ 1 ] [ - len ( train_x ) : ] ) k_matrix [ diagonal ] += self . alpha try : self . _l_matrix = cholesky ( k_matrix , lower = True ) except LinAlgError : return self self . _x = np . concatenate ( ( self . _x , train_x ) , axis = 0 ) self . _y = np . concatenate ( ( self . _y , train_y ) , axis = 0 ) self . _distance_matrix = temp_distance_matrix self . _alpha_vector = cho_solve ( ( self . _l_matrix , True ) , self . _y ) return self
Incrementally fit the regressor.