public void MultipleTests_Examples() { // Let's say we would like to compute the definite // integral of the function f(x) = cos(x) from -1 to 1 Func <double, double> f = (x) => Math.Cos(x); double a = -1; double b = +1; double trapez = TrapezoidalRule.Integrate(f, a, b, steps: 1000); // 1.6829414 double romberg = RombergMethod.Integrate(f, a, b); // 1.6829419 double nagk = NonAdaptiveGaussKronrod.Integrate(f, a, b); // 1.6829419 // Now let's say we would like to compute an improper integral // from -infinite to +infinite, such as the integral of a Gaussian // PDF (which should evaluate to 1): Func <double, double> g = (x) => (1 / Math.Sqrt(2 * Math.PI)) * Math.Exp(-(x * x) / 2); double iagk = InfiniteAdaptiveGaussKronrod.Integrate(g, Double.NegativeInfinity, Double.PositiveInfinity); // Output should be 0.99999... Assert.AreEqual(1.6829414086350976, trapez); // 1.6829414086350976 Assert.AreEqual(1.682941969615797, romberg); // 1.682941969615797 Assert.AreEqual(1.6829419595739716, nagk); // 1.6829419595739716 Assert.AreEqual(0.99999999999999978, iagk); // 0.99999999999999978 }
public void test2() { string path = @"C:\Users\Rui Zhang\Downloads\Serum_1_C18_03292019_Ali.raw"; ISpectrumReader reader = new ThermoRawSpectrumReader(); reader.Init(path); RidgeLineFinder coeffMatrix = new RidgeLineFinder(1.0, 2, 1, 2); IProcess processer = new PeakPickingCWT(coeffMatrix); //for (int i = reader.GetFirstScan(); i < reader.GetLastScan(); i++) int i = 347; { if (reader.GetMSnOrder(i) < 2) { ISpectrum spectrum = reader.GetSpectrum(i); List <IPeak> peaks = spectrum.GetPeaks(); spectrum = processer.Process(spectrum); IAreaCalculator calculator = new TrapezoidalRule(); IBounder bounder = new PerpendicularDrop(); PeakAreaCalculator areaCalculator = new PeakAreaCalculator(calculator, bounder); areaCalculator.Init(peaks); foreach (IPeak peak in spectrum.GetPeaks()) { Console.WriteLine(peak.GetMZ() + " : " + areaCalculator.Area(peak).ToString()); } } } }
private void Defuzzificate() { Func <double, double> numeratorSubFunction = (x) => x *JointFunctions.GetValue(x); Func <double, double> denumeratorSubFunction = (x) => JointFunctions.GetValue(x); double max = JointFunctions.MaxInputValue; double min = JointFunctions.MinInputValue; // Integrate! double numerator = TrapezoidalRule.Integrate(numeratorSubFunction, min, max, steps: 100); double denumerator = TrapezoidalRule.Integrate(denumeratorSubFunction, min, max, steps: 100); Output = numerator / denumerator; }
public void test1() { double[] mz = new double[] { 1, 2, 3, 4, 5 }; double[] intensity = new double[] { 1, 2, 3, 4, 1 }; List <IPeak> peaks = new List <IPeak>(); for (int i = 0; i < mz.Length; i++) { peaks.Add(new GeneralPeak(mz[i], intensity[i])); } IAreaCalculator calculator = new TrapezoidalRule(); IBounder bounder = new PerpendicularDrop(); PeakAreaCalculator areaCalculator = new PeakAreaCalculator(calculator, bounder); areaCalculator.Init(peaks); Console.WriteLine(areaCalculator.Area(new GeneralPeak(4.0, 1))); }
public void TrapezoidalTest() { double actual; actual = TrapezoidalRule.Integrate(function1, 0, 2, 1); Assert.AreEqual(4.0486368718741526, actual, 1e-15); Assert.IsFalse(Double.IsNaN(actual)); actual = TrapezoidalRule.Integrate(function1, 0, 2, 2); Assert.AreEqual(3.6081715993899337, actual, 1e-15); Assert.IsFalse(Double.IsNaN(actual)); actual = TrapezoidalRule.Integrate(function1, 0, 2, 4); Assert.AreEqual(3.4971047822027077, actual, 1e-15); Assert.IsFalse(Double.IsNaN(actual)); actual = TrapezoidalRule.Integrate(function1, 0, 2, 8); Assert.AreEqual(3.4692784302833672, actual, 1e-15); Assert.IsFalse(Double.IsNaN(actual)); actual = TrapezoidalRule.Integrate(function1, 0, 2, 16); Assert.AreEqual(3.4623181105467689, actual, 1e-15); Assert.IsFalse(Double.IsNaN(actual)); }