示例#1
0
        public void MatrixAddTest()
        {
            MathMatrix <decimal> m1 = CreateMatrix();
            MathMatrix <decimal> m2 = CreateMatrix();

            var res = m1.Add(m2);

            Assert.AreEqual(2, res[0, 0]);
            Assert.AreEqual(4, res[1, 0]);
            Assert.AreEqual(6, res[0, 1]);
            Assert.AreEqual(8, res[1, 1]);
        }
        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);
        }