예제 #1
0
 public static SymmetricMatrix operator -(SymmetricMatrix left, SymmetricMatrix right)
 {
     return(new SymmetricMatrix(MatrixUtil.GetMinus(left.Vector, right.Vector)));
 }
예제 #2
0
 public static SymmetricMatrix operator *(SymmetricMatrix left, double right)
 {
     return(new SymmetricMatrix(MatrixUtil.GetMultiply(left.Vector, right)));
 }
예제 #3
0
 public void testEmbedBasicPatterns()
 {
     {
         // Version 1.
         String expected =
             " 1 1 1 1 1 1 1 0           0 1 1 1 1 1 1 1\n" +
             " 1 0 0 0 0 0 1 0           0 1 0 0 0 0 0 1\n" +
             " 1 0 1 1 1 0 1 0           0 1 0 1 1 1 0 1\n" +
             " 1 0 1 1 1 0 1 0           0 1 0 1 1 1 0 1\n" +
             " 1 0 1 1 1 0 1 0           0 1 0 1 1 1 0 1\n" +
             " 1 0 0 0 0 0 1 0           0 1 0 0 0 0 0 1\n" +
             " 1 1 1 1 1 1 1 0 1 0 1 0 1 0 1 1 1 1 1 1 1\n" +
             " 0 0 0 0 0 0 0 0           0 0 0 0 0 0 0 0\n" +
             "             1                            \n" +
             "             0                            \n" +
             "             1                            \n" +
             "             0                            \n" +
             "             1                            \n" +
             " 0 0 0 0 0 0 0 0 1                        \n" +
             " 1 1 1 1 1 1 1 0                          \n" +
             " 1 0 0 0 0 0 1 0                          \n" +
             " 1 0 1 1 1 0 1 0                          \n" +
             " 1 0 1 1 1 0 1 0                          \n" +
             " 1 0 1 1 1 0 1 0                          \n" +
             " 1 0 0 0 0 0 1 0                          \n" +
             " 1 1 1 1 1 1 1 0                          \n";
         ByteMatrix matrix = new ByteMatrix(21, 21);
         MatrixUtil.clearMatrix(matrix);
         MatrixUtil.embedBasicPatterns(Version.getVersionForNumber(1), matrix);
         Assert.AreEqual(expected, matrix.ToString());
     }
     {
         // Version 2.  Position adjustment pattern should apppear at right
         // bottom corner.
         String expected =
             " 1 1 1 1 1 1 1 0                   0 1 1 1 1 1 1 1\n" +
             " 1 0 0 0 0 0 1 0                   0 1 0 0 0 0 0 1\n" +
             " 1 0 1 1 1 0 1 0                   0 1 0 1 1 1 0 1\n" +
             " 1 0 1 1 1 0 1 0                   0 1 0 1 1 1 0 1\n" +
             " 1 0 1 1 1 0 1 0                   0 1 0 1 1 1 0 1\n" +
             " 1 0 0 0 0 0 1 0                   0 1 0 0 0 0 0 1\n" +
             " 1 1 1 1 1 1 1 0 1 0 1 0 1 0 1 0 1 0 1 1 1 1 1 1 1\n" +
             " 0 0 0 0 0 0 0 0                   0 0 0 0 0 0 0 0\n" +
             "             1                                    \n" +
             "             0                                    \n" +
             "             1                                    \n" +
             "             0                                    \n" +
             "             1                                    \n" +
             "             0                                    \n" +
             "             1                                    \n" +
             "             0                                    \n" +
             "             1                   1 1 1 1 1        \n" +
             " 0 0 0 0 0 0 0 0 1               1 0 0 0 1        \n" +
             " 1 1 1 1 1 1 1 0                 1 0 1 0 1        \n" +
             " 1 0 0 0 0 0 1 0                 1 0 0 0 1        \n" +
             " 1 0 1 1 1 0 1 0                 1 1 1 1 1        \n" +
             " 1 0 1 1 1 0 1 0                                  \n" +
             " 1 0 1 1 1 0 1 0                                  \n" +
             " 1 0 0 0 0 0 1 0                                  \n" +
             " 1 1 1 1 1 1 1 0                                  \n";
         ByteMatrix matrix = new ByteMatrix(25, 25);
         MatrixUtil.clearMatrix(matrix);
         MatrixUtil.embedBasicPatterns(Version.getVersionForNumber(2), matrix);
         Assert.AreEqual(expected, matrix.ToString());
     }
 }
예제 #4
0
 private void EmbedAlignmentPattern(ByteMatrix matrix, int version)
 {
     matrix.Clear(-1);
     MatrixUtil.embedBasicPatterns(version, matrix);
     MatrixUtil.maybeEmbedVersionInfo(version, matrix);
 }
 private void RotateGrid180()
 {
     Pixels.Reset(MatrixUtil.RotateMatrix180(Pixels.ToArray(), GridWidth, GridHeight));
     AddHistoryState("Rotate Grid 180°");
     IsDirty = true;
 }
 private void FlipGridHorizontally()
 {
     Pixels.Reset(MatrixUtil.FlipMatrixHorizontally(Pixels.ToArray(), GridWidth, GridHeight));
     AddHistoryState("Flip Grid Horizontally");
     IsDirty = true;
 }
 public double[,] times(double[,] m, double[,] other)
 {
     return(MatrixUtil.times(m, other));
 }
예제 #8
0
        internal virtual void TransformRect(ref Rect rect)
        {
            Matrix matrix = Value;

            MatrixUtil.TransformRect(ref rect, ref matrix);
        }
예제 #9
0
 /// <summary>
 /// Updates rectangle to be the bounds of the original value transformed
 /// by the matrix.
 /// The Empty Rect is not affected by this call.
 /// </summary>
 /// <param name="matrix"> Matrix </param>
 public void Transform(Matrix matrix)
 {
     MatrixUtil.TransformRect(ref this, ref matrix);
 }
예제 #10
0
 protected override int ReferenceExpectedResult(int inputNum)
 {
     return(MatrixUtil.calculateBCHCode(inputNum, VERSION_INFO_POLY));
 }
예제 #11
0
 /// <summary>
 /// Returns the bounds of the transformed rectangle.
 /// The Empty Rect is not affected by this call.
 /// </summary>
 /// <returns>
 /// The rect which results from the transformation.
 /// </returns>
 /// <param name="rect"> The Rect to transform. </param>
 /// <param name="matrix"> The Matrix by which to transform. </param>
 public static Rect Transform(Rect rect, Matrix matrix)
 {
     MatrixUtil.TransformRect(ref rect, ref matrix);
     return(rect);
 }
예제 #12
0
        /// <summary>
        /// 基于 Sinex 文件的分区平差。
        /// </summary>
        /// <param name="files">具有公共参数的分区</param>
        public SinexBlockAdjust(params SinexFile[] files)
        {
            if (files.Length <= 1)
            {
                throw new ArgumentException("输入的SINEX文件数量不可少于2!");
            }
            this.files = files;

            //检查一下是否只包含坐标,如否,则清理。
            foreach (var item in files)
            {
                if (!item.IsOnlyEstimateCoordValue)
                {
                    item.CleanNonCoordSolutionValue();
                }
            }

            //提取公共测站名称
            List <string> sameSites = null; new List <string>();

            foreach (var item in files)
            {
                if (sameSites == null)
                {
                    sameSites = new List <string>(); sameSites.AddRange(item.GetSiteCods());
                }
                else
                {
                    sameSites = SinexFile.GetSameSiteCodes(item, sameSites);
                }
            }
            if (sameSites.Count == 0)
            {
                throw new ArgumentException("分区没有公共点,不可执行分区平差!");
            }

            //计算统一单位权中误差
            double commonVarFactor = GetVarianceFactor(files);


            //组建分区
            DateTime from = DateTime.Now;
            List <BlockAdjustItem> items = new List <BlockAdjustItem>();

            foreach (var file in files)
            {
                //获取公共参数所在的编号,都转化为X,Y,Z分别的参数
                List <int> commonParamIndexes = file.GetParamIndexes(sameSites);       //公共参数的索引
                List <int> blockParamIndexes  = file.GetParamIndexesExcept(sameSites); //区内参数的索引
                List <int> newIndexes         = new List <int>(blockParamIndexes);     //新索引顺序

                newIndexes.AddRange(commonParamIndexes);

                int blockParamCount  = blockParamIndexes.Count;
                int obsCount         = file.EstimateParamCount;
                int commonParamCount = commonParamIndexes.Count;
                //分区内参数系数阵 obsCount x paramCount
                double[][] coeffA = MatrixUtil.Create(obsCount, blockParamCount);
                for (int i = 0; i < blockParamCount; i++)
                {
                    coeffA[i][i] = 1.0;
                }
                //观测值 obsCount x 1
                double[][] obs = MatrixUtil.Create(obsCount, 1);
                for (int i = 0; i < obsCount; i++)
                {
                    if (i < blockParamCount)//区内参数
                    {
                        obs[i][0] = file.SolutionEstimateBlock.Items[blockParamIndexes[i]].ParameterValue;
                    }
                    else//公共参数
                    {
                        obs[i][0] = file.SolutionEstimateBlock.Items[commonParamIndexes[i - blockParamCount]].ParameterValue;
                    }
                }
                //观测值权逆阵 obsCount x obsCount
                //注意:此处应该统一化权阵
                double[][] inverseOfObs = null;
                if (file.HasEstimateCovaMatrix)
                {
                    inverseOfObs = file.GetEstimateCovaMatrix();
                    MatrixUtil.SymmetricExchange(inverseOfObs, newIndexes);
                    MatrixUtil.Multiply(inverseOfObs, commonVarFactor / file.GetStatistic().VarianceOfUnitWeight);
                }
                //else if (file.HasNormalEquationMatrix && file.HasNormalEquationVectorMatrix)
                //{
                //    //方法待验证
                //    double[][]  normal = file.GetNormalEquationMatrix();
                //    double[] righHand = file.GetNormalEquationVector();
                //    Geo.Algorithm.Matrix n = new Geo.Algorithm.Matrix(normal);
                //    Geo.Algorithm.Matrix u = new Geo.Algorithm.Matrix(MatrixUtil.Create( righHand));
                //    inverseOfObs = n.Inverse.Array;
                //    double lTpl = file.GetStatistic().WeightedSqureSumOfOMinusC;
                //    double vTpv = lTpl - (u.Transpose() * n * u)[0,0];
                //    double varFactor = vTpv / file.GetStatistic().NumberOfDegreesOfFreedom;
                //    MatrixUtil.Multiply(inverseOfObs, varFactor);

                //    MatrixUtil.SymmetricExchange(inverseOfObs, newIndexes);
                //    MatrixUtil.Multiply(inverseOfObs, commonVarFactor / file.GetStatistic().VarianceOfUnitWeight);
                //}
                else//去相关
                {
                    inverseOfObs = MatrixUtil.Create(obsCount);
                    for (int i = 0; i < obsCount; i++)
                    {
                        if (i < blockParamCount)//区内参数
                        {
                            inverseOfObs[i][i] = Math.Pow(file.SolutionEstimateBlock.Items[blockParamIndexes[i]].StdDev, 2);
                        }
                        else//公共参数
                        {
                            inverseOfObs[i][i] = Math.Pow(file.SolutionEstimateBlock.Items[commonParamIndexes[i - blockParamCount]].StdDev, 2);
                        }
                    }
                    MatrixUtil.Multiply(inverseOfObs, commonVarFactor / file.GetStatistic().VarianceOfUnitWeight);
                }

                //分区内对公共参数的系数阵 obsCount x commonParamCount
                double[][] coeffB = MatrixUtil.Create(obsCount, commonParamCount);
                for (int i = blockParamCount; i < obsCount; i++)
                {
                    coeffB[i][i - blockParamCount] = 1;
                }

                BlockAdjustItem item = new BlockAdjustItem(coeffA, obs, inverseOfObs, coeffB);
                items.Add(item);
            }

            ba = new BlockAdjustment(items.ToArray(), false);


            //创建结果SINEX文件,文件只包含公共参数的内容
            ResultSinexFile = new SinexFile("Gnsser");
            //测站名称
            int           commonSiteCount = ba.CommonParamCount / 3;
            List <SiteId> siteIds         = new List <SiteId>();

            for (int i = 0; i < commonSiteCount; i++)
            {
                siteIds.Add(files[0].GetSiteId(sameSites[i]));
            }
            ResultSinexFile.SiteIdBlock = SinexFactory.CreateSiteIdBlock(siteIds);
            //统计信息
            SinexStatistic statistic = new SinexStatistic()
            {
                NumberOfUnknown          = ba.CommonParamCount,
                NumberOfDegreesOfFreedom = ba.Freedom,
                VarianceOfUnitWeight     = ba.VarianceOfUnitWeight,
                SquareSumOfResidualsVTPV = ba.SquareSumOfResidualsVTPV,
                NumberOfObservations     = ba.ObsCount
            };

            ResultSinexFile.SolutionStattisticsBlock =
                SinexFactory.CreateSolutionStattisticsBlock(statistic.GetSolutionStatistics());

            //估值
            List <SolutionValue> estList = new List <SolutionValue>();
            Time refEchop = files[0].SolutionEstimateBlock.Items[0].RefEpoch;

            for (int i = 0; i < commonSiteCount; i++)
            {
                int           paramIndex = i * 3;
                SolutionValue svX        = new SolutionValue(paramIndex + 1, siteIds[i].SiteCode, "STAX", ba.CommonParams[paramIndex + 0][0], refEchop, ba.CommonParamRmsVector[paramIndex + 0]);
                SolutionValue svY        = new SolutionValue(paramIndex + 2, siteIds[i].SiteCode, "STAY", ba.CommonParams[paramIndex + 1][0], refEchop, ba.CommonParamRmsVector[paramIndex + 1]);
                SolutionValue svZ        = new SolutionValue(paramIndex + 3, siteIds[i].SiteCode, "STAZ", ba.CommonParams[paramIndex + 2][0], refEchop, ba.CommonParamRmsVector[paramIndex + 2]);
                estList.AddRange(new SolutionValue[] {
                    svX, svY, svZ
                });
            }
            ResultSinexFile.SolutionEstimateBlock = SinexFactory.CreateSolutionEstimateBlock(estList);
            //协方差
            ResultSinexFile.SolutionMatrixEstimateCova = SinexFactory.CreateSolutionMatrixEstimateCova(ba.CovaOfCommonParams);

            this.TimeSpan = DateTime.Now - from;
        }
예제 #13
0
 /// <summary>
 /// MultiplyValueByMatrix - result is set equal to "this" * matrixToMultiplyBy.
 /// </summary>
 /// <param name="result"> The result is stored here. </param>
 /// <param name="matrixToMultiplyBy"> The multiplicand. </param>
 internal virtual void MultiplyValueByMatrix(ref Matrix result, ref Matrix matrixToMultiplyBy)
 {
     result = Value;
     MatrixUtil.MultiplyMatrix(ref result, ref matrixToMultiplyBy);
 }
예제 #14
0
 public static SymmetricMatrix operator -(SymmetricMatrix left)
 {
     return(new SymmetricMatrix(MatrixUtil.GetOpposite(left.Vector)));
 }
 double vectorDot(double[] v1, double[] v2)
 {
     return(MatrixUtil.vectorDot(v1, v2));
 }
예제 #16
0
 /// <summary>
 /// 完全克隆
 /// </summary>
 /// <returns></returns>
 public override IMatrix Clone()
 {
     return(new SymmetricMatrix(MatrixUtil.Clone(this._vector)));
 }
예제 #17
0
 /* Implement Drawer */
 public bool Draw(int[,] matrix)
 {
     return(startX >= MatrixUtil.GetX(matrix) || startY >= MatrixUtil.GetY(matrix) ? false : DrawNormal(matrix));
 }