public KNNMeasure(IndexTransformator transformator, Array histogram, Shell[] shells, int spaceDimension, int histogramResolution, int serverNO, int pointNO, int kNN) { this.transformator = transformator; this.histogram = histogram; this.shells = shells; this.spaceDimension = spaceDimension; this.histogramResolution = histogramResolution; this.serverNO = serverNO; this.pointNO = pointNO; this.kNN = kNN; }
public Shell[] createShells(int shellNO, int spaceDimension) { List<Shell> shells = new List<Shell>(); // The shellIdx is only a candidate shell index based on Fermat's theorem on sum of two squares // and Legendre's three-square theorem int shellIdx = 1; while (shells.Count < shellNO) { Shell currentShell = new Shell(); IntTuple[] currentIntTuples = backtrackingMethod.decomposeByBacktracking(shellIdx, spaceDimension); if (currentIntTuples.Length != 0) { currentShell.setIntTuplesWithSwapsAndSignChange(currentIntTuples, backtrackingMethod.getComparer()); shells.Add(currentShell); } shellIdx++; } return shells.ToArray(); }
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; }
public Dictionary<int, List<int[]>> convertIntPairsOfShellsToListOfIdxArrays(int histogramResolution, int[] inputIndicesArray, Shell[] shells) { Dictionary<int, List<int[]>> result = new Dictionary<int, List<int[]>>(); int shellIdx = 0; foreach (var shell in shells) { List<int[]> indicesArraysInCurrentShell = new List<int[]>(); IntTuple[] intTuples = shell.getIntTuples(); foreach (var intTuple in intTuples) { int[] currentIndicesArray; if (intTuple.determineIdxArrayRelativeTo(histogramResolution, inputIndicesArray, out currentIndicesArray)) { indicesArraysInCurrentShell.Add(currentIndicesArray); } } result.Add(shellIdx, indicesArraysInCurrentShell); shellIdx++; } return result; }