Skip to content

Commit

Permalink
Adding couple of methods. To enable an increment of a histogram by th…
Browse files Browse the repository at this point in the history
…e specified amount. (#54)
  • Loading branch information
IlshatGaripov authored Aug 3, 2020
1 parent e95ad39 commit b512950
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion Numerics/Statistics/Histogram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public Interval GetBorders (int index) {
return (Interval.FromEndpoints(borders[borders.Length - 1], Double.PositiveInfinity));
}
}

public Interval Range {
get {
return (Interval.FromEndpoints(borders[0], borders[borders.Length - 1]));
Expand All @@ -70,6 +70,16 @@ public void Increment (int index) {
total++;
}

/// <summary>
/// Increments a bin of a histogram by the specified amount.
/// </summary>
/// <param name="index">The index of a bin.</param>
/// <param name="weight">Amount to increase a bin to.</param>
public void Increment(int index, int weight) {
counts[index] += weight;
total += weight;
}

public void Decriment (int index) {
if (counts[index] > 0) {
counts[index]--;
Expand Down Expand Up @@ -174,6 +184,15 @@ public void Add (double value) {
storage.Increment(storage.FindIndex(value));
}

/// <summary>
/// Increments a histogram bin corredponding to value by the specified amount.
/// </summary>
/// <param name="value">Value to determine a bin to increment</param>
/// <param name="weight">Amount to increase a bin to.</param>
public void Add(double value, int weight) {
storage.Increment(storage.FindIndex(value), weight);
}

/// <summary>
/// Sets all bin counts to zero.
/// </summary>
Expand Down

0 comments on commit b512950

Please sign in to comment.