/// <summary> /// Run example /// </summary> public void Run() { // 1. Get 11 samples of f(x) = (x * x) / 2 equidistant within interval [-5, 5] var result = SignalGenerator.EquidistantInterval(Function, -5, 5, 11); Console.WriteLine(@"1. Get 11 samples of f(x) = (x * x) / 2 equidistant within interval [-5, 5]"); for (var i = 0; i < result.Length; i++) { Console.Write(result[i].ToString("N") + @" "); } Console.WriteLine(); Console.WriteLine(); // 2. Get 10 samples of f(x) = (x * x) / 2 equidistant starting at x=1 with step = 0.5 and retrieve sample points double[] samplePoints; result = SignalGenerator.EquidistantStartingAt(Function, 1, 0.5, 10, out samplePoints); Console.WriteLine(@"2. Get 10 samples of f(x) = (x * x) / 2 equidistant starting at x=1 with step = 0.5 and retrieve sample points"); Console.Write(@"Points: "); for (var i = 0; i < samplePoints.Length; i++) { Console.Write(samplePoints[i].ToString("N") + @" "); } Console.WriteLine(); Console.Write(@"Values: "); for (var i = 0; i < result.Length; i++) { Console.Write(result[i].ToString("N") + @" "); } Console.WriteLine(); Console.WriteLine(); // 3. Get 10 samples of f(x) = (x * x) / 2 equidistant within period = 10 and period offset = 5 result = SignalGenerator.EquidistantPeriodic(Function, 10, 5, 10); Console.WriteLine(@"3. Get 10 samples of f(x) = (x * x) / 2 equidistant within period = 10 and period offset = 5"); for (var i = 0; i < result.Length; i++) { Console.Write(result[i].ToString("N") + @" "); } Console.WriteLine(); Console.WriteLine(); // 4. Sample f(x) = (x * x) / 2 equidistant to an integer-domain function starting at x = 0 and step = 2 var equidistant = SignalGenerator.EquidistantToFunction(Function, 0, 2); Console.WriteLine(@" 4. Sample f(x) = (x * x) / 2 equidistant to an integer-domain function starting at x = 0 and step = 2"); for (var i = 0; i < 10; i++) { Console.Write(equidistant(i).ToString("N") + @" "); } Console.WriteLine(); }
/// <summary> /// Run example /// </summary> /// <seealso cref="http://en.wikipedia.org/wiki/Spline_interpolation">Spline interpolation</seealso> public void Run() { // 1. Generate 10 samples of the function x*x-2*x on interval [0, 10] Console.WriteLine(@"1. Generate 10 samples of the function x*x-2*x on interval [0, 10]"); double[] points; var values = SignalGenerator.EquidistantInterval(TargetFunction, 0, 10, 10, out points); Console.WriteLine(); // 2. Create akima spline interpolation var method = new AkimaSplineInterpolation(points, values); Console.WriteLine(@"2. Create akima spline interpolation based on arbitrary points"); Console.WriteLine(); // 3. Check if interpolation support integration Console.WriteLine(@"3. Support integration = {0}", ((IInterpolation)method).SupportsIntegration); Console.WriteLine(); // 4. Check if interpolation support differentiation Console.WriteLine(@"4. Support differentiation = {0}", ((IInterpolation)method).SupportsDifferentiation); Console.WriteLine(); // 5. Differentiate at point 5.2 Console.WriteLine(@"5. Differentiate at point 5.2 = {0}", method.Differentiate(5.2)); Console.WriteLine(); // 6. Integrate at point 5.2 Console.WriteLine(@"6. Integrate at point 5.2 = {0}", method.Integrate(5.2)); Console.WriteLine(); // 7. Interpolate ten random points and compare to function results Console.WriteLine(@"7. Interpolate ten random points and compare to function results"); var rng = new MersenneTwister(1); for (var i = 0; i < 10; i++) { // Generate random value from [0, 10] var point = rng.NextDouble() * 10; Console.WriteLine(@"Interpolate at {0} = {1}. Function({0}) = {2}", point.ToString("N05"), method.Interpolate(point).ToString("N05"), TargetFunction(point).ToString("N05")); } Console.WriteLine(); }
/// <summary> /// Run example /// </summary> /// <seealso cref="http://en.wikipedia.org/wiki/Interpolation">Interpolation</seealso> public void Run() { // 1. Generate 10 samples of the function 1/(1+x*x) on interval [-5, 5] Console.WriteLine(@"1. Generate 10 samples of the function 1/(1+x*x) on interval [-5, 5]"); double[] points; var values = SignalGenerator.EquidistantInterval(TargetFunction, -5, 5, 10, out points); Console.WriteLine(); // 2. Create a floater hormann rational pole-free interpolation based on arbitrary points // This method is used by default when create an interpolation using Interpolate.Common method var method = Interpolate.RationalWithoutPoles(points, values); Console.WriteLine(@"2. Create a floater hormann rational pole-free interpolation based on arbitrary points"); Console.WriteLine(); // 3. Check if interpolation support integration Console.WriteLine(@"3. Support integration = {0}", method.SupportsIntegration); Console.WriteLine(); // 4. Check if interpolation support differentiation Console.WriteLine(@"4. Support differentiation = {0}", method.SupportsDifferentiation); Console.WriteLine(); // 5. Interpolate ten random points and compare to function results Console.WriteLine(@"5. Interpolate ten random points and compare to function results"); var rng = new MersenneTwister(1); for (var i = 0; i < 10; i++) { // Generate random value from [0, 5] var point = rng.NextDouble() * 5; Console.WriteLine(@"Interpolate at {0} = {1}. Function({0}) = {2}", point.ToString("N05"), method.Interpolate(point).ToString("N05"), TargetFunction(point).ToString("N05")); } Console.WriteLine(); }
/// <summary> /// Run example /// </summary> public void Run() { // 1. Generate 20 samples of the function f(x) = x on interval [-5, 5] Console.WriteLine(@"1. Generate 20 samples of the function f(x) = x on interval [-5, 5]"); double[] points; var values = SignalGenerator.EquidistantInterval(TargetFunction, -5, 5, 20, out points); Console.WriteLine(); // 2. Create a burlish stoer rational interpolation based on arbitrary points var method = Interpolate.RationalWithPoles(points, values); Console.WriteLine(@"2. Create a burlish stoer rational interpolation based on arbitrary points"); Console.WriteLine(); // 3. Check if interpolation support integration Console.WriteLine(@"3. Support integration = {0}", method.SupportsIntegration); Console.WriteLine(); // 4. Check if interpolation support differentiation Console.WriteLine(@"4. Support differentiation = {0}", method.SupportsDifferentiation); Console.WriteLine(); // 5. Interpolate ten random points and compare to function results Console.WriteLine(@"5. Interpolate ten random points and compare to function results"); var rng = new MersenneTwister(1); for (var i = 0; i < 10; i++) { // Generate random value from [0, 5] var point = rng.Next(0, 5); Console.WriteLine(@"Interpolate at {0} = {1}. Function({0}) = {2}", point.ToString("N05"), method.Interpolate(point).ToString("N05"), TargetFunction(point).ToString("N05")); } Console.WriteLine(); }
/// <summary> /// Run example /// </summary> /// <seealso cref="http://en.wikipedia.org/wiki/Pearson_product-moment_correlation_coefficient">Pearson product-moment correlation coefficient</seealso> public void Run() { // 1. Initialize the new instance of the ChiSquare distribution class with parameter dof = 5. var chiSquare = new ChiSquared(5); Console.WriteLine(@"1. Initialize the new instance of the ChiSquare distribution class with parameter DegreesOfFreedom = {0}", chiSquare.DegreesOfFreedom); Console.WriteLine(@"{0} distributuion properties:", chiSquare); Console.WriteLine(@"{0} - Largest element", chiSquare.Maximum.ToString(" #0.00000;-#0.00000")); Console.WriteLine(@"{0} - Smallest element", chiSquare.Minimum.ToString(" #0.00000;-#0.00000")); Console.WriteLine(@"{0} - Mean", chiSquare.Mean.ToString(" #0.00000;-#0.00000")); Console.WriteLine(@"{0} - Median", chiSquare.Median.ToString(" #0.00000;-#0.00000")); Console.WriteLine(@"{0} - Mode", chiSquare.Mode.ToString(" #0.00000;-#0.00000")); Console.WriteLine(@"{0} - Variance", chiSquare.Variance.ToString(" #0.00000;-#0.00000")); Console.WriteLine(@"{0} - Standard deviation", chiSquare.StdDev.ToString(" #0.00000;-#0.00000")); Console.WriteLine(@"{0} - Skewness", chiSquare.Skewness.ToString(" #0.00000;-#0.00000")); Console.WriteLine(); // 2. Generate 1000 samples of the ChiSquare(5) distribution Console.WriteLine(@"2. Generate 1000 samples of the ChiSquare(5) distribution"); var data = new double[1000]; for (var i = 0; i < data.Length; i++) { data[i] = chiSquare.Sample(); } // 3. Get basic statistics on set of generated data using extention methods Console.WriteLine(@"3. Get basic statistics on set of generated data using extention methods"); Console.WriteLine(@"{0} - Largest element", data.Maximum().ToString(" #0.00000;-#0.00000")); Console.WriteLine(@"{0} - Smallest element", data.Minimum().ToString(" #0.00000;-#0.00000")); Console.WriteLine(@"{0} - Mean", data.Mean().ToString(" #0.00000;-#0.00000")); Console.WriteLine(@"{0} - Median", data.Median().ToString(" #0.00000;-#0.00000")); Console.WriteLine(@"{0} - Biased population variance", data.PopulationVariance().ToString(" #0.00000;-#0.00000")); Console.WriteLine(@"{0} - Variance", data.Variance().ToString(" #0.00000;-#0.00000")); Console.WriteLine(@"{0} - Standard deviation", data.StandardDeviation().ToString(" #0.00000;-#0.00000")); Console.WriteLine(@"{0} - Biased sample standard deviation", data.PopulationStandardDeviation().ToString(" #0.00000;-#0.00000")); Console.WriteLine(); // 4. Compute the basic statistics of data set using DescriptiveStatistics class Console.WriteLine(@"4. Compute the basic statistics of data set using DescriptiveStatistics class"); var descriptiveStatistics = new DescriptiveStatistics(data); Console.WriteLine(@"{0} - Kurtosis", descriptiveStatistics.Kurtosis.ToString(" #0.00000;-#0.00000")); Console.WriteLine(@"{0} - Largest element", descriptiveStatistics.Maximum.ToString(" #0.00000;-#0.00000")); Console.WriteLine(@"{0} - Smallest element", descriptiveStatistics.Minimum.ToString(" #0.00000;-#0.00000")); Console.WriteLine(@"{0} - Mean", descriptiveStatistics.Mean.ToString(" #0.00000;-#0.00000")); Console.WriteLine(@"{0} - Variance", descriptiveStatistics.Variance.ToString(" #0.00000;-#0.00000")); Console.WriteLine(@"{0} - Standard deviation", descriptiveStatistics.StandardDeviation.ToString(" #0.00000;-#0.00000")); Console.WriteLine(@"{0} - Skewness", descriptiveStatistics.Skewness.ToString(" #0.00000;-#0.00000")); Console.WriteLine(); // Generate 1000 samples of the ChiSquare(2.5) distribution var chiSquareB = new ChiSquared(2); var dataB = new double[1000]; for (var i = 0; i < data.Length; i++) { dataB[i] = chiSquareB.Sample(); } // 5. Correlation coefficient between 1000 samples of ChiSquare(5) and ChiSquare(2.5) Console.WriteLine(@"5. Correlation coefficient between 1000 samples of ChiSquare(5) and ChiSquare(2.5) is {0}", Correlation.Pearson(data, dataB).ToString("N04")); Console.WriteLine(@"6. Ranked correlation coefficient between 1000 samples of ChiSquare(5) and ChiSquare(2.5) is {0}", Correlation.Spearman(data, dataB).ToString("N04")); Console.WriteLine(); // 6. Correlation coefficient between 1000 samples of f(x) = x * 2 and f(x) = x * x data = SignalGenerator.EquidistantInterval(x => x * 2, 0, 100, 1000); dataB = SignalGenerator.EquidistantInterval(x => x * x, 0, 100, 1000); Console.WriteLine(@"7. Correlation coefficient between 1000 samples of f(x) = x * 2 and f(x) = x * x is {0}", Correlation.Pearson(data, dataB).ToString("N04")); Console.WriteLine(@"8. Ranked correlation coefficient between 1000 samples of f(x) = x * 2 and f(x) = x * x is {0}", Correlation.Spearman(data, dataB).ToString("N04")); Console.WriteLine(); }
/// <summary> /// Run example /// </summary> /// <seealso cref="http://en.wikipedia.org/wiki/Error_function">Error function</seealso> public void Run() { // 1. Calculate the error function at point 2 Console.WriteLine(@"1. Calculate the error function at point 2"); Console.WriteLine(SpecialFunctions.Erf(2)); Console.WriteLine(); // 2. Sample 10 values of the error function in [-1.0; 1.0] Console.WriteLine(@"2. Sample 10 values of the error function in [-1.0; 1.0]"); var data = SignalGenerator.EquidistantInterval(SpecialFunctions.Erf, -1.0, 1.0, 10); for (var i = 0; i < data.Length; i++) { Console.Write(data[i].ToString("N") + @" "); } Console.WriteLine(); Console.WriteLine(); // 3. Calculate the complementary error function at point 2 Console.WriteLine(@"3. Calculate the complementary error function at point 2"); Console.WriteLine(SpecialFunctions.Erfc(2)); Console.WriteLine(); // 4. Sample 10 values of the complementary error function in [-1.0; 1.0] Console.WriteLine(@"4. Sample 10 values of the complementary error function in [-1.0; 1.0]"); data = SignalGenerator.EquidistantInterval(SpecialFunctions.Erfc, -1.0, 1.0, 10); for (var i = 0; i < data.Length; i++) { Console.Write(data[i].ToString("N") + @" "); } Console.WriteLine(); Console.WriteLine(); // 5. Calculate the inverse error function at point z=0.5 Console.WriteLine(@"5. Calculate the inverse error function at point z=0.5"); Console.WriteLine(SpecialFunctions.ErfInv(0.5)); Console.WriteLine(); // 6. Sample 10 values of the inverse error function in [-1.0; 1.0] Console.WriteLine(@"6. Sample 10 values of the inverse error function in [-1.0; 1.0]"); data = SignalGenerator.EquidistantInterval(SpecialFunctions.ErfInv, -1.0, 1.0, 10); for (var i = 0; i < data.Length; i++) { Console.Write(data[i].ToString("N") + @" "); } Console.WriteLine(); Console.WriteLine(); // 7. Calculate the complementary inverse error function at point z=0.5 Console.WriteLine(@"7. Calculate the complementary inverse error function at point z=0.5"); Console.WriteLine(SpecialFunctions.ErfcInv(0.5)); Console.WriteLine(); // 8. Sample 10 values of the complementary inverse error function in [-1.0; 1.0] Console.WriteLine(@"8. Sample 10 values of the complementary inverse error function in [-1.0; 1.0]"); data = SignalGenerator.EquidistantInterval(SpecialFunctions.ErfcInv, -1.0, 1.0, 10); for (var i = 0; i < data.Length; i++) { Console.Write(data[i].ToString("N") + @" "); } Console.WriteLine(); }