Repository navigation
Module_Statistics_Basic
Location: Home / Statistics module / Basic statistics functions
Vorcyc.Mathematics.Statistics.Basic is a class that provides basic statistical functions, including methods for mean, median, mode, variance, standard deviation, and coefficient of variation.
All methods below are located in class: Vorcyc.Mathematics.Statistics.Basic
📒Contents
- 🔖 Sum method
- 🔖 Average method
- 🔖 Median method
- 🔖 Mode method
- 🔖 Variance method
- 🔖 StandardDeviation method
- 🔖 CoefficientOfVariation method
- 🔖 CalculateAllStatistics method
Vorcyc.Mathematics.Statistics.Basic is a class that provides basic statistical functions, including methods for mean, median, mode, variance, standard deviation, and coefficient of variation.
-
public static T Sum<T>(this Span<T> values) where T : INumber<T>- Computes the sum of elements in a set of values, optimized with SIMD.
- Parameters:
-
values: The set of values to sum.
-
- Returns: The sum of elements in the set of values.
- Exceptions:
-
ArgumentException: Thrown whenvaluesis empty.
-
-
public static T Sum<T>(this Span<T> values, Func<T, T> selector) where T : INumber<T>- Computes the sum of elements in a set of values using the specified selector function.
- Parameters:
-
values: The set of values to sum. -
selector: A function used to select values.
-
- Returns: The sum of elements in the set of values.
- Exceptions:
-
ArgumentException: Thrown whenvaluesis empty.
-
-
public static T Average<T>(this Span<T> values) where T : INumber<T>- Computes the average of elements in a set of values.
- Parameters:
-
values: The set of values to average.
-
- Returns: The average of elements in the set of values.
- Exceptions:
-
ArgumentException: Thrown whenvaluesis empty.
-
-
public static T Median<T>(this Span<T> values) where T : INumber<T>- Computes the median of elements in a set of values.
- Parameters:
-
values: The set of values for which to compute the median.
-
- Returns: The median of elements in the set of values.
- Exceptions:
-
ArgumentException: Thrown whenvaluesis empty.
-
-
public static T Mode<T>(this Span<T> values) where T : INumber<T>- Computes the mode of elements in a set of values.
- Parameters:
-
values: The set of values for which to compute the mode.
-
- Returns: The element with the highest frequency in the set of values.
- Exceptions:
-
ArgumentException: Thrown whenvaluesis empty.
-
-
public static (T average, T variance) Variance<T>(this Span<T> values) where T : INumber<T>- Computes the average and variance of elements in a set of values.
- Parameters:
-
values: The set of values for which to compute average and variance.
-
- Returns: A tuple containing the average and variance of elements in the set of values.
- Exceptions:
-
ArgumentException: Thrown whenvaluesis empty.
-
-
public static T StandardDeviation<T>(this Span<T> values) where T : IFloatingPointIeee754<T>- Computes the standard deviation of elements in a set of values.
- Parameters:
-
values: The set of values for which to compute standard deviation.
-
- Returns: The standard deviation of elements in the set of values.
- Exceptions:
-
ArgumentException: Thrown whenvaluesis empty.
-
-
public static T CoefficientOfVariation<T>(this Span<T> values) where T : IFloatingPointIeee754<T>- Computes the coefficient of variation of elements in a set of values.
- Parameters:
-
values: The set of values for which to compute the coefficient of variation.
-
- Returns: The coefficient of variation of elements in the set of values.
- Exceptions:
-
ArgumentException: Thrown whenvaluesis empty.
-
-
public static (T Mean, T Median, T Mode, T Variance, T StandardDeviation, T CoefficientOfVariation) CalculateAllStatistics<T>(this Span<T> values) where T : IFloatingPointIeee754<T>- Computes all statistics for a set of values, including mean, median, mode, variance, standard deviation, and coefficient of variation.
- Parameters:
-
values: The set of values for which to compute statistics.
-
- Returns: A tuple containing mean, median, mode, variance, standard deviation, and coefficient of variation.
- Exceptions:
-
ArgumentException: Thrown whenvaluesis empty.
-
The following example uses several methods from the Basic class, with comments in the sample:
using System;
using System.Collections.Generic;
using Vorcyc.Mathematics.Statistics;
using static System.Runtime.InteropServices.JavaScript.JSType;
public class BasicStatisticsExample
{
public static void Main()
{
// Define dataset
Span<double> data = new double[] { 1.0, 2.0, 2.0, 3.0, 4.0, 5.0 };
// Compute sum
double sum = data.Sum();
Console.WriteLine("Sum: " + sum);
// Compute average
double average = data.Average();
Console.WriteLine("Average: " + average);
// Compute median
double median = data.Median();
Console.WriteLine("Median: " + median);
// Compute mode
double mode = data.Mode();
Console.WriteLine("Mode: " + mode);
// Compute variance
var (mean, variance) = data.Variance();
Console.WriteLine("Variance: " + variance);
// Compute standard deviation
double standardDeviation = data.StandardDeviation();
Console.WriteLine("Standard Deviation: " + standardDeviation);
// Compute coefficient of variation
double coefficientOfVariation = data.CoefficientOfVariation();
Console.WriteLine("Coefficient of Variation: " + coefficientOfVariation);
// Compute all statistics
var (meanAll, medianAll, modeAll, varianceAll, standardDeviationAll, coefficientOfVariationAll) = data.CalculateAllStatistics();
Console.WriteLine($"Mean: {meanAll}, Median: {medianAll}, Mode: {modeAll}, Variance: {varianceAll}, Standard Deviation: {standardDeviationAll}, Coefficient of Variation: {coefficientOfVariationAll}");
}
}-
- 🔖 ArrayExtension class
- 🔖 BaseConverter class
- 🔖 BitMathExtension class
- 🔖 Combinatorics class
- 🔖 ConstantsFp32 class
- 🔖 NumberMapper class
- 🔖 PinnableArray<T> class
- 🔖 SimpleRNG_Fp32 and SimpleRNG_Fp64 classes
- 🔖 TrigonometryHelper class
- 🔖 VMath class
- 🔖 Pinned buffers (Buffers)
- 🔖 IPinnedBuffer<T> interface
- 🔖 POHBuffer<T> class
- 🔖 NativeBuffer<T> class
-
- 🔖 0.9 classifier walkthrough
- 🔖 KNN<T> class
- 🔖 MultipleLinearRegression<T> class
- 🔖 SimpleLinearRegression<T> class
- 🔖 SupportVectorMachine<TSelf> class
- 🔖 DBSCAN<T> class
- 🔖 ExpectationMaximization<T> class
- 🔖 GMM<T> class
- 🔖 HierarchicalClustering<T> class
- 🔖 KMeansClusterer<T> class
- 🔖 VectorQuantization<T> class
- 🔖 FactorAnalysis<T> class
- 🔖 PCA<TSelf> class
- 🔖 TSNE<T> class
- 🔖 Distance metric classes
-
📒 Examples
-
📒 GPU 策略说明
- 🔖 为何放弃主包 GPU
- 🔖 当前性能路径
- 🔖 若仍需要更强算力
-
📒 计算上下文模块
-
📒 核心模块
-
📒 深度学习模块
-
📒 线性代数模块
-
📒 机器学习模块
- 🔖 0.9 分类器完整示例
- 🔖 KNN<T> 类
- 🔖 MultipleLinearRegression<T> 类
- 🔖 SimpleLinearRegression<T> 类
- 🔖 SupportVectorMachine<TSelf> 类
- 🔖 DBSCAN<T> 类
- 🔖 ExpectationMaximization<T> 类
- 🔖 GMM<T> 类
- 🔖 HierarchicalClustering<T> 类
- 🔖 KMeansClusterer<T> 类
- 🔖 VectorQuantization<T> 类
- 🔖 FactorAnalysis<T> 类
- 🔖 PCA<TSelf> 类
- 🔖 TSNE<T> 类
- 🔖 距离度量类
-
📒 信号处理模块
-
📒 数值模块
-
📒 统计模块
- 🔖 基础统计函数
- 🔖 高级统计函数
- 🔖 稳健统计 / RunningMoments
- 🔖 其它统计函数
- 🔖 分布相关函数
- 🔖 时间序列分析
- 🔖 IComparable 扩展
- 🔖 ExtremeValueFinder
- 🔖 INumber 扩展
-
📒 FFTW 扩展
-
📒 示例