public void MatrixColumnSumTest() { MathMatrix <decimal> m = CreateMatrix(); var colSum1 = m.ColumnSum(0); var colSum2 = m.ColumnSum(1); Assert.AreEqual(3, colSum1); Assert.AreEqual(7, colSum2); }
private void Compute() { var progressVal = new IterationArgument(); start(); progressVal.Value = iterations; resetProgressBar?.Invoke(progressVal); result = new MathMatrix <decimal>(1, signals.Width); if (!randomStart) { decimal averageVelocity = 0; for (int i = 0; i < times.Height; i++) { averageVelocity += signals.RowSum(i) / times[i, 0]; } averageVelocity = averageVelocity / times.Height; averageVelocity -= averageVelocity - (int)averageVelocity; averageVelocity -= averageVelocity % 100; for (int i = 0; i < result.Height; i++) { result[i, 0] = averageVelocity; } } else { result.PutRandomValuesIntoMatrix(300, 2000, 2); } result = result.ConvertResultToVelociti(); var AT = signals.Transpose(); var C = new MathMatrix <decimal>(signals.Width, signals.Width); for (int i = 0; i < C.Width; i++) { C[i, i] = signals.ColumnSum(i) == 0 ? 0 : 1 / signals.ColumnSum(i); } var R = new MathMatrix <decimal>(signals.Height, signals.Height); for (int i = 0; i < R.Width; i++) { R[i, i] = signals.RowSum(i) == 0 ? 0 : 1 / signals.RowSum(i); } var CATR = C.Multiply(AT).Multiply(R); StartWriter(); for (iter = 0; iter < iterations; iter++) { var m1 = signals.Multiply(result); var m2 = times.Subtract(m1); var m3 = CATR.Multiply(m2); result = result.Add(m3); progressVal.Value = iter; WriteData(iter, signals.Multiply(result).AverageStatisticError(times)); updateProgressBar?.Invoke(progressVal); } ConvertResultToVelociti(); writer.Close(); stop(); var tmp = DateTime.Now; var filename = ("\\" + "Sirt_Result" + tmp.ToShortDateString() + tmp.ToShortTimeString()).Replace('.', '_').Replace(':', '_') + ".txt"; result.PrinttoFile(filename); }