Ejemplo n.º 1
0
 private void determineBiPartitionOfGraph(Vector<double> secondLargestEigVec, SpectralTreeNode spectralTreeRoot,
     out List<int> firstPartIdx, out List<int> secondPartIdx)
 {
     firstPartIdx = new List<int>();
     secondPartIdx = new List<int>();
     List<int> firstPart = new List<int>();
     List<int> secondPart = new List<int>();
     for (int idx = 0; idx < secondLargestEigVec.Count; idx++)
     {
         if (secondLargestEigVec[idx] >= 0)
         {
             firstPartIdx.Add(idx);
             firstPart.Add(spectralTreeRoot.VertexList[idx]);
         }
         else
         {
             secondPartIdx.Add(idx);
             secondPart.Add(spectralTreeRoot.VertexList[idx]);
         }
     }
     SpectralTreeNode spectralFirstTreeNode = new SpectralTreeNode() { VertexList = firstPart };
     spectralTreeRoot.FirstChild = spectralFirstTreeNode;
     SpectralTreeNode spectralSecondTreeNode = new SpectralTreeNode() { VertexList = secondPart };
     spectralTreeRoot.SecondChild = spectralSecondTreeNode;
 }
Ejemplo n.º 2
0
 public double computeMeasure(SpectralTreeNode[] spectralTreeLeaves)
 {
     double measure = 0.0;
     foreach (var spectralTreeLeaf in spectralTreeLeaves)
     {
         measure += computeMeasureForRegion(spectralTreeLeaf);
     }
     measure = measure / (double)serverNO;
     return measure;
 }
Ejemplo n.º 3
0
 public SpectralTreeNode[] apply(int vertexNO)
 {
     SpectralTreeNode spectralTreeRoot = new SpectralTreeNode()
     {
         VertexList = Enumerable.Range(0, vertexNO).ToList()
     };
     innerDetermineNormCutAndChildren(spectralTreeRoot, weightMX);
     innerDeterminePartition(spectralTreeRoot.FirstChild, spectralTreeRoot.SecondChild);
     return listOfLeaves.ToArray();
 }
Ejemplo n.º 4
0
 public double computeMeasureForRegion(SpectralTreeNode spectralTreeLeaf)
 {
     double measureForRegion = 0.0;
     int binNOInRegionWithoutZeroHeft = 0;
     foreach (var vertexIdx in spectralTreeLeaf.VertexList)
     {
         int[] indicesArrayOfBin = new int[spaceDimension];
         transformator.transformCellIdxToIndicesArray(histogramResolution, indicesArrayOfBin, vertexIdx);
         int binValue = (int)histogram.GetValue(indicesArrayOfBin);
         if (binValue > 0)
         {
             binNOInRegionWithoutZeroHeft++;
             measureForRegion += computeMeasureForBin(indicesArrayOfBin, spectralTreeLeaf);
         }
     }
     measureForRegion = measureForRegion / (double)binNOInRegionWithoutZeroHeft;
     return measureForRegion;
 }
Ejemplo n.º 5
0
 public double computeMeasureForBin(int[] indicesArrayOfBin, SpectralTreeNode spectralTreeLeaf)
 {
     double measureForBin = 0.0;
     int binValue = (int)histogram.GetValue(indicesArrayOfBin);
     int currentKNN = (kNN < pointNO) ? kNN : pointNO - 1;
         int nnInServer = binValue - 1;
         int nnOutserver = 0;
         if (currentKNN - binValue + 1 > 0)
         {
             Shell[] currentShells = new Shell[currentKNN - binValue + 1];
             Array.Copy(shells, currentShells, currentKNN - binValue + 1);
             var dictOfShells = transformator.convertIntPairsOfShellsToListOfIdxArrays(
                 histogramResolution, indicesArrayOfBin, shells);
             iterateOverShells(spectralTreeLeaf, currentKNN, ref nnInServer, ref nnOutserver, dictOfShells);
         }
         //nnInServer should not be greater than (kNN - nnOutserver) because nnOutserver has been 'commited':
         nnInServer = (nnInServer <= currentKNN - nnOutserver) ? nnInServer : currentKNN - nnOutserver;
         measureForBin = (double)nnInServer / (double)currentKNN;
     return measureForBin;
 }
Ejemplo n.º 6
0
 private bool isIdxArrayInTheSpectralTreeLeaf(int[] idxArray, SpectralTreeNode spectralTreeLeaf)
 {
     bool result = false;
     int targetVertexIdx = transformator.transformIndicesArrayToCellIdx(histogramResolution, idxArray);
     foreach (var vertexIdx in spectralTreeLeaf.VertexList)
     {
         if (targetVertexIdx == vertexIdx)
         {
             result = true;
         }
     }
     return result;
 }
Ejemplo n.º 7
0
 private void updateNNCountsWithBinsOnCurrentShell(SpectralTreeNode spectralTreeLeaf, ref int nnInServer,
     ref int tmpNNOutServer, List<int[]> idxArraysOnCurrentShell)
 {
     foreach (var idxArray in idxArraysOnCurrentShell)
     {
         int currentBinValue = (int)histogram.GetValue(idxArray);
         if (isIdxArrayInTheSpectralTreeLeaf(idxArray, spectralTreeLeaf))
         {
             nnInServer += currentBinValue;
         }
         else
         {
             tmpNNOutServer += currentBinValue;
         }
     }
 }
Ejemplo n.º 8
0
 private void iterateOverShells(SpectralTreeNode spectralTreeLeaf, int kNN, ref int nnInServer, ref int nnOutserver,
     Dictionary<int, List<int[]>> dictOfShells)
 {
     foreach (var shellIdx in dictOfShells.Keys)
     {
         int tmpNNOutServer = 0;
         List<int[]> idxArraysOnCurrentShell = dictOfShells[shellIdx];
         updateNNCountsWithBinsOnCurrentShell(spectralTreeLeaf, ref nnInServer, ref tmpNNOutServer,
             idxArraysOnCurrentShell);
         if (nnInServer + nnOutserver >= kNN)
         {
             break;
         }
         else
         {
             if (nnInServer + nnOutserver + tmpNNOutServer >= kNN)
             {
                 nnOutserver = kNN - nnInServer;
                 break;
             }
             else
             {
                 nnOutserver += tmpNNOutServer;
             }
         }
     }
 }
Ejemplo n.º 9
0
 private void innerDeterminePartition(SpectralTreeNode spectralTreeNode1, SpectralTreeNode spectralTreeNode2)
 {
     innerDetermineNormCutAndChildren(spectralTreeNode1, determinePartOfWeightMX(spectralTreeNode1.VertexList));
     innerDetermineNormCutAndChildren(spectralTreeNode2, determinePartOfWeightMX(spectralTreeNode2.VertexList));
     listOfLeaves.Add(spectralTreeNode1);
     listOfLeaves.Add(spectralTreeNode2);
     if (listOfLeaves.Count < serverNO)
     {
         listOfLeaves.Sort(comparer);
         SpectralTreeNode leafWithMinNormCut = listOfLeaves[0];
         SpectralTreeNode firstChildOfLeafWithMinNormCut = leafWithMinNormCut.FirstChild;
         SpectralTreeNode secondChildOfLeafWithMinNormCut = leafWithMinNormCut.SecondChild;
         listOfLeaves.Remove(leafWithMinNormCut);
         innerDeterminePartition(firstChildOfLeafWithMinNormCut, secondChildOfLeafWithMinNormCut);
     }
 }
Ejemplo n.º 10
0
 private void innerDetermineNormCutAndChildren(SpectralTreeNode spectralTreeRoot, Matrix<double> partOfWeightMX)
 {
     Matrix<double> randomWalkMX = randomWalkDesigner.createPageRankMX(partOfWeightMX, alpha);
     Vector<double> pi = randomWalkDesigner.createStationaryDistributionOf(randomWalkMX);
     Matrix<double> theta = thetaMatrixFormation.createThetaMX(randomWalkMX, pi);
     Vector<double> secondLargestEigVec = thetaMatrixFormation.determineSecondLargestEigVec(theta);
     List<int> firstPartIdx, secondPartIdx;
     determineBiPartitionOfGraph(secondLargestEigVec, spectralTreeRoot, out firstPartIdx, out secondPartIdx);
     double normCutValue = determineNormCut(randomWalkMX, pi, firstPartIdx, secondPartIdx);
     spectralTreeRoot.NormCutValue = normCutValue;
 }