Skip to content

Commit

Permalink
Added XML documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
lpeyr committed Jan 7, 2023
1 parent edc11c3 commit 4a36876
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions PeyrSharp.Core/Maths/Stats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ namespace PeyrSharp.Core.Maths
/// </summary>
public static class Stats
{
/// <summary>
/// Calculates the mean (average) of a dataset.
/// </summary>
/// <param name="values">The dataset to calculate the mean of.</param>
/// <returns>The mean of the dataset.</returns>
/// <exception cref="ArgumentException">Thrown if the dataset is empty.</exception>
public static double Mean(List<double> values)
{
// Check for empty input
Expand All @@ -52,6 +58,12 @@ public static double Mean(List<double> values)
return mean;
}

/// <summary>
/// Calculates the median of a dataset.
/// </summary>
/// <param name="values">The dataset to calculate the median of.</param>
/// <returns>The median of the dataset.</returns>
/// <exception cref="ArgumentException">Thrown if the dataset is empty.</exception>
public static double Median(List<double> values)
{
// Check for empty input
Expand Down Expand Up @@ -80,5 +92,26 @@ public static double Median(List<double> values)
return median;
}

/// <summary>
/// Calculates the mode of a dataset.
/// </summary>
/// <param name="values">The dataset to calculate the mode of.</param>
/// <returns>The mode of the dataset.</returns>
/// <exception cref="ArgumentException">Thrown if the dataset is empty.</exception>
public static double Mode(List<double> values)
{
// Check for empty input
if (values.Count == 0)
{
throw new ArgumentException("Cannot calculate mode of empty dataset", "values");
}

// Group values by frequency
var frequencyGroups = values.GroupBy(x => x).OrderByDescending(g => g.Count());

// Return most common value (if more than one, return first)
return frequencyGroups.First().Key;
}

}
}

0 comments on commit 4a36876

Please sign in to comment.