public virtual void ConstructorTests() { double[][] data = new double[][] { new double[] { 3.0, 3.0, 3.0 }, new double[] { 3.0, 3.0, 3.0 }, new double[] { 3.0, 3.0, 3.0 } }; InsightsMatrix im1 = new InsightsMatrix(data, false); Assert.True(im1.NumberOfColumns == 3); Assert.True(im1.NumberOfRows == 3); for (int i = 0; i < im1.NumberOfColumns; i++) { for (int j = 0; j < im1.NumberOfColumns; j++) { Assert.True(im1.get(i, j) == 3.0); } } im1.set(0, 0, 0.0); Assert.True(im1.get(0, 0) == 0.0); im1.set(0, 0, 3.0); InsightsVector iv = new InsightsVector(3, 3.0); for (int i = 0; i < im1.NumberOfColumns; i++) { Assert.True(im1.timesVector(iv).get(i) == 27.0); } }
//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 TimesVectorTestIncorrectDimension() { double[][] A = new double[][] { new double[] { 1.0, 1.0, 1.0 }, new double[] { 2.0, 2.0, 2.0 }, new double[] { 3.0, 3.0, 3.0 } }; double[] x = new double[] { 4.0, 4.0, 4.0, 4.0 }; InsightsMatrix im = new InsightsMatrix(A, true); InsightsVector iv = new InsightsVector(x, true); Exception ex = Assert.Throws <Exception>(() => im.timesVector(iv)); //InsightsVector solved = Assert.Equal("[InsightsMatrix][timesVector] size mismatch", ex.Message); }
public virtual void TimesVectorTestSimple() { double[][] A = new double[][] { new double[] { 1.0, 1.0 }, new double[] { 2.0, 2.0 } }; double[] x = new double[] { 3.0, 4.0 }; double[] solution = new double[] { 7.0, 14.0 }; InsightsMatrix im = new InsightsMatrix(A, true); InsightsVector iv = new InsightsVector(x, true); InsightsVector solved = im.timesVector(iv); for (int i = 0; i < solved.size(); i++) { Assert.True(solved.get(i) == solution[i]); } }