/// <summary> /// Initializes a new instance of the <see cref="FitLine"/> class. /// </summary> /// <param name="fitPoints"> /// The points to calculate the fit FitLine from /// </param> /// <param name="outlierThreshold"> /// The cook's distance threshold for a point to be identified as outliers. /// </param> public FitLine() { this.Mse = 0; this.RSquared = 0; this.Slope = 0; this.Intercept = 0; this.outlierCollection = new HashSet<FitlinePoint>(); this.fitPointCollection = new List<FitlinePoint>(); this.state = FitlineState.Observing; }
public void RemovePoint(ContinuousXYPoint point) { this.fitPointCollection.Remove(new FitlinePoint(point)); this.state = FitlineState.Observing; }
/// <summary> /// Refit a group of points to the fit line. /// </summary> /// <param name="xyPoints"> /// The xy points. /// </param> public virtual void PerformRegression(IEnumerable<FitlinePoint> xyPoints) { IList<FitlinePoint> fitlinePoints = xyPoints as IList<FitlinePoint> ?? xyPoints.ToList(); this.LeastSquaresFitdLinear(fitlinePoints); this.fitPointCollection.Clear(); this.fitPointCollection.AddRange(fitlinePoints); this.outlierCollection.Clear(); this.state = FitlineState.ModelComplete; }
/// <summary> /// Using current fits points stored in the fitline to initiate regression /// </summary> /// <param name="xyPoints"> /// The xy points. /// </param> public virtual void PerformRegression() { this.LeastSquaresFitdLinear(this.FitPointCollection); this.state = FitlineState.ModelComplete; }
/// <exception cref="Exception">A delegate callback throws an exception.</exception> public void DiagnoseRegression(Func<FitlinePoint, double> weightFunc = null) { // Calculate diagnostic information if (this.state >= FitlineState.ModelComplete) { double mse = this.CalculateMSE(); double r2 = weightFunc == null? this.CalculatedRSquaredVanilla() : this.CalculateRSquared(); this.Mse = mse; this.RSquared = r2; if (weightFunc != null) { this.DiagnosePoints(weightFunc); } else { this.DiagnosePoints(x => 1); } this.state = FitlineState.DiagnosticsComplete; } else { throw new Exception("Has to complete model first, cannot diagnose regression"); } }