Exemplo n.º 1
0
 /// <summary>
 /// 输入检查
 /// </summary>
 /// <param name="inputOne">输入1</param>
 /// <param name="inputTwo">输入2</param>
 /// <exception cref="ArgumentException">输入为Null或维度不相同或维度为0</exception>
 private static void inputCheck(IDimensionValueBean inputOne, IDimensionValueBean inputTwo)
 {
     //null值检查 维度相同检查
     if (null == inputOne || null == inputTwo ||
         inputOne.GetSumDimensionNumber() != inputTwo.GetSumDimensionNumber() ||
         0 >= inputOne.GetSumDimensionNumber()
         )
     {
         throw new ArgumentException();
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// 计算两个多维数据之间的欧几里得距离
        /// </summary>
        /// <param name="inputOne">输入1</param>
        /// <param name="inputTwo">输入2</param>
        /// <returns>欧几里得距离</returns>
        /// <exception cref="ArgumentException">输入为Null或维度不相同或维度为0</exception>
        internal static double CalculateDistanceByEuclidean
            (IDimensionValueBean inputOne, IDimensionValueBean inputTwo, bool ifCheck = true)
        {
            if (ifCheck)
            {
                inputCheck(inputOne, inputTwo);
            }

            double returnValue = 0.0d;

            int tempSize = inputOne.GetSumDimensionNumber();

            //维度距离累计
            for (int tempIndex = 0; tempIndex < tempSize; tempIndex++)
            {
                returnValue = returnValue + Math.Pow
                                  ((inputOne.GetValueAtDimensionIndex(tempIndex) -
                                    inputTwo.GetValueAtDimensionIndex(tempIndex)), 2.0D);
            }

            //开根号
            returnValue = Math.Pow(returnValue, 0.5D);

            return(returnValue);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 比较两个多维数据封装是否相同
        /// </summary>
        /// <param name="inputOne">输入1</param>
        /// <param name="inputTwo">输入2</param>
        /// <param name="ifCheck">是否进行输入检查</param>
        /// <returns>是否相同</returns>
        /// <exception cref="ArgumentException">输入为Null或维度不相同或维度为0</exception>
        internal static bool IfDDimensionIsEqula
            (IDimensionValueBean inputOne, IDimensionValueBean inputTwo, bool ifCheck = true)
        {
            if (ifCheck)
            {
                inputCheck(inputOne, inputTwo);
            }

            bool returnValue = true;

            int sumNumber = inputOne.GetSumDimensionNumber();

            //检查各维度
            for (int tempIndex = 0; tempIndex < sumNumber; tempIndex++)
            {
                //当出现不等时
                if (CompareResultEnum.Equal != CompareDoulbe
                        (inputOne.GetValueAtDimensionIndex(tempIndex),
                        inputTwo.GetValueAtDimensionIndex(tempIndex)))
                {
                    returnValue = false;
                }
            }

            return(returnValue);
        }
Exemplo n.º 4
0
 /// <summary>
 /// 输入检查
 /// </summary>
 /// <param name="inputValue"></param>
 private void inputCheck(IDimensionValueBean inputValue, bool ifCheckDimensionNumber = true)
 {
     //若需检查维度数
     if (ifCheckDimensionNumber)
     {
         if (null == inputValue ||
             inputValue.GetSumDimensionNumber() != nodeCount ||
             0 >= inputValue.GetSumDimensionNumber())
         {
             throw new ArgumentException();
         }
     }
     else
     {
         if (null == inputValue ||
             0 >= inputValue.GetSumDimensionNumber())
         {
             throw new ArgumentException();
         }
     }
 }