def set_polynomial_degree(self):
     """Set fitting function to be polynomial based on given degree."""
     degree = int(self.polynomial_degree_input.value)
     self.fitting_function = polynomial(degree)
     if degree == 1:
         self.fitting_function_syntax.value = "a[0] + a[1] * x"
     else:
         self.fitting_function_syntax.value = "a[0] + a[1] * x + " + " + ".join(
             [f"a[{i}] * x ^ {i}" for i in range(2, degree + 1)])
Example #2
0
def case_polynomial_1():
    return dict(
        func=polynomial(1),
        func_name="linear",
        title="Linear",
        n=2,
        syntax="a[0] + a[1] * x",
        a=np.array([-7, 2]),
        x=np.arange(5),
        y=[-7, -5, -3, -1, 1],
        x_derivatives=[2, 2, 2, 2, 2],
        a_derivatives=[[1, 0], [1, 1], [1, 2], [1, 3], [1, 4]],
    )
Example #3
0
def case_polynomial_3():
    return dict(
        func=polynomial(3),
        func_name="polynomial_3",
        title="Polynomial 3",
        syntax="a[0] + a[1] * x + a[2] * x ^ 2 + a[3] * x ^ 3",
        n=4,
        a=np.array([3, 4, -2, 1]),
        x=np.arange(5),
        y=[3, 6, 11, 24, 51],
        x_derivatives=[4, 3, 8, 19, 36],
        a_derivatives=[
            [1, 0, 0, 0],
            [1, 1, 1, 1],
            [1, 2, 4, 8],
            [1, 3, 9, 27],
            [1, 4, 16, 64],
        ],
    )
Example #4
0
def test_initialize_polynomial_with_negative_degree_raises_error():
    with pytest.raises(FittingFunctionLoadError,
                       match="^n must be positive, got -1$"):
        polynomial(-1)
Example #5
0
def test_initialize_polynomial_with_0_degree_raises_error():
    with pytest.raises(FitFunctionLoadError,
                       match="^n must be positive, got 0$"):
        polynomial(0)