private KnnMultiDimensional(INeighbour[] population, int dimensions) : base(population) { _vectorDimensions = population[0].KnnVectors[0].Length; _vectorMins = new double?[_vectorDimensions]; _vectorMaxs = new double?[_vectorDimensions]; }
public static KnnMultiDimensional Create(INeighbour[] population, int dimensions) { if (population == null || population.Length == 0) throw new ArgumentException("Population was null or empty"); if (population[0].KnnVectors == null || population[0].KnnVectors.Length == 0) throw new ArgumentException("Knn vectors not instantiated"); if (population[0].KnnVectors[0] == null || population[0].KnnVectors[0].Length == 0) throw new ArgumentException("Zero dimensionality knn vector"); KnnMultiDimensional knn = new KnnMultiDimensional(population, dimensions); return knn; }
public double AverageDistToKnn(INeighbour neighbour, int k) { double[] neighbourhood = _neighbourhoods[neighbour]; if (k > neighbourhood.Length) { _log.Warn($"K was larger than neighbourhood size for KNN (K = {k}, size = {neighbourhood.Length}"); k = neighbourhood.Length; } double total = 0; for (int i = 0; i < k; i++) { total += neighbourhood[i]; } return total / k; }
protected double[] GetNeighbourhood(INeighbour neighbour, int count) { double[] neighbourhood; if (!_neighbourhoods.TryGetValue(neighbour, out neighbourhood)) { _neighbourhoods.Add(neighbour, neighbourhood = new double[count - 1]); } return neighbourhood; }
protected Knn(INeighbour[] population) { _population = population; _count = _population.Length; _neighbourhoods = new Dictionary<INeighbour, double[]>(_count); }
public KnnSingleDimension(INeighbour[] population) : base(population) { }