-
-
Notifications
You must be signed in to change notification settings - Fork 145
/
data_regression.py
37 lines (29 loc) · 1.26 KB
/
data_regression.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# Copyright (C) Unitary Fund
#
# This source code is licensed under the GPL license (v3) found in the
# LICENSE file in the root directory of this source tree.
"""The data regression portion of Clifford data regression."""
from typing import Sequence
import numpy as np
import numpy.typing as npt
def linear_fit_function(
x_data: npt.NDArray[np.float64], params: Sequence[float]
) -> float:
r"""Returns :math:`y(x) = a_1 x_1 + \cdots + a_n x_n + b`.
Args:
x_data: The independent variables $x_1, ..., x_n$. In CDR, these are
nominally the noisy expectation values to perform regression on.
params: Parameters $a_1, ..., a_n, b$ of the linear fit. Note the $b$
parameter is the intercept of the fit.
"""
return sum(a * x for a, x in zip(params, x_data)) + params[-1]
def linear_fit_function_no_intercept(
x_data: npt.NDArray[np.float64], params: Sequence[float]
) -> float:
r"""Returns :math:`y(x) = a_1 x_1 + \cdots + a_n x_n`.
Args:
x_data: The independent variables $x_1, ..., x_n$. In CDR, these are
nominally the noisy expectation values to perform regression on.
params: Parameters $a_1, ..., a_n$ of the linear fit.
"""
return sum(a * x for a, x in zip(params, x_data))