Beispiel #1
0
            public override double DoubleVal(int doc)
            {
                var vals = cache.GetShapes(doc);

                if (vals != null)
                {
                    double v = calculator.Distance(from, vals[0]);
                    for (int i = 1; i < vals.Count; i++)
                    {
                        v = Math.Min(v, calculator.Distance(from, vals[i]));
                    }
                    // Solr's 'recip' function where v = distance and v > 0.
                    return(v > 0 ? 1000 / (1 * v + 1000) : 0);
                }
                return(Double.NaN);
            }
Beispiel #2
0
    static void Main()
    {
        Point3D first  = new Point3D(-4, -1, -3);
        Point3D second = new Point3D(1, 2, 3);

        Console.WriteLine(DistanceCalculator.Distance(first, second));
    }
 private static void PaintKernel(
     Index i,
     Template template,
     ArrayView <float> series,
     ArrayView2D <float> clusters,
     ArrayView <int> outPutHeatMap,
     float error)
 {
     //TODO: refactor this peace of vector creation
     for (int i5 = template.Distance1 + template.Distance2 + template.Distance3 + template.Distance4,
          i4 = i5 - template.Distance4,
          i3 = i5 - template.Distance4 - template.Distance3,
          i2 = i5 - template.Distance4 - template.Distance3 - template.Distance2,
          i1 = i5 - template.Distance4 - template.Distance3 - template.Distance2 - template.Distance1;
          i5 < series.Length - 1; i5++, i4++, i3++, i2++, i1++)
     {
         if (Math.Abs(series[i5] - clusters[i, 4]) < 0.1)
         {
             var    vector   = new float[] { series[i1], series[i2], series[i3], series[i4], series[i5] };
             var    cluster  = new float[] { clusters[i, 0], clusters[i, 1], clusters[i, 2], clusters[i, 3], clusters[i, 4] };
             double distance = DistanceCalculator.Distance(vector, cluster);
             if (distance <= error)
             {
                 outPutHeatMap[i1]++;
                 outPutHeatMap[i2]++;
                 outPutHeatMap[i3]++;
                 outPutHeatMap[i4]++;
             }
         }
     }
 }
Beispiel #4
0
    static void Main()
    {
        Point point  = new Point(5, 10, 15);
        Point point2 = new Point(10, 15, 20);

        double distance = DistanceCalculator.Distance(point, point2);

        Console.WriteLine(distance);
    }
Beispiel #5
0
        // Forecast one point further
        private static float ForecastNext(
            IList <Template> templates,
            IList <float[][]> clusters,
            ReadOnlySpan <float> tmp,
            float error)
        {
            float forecastedPoint     = float.NaN;
            float forecastintDistance = float.MaxValue;
            int   clustersCount       = 0;

            var cnt            = tmp.Length;
            var realVectorData = new float[4];

            foreach (var template in templates)
            {
                int idx4      = cnt - template.Distance4,
                         idx3 = idx4 - template.Distance3,
                         idx2 = idx3 - template.Distance2,
                         idx1 = idx2 - template.Distance1;

                realVectorData[0] = tmp[idx1];
                realVectorData[1] = tmp[idx2];
                realVectorData[2] = tmp[idx3];
                realVectorData[3] = tmp[idx4];

                var clustersOfTemplate = clusters[templateToIndex(template)];

                foreach (var cluster in clustersOfTemplate)
                {
                    if (DistanceCalculator.Distance(realVectorData, cluster) < error)
                    {
                        clustersCount++;

                        if (DistanceCalculator.Distance(realVectorData, cluster) < forecastintDistance)
                        {
                            forecastintDistance = DistanceCalculator.Distance(realVectorData, cluster);
                            forecastedPoint     = cluster[4];
                        }
                    }
                }
            }

            return(forecastedPoint);

            //return (currResult, clustersCount);

            // additional local functions
            int templateToIndex(Template tpl)
            {
                // TODO: replace -1 with the lowest template distance-values
                return((tpl.Distance1 - 1) * 1000 +
                       (tpl.Distance2 - 1) * 100 +
                       (tpl.Distance3 - 1) * 10 +
                       (tpl.Distance4 - 1));
            }
        }
Beispiel #6
0
 public override double DoubleVal(int doc)
 {
     // make sure it has minX and area
     if (validX.Get(doc))
     {
         Debug.Assert(validY.Get(doc));
         return(calculator.Distance(from, ptX[doc], ptY[doc]));
     }
     return(nullValue);
 }
Beispiel #7
0
        /// <summary>
        /// Returns the normalized direction of 2 vectors
        /// </summary>
        /// <param name="origin"></param>
        /// <param name="destination"></param>
        /// <returns></returns>
        public Vector3d GetDirectional(Vector3d origin, Vector3d destination)
        {
            var distance = _distanceCalculator.Distance(origin, destination);

            return(new Vector3d
            {
                X = distance == 0 ? 0 : destination.X / distance,
                Y = distance == 0 ? 0 : destination.Y / distance,
                Z = distance == 0 ? 0 : destination.Z / distance
            });
        }
        private static void PaintKernel2d(
            Index2 i,
            ArrayView <Template> templates,
            ArrayView <float> series,
            ArrayView3D <float> clusters,
            ArrayView <int> outPutHeatMap,
            float error)
        {
            var template = templates[i.X];
            var cluster  = new float[] { clusters[i.X, i.Y, 0], clusters[i.X, i.Y, 1], clusters[i.X, i.Y, 2], clusters[i.X, i.Y, 3], clusters[i.X, i.Y, 4] };

            bool isExtra = true;

            for (int j = 0; j < cluster.Length; j++)
            {
                if (cluster[j] != 0f)
                {
                    isExtra = false;
                }
            }

            if (!isExtra)
            {
                for (int i5 = template.Distance1 + template.Distance2 + template.Distance3 + template.Distance4,
                     i4 = i5 - template.Distance4,
                     i3 = i5 - template.Distance4 - template.Distance3,
                     i2 = i5 - template.Distance4 - template.Distance3 - template.Distance2,
                     i1 = i5 - template.Distance4 - template.Distance3 - template.Distance2 - template.Distance1;
                     i5 < series.Length - 1; i5++, i4++, i3++, i2++, i1++)
                {
                    if (Math.Abs(series[i5] - clusters[i.X, i.Y, 4]) < 0.1)
                    {
                        var    vector   = new float[] { series[i1], series[i2], series[i3], series[i4], series[i5] };
                        double distance = DistanceCalculator.Distance(vector, cluster);
                        if (distance <= error)
                        {
                            outPutHeatMap[i1]++;
                            outPutHeatMap[i2]++;
                            outPutHeatMap[i3]++;
                            outPutHeatMap[i4]++;
                        }
                    }
                }
            }
        }
Beispiel #9
0
        public async Task <List <Event> > FindByCoordinates(double latitude, double longitude, double distance)
        {
            // Unfortunately DbGeography is not implemented in EF7 - will have to fetch all locations with coordinates and then manually calculate distance
            var locations = await _eventLocationRepository.FindAll(el => el.Latitude.HasValue && el.Longitude.HasValue)
                            .Select(el => new { el.Id, Latitude = el.Latitude.Value, Longitude = el.Longitude.Value })
                            .ToListAsync();

            var locationIds = locations.Where(l => DistanceCalculator.Distance(l.Latitude, l.Longitude, latitude, longitude) <= distance)
                              .Select(l => l.Id)
                              .ToList();

            return(await _eventRepository.FindAll(e => locationIds.Contains(e.StartEventLocationId))
                   .Where(e => !e.IsDeleted.HasValue || e.IsDeleted.Value == false)
                   .Include(e => e.OwnerUser)
                   .Include(e => e.EventType)
                   .Include(e => e.StartLocation)
                   .Include(e => e.EndLocation)
                   .ToListAsync());
        }
Beispiel #10
0
        public double Score(Rectangle indexRect, Explanation exp)
        {
            double score;

            if (indexRect == null)
            {
                score = nullValue;
            }
            else
            {
                score = distCalc.Distance(queryPoint, indexRect.GetCenter());
            }
            if (exp != null)
            {
                exp.SetValue((float)score);
                exp.SetDescription(GetType().Name);
                exp.AddDetail(new Explanation(-1f, "" + queryPoint));
                exp.AddDetail(new Explanation(-1f, "" + indexRect));
            }
            return(score);
        }
Beispiel #11
0
        public static ReadOnlySpan <int> Paint(IList <Template> templates,
                                               IList <float[][]> clusters,
                                               float[] series,
                                               float error)
        {
            Span <int> seriesHeatMap = new int[series.Length];

            for (int i = 0; i < templates.Count; i++)
            {
                var template = templates[i];
                foreach (var cluster in clusters[i])
                {
                    //TODO: refactor this peace of vector creation
                    for (int i5 = template.Distance1 + template.Distance2 + template.Distance3 + template.Distance4,
                         i4 = i5 - template.Distance4,
                         i3 = i5 - template.Distance4 - template.Distance3,
                         i2 = i5 - template.Distance4 - template.Distance3 - template.Distance2,
                         i1 = i5 - template.Distance4 - template.Distance3 - template.Distance2 - template.Distance1;
                         i5 < series.Length - 1; i5++, i4++, i3++, i2++, i1++)
                    {
                        if (Math.Abs(series[i5] - cluster[4]) < 0.1)
                        {
                            var    vector   = new float[] { series[i1], series[i2], series[i3], series[i4], series[i5] };
                            double distance = DistanceCalculator.Distance(vector, cluster);
                            if (distance <= error)
                            {
                                seriesHeatMap[i1]++;
                                seriesHeatMap[i2]++;
                                seriesHeatMap[i3]++;
                                seriesHeatMap[i4]++;
                            }
                        }
                    }
                }
            }
            return(seriesHeatMap);
        }
        public async Task <List <Event> > DownloadEvents(DateTime startDate, DateTime endDate, GeoPoint usersLocation = null)
        {
            var baseUrl = "https://developer.microsoft.com/en-us/reactor/api/sp/events";

            var start = startDate.ToString("s");
            var end   = endDate.ToString("s");

            var webClient = new WebClient();
            var json      = await webClient.DownloadStringTaskAsync($"{baseUrl}?from={start}.111Z&to={end}.111Z");

            var eventsResponse = Response.FromJson(json);

            foreach (var e in eventsResponse.Events)
            {
                GeoPoint geoPoint = null;

                switch (e.City)
                {
                case Models.Enums.City.London:
                    geoPoint   = new GeoPoint(51.521661, -0.084660);
                    e.Location = new Location()
                    {
                        Name = "London", GeoPoint = geoPoint
                    };
                    break;

                case Models.Enums.City.NewYork:
                    geoPoint   = new GeoPoint(40.756989, -73.989708);
                    e.Location = new Location()
                    {
                        Name = "New York", GeoPoint = geoPoint
                    };
                    break;

                case Models.Enums.City.RedmondB20:
                    geoPoint   = new GeoPoint(47.643826, -122.130709);
                    e.Location = new Location()
                    {
                        Name = "Redmond Building 20", GeoPoint = geoPoint
                    };
                    break;

                case Models.Enums.City.RedmondB25:
                    geoPoint   = new GeoPoint(47.644840, -122.130031);
                    e.Location = new Location()
                    {
                        Name = "Redmond Building 25", GeoPoint = geoPoint
                    };
                    break;

                case Models.Enums.City.Seattle:
                    geoPoint   = new GeoPoint(47.621460, -122.338058);
                    e.Location = new Location()
                    {
                        Name = "Seattle", GeoPoint = geoPoint
                    };
                    break;

                case Models.Enums.City.SanFrancisco:
                    geoPoint   = new GeoPoint(37.784599, -122.398529);
                    e.Location = new Location()
                    {
                        Name = "San Francisco", GeoPoint = geoPoint
                    };
                    break;

                case Models.Enums.City.Sydney:
                    geoPoint   = new GeoPoint(-33.767048, 151.090646);
                    e.Location = new Location()
                    {
                        Name = "Sydney", GeoPoint = geoPoint
                    };
                    break;
                }

                if (usersLocation != null)
                {
                    e.Location.DistanceFromUser = DistanceCalculator.Distance(geoPoint, usersLocation);
                }
            }

            var results = eventsResponse.Events.ToList();

            //Lets order by closest Reactor space.
            if (usersLocation != null)
            {
                results = results.OrderBy(x => x.Location.DistanceFromUser).ToList();
            }

            return(results);
        }
Beispiel #13
0
 public override double Distance(Point @from, double toX, double toY)
 {
     return(Round(_delegate.Distance(from, toX, toY)));
 }