Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Numerics/Data/Interpolation/Bilinear.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/


using Numerics.Distributions;
using System;
using System.Linq;
Expand Down Expand Up @@ -56,6 +57,7 @@ namespace Numerics.Data
/// <see href="https://en.wikipedia.org/wiki/Bilinear_interpolation"/>
/// </para>
/// </remarks>

[Serializable]
public class Bilinear
{
Expand Down
2 changes: 1 addition & 1 deletion Numerics/Data/Paired Data/ProbabilityOrdinate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public class ProbabilityOrdinates : List<double>, INotifyCollectionChanged, INot
public event NotifyCollectionChangedEventHandler CollectionChanged;

/// <summary>
/// Occurs when a property value changes, such as <see cref="Count"/>
/// Occurs when a property value changes/>
/// or the indexer <c>Item[]</c>.
/// </summary>
public event PropertyChangedEventHandler PropertyChanged;
Expand Down
8 changes: 6 additions & 2 deletions Numerics/Numerics.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@
<AssemblyVersion>2.0.0.0</AssemblyVersion>
</PropertyGroup>


<ItemGroup>
<PropertyGroup>
<Nullable>enable</Nullable>
</PropertyGroup>


<ItemGroup>
<!--https://github.com/dotnet/reproducible-builds-->
<PackageReference Include="DotNet.ReproducibleBuilds" Version="1.2.25">
<PrivateAssets>all</PrivateAssets>
Expand Down
10 changes: 5 additions & 5 deletions Test_Numerics/Data/Paired Data/Test_PairedData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ public Test_PairedData()
double[] xVals = new double[] { 230408, 288010, 345611, 403213, 460815, 518417, 576019, 633612, 691223, 748825, 806427, 864029, 921631, 1036834, 1152038 };
double[] yVals = new double[] { 1519.7, 1520.5, 1520.9, 1521.7, 1523.5, 1525.9, 1528.4, 1530.9, 1533.2, 1534.7, 1535.9, 1538, 1541.3, 1547.7, 1552.7 };
_dataset1 = new OrderedPairedData(xVals, yVals, true, SortOrder.Ascending, true, SortOrder.Ascending);
_dataset2 = new OrderedPairedData(xVals.Reverse().ToArray(), yVals, true, SortOrder.Descending, true, SortOrder.Ascending);
_dataset3 = new OrderedPairedData(xVals, yVals.Reverse().ToArray(), true, SortOrder.Ascending, true, SortOrder.Descending);
_dataset4 = new OrderedPairedData(xVals.Reverse().ToArray(), yVals.Reverse().ToArray(), true, SortOrder.Descending, true, SortOrder.Descending);
_dataset2 = new OrderedPairedData(Enumerable.Reverse(xVals).ToArray(), yVals, true, SortOrder.Descending, true, SortOrder.Ascending);
_dataset3 = new OrderedPairedData(xVals, Enumerable.Reverse(yVals).ToArray(), true, SortOrder.Ascending, true, SortOrder.Descending);
_dataset4 = new OrderedPairedData(Enumerable.Reverse(xVals).ToArray(), Enumerable.Reverse(yVals).ToArray(), true, SortOrder.Descending, true, SortOrder.Descending);
}

/// <summary>
Expand Down Expand Up @@ -184,12 +184,12 @@ public void Test_Indexing()

dataset11.Remove(ordinate);
bool test4 = dataset11.Contains(ordinate);
Assert.AreEqual(false, test4);
Assert.IsFalse(test4);

Ordinate newOrdinate = dataset11[4];
dataset11.RemoveAt(4);
bool test5 = dataset11.Contains(newOrdinate);
Assert.AreEqual(false, test5);
Assert.IsFalse(test5);

Ordinate newOrdinate2 = new Ordinate(1243177, 1563.8);
dataset11.Add(newOrdinate2);
Expand Down
12 changes: 6 additions & 6 deletions Test_Numerics/Data/Paired Data/Test_UncertainOrdinate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@ public void Test_Construction()
// Also testing overloaded equality operators
Assert.IsTrue(unordinate1 == unordinate3);
Assert.IsTrue(unordinate1 == unordinate2);
Assert.AreEqual(unordinate1.X, 2);
Assert.AreEqual(unordinate1.Y, distribution);
Assert.AreEqual(unordinate3.X, 2);
Assert.AreEqual(2,unordinate1.X);
Assert.AreEqual(distribution, unordinate1.Y);
Assert.AreEqual(2,unordinate3.X );
Assert.IsTrue(unordinate3.Y == distribution);

Assert.AreEqual(unordinate1.IsValid, true);
Assert.AreEqual(unordinate4.IsValid, false);
Assert.AreEqual(unordinate5.IsValid, false);
Assert.IsTrue(unordinate1.IsValid );
Assert.IsFalse(unordinate4.IsValid);
Assert.IsFalse(unordinate5.IsValid);

Assert.IsTrue(unordinate1 != unordinate4);
Assert.IsTrue(unordinate1 != unordinate5);
Expand Down
22 changes: 11 additions & 11 deletions Test_Numerics/Data/Paired Data/Test_UncertainPairedData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ public Test_UncertainPairedData()
UnivariateDistributionBase[] yVals = new UnivariateDistributionBase[] { new Triangular(1, 2, 3), new Triangular(2, 4, 5), new Triangular(6, 8, 12), new Triangular(13, 19, 20) };

_dataset1 = new UncertainOrderedPairedData(xVals, yVals, true, SortOrder.Ascending, true, SortOrder.Ascending, UnivariateDistributionType.Triangular);
_dataset2 = new UncertainOrderedPairedData(xVals.Reverse().ToArray(), yVals, true, SortOrder.Descending, true, SortOrder.Ascending, UnivariateDistributionType.Triangular);
_dataset3 = new UncertainOrderedPairedData(xVals, yVals.Reverse().ToArray(), true, SortOrder.Ascending, true, SortOrder.Descending, UnivariateDistributionType.Triangular);
_dataset4 = new UncertainOrderedPairedData(xVals.Reverse().ToArray(), yVals.Reverse().ToArray(), true, SortOrder.Descending, true, SortOrder.Descending, UnivariateDistributionType.Triangular);
_dataset2 = new UncertainOrderedPairedData(Enumerable.Reverse(xVals).ToArray(), yVals, true, SortOrder.Descending, true, SortOrder.Ascending, UnivariateDistributionType.Triangular);
_dataset3 = new UncertainOrderedPairedData(xVals, Enumerable.Reverse(yVals).ToArray(), true, SortOrder.Ascending, true, SortOrder.Descending, UnivariateDistributionType.Triangular);
_dataset4 = new UncertainOrderedPairedData(Enumerable.Reverse(xVals).ToArray(), Enumerable.Reverse(yVals).ToArray(), true, SortOrder.Descending, true, SortOrder.Descending, UnivariateDistributionType.Triangular);
}

/// <summary>
Expand Down Expand Up @@ -112,9 +112,9 @@ public void Test_CurveSample()
double[] yMeanVals = new double[] { 2, 3.66667, 8.66667, 17.33333 };

var data1Expected = new OrderedPairedData(xVals, yMeanVals, true, SortOrder.Ascending, true, SortOrder.Ascending);
var data2Expected = new OrderedPairedData(xVals.Reverse().ToArray(), yMeanVals, true, SortOrder.Descending, true, SortOrder.Ascending);
var data3Expected = new OrderedPairedData(xVals, yMeanVals.Reverse().ToArray(), true, SortOrder.Ascending, true, SortOrder.Descending);
var data4Expected = new OrderedPairedData(xVals.Reverse().ToArray(), yMeanVals.Reverse().ToArray(), true, SortOrder.Descending, true, SortOrder.Descending);
var data2Expected = new OrderedPairedData(Enumerable.Reverse(xVals).ToArray(), yMeanVals, true, SortOrder.Descending, true, SortOrder.Ascending);
var data3Expected = new OrderedPairedData(xVals, Enumerable.Reverse(yMeanVals).ToArray(), true, SortOrder.Ascending, true, SortOrder.Descending);
var data4Expected = new OrderedPairedData(Enumerable.Reverse(xVals).ToArray(), Enumerable.Reverse(yMeanVals).ToArray(), true, SortOrder.Descending, true, SortOrder.Descending);

for (int i = 0; i < data1.Count; i++)
{
Expand Down Expand Up @@ -153,9 +153,9 @@ public void Test_Curve_Sample_Probability()
double[] yInverseVals = new double[] { 2, 3.732051, 8.535898, 17.58258 };

var data1Expected = new OrderedPairedData(xVals, yInverseVals, true, SortOrder.Ascending, true, SortOrder.Ascending);
var data2Expected = new OrderedPairedData(xVals.Reverse().ToArray(), yInverseVals, true, SortOrder.Descending, true, SortOrder.Ascending);
var data3Expected = new OrderedPairedData(xVals, yInverseVals.Reverse().ToArray(), true, SortOrder.Ascending, true, SortOrder.Descending);
var data4Expected = new OrderedPairedData(xVals.Reverse().ToArray(), yInverseVals.Reverse().ToArray(), true, SortOrder.Descending, true, SortOrder.Descending);
var data2Expected = new OrderedPairedData(Enumerable.Reverse(xVals).ToArray(), yInverseVals, true, SortOrder.Descending, true, SortOrder.Ascending);
var data3Expected = new OrderedPairedData(xVals, Enumerable.Reverse(yInverseVals).ToArray(), true, SortOrder.Ascending, true, SortOrder.Descending);
var data4Expected = new OrderedPairedData(Enumerable.Reverse(xVals).ToArray(), Enumerable.Reverse(yInverseVals).ToArray(), true, SortOrder.Descending, true, SortOrder.Descending);

for (int i = 0; i < data1.Count; i++)
{
Expand Down Expand Up @@ -189,12 +189,12 @@ public void Test_IList()
// Test Remove and Contains
pairedData.Remove(ordinate);
bool test2 = pairedData.Contains(ordinate);
Assert.AreEqual(false, test2);
Assert.IsFalse(test2);

// Test RemoveAt and Contains
pairedData.RemoveAt(2);
bool test3 = pairedData.Contains(ordinate);
Assert.AreEqual(false, test3);
Assert.IsFalse(test3);

// Test Insert and IndexOf
pairedData.Insert(2, ordinate);
Expand Down
16 changes: 8 additions & 8 deletions Test_Numerics/Data/Statistics/Test_GoodnessOfFit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -826,11 +826,11 @@ public void Test_MetricsConsistency_GoodModel()
double RSR = GoodnessOfFit.RSR(observed, modeled);

// Good model expectations
Assert.IsTrue(NSE > 0.9, "NSE should be > 0.9 for a good model");
Assert.IsTrue(KGE > 0.9, "KGE should be > 0.9 for a good model");
Assert.IsTrue(RMSE < 5.0, "RMSE should be low for a good model");
Assert.IsTrue(Math.Abs(PBIAS) < 5.0, "PBIAS should be low for a good model");
Assert.IsTrue(RSR < 0.5, "RSR should be < 0.5 for a good model");
Assert.IsGreaterThan(0.9, NSE);
Assert.IsGreaterThan(0.9, KGE);
Assert.IsLessThan(5.0, RMSE);
Assert.IsLessThan(5.0, Math.Abs(PBIAS));
Assert.IsLessThan(0.5, RSR);
}

/// <summary>
Expand All @@ -854,12 +854,12 @@ public void Test_MetricsConsistency_PoorModel()
// - RMSE equals the standard deviation of observations
// - RSR should be exactly 1.0 (RMSE / StdDev)

Assert.IsTrue(NSE <= 0.05, $"NSE should be near 0 for constant-at-mean prediction, got {NSE}");
Assert.IsLessThanOrEqualTo(0.05, NSE);

// KGE returns -10.0 for zero-variance predictions (degenerate case)
Assert.IsTrue(KGE < -5.0, $"KGE should be very poor for constant predictions (zero variance), got {KGE}");
Assert.IsLessThan(-5.0, KGE);

Assert.IsTrue(RMSE > 15.0, "RMSE should be high for a poor model");
Assert.IsGreaterThan(15.0, RMSE);
Assert.IsTrue(RSR >= 0.95 && RSR <= 1.05, $"RSR should be approximately 1.0 for constant-at-mean prediction, got {RSR}");
}

Expand Down
8 changes: 4 additions & 4 deletions Test_Numerics/Data/Time Series/Test_TimeSeriesDownload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public class Test_TimeSeriesDownload
private static void AssertDailySeriesMonotonic(TimeSeries ts)
{
Assert.IsNotNull(ts, "Time series is null.");
Assert.IsTrue(ts.Count > 0, "Time series is empty.");
Assert.IsGreaterThan( 0, ts.Count);

DateTime? prev = null;
foreach (var pt in ts)
Expand Down Expand Up @@ -175,9 +175,9 @@ private static void AssertRoughlyEqual(double a, double b, double relTol = 1e-6,

double denom = Math.Max(Math.Abs(a), Math.Abs(b));
if (denom == 0)
Assert.IsTrue(diff <= absTol);
Assert.IsLessThanOrEqualTo(absTol,diff);
else
Assert.IsTrue(diff / denom <= relTol, $"Values differ: {a} vs {b}");
Assert.IsLessThanOrEqualTo(relTol, diff / denom);
}

#endregion
Expand Down Expand Up @@ -572,7 +572,7 @@ public async Task BOM_WindowedDownload_Works()
startDate: WinStart, endDate: WinEnd);

Assert.IsNotNull(ts, "Time series is null.");
Assert.IsTrue(ts.Count > 0, "Time series is empty.");
Assert.IsGreaterThan(0, ts.Count);

// Verify data is within requested window (allowing for some timezone flexibility)
var firstDate = ts.First().Index;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public void Test_ConvolveFiveDistributions()
var convolved = EmpiricalDistribution.Convolve(distributions, 1024);

// Assert number of points
Assert.AreEqual(1024, convolved.XValues.Count, "Should have exactly 1024 points");
Assert.HasCount(1024, convolved.XValues);

// Expected: Range ≈ [0, 10], Mean ≈ 5
Assert.AreEqual(0.0, convolved.Minimum, 0.2, "Minimum should be approximately 0");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public void HeapTest4()
//Compare
for (int i = 0; i < weights.Length; i++)
{
Assert.AreEqual(heap.RemoveMin().Value == weights[i], false);
Assert.AreNotEqual(heap.RemoveMin().Value , weights[i]);
}
}

Expand Down
44 changes: 22 additions & 22 deletions Test_Numerics/Mathematics/Optimization/Dynamic/DijkstraTesting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ public void SimpleEdgeGraphCost()

float[,] result = Dijkstra.Solve(edges, 3,6);

Assert.AreEqual(result[3, 2], 0f);
Assert.AreEqual(result[2, 2], 3f);
Assert.AreEqual(result[1, 2], 4f);
Assert.AreEqual(result[0, 2], 6f);
Assert.AreEqual(result[4, 2], 7f);
Assert.AreEqual(0f, result[3, 2]);
Assert.AreEqual(3f, result[2, 2]);
Assert.AreEqual(4f, result[1, 2]);
Assert.AreEqual(6f, result[0, 2]);
Assert.AreEqual(7f, result[4, 2]);
Assert.IsTrue(float.IsPositiveInfinity(result[5,2]));

}
Expand Down Expand Up @@ -117,11 +117,11 @@ public void SimpleNetworkRouting()

float[,] result = Dijkstra.Solve(edges,9);

Assert.AreEqual(result[0, 0], 5f); //Algorithm is choosing the next node that yields the shortest paths
Assert.AreEqual(result[0, 2], 8f);
Assert.AreEqual(5f, result[0, 0]); //Algorithm is choosing the next node that yields the shortest paths
Assert.AreEqual(8f, result[0, 2]);

Assert.AreEqual(result[1, 0], 7);
Assert.AreEqual(result[1, 2], 5);
Assert.AreEqual(7, result[1, 0]);
Assert.AreEqual(5, result[1, 2]);

Assert.AreEqual(1, result[2, 0]);
Assert.AreEqual(6, result[2, 2]);
Expand Down Expand Up @@ -241,10 +241,10 @@ public void MultipleDestSharedPath()

var result = Dijkstra.Solve(edges, [0,3],4);

Assert.AreEqual(result[1, 0], 0);
Assert.AreEqual(result[1, 2], 3);
Assert.AreEqual(result[2, 0], 1);
Assert.AreEqual(result[2, 2], 5);
Assert.AreEqual(0, result[1, 0]);
Assert.AreEqual(3, result[1, 2]);
Assert.AreEqual(1, result[2, 0]);
Assert.AreEqual(5, result[2, 2]);
}

/// <summary>
Expand All @@ -262,10 +262,10 @@ public void DisconnectedComponent()
new Edge(2,3,1,2)
};
var result = Dijkstra.Solve(edges, [0, 3], 4);
Assert.AreEqual(result[1,0],0);
Assert.AreEqual(result[1, 2], 3);
Assert.AreEqual(result[2, 0], 3);
Assert.AreEqual(result[2, 2], 1);
Assert.AreEqual(0, result[1, 0]);
Assert.AreEqual(3, result[1, 2]);
Assert.AreEqual(3, result[2, 0]);
Assert.AreEqual(1, result[2, 2]);
}

/// <summary>
Expand Down Expand Up @@ -304,11 +304,11 @@ public void TrianglePath()
};

var result = Dijkstra.Solve(edges, [0, 2], 3);
Assert.AreEqual(result[0, 0], 0);
Assert.AreEqual(result[0, 2], 0);
Assert.AreEqual(result[1, 0], 2);
Assert.AreEqual(result[1, 2], 1);
Assert.AreEqual(result[2, 0], 2);
Assert.AreEqual(0, result[0, 0]);
Assert.AreEqual(0, result[0, 2]);
Assert.AreEqual(2, result[1, 0]);
Assert.AreEqual(1, result[1, 2]);
Assert.AreEqual(2, result[2, 0]);
}
}
}
2 changes: 2 additions & 0 deletions Test_Numerics/Test_Numerics.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
<PackageReference Include="MSTest.TestAdapter" Version="4.0.2" />
<PackageReference Include="MSTest.TestFramework" Version="4.0.2" />
<PackageReference Include="NUnit" Version="4.4.0" />
<PackageReference Include="NUnit3TestAdapter" Version="6.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading