internal Prediction(DiscreteChoiceModel model, bool newRun, string name, Area predictionArea, int predictionPointSpacing, DateTime predictionStartTime, DateTime predictionEndTime, bool vacuum) { _model = model; _runId = MaxRunId + (newRun ? 1 : 0); _name = name; _predictionArea = predictionArea; _predictionPointSpacing = predictionPointSpacing; _predictionStartTime = predictionStartTime; _predictionEndTime = predictionEndTime; _assessmentPlots = new List <Plot>(); _sliceCrimeThreatCorrelation = new Dictionary <long, float>(); _overallCrimeThreatCorrelation = float.NaN; _done = false; _mostRecentlyEvaluatedIncidentTime = DateTime.MinValue; _modelDetails = _smoothingDetails = null; BinaryFormatter bf = new BinaryFormatter(); MemoryStream ms = new MemoryStream(); bf.Serialize(ms, this); _id = Convert.ToInt32(DB.Connection.ExecuteScalar("INSERT INTO " + Table + " (" + Columns.Insert + ") VALUES (" + _model.Id + ",@bytes," + _predictionArea.Id + ") RETURNING " + Columns.Id, new Parameter("bytes", NpgsqlDbType.Bytea, ms.ToArray()))); if (vacuum) { VacuumTable(); } }
public static Dictionary <long, Dictionary <string, int> > GetSliceLocationTrueCount(IEnumerable <Incident> incidents, Prediction prediction) { Dictionary <long, Dictionary <string, int> > sliceLocationTrueCount = new Dictionary <long, Dictionary <string, int> >(); DiscreteChoiceModel model = prediction.Model; long sliceTicks = -1; if (model is TimeSliceDCM) { sliceTicks = (model as TimeSliceDCM).TimeSliceTicks; } foreach (Incident incident in incidents) { long slice = 1; if (sliceTicks > 0) { slice = incident.Time.Ticks / sliceTicks; } int row = (int)((incident.Location.Y - prediction.PredictionArea.BoundingBox.MinY) / prediction.PredictionPointSpacing); int col = (int)((incident.Location.X - prediction.PredictionArea.BoundingBox.MinX) / prediction.PredictionPointSpacing); string location = row + "-" + col; sliceLocationTrueCount.EnsureContainsKey(slice, typeof(Dictionary <string, int>)); sliceLocationTrueCount[slice].EnsureContainsKey(location, typeof(int)); sliceLocationTrueCount[slice][location]++; } return(sliceLocationTrueCount); }
internal void CommitValues(DiscreteChoiceModel model) { model.Name = ModelName; model.TrainingArea = TrainingArea; model.TrainingStart = TrainingStart; model.TrainingEnd = TrainingEnd; model.IncidentTypes = IncidentTypes; model.Smoothers = Smoothers; }
public void Populate(DiscreteChoiceModel m) { Items.Clear(); if (m != null) { foreach (Smoother s in m.Smoothers) { Items.Add(s); SetSelected(Items.IndexOf(s), true); } } foreach (Smoother available in Smoother.Available) { if (Items.Cast <Smoother>().Count(present => present.GetType().Equals(available.GetType())) == 0) { Items.Add(available); } } }
public static Dictionary <long, Dictionary <string, List <double> > > GetSliceLocationThreats(Prediction prediction) { Dictionary <long, Dictionary <string, List <double> > > sliceLocationThreats = new Dictionary <long, Dictionary <string, List <double> > >(); DiscreteChoiceModel model = prediction.Model; long sliceTicks = -1; if (model is TimeSliceDCM) { sliceTicks = (model as TimeSliceDCM).TimeSliceTicks; } Dictionary <int, Point> idPoint = new Dictionary <int, Point>(); foreach (Point point in prediction.Points) { idPoint.Add(point.Id, point); } foreach (PointPrediction pointPrediction in prediction.PointPredictions) { long slice = 1; if (sliceTicks > 0) { slice = pointPrediction.Time.Ticks / sliceTicks; } PostGIS.Point point = idPoint[pointPrediction.PointId].Location; int row = (int)((point.Y - prediction.PredictionArea.BoundingBox.MinY) / prediction.PredictionPointSpacing); int col = (int)((point.X - prediction.PredictionArea.BoundingBox.MinX) / prediction.PredictionPointSpacing); string location = row + "-" + col; sliceLocationThreats.EnsureContainsKey(slice, typeof(Dictionary <string, List <double> >)); sliceLocationThreats[slice].EnsureContainsKey(location, typeof(List <double>)); sliceLocationThreats[slice][location].Add(pointPrediction.TotalThreat); } return(sliceLocationThreats); }
public static List <Prediction> GetForModel(DiscreteChoiceModel model, bool onlyFinishedPredictions) { return(GetAll(onlyFinishedPredictions).Where(p => p.Model.Id == model.Id).ToList()); }