Example #1
0
        // <inheritdoc>
        public double Evaluate(DateTime testStart, DateTime testEnd, double Radius)
        {
            this.logger.info("Evaluating the Model.");

            IList <Incident> testSet = this.incidentService.getForDateRange(testStart, testEnd).OrderBy(x => x.DateCreated).ToList();
            IKdTreeWrapper <double, string> kdTree = this.generateKdTree(testSet);

            double correct = 0;
            double error   = 0;

            double countDone = 0;
            double countToDo = testSet.Count;

            foreach (var currentIncident in testSet)
            {
                CrimeType currentType = default(CrimeType);
                if (!Enum.TryParse(currentIncident.CrimeType, out currentType))
                {
                    this.logger.debug($"Could not parse crime type {currentIncident.CrimeType}");
                    continue;
                }

                if (!this.mixedMarkovModel.IsGenerated(currentType))
                {
                    this.logger.debug($"model was not generated for {currentType}");
                    continue;
                }

                var predictedPoint = this.mixedMarkovModel.Predict(currentType);
                if (predictedPoint == null)
                {
                    this.logger.debug($"predicted point was null for {currentIncident.ID}");
                    continue;
                }

                var nearest = kdTree.GetNearestNeighbours(predictedPoint);

                if (this.distanceMeasure.measure(nearest, predictedPoint) <= Radius)
                {
                    this.logger.debug($"Match found between predicted { predictedPoint[0] } , { predictedPoint[1] } and Incident { nearest }");
                    correct++;
                }
                else
                {
                    error++;
                }

                this.mixedMarkovModel.AddIncident(currentIncident);
                this.progressCheck(++countDone, countToDo);
            }

            return(correct / (correct + error));
        }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:com.kiranpatel.crimecluster.framework.Cluster"/> class.
        /// </summary>
        /// <param name="label">Label.</param>
        /// <param name="cluster">Cluster.</param>
        public Cluster(int label, HashSet <double[]> cluster)
        {
            this.Label  = label;
            this.Points = new KdTreeWrapper <double, string>(new DoubleMath());

            foreach (var currentPoint in cluster)
            {
                this.Points.Add(currentPoint, label.ToString());
            }

            this.Points.Balance();
        }
Example #3
0
        /// <summary>
        /// Computes the average latitude and longitude for a given kd-tree.
        /// </summary>
        /// <param name="value">Value.</param>
        public static double[] Average(this IKdTreeWrapper <double, string> value)
        {
            var    enumerator = value.GetEnumerator();
            double latitude   = 0;
            double longitude  = 0;

            while (enumerator.MoveNext())
            {
                double[] current = enumerator.Current.Point;
                latitude  += current[0];
                longitude += current[1];
            }

            latitude  /= value.Count();
            longitude /= value.Count();

            return(new double[] { latitude *2, longitude *2 });
        }