Quanlse/ErrorMitigation/ZNE/Extrapolation.py
def polyRegression(x: list, y: list, d: int):
    r"""
    Polynomial regression method to the d-th order. Fit the given data points to the following linear model:

    :math:`y = \sum_{i=0}^d a_i x^i`

    :param x: a list of independent variables
    :param y: a list of dependent variables
    :param d: the polynomial regression order
    :return: an array of polynomial regression coefficients :math:`[a_0, a_1, \cdots, a_d]`
    """
    x = np.array(x).ravel()
    y = np.array(y).ravel()
    X = []  # shape: [m, d+1]
    for k in range(d + 1):
        X.append(np.expand_dims(x, axis=1))
    X = np.concatenate(X, axis=1)
    return np.dot(np.dot(np.linalg.pinv(np.dot(X.T, X)), X.T), y)
r"""
    Polynomial regression method to the d-th order. Fit the given data points to the following linear model:

    :math:`y = \sum_{i=0}^d a_i x^i`

    :param x: a list of independent variables
    :param y: a list of dependent variables
    :param d: the polynomial regression order
    :return: an array of polynomial regression coefficients :math:`[a_0, a_1, \cdots, a_d]`
    
r"""
Polynomial regression method to the d-th order. Fit the given data points to the following linear model.
r " " " Polynomial regression method to the d - th order . Fit the given data points to the following linear model .
def polyRegression(x: list, y: list, d: int):
    x = np.array(x).ravel()
    y = np.array(y).ravel()
    X = []  
    for k in range(d + 1):
        X.append(np.expand_dims(x, axis=1))
    X = np.concatenate(X, axis=1)
    return np.dot(np.dot(np.linalg.pinv(np.dot(X.T, X)), X.T), y)
def polyRegression ( x : list , y : list , d : int ) : x = np . array ( x ) . ravel ( ) y = np . array ( y ) . ravel ( ) X = [ ] for k in range ( d + 1 ) : X . append ( np . expand_dims ( x , axis = 1 ) ) X = np . concatenate ( X , axis = 1 ) return np . dot ( np . dot ( np . linalg . pinv ( np . dot ( X . T , X ) ) , X . T ) , y )
r"""
Polynomial regression method to the d-th order.
r " " " Polynomial regression method to the d - th order .
r"""
    Polynomial regression method to the d-th order. Fit the given data points to the following linear model:

    :math:`y = \sum_{i=0}^d a_i x^i`

    :param x: a list of independent variables
    :param y: a list of dependent variables
    :param d: the polynomial regression order
    :return: an array of polynomial regression coefficients :math:`[a_0, a_1, \cdots, a_d]`
    """ # shape: [m, d+1]
an array of polynomial regression coefficients :math:`[a_0, a_1, \cdots, a_d]`
an array of polynomial regression coefficients : math : ` [ a_0 a_1 \ cdots a_d ] `
x
list
a list of independent variables
a list of independent variables
y
list
a list of dependent variables
a list of dependent variables
d
int
the polynomial regression order
the polynomial regression order
math
None