Esempio n. 1
0
    def penalty_matrix(self, basis):
        r"""
        Return a penalty matrix for ordinary least squares.

        """
        return self.regularization_parameter * gramian_matrix(
            self.linear_operator, basis)
    def _test_penalty(self, basis, linear_diff_op, atol=0, result=None):

        operator = LinearDifferentialOperator(linear_diff_op)

        penalty = gramian_matrix(operator, basis)
        numerical_penalty = gramian_matrix_numerical(operator, basis)

        np.testing.assert_allclose(penalty, numerical_penalty, atol=atol)

        if result is not None:
            np.testing.assert_allclose(penalty, result, atol=atol)
    def test_bspline_penalty_special_case(self):
        basis = BSpline(n_basis=5)

        res = np.array([[1152., -2016., 1152., -288., 0.],
                        [-2016., 3600., -2304., 1008., -288.],
                        [1152., -2304., 2304., -2304., 1152.],
                        [-288., 1008., -2304., 3600., -2016.],
                        [0., -288., 1152., -2016., 1152.]])

        operator = LinearDifferentialOperator(basis.order - 1)
        penalty = gramian_matrix(operator, basis)
        numerical_penalty = gramian_matrix_numerical(operator, basis)

        np.testing.assert_allclose(penalty, res)

        np.testing.assert_allclose(numerical_penalty, res)