예제 #1
0
 public static double[] ComputeDistanceBiharmonic(int sourceVertex, Eigen eigens)
 {
     double[] biharmonicDistance = new double[eigens.EigenVectorSize];
     for (int i = 0; i < biharmonicDistance.Length; i++)
     {
         biharmonicDistance[i] = 0;
     }
     for (int i = 1; i < eigens.Count; i++)
     {
         EigenPair     pair        = eigens.SortedEigens[i];
         double        eigenValue  = pair.EigenValue;
         List <double> eigenVector = pair.EigenVector;
         for (int j = 0; j < eigenVector.Count; j++)
         {
             double orig = eigenVector[sourceVertex];
             double y    = eigenVector[j];
             double res  = orig - y;
             biharmonicDistance[j] += (res * res) / ((eigenValue) * (eigenValue));
         }
     }
     for (int i = 0; i < biharmonicDistance.Length; i++)
     {
         biharmonicDistance[i] = Math.Sqrt(biharmonicDistance[i]);
     }
     return(biharmonicDistance);
 }
예제 #2
0
        public static double[] ComputeDistanceDiffusion(int originVertexIndex,
                                                        double parameterT,
                                                        Eigen eigens)
        {
            double[] diffusionDistance = new double[eigens.EigenVectorSize];
            for (int i = 0; i < diffusionDistance.Length; i++)
            {
                diffusionDistance[i] = 0;
            }
            double optParamterT = parameterT / (2 * eigens.GetEigenValue(1));

            for (int i = 1; i < eigens.Count; i++)
            {
                EigenPair     pair        = eigens.SortedEigens[i];
                double        eigenValue  = pair.EigenValue;
                List <double> eigenVector = pair.EigenVector;
                for (int j = 0; j < eigenVector.Count; j++)
                {
                    double orig = eigenVector[originVertexIndex];
                    double y    = eigenVector[j];
                    double res  = orig - y;
                    diffusionDistance[j] += Math.Exp(-2 * optParamterT * eigenValue)
                                            * (res * res);
                }
            }
            for (int i = 0; i < diffusionDistance.Length; i++)
            {
                diffusionDistance[i] = Math.Sqrt(diffusionDistance[i]);
            }
            return(diffusionDistance);
        }
예제 #3
0
 public static double[] ComputeDistanceCommuteTime(int originVertexIndex,
                                                   Eigen eigens)
 {
     double[] diffusionDistance = new double[eigens.EigenVectorSize];
     for (int i = 0; i < diffusionDistance.Length; i++)
     {
         diffusionDistance[i] = 0;
     }
     for (int i = 1; i < eigens.Count; i++)
     {
         EigenPair     pair        = eigens.SortedEigens[i];
         double        eigenValue  = pair.EigenValue;
         List <double> eigenVector = pair.EigenVector;
         for (int j = 0; j < eigenVector.Count; j++)
         {
             double orig = eigenVector[originVertexIndex];
             double y    = eigenVector[j];
             double res  = orig - y;
             diffusionDistance[j] += (1 / eigenValue) * (res * res);
         }
     }
     for (int i = 0; i < diffusionDistance.Length; i++)
     {
         diffusionDistance[i] = Math.Sqrt(diffusionDistance[i]);
     }
     return(diffusionDistance);
 }
예제 #4
0
        public Eigen ReadEigen(string modelName)
        {
            string fileName = Path.GetFileNameWithoutExtension(modelName);
            string path     = GetPath() + fileName + ".eigens";

            Eigen            eigen = new Eigen();
            List <EigenPair> list  = new List <EigenPair>();

            //Read File
            using (StreamReader sr = new StreamReader(path))
            {
                String        line          = null;
                List <double> currentVector = null;
                while ((line = sr.ReadLine()) != null)
                {
                    if (line != "" && line[0] == '#')
                    {
                        String[]      tokens  = line.Split(' ');
                        List <double> aVector = new List <double>();
                        currentVector = aVector;

                        EigenPair pair = new EigenPair(double.Parse(tokens[1]), aVector);
                        list.Add(pair);
                    }
                    else if (line != "")
                    {
                        double value = double.Parse(line);
                        currentVector.Add(value);
                    }
                }
            }
            list.Sort();
            eigen.SortedEigens = list.ToArray();
            return(eigen);
        }
예제 #5
0
        public Eigen ComputeEigensByLib(SparseMatrixDouble sparse, double sigma, int count)
        {
            int[]    pCol;
            int[]    iRow;
            double[] Values;
            int      NNZ;

            int m = sparse.RowCount;

            sparse.ToCCS(out pCol, out iRow, out Values, out NNZ);

            double[] ImagePart = new double[count];
            double[] RealPart  = new double[count];
            double[] Vectors   = new double[count * m];

            fixed(int *ri = iRow, cp = pCol)
            fixed(double *val = Values, vets = Vectors, imgPart = ImagePart, relPart = RealPart)
            {
                int result = ComputeEigenNoSymmetricShiftModeCRS(ri, cp, val, NNZ, m, count, sigma, relPart, imgPart, vets);
            }



            List <EigenPair> list = new List <EigenPair>();

            for (int i = 0; i < count; i++)
            {
                double realPart = RealPart[i];



                List <double> vector = new List <double>();

                int startIndex = i * m;
                int endIndex   = i * m + m;

                for (int j = startIndex; j < endIndex; j++)
                {
                    double value = Vectors[j];
                    vector.Add(value);
                }

                EigenPair newPair = new EigenPair(realPart, vector);


                list.Add(newPair);
            }

            list.Sort();

            Eigen eigen = new Eigen();

            eigen.SortedEigens = list.ToArray();
            return(eigen);
        }
예제 #6
0
        public Eigen GetEigen(SparseMatrix sparse, int num)
        {
            OutPut(sparse, "L");
            matlab.Execute(@"[EV,ED] = eigs(L," + num.ToString() + ",'sm') ");

            double[,] eigVector = GetMatrix("EV");
            double[,] eigValue  = GetMatrix("ED");

            int len = eigVector.GetLength(0);
            List <EigenPair> list = new List <EigenPair>();

            for (int i = 0; i < num; i++)
            {
                double realPart = eigValue[i, i];

                List <double> vector = new List <double>();

                for (int j = 0; j < len; j++)
                {
                    double value = eigVector[j, i];
                    vector.Add(value);
                }

                EigenPair newPair = new EigenPair(realPart, vector);


                list.Add(newPair);
            }

            list.Sort();

            Eigen eigen = new Eigen();

            eigen.SortedEigens = list.ToArray();

            return(eigen);
        }