hiperwalk.QuantumWalk.fit_sin_squared#

static QuantumWalk.fit_sin_squared(x, y)[source]#

Fit data to the squared sine function.

Parameters:
xnumpy.ndarray

The domain values. It is assumed that the entries are evenly spaced. That is, x[i + 1] - x[i] == x[j + 1] - x[j] for any valid i and j.

ynumpy.ndarray

The image values evaluated at each x[i]. It is required that y[i] corresponds to the evaluation at x[i].

Returns:
ddict

It contains information about the best fit found. The dictionary keys are

fit function

A pointer to the obtained sine squared function. Issuing d["fit function"](theta) evaluates the function at point theta.

amplitude:

Amplitude of the obtained fit function.

angular frequency

Angular frequency of the obtained fit function.

phase shift

Phase shift of the obtained fit function.

vertical offset

Vertical offset of the obtained fit function.

frequency

Frequency of the obtained fit function.

period

Period of the obtained fit function.

Notes

The returned d["fit function"] is a pointer to

def fit_func(theta):
    return d["amplitude"]*np.sin(
               d["angular frequency"]*theta +
               d["phase shift"]
           )**2 + d["vertical offset"]

The code was adapted from https://stackoverflow.com/questions/16716302/how-do-i-fit-a-sine-curve-to-my-data-with-pylab-and-numpy