2

SplineInterpolator PolynomialSplineFunctionを使用してデータセットを 2 倍にしようとしています。私はパスに沿ってかなり遠くにいると思います(おそらくいくつかの例外処理が欠けています):

SplineInterpolator splineInterp;

public double[] doubledArray(double[] y){
    double[] yy = new double[y.length*2];
    // make a double version of y w/ -1 for "null" values
    for(int i = 0; i < yy.length; i++){
        if(i%2 == 0)
            yy[i] = y[i];
        else if(i == yy.length-1)
            yy[i] = yy[0];
        else
            yy[i] = -1;
    }
    // make a corresponding x array to satisfy SplineInterpolator.interpolate
    double[] x = new double[y.length];
    for(int i = 0; i < x.length; i++)
        x[i] = i;
    splineInterp = new SplineInterpolator();
    PolynomialSplineFunction polySplineF = splineInterp.interpolate(x, y);
    for(int i = 0; i < yy.length; i++){
        if(yy[i] == -1){
            yy[i] = polySplineF.value(i);
           // breaks down halfway through polySplineF.value expects and array of y.length
        }
    }
    return yy;
}

しかし、上記は遅くとも最後の for ループでクラッシュします。それで、最初の部分は多かれ少なかれ正しいですか?多項式スプライン関数を作成した後、それを使用してより大きなデータセットを作成するにはどうすればよいですか?

4

1 に答える 1

2

誰かが家でフォローしている場合のために、私が思いついた実装を次に示します。

private double[] multiplyArray(double[] y){
    // An array 2 or 4 or N times bigger than the original:
    double[] yy = new double[y.length*arrayMultiplier];
    // An array representing the indices of the original:
    double[] x = new double[y.length];
    for(int i = 0; i < x.length; i++)
        x[i] = i;
    // Get and instance of SplineInterpolator:
    SplineInterpolator splineInterp = new SplineInterpolator();
    // Use that instance's interpolate() function to a PolynomialSplineFunction
    // fitting your data, points y at indices x.
    PolynomialSplineFunction polySplineF = splineInterp.interpolate(x, y);

    // Use the PolynomialSplineFunction to fill in your larger array by supplying
    // index values divided by the arrayMultiplier
    for(int i = 0; i < yy.length; i++){
        yy[i] = polySplineF.value((double)(i/arrayMultiplier));
    }
    return yy;
}

また、誰かがそれを必要とする場合に、おそらくより便利な穴埋めの使用方法を考え出しました。

于 2012-12-09T21:39:44.010 に答える