Exemple #1
0
        public override void Apply(Prediction prediction)
        {
            List <PointPrediction> pointPredictions = prediction.PointPredictions;

            if (pointPredictions.Count > 0)
            {
                Dictionary <int, Point> idPoint = new Dictionary <int, Point>();
                foreach (Point p in prediction.Points)
                {
                    idPoint.Add(p.Id, p);
                }

                IEnumerable <PostGIS.Point> kdeEvalPoints = pointPredictions.Select(p => idPoint[p.PointId].Location);

                List <PostGIS.Point> kdeInputPoints = new List <PostGIS.Point>();
                foreach (string incident in pointPredictions[0].IncidentScore.Keys.ToArray())
                {
                    if (incident != PointPrediction.NullLabel)
                    {
                        double minScore = pointPredictions.Min(p => p.IncidentScore[incident]);
                        kdeInputPoints.Clear();
                        foreach (PointPrediction pointPrediction in pointPredictions)
                        {
                            PostGIS.Point pointPredictionLocation = idPoint[pointPrediction.PointId].Location;
                            double        replicates = pointPrediction.IncidentScore[incident] / minScore;
                            for (int i = 0; i < replicates; ++i)
                            {
                                kdeInputPoints.Add(pointPredictionLocation);
                            }
                        }

                        List <float> density = KernelDensityDCM.GetDensityEstimate(kdeInputPoints, _sampleSize, false, 0, 0, kdeEvalPoints, _normalize);
                        for (int i = 0; i < density.Count; ++i)
                        {
                            pointPredictions[i].IncidentScore[incident] = density[i];
                        }
                    }
                }

                foreach (PointPrediction pointPrediction in pointPredictions)
                {
                    pointPrediction.TotalThreat = pointPrediction.IncidentScore.Keys.Sum(incident => incident == PointPrediction.NullLabel ? 0 : pointPrediction.IncidentScore[incident]);
                }

                PointPrediction.UpdateThreatScores(pointPredictions, prediction);
            }

            prediction.SmoothingDetails = GetSmoothingDetails();
        }
        private void ok_Click(object sender, EventArgs e)
        {
            string errors = discreteChoiceModelOptions.ValidateInput() + kernelDensityDcmOptions.ValidateInput();

            if (errors != "")
            {
                MessageBox.Show(errors);
                return;
            }

            _resultingModel = kernelDensityDcmOptions.KernelDensityDCM;
            if (_resultingModel == null)
            {
                _resultingModel = new KernelDensityDCM();
            }

            discreteChoiceModelOptions.CommitValues(_resultingModel);
            kernelDensityDcmOptions.CommitValues(_resultingModel);

            DialogResult = System.Windows.Forms.DialogResult.OK;
            Close();
        }
Exemple #3
0
 internal void CommitValues(KernelDensityDCM model)
 {
     model.TrainingSampleSize = TrainingSampleSize;
     model.Normalize          = Normalize;
 }
 public KernelDensityDcmForm(KernelDensityDCM current)
     : this()
 {
     discreteChoiceModelOptions.DiscreteChoiceModel = kernelDensityDcmOptions.KernelDensityDCM = current;
 }