public List<StoragePoint> PointsNear(StoragePoint p, double distance) { if (AreaContains(p, distance) && !(this.point == null && this.smaller == null && this.greater == null)) { List<StoragePoint> list = new List<StoragePoint>(); if (this.point != null) { if (point.DistanceSquared(p) < distance*distance) list.Add(point); return list; } if (this.smaller != null) { list.AddRange(this.smaller.PointsNear(p, distance)); } if (this.greater != null) { list.AddRange(this.greater.PointsNear(p, distance)); } return list; } else { return new List<StoragePoint>(); } }
public double DistanceSquared(StoragePoint p) { double sum = 0; int min = Math.Min(coord.Length, p.coord.Length); for (int i = 0; i < min; ++i) { sum += (this.coord[i] - p.coord[i]) * (this.coord[i] - p.coord[i]); } return sum; }
public List<StoragePoint> PointsNear(StoragePoint point, double distance) { List<StoragePoint> list2 = new List<StoragePoint>(); foreach (StoragePoint sp in list) { if (sp.DistanceSquared(point) < distance * distance) { list2.Add(sp); } } return list2; }
public void AddPoint(StoragePoint point) { if (this.point == null && this.smaller == null && this.greater == null) { this.point = point; } else { if (this.point != null) { SortPoint(this.point); this.point = null; } SortPoint(point); } }
public static double InferUtility(Storage s, StoragePoint sp) { double sum = 0; double sum2 = 0; List<StoragePoint> list = s.PointsNear(sp, distance * 2); foreach (StoragePoint spp in list) { double q = spp.value; double sigma = 3 * distance; double relevance = 1; //double relevance = 1 / Math.Pow(2*Math.PI*sigma, spp.coord.Length/2) * Math.Exp(-0.5 * spp.DistanceSquared(sp) / sigma); //egyseg szorasu gauss sum += q * relevance; sum2 += relevance; } return (sum2 == 0) ? 0 : sum / sum2; }
public void AddPoint(StoragePoint point) { long hash = 0; int cc = (int)Math.Ceiling(1 / distance); for (int i = 0; i < coordHashCount; ++i) { int c = (int)Math.Floor(point.coord[i] / distance); hash += c; hash *= cc; } List<StoragePoint> list = hashmap[hash]; if (list == null) { list = new List<StoragePoint>(); hashmap[hash] = list; } list.Add(point); }
public List<StoragePoint> PointsNear(StoragePoint point, double distance) { return root.PointsNear(point, distance); }
public void AddPoint(StoragePoint point) { root.AddPoint(point); }
private void SortPoint(StoragePoint p) { if (p.coord[dimension] < limit) { if (smaller == null) { double[] amin = (double[])min.Clone(); double[] amax = (double[])max.Clone(); amax[dimension] = limit; smaller = new StorageLevel((dimension + 1) % maxdimension, maxdimension, amin, amax); } smaller.AddPoint(p); } else { if (greater == null) { double[] amin = (double[])min.Clone(); double[] amax = (double[])max.Clone(); amin[dimension] = limit; greater = new StorageLevel((dimension + 1) % maxdimension, maxdimension, amin, amax); } greater.AddPoint(p); } }
private bool AreaContains(StoragePoint p, double distance) { bool b = true; for (int i = 0; i < maxdimension; ++i) { b = b && (p.coord[i] + distance > min[i]) && (p.coord[i] - distance < max[i]); if (!b) return false; } return true; }
public void AddPoint(StoragePoint point) { list.Add(point); }