public void Interpolate() { var regressorFactory = new LinearRegressorFactory(); foreach (var key in Keys) { var readings = this[key]; var regressorPair = regressorFactory.GetAutoCalibrated(key); if (regressorPair == null) { continue; } Action <PanTiltAxis> interpolateAxis = (axis) => { var calibrationReadings = readings[axis]; var pixelDeviations = calibrationReadings.Keys.ToList(); pixelDeviations.Sort(); var minimumDeviation = pixelDeviations[0]; var maximumDeviation = pixelDeviations[pixelDeviations.Count - 1]; for (int i = minimumDeviation; i < maximumDeviation; i++) { if (!calibrationReadings.ContainsKey(i)) { var readingSet = new ReadingSet(); readingSet.Accepted = regressorPair[axis].Calculate(i); readingSet.IsInterpolated = true; calibrationReadings.Add(i, readingSet); } } }; interpolateAxis(PanTiltAxis.Horizontal); interpolateAxis(PanTiltAxis.Vertical); } }
/// <summary> /// Perform target alignment /// </summary> /// <param name="evidences">Evidences to align</param> /// <param name="baseline">Baseline evidences</param> /// <returns></returns> public LinearRegressionResult AlignTargets(List <Evidence> evidences, List <Evidence> baseline) { var observed = new List <double>(); var predicted = new List <double>(); foreach (var evidence in baseline) { Predictor = RetentionTimePredictorFactory.CreatePredictor(Options.PredictorType); evidence.PredictedNet = Predictor.GetElutionTime(Evidence.CleanSequence(evidence.Sequence)); observed.Add(evidence.ObservedNet); predicted.Add(evidence.PredictedNet); } Regressor = LinearRegressorFactory.Create(Options.RegressionType); var result = Regressor.CalculateRegression(observed, predicted); foreach (var evidence in evidences) { evidence.ObservedNet = Regressor.Transform(result, evidence.ObservedNet); } return(result); }