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; }
public double computeMeasure(SpectralTreeNode[] spectralTreeLeaves) { double measure = 0.0; foreach (var spectralTreeLeaf in spectralTreeLeaves) { measure += computeMeasureForRegion(spectralTreeLeaf); } measure = measure / (double)serverNO; return measure; }
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(); }
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; }
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; }
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; }
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; } } }
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; } } } }
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); } }
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; }