/// <summary> /// Perform Yule-Walker algorithm to the given timeseries data /// </summary> /// <param name="data"> input data </param> /// <param name="p"> YuleWalker Parameter </param> /// <returns> array of Auto-Regressive parameter estimates. Index 0 contains coefficient of lag 1 </returns> //JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET: //ORIGINAL LINE: public static double[] fit(final double[] data, final int p) public static double[] fit(double[] data, int p) { int length = data.Length; if (length == 0 || p < 1) { throw new Exception("fitYuleWalker - Invalid Parameters" + "length=" + length + ", p = " + p); } double[] r = new double[p + 1]; foreach (double aData in data) { r[0] += Math.Pow(aData, 2); } r[0] /= length; for (int j = 1; j < p + 1; j++) { for (int i = 0; i < length - j; i++) { r[j] += data[i] * data[i + j]; } r[j] /= (length); } //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final TimeSeries.Forecast.matrix.InsightsMatrix toeplitz = TimeSeries.Forecast.timeseries.timeseriesutil.ForecastUtil.initToeplitz(java.util.Arrays.copyOfRange(r, 0, p)); InsightsMatrix toeplitz = ForecastUtil.initToeplitz(Utilities.CopyOfRange(r, 0, p)); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final TimeSeries.Forecast.matrix.InsightsVector rVector = new TimeSeries.Forecast.matrix.InsightsVector(java.util.Arrays.copyOfRange(r, 1, p + 1), false); InsightsVector rVector = new InsightsVector(Utilities.CopyOfRange(r, 1, p + 1), false); return(toeplitz.solveSPDIntoVector(rVector, ForecastUtil.maxConditionNumber).deepCopy()); }
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET: //ORIGINAL LINE: private static TimeSeries.Forecast.matrix.InsightsVector iterationStep(final TimeSeries.Forecast.TimeSeries.Arima.struct.ArimaParams params, final double[] data, final double[] errors, final double[][] matrix, final int r, final int length, final int size) private static InsightsVector iterationStep(ArimaParams @params, double[] data, double[] errors, double[][] matrix, int r, int length, int size) { int rowIdx = 0; // copy over shifted timeseries data into matrix //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int[] offsetsAR = params.getOffsetsAR(); int[] offsetsAR = @params.OffsetsAR; foreach (int pIdx in offsetsAR) { Array.Copy(data, r - pIdx, matrix[rowIdx], 0, size); ++rowIdx; } // copy over shifted errors into matrix //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int[] offsetsMA = params.getOffsetsMA(); int[] offsetsMA = @params.OffsetsMA; foreach (int qIdx in offsetsMA) { Array.Copy(errors, r - qIdx, matrix[rowIdx], 0, size); ++rowIdx; } // instantiate matrix to perform least squares algorithm //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final TimeSeries.Forecast.matrix.InsightsMatrix zt = new TimeSeries.Forecast.matrix.InsightsMatrix(matrix, false); InsightsMatrix zt = new InsightsMatrix(matrix, false); // instantiate target vector //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final double[] vector = new double[size]; double[] vector = new double[size]; Array.Copy(data, r, vector, 0, size); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final TimeSeries.Forecast.matrix.InsightsVector x = new TimeSeries.Forecast.matrix.InsightsVector(vector, false); InsightsVector x = new InsightsVector(vector, false); // obtain least squares solution //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final TimeSeries.Forecast.matrix.InsightsVector ztx = zt.timesVector(x); InsightsVector ztx = zt.timesVector(x); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final TimeSeries.Forecast.matrix.InsightsMatrix ztz = zt.computeAAT(); InsightsMatrix ztz = zt.computeAAT(); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final TimeSeries.Forecast.matrix.InsightsVector estimatedVector = ztz.solveSPDIntoVector(ztx, TimeSeries.Forecast.timeseries.timeseriesutil.ForecastUtil.maxConditionNumber); InsightsVector estimatedVector = ztz.solveSPDIntoVector(ztx, ForecastUtil.maxConditionNumber); return(estimatedVector); }
public virtual void SolverTestSimple() { double[][] A = new double[][] { new double[] { 2.0 } }; double[] B = new double[] { 4.0 }; double[] solution = new double[] { 2.0 }; InsightsMatrix im = new InsightsMatrix(A, true); InsightsVector iv = new InsightsVector(B, true); InsightsVector solved = im.solveSPDIntoVector(iv, -1); for (int i = 0; i < solved.size(); i++) { Assert.True(solved.get(i) == solution[i]); } }