public static IInterpolation GetLinearInterpolationMethod(Peak peak) { var xValues = new List <double>(); var yValues = new List <double>(); peak.GetXAndYValuesAsLists(out xValues, out yValues); IInterpolation interpolation = LinearSpline.Interpolate(xValues, yValues); return(interpolation); }
/* * public static List<int> DetectGaussianPeaks(List<double> peak) * { * int peakWindow = 5; * int halfWindow = (int)Math.Floor(peakWindow / 2.0); * * List<double> gaussianPeak = CreateTheoreticalGaussianPeak(peakWindow / 2.0, peakWindow, peakWindow); * * Dictionary<int, double> peakIndexToScoreMap = new Dictionary<int, double>(); * * for (int i = peakWindow - halfWindow - 1; i + peakWindow < peak.Count; i++) * { * List<double> currentPeakPoints = peak.GetRange(i, peakWindow); * * //double maximumValue = double.NaN; * //FindPositionOfMaximum(currentPeakPoints, out maximumValue); * * double fitScore = CalculatePeakFit(currentPeakPoints, gaussianPeak, 0.05); * peakIndexToScoreMap.Add(i, fitScore); * } * * // TODO: Use the scores to find peaks?? * int referenceIndex = -99; * double referenceScore = -99; * bool movingUp = false; * List<int> peakIndices = new List<int>(); * * foreach (KeyValuePair<int, double> kvp in peakIndexToScoreMap) * { * Console.WriteLine(kvp.Key + ": " + kvp.Value); * * int index = kvp.Key; * double score = kvp.Value; * * if (score > referenceScore) * { * movingUp = true; * } * else * { * if (movingUp) * { * peakIndices.Add(referenceIndex); * } * * movingUp = false; * } * * referenceScore = score; * referenceIndex = index; * } * * Console.WriteLine("*******************************************************************"); * * Console.Write("Peaks found at: "); * foreach (int index in peakIndices) * { * Console.Write(index + "\t"); * } * Console.Write("\n"); * * Console.WriteLine("==================================================================="); * * return null; * } */ // TODO: Verify this actually works --- Da's code, slightly modified by me public static Peak KDESmooth(Peak peak, double bandwidth) { var xValueList = new List <double>(); var yValueList = new List <double>(); peak.GetXAndYValuesAsLists(out xValueList, out yValueList); var numPoints = xValueList.Count; var numBins = numPoints; var newYValueList = new List <double>(); foreach (var point in xValueList) { double sumWInv = 0; double sumXoW = 0; double sumX2oW = 0; double sumYoW = 0; double sumXYoW = 0; for (var j = 0; j < numPoints; j++) { var x = xValueList[j]; var y = yValueList[j]; var standardized = Math.Abs(x - point) / bandwidth; double w = 0; if (standardized < 6) { w = 2 * Math.Sqrt(2 * Math.PI) * Math.Exp(-2 * standardized * standardized); sumWInv += 1 / w; } sumXoW += x * w; sumX2oW += x * x * w; sumYoW += y * w; sumXYoW += x * y * w; } var intercept = 1 / (sumWInv * sumX2oW - sumXoW * sumXoW) * (sumX2oW * sumYoW - sumXoW * sumXYoW); var slope = 1 / (sumWInv * sumX2oW - sumXoW * sumXoW) * (sumWInv * sumXYoW - sumXoW * sumYoW); newYValueList.Add(intercept + slope * point); } var newPeak = new Peak(xValueList, newYValueList); return(newPeak); }