Пример #1
0
		public PolynomialImageTransformer(RegistrationDefinition registration, InterpolationMode interpolationMode, int polynomialDegree) : base(registration, interpolationMode)
		{
			List<PositionAssociation> associationList = registration.GetAssociationList();
			TransformationStyle arg_15_0 = registration.warpStyle;
			int num = associationList.Count;
			if (num == 2)
			{
				num++;
			}
			JamaMatrix jamaMatrix = new JamaMatrix(num, 2);
			JamaMatrix jamaMatrix2 = new JamaMatrix(num, 2);
			for (int i = 0; i < num; i++)
			{
				LatLon latLon = (i == associationList.Count) ? PolynomialImageTransformer.getThirdPosition(associationList[0].sourcePosition.pinPosition.latlon, associationList[1].sourcePosition.pinPosition.latlon, true) : associationList[i].sourcePosition.pinPosition.latlon;
				jamaMatrix.SetElement(i, 0, latLon.lon);
				jamaMatrix.SetElement(i, 1, latLon.lat);
				LatLon latLon2 = (i == associationList.Count) ? PolynomialImageTransformer.getThirdPosition(MercatorCoordinateSystem.LatLonToMercator(associationList[0].globalPosition.pinPosition.latlon), MercatorCoordinateSystem.LatLonToMercator(associationList[1].globalPosition.pinPosition.latlon), false) : MercatorCoordinateSystem.LatLonToMercator(associationList[i].globalPosition.pinPosition.latlon);
				jamaMatrix2.SetElement(i, 0, latLon2.lon);
				jamaMatrix2.SetElement(i, 1, latLon2.lat);
			}
			this.destMercatorToSourceTransformer = PolynomialImageTransformer.getPolyPointTransformer(jamaMatrix, jamaMatrix2, polynomialDegree);
			this.sourceToDestMercatorTransformer_approximate = PolynomialImageTransformer.getApproximateInverterPolyPointTransformer(jamaMatrix, jamaMatrix2, polynomialDegree);
			DownhillInverterPointTransformer flakyPointTransformer = new DownhillInverterPointTransformer(this.destMercatorToSourceTransformer, this.sourceToDestMercatorTransformer_approximate);
			IPointTransformer sourceToMercator = new RobustPointTransformer(flakyPointTransformer, this.sourceToDestMercatorTransformer_approximate);
			this.destLatLonToSourceTransformer = new LatLonToSourceTransform(this.destMercatorToSourceTransformer);
			this.sourceToDestLatLonTransformer = new SourceToLatLonTransform(sourceToMercator);
		}
Пример #2
0
		public CholeskyDecomposition(JamaMatrix Arg)
		{
			double[][] array = Arg.Array;
			this.n = Arg.RowDimension;
			this.L = new double[this.n][];
			for (int i = 0; i < this.n; i++)
			{
				this.L[i] = new double[this.n];
			}
			this.isspd = (Arg.ColumnDimension == this.n);
			for (int j = 0; j < this.n; j++)
			{
				double[] array2 = this.L[j];
				double num = 0.0;
				for (int k = 0; k < j; k++)
				{
					double[] array3 = this.L[k];
					double num2 = 0.0;
					for (int i = 0; i < k; i++)
					{
						num2 += array3[i] * array2[i];
					}
					num2 = (array2[k] = (array[j][k] - num2) / this.L[k][k]);
					num += num2 * num2;
					this.isspd &= (array[k][j] == array[j][k]);
				}
				num = array[j][j] - num;
				this.isspd &= (num > 0.0);
				this.L[j][j] = Math.Sqrt(Math.Max(num, 0.0));
				for (int k = j + 1; k < this.n; k++)
				{
					this.L[j][k] = 0.0;
				}
			}
		}
Пример #3
0
		public FastPoly2PointTransformer(JamaMatrix matrix) : base(matrix)
		{
			this.polynomialDegree = 2;
			for (int i = 0; i < 12; i++)
			{
				this.c[i] = matrix.GetElement(i, 0);
			}
		}
		public override void doTransform(PointD p0, PointD p1)
		{
			JamaMatrix jamaMatrix = new JamaMatrix(1, 2);
			jamaMatrix.SetElement(0, 0, p0.x);
			jamaMatrix.SetElement(0, 1, p0.y);
			JamaMatrix jamaMatrix2 = IPolyPointTransformer.Polynomialize(jamaMatrix, this.polynomialDegree).times(this.matrix);
			p1.x = jamaMatrix2.GetElement(0, 0);
			p1.y = jamaMatrix2.GetElement(1, 0);
		}
Пример #5
0
		public Affine2DPointTransformer(JamaMatrix matrix)
		{
			this.c0 = matrix.GetElement(0, 0);
			this.c1 = matrix.GetElement(0, 1);
			this.c2 = matrix.GetElement(0, 2);
			this.c3 = matrix.GetElement(1, 0);
			this.c4 = matrix.GetElement(1, 1);
			this.c5 = matrix.GetElement(1, 2);
		}
Пример #6
0
		private static IPolyPointTransformer getPolyPointTransformer(JamaMatrix sourcePoints, JamaMatrix destPoints, int polynomialDegree)
		{
			JamaMatrix am = IPolyPointTransformer.Polynomialize(destPoints, polynomialDegree);
			JamaMatrix matrix = PolynomialImageTransformer.SVDSolveApply(am, PolynomialImageTransformer.PointUnroll(sourcePoints));
			switch (polynomialDegree)
			{
			case 1:
				return new FastPoly1PointTransformer(matrix);
			case 2:
				return new FastPoly2PointTransformer(matrix);
			default:
				return new SlowGeneralPolyPointTransformer(polynomialDegree, matrix);
			}
		}
Пример #7
0
		public static JamaMatrix Polynomialize(JamaMatrix values, int degree)
		{
			JamaMatrix jamaMatrix = IPolyPointTransformer.PolyExps(degree);
			JamaMatrix jamaMatrix2 = new JamaMatrix(values.RowDimension, jamaMatrix.RowDimension);
			for (int i = 0; i < jamaMatrix.RowDimension; i++)
			{
				for (int j = 0; j < values.RowDimension; j++)
				{
					jamaMatrix2.SetElement(j, i, Math.Pow(values.GetElement(j, 0), jamaMatrix.GetElement(i, 0)) * Math.Pow(values.GetElement(j, 1), jamaMatrix.GetElement(i, 1)));
				}
			}
			JamaMatrix jamaMatrix3 = new JamaMatrix(jamaMatrix2.RowDimension * 2, jamaMatrix2.ColumnDimension * 2);
			jamaMatrix3.setMatrix(0, jamaMatrix2.RowDimension - 1, 0, jamaMatrix2.ColumnDimension - 1, jamaMatrix2);
			jamaMatrix3.setMatrix(jamaMatrix2.RowDimension, 2 * jamaMatrix2.RowDimension - 1, jamaMatrix2.ColumnDimension, 2 * jamaMatrix2.ColumnDimension - 1, jamaMatrix2);
			return jamaMatrix3;
		}
Пример #8
0
		public static JamaMatrix PolyExps(int degree)
		{
			JamaMatrix jamaMatrix = new JamaMatrix((degree + 1) * (degree + 2) / 2, 2);
			int num = 0;
			for (int i = 0; i <= degree; i++)
			{
				for (int j = 0; j <= degree - i; j++)
				{
					jamaMatrix.SetElement(num, 0, (double)i);
					jamaMatrix.SetElement(num, 1, (double)j);
					num++;
				}
			}
			D.Assert(num == jamaMatrix.RowDimension);
			return jamaMatrix;
		}
		public HomographicImageTransformer(RegistrationDefinition registration, InterpolationMode interpolationMode) : base(registration, interpolationMode)
		{
			List<PositionAssociation> associationList = registration.GetAssociationList();
			TransformationStyle arg_15_0 = registration.warpStyle;
			int count = associationList.Count;
			JamaMatrix jamaMatrix = new JamaMatrix(count, 2);
			JamaMatrix jamaMatrix2 = new JamaMatrix(count, 2);
			for (int i = 0; i < count; i++)
			{
				LatLon latlon = associationList[i].sourcePosition.pinPosition.latlon;
				jamaMatrix.SetElement(i, 0, latlon.lon);
				jamaMatrix.SetElement(i, 1, latlon.lat);
				LatLon latLon = MercatorCoordinateSystem.LatLonToMercator(associationList[i].globalPosition.pinPosition.latlon);
				jamaMatrix2.SetElement(i, 0, latLon.lon);
				jamaMatrix2.SetElement(i, 1, latLon.lat);
			}
		}
Пример #10
0
		private static JamaMatrix CornersToVectorMatrix(MapRectangle rect)
		{
			JamaMatrix jamaMatrix = new JamaMatrix(3, 4);
			jamaMatrix.SetElement(0, 0, rect.lon0);
			jamaMatrix.SetElement(0, 1, rect.lon0);
			jamaMatrix.SetElement(0, 2, rect.lon1);
			jamaMatrix.SetElement(0, 3, rect.lon1);
			jamaMatrix.SetElement(1, 0, rect.lat0);
			jamaMatrix.SetElement(1, 1, rect.lat1);
			jamaMatrix.SetElement(1, 2, rect.lat0);
			jamaMatrix.SetElement(1, 3, rect.lat1);
			jamaMatrix.SetElement(2, 0, 1.0);
			jamaMatrix.SetElement(2, 1, 1.0);
			jamaMatrix.SetElement(2, 2, 1.0);
			jamaMatrix.SetElement(2, 3, 1.0);
			return jamaMatrix;
		}
Пример #11
0
		public static double Min(JamaMatrix gm)
		{
			bool flag = true;
			double num = 0.0;
			if (gm.RowDimension * gm.ColumnDimension <= 0)
			{
				throw new Exception("No elements.");
			}
			for (int i = 0; i < gm.RowDimension; i++)
			{
				for (int j = 0; j < gm.ColumnDimension; j++)
				{
					double element = gm.GetElement(i, j);
					if (flag || element < num)
					{
						num = element;
						flag = false;
					}
				}
			}
			return num;
		}
Пример #12
0
		public virtual JamaMatrix solve(JamaMatrix B)
		{
			if (B.RowDimension != this.n)
			{
				throw new ArgumentException("Matrix row dimensions must agree.");
			}
			if (!this.isspd)
			{
				throw new SystemException("Matrix is not symmetric positive definite.");
			}
			double[][] arrayCopy = B.ArrayCopy;
			int columnDimension = B.ColumnDimension;
			for (int i = 0; i < this.n; i++)
			{
				for (int j = 0; j < columnDimension; j++)
				{
					for (int k = 0; k < i; k++)
					{
						arrayCopy[i][j] -= arrayCopy[k][j] * this.L[i][k];
					}
					arrayCopy[i][j] /= this.L[i][i];
				}
			}
			for (int i = this.n - 1; i >= 0; i--)
			{
				for (int j = 0; j < columnDimension; j++)
				{
					for (int k = i + 1; k < this.n; k++)
					{
						arrayCopy[i][j] -= arrayCopy[k][j] * this.L[k][i];
					}
					arrayCopy[i][j] /= this.L[i][i];
				}
			}
			return new JamaMatrix(arrayCopy, this.n, columnDimension);
		}
Пример #13
0
		public virtual JamaMatrix minusEquals(JamaMatrix B)
		{
			this.checkMatrixDimensions(B);
			for (int i = 0; i < this.m; i++)
			{
				for (int j = 0; j < this.n; j++)
				{
					this.A[i][j] = this.A[i][j] - B.A[i][j];
				}
			}
			return this;
		}
Пример #14
0
		public virtual JamaMatrix transpose()
		{
			JamaMatrix jamaMatrix = new JamaMatrix(this.n, this.m);
			double[][] array = jamaMatrix.Array;
			for (int i = 0; i < this.m; i++)
			{
				for (int j = 0; j < this.n; j++)
				{
					array[j][i] = this.A[i][j];
				}
			}
			return jamaMatrix;
		}
Пример #15
0
		public virtual void setMatrix(int i0, int i1, int[] c, JamaMatrix X)
		{
			try
			{
				for (int j = i0; j <= i1; j++)
				{
					for (int k = 0; k < c.Length; k++)
					{
						this.A[j][c[k]] = X.get_Renamed(j - i0, k);
					}
				}
			}
			catch (IndexOutOfRangeException)
			{
				throw new IndexOutOfRangeException("Submatrix indices");
			}
		}
Пример #16
0
		public virtual void setMatrix(int[] r, int j0, int j1, JamaMatrix X)
		{
			try
			{
				for (int i = 0; i < r.Length; i++)
				{
					for (int k = j0; k <= j1; k++)
					{
						this.A[r[i]][k] = X.get_Renamed(i, k - j0);
					}
				}
			}
			catch (IndexOutOfRangeException)
			{
				throw new IndexOutOfRangeException("Submatrix indices");
			}
		}
Пример #17
0
		public virtual void setMatrix(int[] r, int[] c, JamaMatrix X)
		{
			try
			{
				for (int i = 0; i < r.Length; i++)
				{
					for (int j = 0; j < c.Length; j++)
					{
						this.A[r[i]][c[j]] = X.get_Renamed(i, j);
					}
				}
			}
			catch (IndexOutOfRangeException)
			{
				throw new IndexOutOfRangeException("Submatrix indices");
			}
		}
Пример #18
0
 public virtual JamaMatrix solveTranspose(JamaMatrix B)
 {
     return(this.transpose().solve(B.transpose()));
 }
Пример #19
0
		public virtual JamaMatrix times(double s)
		{
			JamaMatrix jamaMatrix = new JamaMatrix(this.m, this.n);
			double[][] array = jamaMatrix.Array;
			for (int i = 0; i < this.m; i++)
			{
				for (int j = 0; j < this.n; j++)
				{
					array[i][j] = s * this.A[i][j];
				}
			}
			return jamaMatrix;
		}
Пример #20
0
		public static JamaMatrix random(int m, int n)
		{
			JamaMatrix jamaMatrix = new JamaMatrix(m, n);
			double[][] array = jamaMatrix.Array;
			for (int i = 0; i < m; i++)
			{
				for (int j = 0; j < n; j++)
				{
					array[i][j] = SupportClass.Random.NextDouble();
				}
			}
			return jamaMatrix;
		}
Пример #21
0
		private void checkMatrixDimensions(JamaMatrix B)
		{
			if (B.m != this.m || B.n != this.n)
			{
				throw new ArgumentException("Matrix dimensions must agree.");
			}
		}
Пример #22
0
		public virtual JamaMatrix solve(JamaMatrix B)
		{
			return (this.m == this.n) ? new LUDecomposition(this).solve(B) : new QRDecomposition(this).solve(B);
		}
Пример #23
0
        public LUDecomposition(JamaMatrix A)
        {
            LU  = A.ArrayCopy;
            m   = A.RowDimension;
            n   = A.ColumnDimension;
            piv = new int[m];
            for (int i = 0; i < m; i++)
            {
                piv[i] = i;
            }

            pivsign = 1;
            double[] array = new double[m];
            for (int j = 0; j < n; j++)
            {
                for (int i = 0; i < m; i++)
                {
                    array[i] = LU[i][j];
                }

                for (int i = 0; i < m; i++)
                {
                    double[] array2 = LU[i];
                    int      num    = Math.Min(i, j);
                    double   num2   = 0.0;
                    for (int k = 0; k < num; k++)
                    {
                        num2 += array2[k] * array[k];
                    }

                    array2[j] = array[i] -= num2;
                }

                int num3 = j;
                for (int i = j + 1; i < m; i++)
                {
                    if (Math.Abs(array[i]) > Math.Abs(array[num3]))
                    {
                        num3 = i;
                    }
                }

                if (num3 != j)
                {
                    for (int k = 0; k < n; k++)
                    {
                        double num4 = LU[num3][k];
                        LU[num3][k] = LU[j][k];
                        LU[j][k]    = num4;
                    }

                    int num5 = piv[num3];
                    piv[num3] = piv[j];
                    piv[j]    = num5;
                    pivsign   = -pivsign;
                }

                if ((j < m) & (LU[j][j] != 0.0))
                {
                    for (int i = j + 1; i < m; i++)
                    {
                        LU[i][j] /= LU[j][j];
                    }
                }
            }
        }
Пример #24
0
 public virtual JamaMatrix solve(JamaMatrix B)
 {
     return((this.m == this.n) ? new LUDecomposition(this).solve(B) : new QRDecomposition(this).solve(B));
 }
Пример #25
0
		public virtual JamaMatrix arrayLeftDivide(JamaMatrix B)
		{
			this.checkMatrixDimensions(B);
			JamaMatrix jamaMatrix = new JamaMatrix(this.m, this.n);
			double[][] array = jamaMatrix.Array;
			for (int i = 0; i < this.m; i++)
			{
				for (int j = 0; j < this.n; j++)
				{
					array[i][j] = B.A[i][j] / this.A[i][j];
				}
			}
			return jamaMatrix;
		}
Пример #26
0
		public virtual JamaMatrix getMatrix(int[] r, int j0, int j1)
		{
			JamaMatrix jamaMatrix = new JamaMatrix(r.Length, j1 - j0 + 1);
			double[][] array = jamaMatrix.Array;
			try
			{
				for (int i = 0; i < r.Length; i++)
				{
					for (int k = j0; k <= j1; k++)
					{
						array[i][k - j0] = this.A[r[i]][k];
					}
				}
			}
			catch (IndexOutOfRangeException)
			{
				throw new IndexOutOfRangeException("Submatrix indices");
			}
			return jamaMatrix;
		}
Пример #27
0
		public virtual JamaMatrix arrayLeftDivideEquals(JamaMatrix B)
		{
			this.checkMatrixDimensions(B);
			for (int i = 0; i < this.m; i++)
			{
				for (int j = 0; j < this.n; j++)
				{
					this.A[i][j] = B.A[i][j] / this.A[i][j];
				}
			}
			return this;
		}
Пример #28
0
		public virtual void setMatrix(int i0, int i1, int j0, int j1, JamaMatrix X)
		{
			try
			{
				for (int k = i0; k <= i1; k++)
				{
					for (int l = j0; l <= j1; l++)
					{
						this.A[k][l] = X.get_Renamed(k - i0, l - j0);
					}
				}
			}
			catch (IndexOutOfRangeException)
			{
				throw new IndexOutOfRangeException("Submatrix indices");
			}
		}
Пример #29
0
		public virtual JamaMatrix times(JamaMatrix B)
		{
			if (B.m != this.n)
			{
				throw new ArgumentException("Matrix inner dimensions must agree.");
			}
			JamaMatrix jamaMatrix = new JamaMatrix(this.m, B.n);
			double[][] array = jamaMatrix.Array;
			double[] array2 = new double[this.n];
			for (int i = 0; i < B.n; i++)
			{
				for (int j = 0; j < this.n; j++)
				{
					array2[j] = B.A[j][i];
				}
				for (int k = 0; k < this.m; k++)
				{
					double[] array3 = this.A[k];
					double num = 0.0;
					for (int j = 0; j < this.n; j++)
					{
						num += array3[j] * array2[j];
					}
					array[k][i] = num;
				}
			}
			return jamaMatrix;
		}
Пример #30
0
 public virtual JamaMatrix inverse()
 {
     return(this.solve(JamaMatrix.identity(this.m, this.m)));
 }
Пример #31
0
		public virtual JamaMatrix solveTranspose(JamaMatrix B)
		{
			return this.transpose().solve(B.transpose());
		}
Пример #32
0
		public virtual JamaMatrix getMatrix(int[] r, int[] c)
		{
			JamaMatrix jamaMatrix = new JamaMatrix(r.Length, c.Length);
			double[][] array = jamaMatrix.Array;
			try
			{
				for (int i = 0; i < r.Length; i++)
				{
					for (int j = 0; j < c.Length; j++)
					{
						array[i][j] = this.A[r[i]][c[j]];
					}
				}
			}
			catch (IndexOutOfRangeException)
			{
				throw new IndexOutOfRangeException("Submatrix indices");
			}
			return jamaMatrix;
		}
Пример #33
0
		public static JamaMatrix identity(int m, int n)
		{
			JamaMatrix jamaMatrix = new JamaMatrix(m, n);
			double[][] array = jamaMatrix.Array;
			for (int i = 0; i < m; i++)
			{
				for (int j = 0; j < n; j++)
				{
					array[i][j] = ((i == j) ? 1.0 : 0.0);
				}
			}
			return jamaMatrix;
		}
Пример #34
0
		public virtual JamaMatrix getMatrix(int i0, int i1, int[] c)
		{
			JamaMatrix jamaMatrix = new JamaMatrix(i1 - i0 + 1, c.Length);
			double[][] array = jamaMatrix.Array;
			try
			{
				for (int j = i0; j <= i1; j++)
				{
					for (int k = 0; k < c.Length; k++)
					{
						array[j - i0][k] = this.A[j][c[k]];
					}
				}
			}
			catch (IndexOutOfRangeException)
			{
				throw new IndexOutOfRangeException("Submatrix indices");
			}
			return jamaMatrix;
		}
Пример #35
0
        public SingularValueDecomposition(JamaMatrix Arg)
        {
            double[][] arrayCopy = Arg.ArrayCopy;
            this.m = Arg.RowDimension;
            this.n = Arg.ColumnDimension;
            int num = Math.Min(this.m, this.n);

            s = new double[Math.Min(this.m + 1, this.n)];
            U = new double[this.m][];
            for (int i = 0; i < this.m; i++)
            {
                U[i] = new double[num];
            }

            V = new double[this.n][];
            for (int j = 0; j < this.n; j++)
            {
                V[j] = new double[n];
            }

            double[] array  = new double[this.n];
            double[] array2 = new double[this.m];
            bool     flag   = true;
            bool     flag2  = true;
            int      num2   = Math.Min(this.m - 1, this.n);
            int      num3   = Math.Max(0, Math.Min(this.n - 2, this.m));

            for (int k = 0; k < Math.Max(num2, num3); k++)
            {
                if (k < num2)
                {
                    s[k] = 0.0;
                    for (int i = k; i < this.m; i++)
                    {
                        s[k] = Maths.hypot(s[k], arrayCopy[i][k]);
                    }

                    if (s[k] != 0.0)
                    {
                        if (arrayCopy[k][k] < 0.0)
                        {
                            s[k] = -s[k];
                        }

                        for (int i = k; i < this.m; i++)
                        {
                            arrayCopy[i][k] /= s[k];
                        }

                        arrayCopy[k][k] += 1.0;
                    }

                    s[k] = -s[k];
                }

                for (int l = k + 1; l < n; l++)
                {
                    if ((k < num2) & (s[k] != 0.0))
                    {
                        double num4 = 0.0;
                        for (int i = k; i < this.m; i++)
                        {
                            num4 += arrayCopy[i][k] * arrayCopy[i][l];
                        }

                        num4 = -num4 / arrayCopy[k][k];
                        for (int i = k; i < this.m; i++)
                        {
                            arrayCopy[i][l] += num4 * arrayCopy[i][k];
                        }
                    }

                    array[l] = arrayCopy[k][l];
                }

                if (flag & (k < num2))
                {
                    for (int i = k; i < this.m; i++)
                    {
                        U[i][k] = arrayCopy[i][k];
                    }
                }

                if (k < num3)
                {
                    array[k] = 0.0;
                    for (int i = k + 1; i < n; i++)
                    {
                        array[k] = Maths.hypot(array[k], array[i]);
                    }

                    if (array[k] != 0.0)
                    {
                        if (array[k + 1] < 0.0)
                        {
                            array[k] = -array[k];
                        }

                        for (int i = k + 1; i < n; i++)
                        {
                            array[i] /= array[k];
                        }

                        array[k + 1] += 1.0;
                    }

                    array[k] = -array[k];
                    if ((k + 1 < this.m) & (array[k] != 0.0))
                    {
                        for (int i = k + 1; i < this.m; i++)
                        {
                            array2[i] = 0.0;
                        }

                        for (int l = k + 1; l < n; l++)
                        {
                            for (int i = k + 1; i < this.m; i++)
                            {
                                array2[i] += array[l] * arrayCopy[i][l];
                            }
                        }

                        for (int l = k + 1; l < n; l++)
                        {
                            double num4 = -array[l] / array[k + 1];
                            for (int i = k + 1; i < this.m; i++)
                            {
                                arrayCopy[i][l] += num4 * array2[i];
                            }
                        }
                    }

                    if (flag2)
                    {
                        for (int i = k + 1; i < n; i++)
                        {
                            V[i][k] = array[i];
                        }
                    }
                }
            }

            int m = Math.Min(this.n, this.m + 1);

            if (num2 < this.n)
            {
                s[num2] = arrayCopy[num2][num2];
            }

            if (this.m < m)
            {
                s[m - 1] = 0.0;
            }

            if (num3 + 1 < m)
            {
                array[num3] = arrayCopy[num3][m - 1];
            }

            array[m - 1] = 0.0;
            if (flag)
            {
                for (int l = num2; l < num; l++)
                {
                    for (int i = 0; i < this.m; i++)
                    {
                        U[i][l] = 0.0;
                    }

                    U[l][l] = 1.0;
                }

                for (int k = num2 - 1; k >= 0; k--)
                {
                    if (s[k] != 0.0)
                    {
                        for (int l = k + 1; l < num; l++)
                        {
                            double num4 = 0.0;
                            for (int i = k; i < this.m; i++)
                            {
                                num4 += U[i][k] * U[i][l];
                            }

                            num4 = -num4 / U[k][k];
                            for (int i = k; i < this.m; i++)
                            {
                                U[i][l] += num4 * U[i][k];
                            }
                        }

                        for (int i = k; i < this.m; i++)
                        {
                            U[i][k] = -U[i][k];
                        }

                        U[k][k] = 1.0 + U[k][k];
                        for (int i = 0; i < k - 1; i++)
                        {
                            U[i][k] = 0.0;
                        }
                    }
                    else
                    {
                        for (int i = 0; i < this.m; i++)
                        {
                            U[i][k] = 0.0;
                        }

                        U[k][k] = 1.0;
                    }
                }
            }

            if (flag2)
            {
                for (int k = n - 1; k >= 0; k--)
                {
                    if ((k < num3) & (array[k] != 0.0))
                    {
                        for (int l = k + 1; l < num; l++)
                        {
                            double num4 = 0.0;
                            for (int i = k + 1; i < n; i++)
                            {
                                num4 += V[i][k] * V[i][l];
                            }

                            num4 = -num4 / V[k + 1][k];
                            for (int i = k + 1; i < n; i++)
                            {
                                V[i][l] += num4 * V[i][k];
                            }
                        }
                    }

                    for (int i = 0; i < n; i++)
                    {
                        V[i][k] = 0.0;
                    }

                    V[k][k] = 1.0;
                }
            }

            int    num5 = m - 1;
            int    num6 = 0;
            double num7 = Math.Pow(2.0, -52.0);
            double num8 = Math.Pow(2.0, -966.0);

            while (m > 0)
            {
                int k;
                for (k = m - 2; k >= -1; k--)
                {
                    if (k == -1)
                    {
                        break;
                    }

                    if (Math.Abs(array[k]) <= num8 + num7 * (Math.Abs(s[k]) + Math.Abs(s[k + 1])))
                    {
                        array[k] = 0.0;
                        break;
                    }
                }

                int num9;
                if (k == m - 2)
                {
                    num9 = 4;
                }
                else
                {
                    int n;
                    for (n = m - 1; n >= k; n--)
                    {
                        if (n == k)
                        {
                            break;
                        }

                        double num4 = (n != m ? Math.Abs(array[n]) : 0.0) + (n != k + 1 ? Math.Abs(array[n - 1]) : 0.0);
                        if (Math.Abs(s[n]) <= num8 + num7 * num4)
                        {
                            s[n] = 0.0;
                            break;
                        }
                    }

                    if (n == k)
                    {
                        num9 = 3;
                    }
                    else
                    {
                        if (n == m - 1)
                        {
                            num9 = 1;
                        }
                        else
                        {
                            num9 = 2;
                            k    = n;
                        }
                    }
                }

                k++;
                switch (num9)
                {
                case 1:
                {
                    double num10 = array[m - 2];
                    array[m - 2] = 0.0;
                    for (int l = m - 2; l >= k; l--)
                    {
                        double num4  = Maths.hypot(s[l], num10);
                        double num11 = s[l] / num4;
                        double num12 = num10 / num4;
                        s[l] = num4;
                        if (l != k)
                        {
                            num10        = -num12 * array[l - 1];
                            array[l - 1] = num11 * array[l - 1];
                        }

                        if (flag2)
                        {
                            for (int i = 0; i < n; i++)
                            {
                                num4        = num11 * V[i][l] + num12 * V[i][m - 1];
                                V[i][m - 1] = -num12 * V[i][l] + num11 * V[i][m - 1];
                                V[i][l]     = num4;
                            }
                        }
                    }

                    break;
                }

                case 2:
                {
                    double num10 = array[k - 1];
                    array[k - 1] = 0.0;
                    for (int l = k; l < m; l++)
                    {
                        double num4  = Maths.hypot(s[l], num10);
                        double num11 = s[l] / num4;
                        double num12 = num10 / num4;
                        s[l]     = num4;
                        num10    = -num12 * array[l];
                        array[l] = num11 * array[l];
                        if (flag)
                        {
                            for (int i = 0; i < this.m; i++)
                            {
                                num4        = num11 * U[i][l] + num12 * U[i][k - 1];
                                U[i][k - 1] = -num12 * U[i][l] + num11 * U[i][k - 1];
                                U[i][l]     = num4;
                            }
                        }
                    }

                    break;
                }

                case 3:
                {
                    double num13 =
                        Math.Max(Math.Max(Math.Max(Math.Max(Math.Abs(s[m - 1]), Math.Abs(s[m - 2])),
                                                   Math.Abs(array[m - 2])),
                                          Math.Abs(s[k])),
                                 Math.Abs(array[k]));
                    double num14 = s[m - 1] / num13;
                    double num15 = s[m - 2] / num13;
                    double num16 = array[m - 2] / num13;
                    double num17 = s[k] / num13;
                    double num18 = array[k] / num13;
                    double num19 = ((num15 + num14) * (num15 - num14) + num16 * num16) / 2.0;
                    double num20 = num14 * num16 * (num14 * num16);
                    double num21 = 0.0;
                    if ((num19 != 0.0) | (num20 != 0.0))
                    {
                        num21 = Math.Sqrt(num19 * num19 + num20);
                        if (num19 < 0.0)
                        {
                            num21 = -num21;
                        }

                        num21 = num20 / (num19 + num21);
                    }

                    double num10 = (num17 + num14) * (num17 - num14) + num21;
                    double num22 = num17 * num18;
                    for (int l = k; l < m - 1; l++)
                    {
                        double num4  = Maths.hypot(num10, num22);
                        double num11 = num10 / num4;
                        double num12 = num22 / num4;
                        if (l != k)
                        {
                            array[l - 1] = num4;
                        }

                        num10    = num11 * s[l] + num12 * array[l];
                        array[l] = num11 * array[l] - num12 * s[l];
                        num22    = num12 * s[l + 1];
                        s[l + 1] = num11 * s[l + 1];
                        if (flag2)
                        {
                            for (int i = 0; i < n; i++)
                            {
                                num4        = num11 * V[i][l] + num12 * V[i][l + 1];
                                V[i][l + 1] = -num12 * V[i][l] + num11 * V[i][l + 1];
                                V[i][l]     = num4;
                            }
                        }

                        num4         = Maths.hypot(num10, num22);
                        num11        = num10 / num4;
                        num12        = num22 / num4;
                        s[l]         = num4;
                        num10        = num11 * array[l] + num12 * s[l + 1];
                        s[l + 1]     = -num12 * array[l] + num11 * s[l + 1];
                        num22        = num12 * array[l + 1];
                        array[l + 1] = num11 * array[l + 1];
                        if (flag && l < this.m - 1)
                        {
                            for (int i = 0; i < this.m; i++)
                            {
                                num4        = num11 * U[i][l] + num12 * U[i][l + 1];
                                U[i][l + 1] = -num12 * U[i][l] + num11 * U[i][l + 1];
                                U[i][l]     = num4;
                            }
                        }
                    }

                    array[m - 2] = num10;
                    num6++;
                    break;
                }

                case 4:
                    if (s[k] <= 0.0)
                    {
                        s[k] = s[k] < 0.0 ? -s[k] : 0.0;
                        if (flag2)
                        {
                            for (int i = 0; i <= num5; i++)
                            {
                                V[i][k] = -V[i][k];
                            }
                        }
                    }

                    while (k < num5)
                    {
                        if (s[k] >= s[k + 1])
                        {
                            break;
                        }

                        double num4 = s[k];
                        s[k]     = s[k + 1];
                        s[k + 1] = num4;
                        if (flag2 && k < n - 1)
                        {
                            for (int i = 0; i < n; i++)
                            {
                                num4        = V[i][k + 1];
                                V[i][k + 1] = V[i][k];
                                V[i][k]     = num4;
                            }
                        }

                        if (flag && k < this.m - 1)
                        {
                            for (int i = 0; i < this.m; i++)
                            {
                                num4        = U[i][k + 1];
                                U[i][k + 1] = U[i][k];
                                U[i][k]     = num4;
                            }
                        }

                        k++;
                    }

                    num6 = 0;
                    m--;
                    break;
                }
            }
        }
Пример #36
0
        public EigenvalueDecomposition(JamaMatrix Arg)
        {
            double[][] array = Arg.Array;
            n = Arg.ColumnDimension;
            V = new double[n][];
            for (int i = 0; i < n; i++)
            {
                V[i] = new double[n];
            }

            d           = new double[n];
            e           = new double[n];
            issymmetric = true;
            int j = 0;

            while ((j < n) & issymmetric)
            {
                int i = 0;
                while ((i < n) & issymmetric)
                {
                    issymmetric = array[i][j] == array[j][i];
                    i++;
                }

                j++;
            }

            if (issymmetric)
            {
                for (int i = 0; i < n; i++)
                {
                    for (j = 0; j < n; j++)
                    {
                        V[i][j] = array[i][j];
                    }
                }

                tred2();
                tql2();
            }
            else
            {
                double[][] array2 = new double[n][];
                for (int k = 0; k < n; k++)
                {
                    array2[k] = new double[n];
                }

                H   = array2;
                ort = new double[n];
                for (j = 0; j < n; j++)
                {
                    for (int i = 0; i < n; i++)
                    {
                        H[i][j] = array[i][j];
                    }
                }

                orthes();
                hqr2();
            }
        }