如何实现表示二阶差分的矩阵来解决惠特克平滑问题?

问题描述 投票:0回答:1

我正在尝试使用 Whittaker-Eilers 来平滑噪声数据。使用这篇文章创建一个方法来求解我写的页面上的方程 11 和 12 中的 A:

private LUDecomposition buildMatrices(int dataSize, double lambda, int filterOrder) {
        RealMatrix identityMatrix = MatrixUtils.createRealMatrix(dataSize, dataSize);
        RealMatrix orderMatrix = MatrixUtils.createRealMatrix(dataSize - filterOrder, dataSize);

        for (int i = 0; i < dataSize; i++) {
            identityMatrix.setEntry(i, i, 1);

            if (i < dataSize - filterOrder) {
                switch (filterOrder) {
                    case 1:
                        orderMatrix.setEntry(i, i, -1);
                        orderMatrix.setEntry(i, i + 1, 1);
                        break;

                    case 2:
                    default:
                        orderMatrix.setEntry(i, i, 1);
                        orderMatrix.setEntry(i, i + 1, -2);
                        orderMatrix.setEntry(i, i + 2, 1);
                        break;
                }
            }
        }

        RealMatrix A = orderMatrix.transpose().scalarMultiply(lambda).multiply(orderMatrix).add(identityMatrix);
        return new LUDecomposition(A);
    }

然后使用返回的 LUDecomposition

private void calculateWhittakerSegment(int endIndex, int period) {
        RealVector measValues = new ArrayRealVector(
                ArrayUtils.subarray(data.getYValues(), endIndex - period, endIndex));

        RealVector y = luDecomposition.getP().multiply(MatrixUtils.inverse(luDecomposition.getL())).operate(measValues);

        RealVector adjValues = MatrixUtils.inverse(luDecomposition.getU()).operate(y);
    }

使用 1 阶滤波器(文章中的等式 8)会得到可接受的结果 1st order results

但是使用 2 阶滤波器(文章中的等式 17)并不会 2nd order results

我改变了求解 A 的运算顺序,但没有导致任何改变的结果。

java matrix linear-algebra apache-commons-math
1个回答
0
投票

我了解到 LUDecomposition 类内部有自己的求解器参数;使用它而不是手动求解方程解决了使用二阶矩阵时的问题。

© www.soinside.com 2019 - 2024. All rights reserved.