Skip to content

Commit 355e3b1

Browse files
committed
staging merge
1 parent ea039d3 commit 355e3b1

56 files changed

Lines changed: 11517 additions & 150 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/Snapshot.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ jobs:
1010
with:
1111
dotnet-version: '9.0.x'
1212
project-names: 'Numerics'
13+
version: '1.0.0'
1314
run-tests: true
1415
nuget-source: 'https://www.hec.usace.army.mil/nexus/repository/consequences-nuget-public/'
1516
secrets:

Numerics/Mathematics/Differentiation/NumericalDerivative.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,7 +1206,7 @@ public static double CalculateStepSize(double x, int order = 1)
12061206
/// <param name="v">Vector to clamp (modified in place).</param>
12071207
/// <param name="lowerBounds">Optional lower bounds for each element.</param>
12081208
/// <param name="upperBounds">Optional upper bounds for each element.</param>
1209-
private static void ClampInPlace(double[] v, double[] lowerBounds, double[] upperBounds)
1209+
private static void ClampInPlace(double[] v, double[]? lowerBounds, double[]? upperBounds)
12101210
{
12111211
if (lowerBounds == null && upperBounds == null)
12121212
return;
@@ -1228,7 +1228,7 @@ private static void ClampInPlace(double[] v, double[] lowerBounds, double[] uppe
12281228
/// <param name="j">Index of the parameter to check.</param>
12291229
/// <param name="lowerBounds">Optional lower bounds.</param>
12301230
/// <returns>Distance to lower bound, or positive infinity if unbounded.</returns>
1231-
private static double AvailableLeft(double[] x, int j, double[] lowerBounds)
1231+
private static double AvailableLeft(double[] x, int j, double[]? lowerBounds)
12321232
{
12331233
return lowerBounds == null ? double.PositiveInfinity : x[j] - lowerBounds[j];
12341234
}
@@ -1240,7 +1240,7 @@ private static double AvailableLeft(double[] x, int j, double[] lowerBounds)
12401240
/// <param name="j">Index of the parameter to check.</param>
12411241
/// <param name="upperBounds">Optional upper bounds.</param>
12421242
/// <returns>Distance to upper bound, or positive infinity if unbounded.</returns>
1243-
private static double AvailableRight(double[] x, int j, double[] upperBounds)
1243+
private static double AvailableRight(double[] x, int j, double[]? upperBounds)
12441244
{
12451245
return upperBounds == null ? double.PositiveInfinity : upperBounds[j] - x[j];
12461246
}

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
# Numerics
22
***Numerics*** is a free and open-source library for .NET developed by the U.S. Army Corps of Engineers Risk Management Center (USACE-RMC). ***Numerics*** provides a comprehensive set of methods and algorithms for numerical computations and statistical analysis. The library includes routines for interpolation, regression, time series data, statistics, machine learning, probability distributions, bootstrap uncertainty analysis, Bayesian Markov Chain Monte Carlo, optimization, root finding, and more.
33

4+
## Documentation
5+
6+
📚 **[User Guide and API Documentation](docs/index.md)** - Comprehensive documentation with examples and mathematical explanations
7+
8+
The documentation covers:
9+
- **Distributions**: Univariate probability distributions, parameter estimation, uncertainty analysis, copulas
10+
- **Statistics**: Descriptive statistics, goodness-of-fit metrics, hypothesis tests
11+
- **Mathematics**: Numerical integration, differentiation, optimization, linear algebra, root finding
12+
- **Data**: Interpolation methods, time series analysis
13+
- **Sampling**: Random number generation, MCMC methods including RWMH, ARWMH, DE-MCz, HMC, and Gibbs sampling
14+
415
## Support
516
The RMC is committed to maintaining and supporting the software, providing regular updates, bug fixes, and enhancements on an annual basis or as needed.
617

Test_Numerics/Distributions/Univariate/Test_EmpiricalDistribution.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public void Test_ConvolveTwoUniformDistributions()
145145
var convolved = EmpiricalDistribution.Convolve(dist1, dist2, 1000);
146146

147147
// Assert number of points
148-
Assert.HasCount(1000, convolved.XValues);
148+
Assert.HasCount(1000, convolved.XValues, "Should have exactly 1000 points");
149149

150150
// Expected: Min ≈ 0, Max ≈ 2, Mean ≈ 1
151151
Assert.AreEqual(0.0, convolved.Minimum, 0.05, "Minimum should be approximately 0");
@@ -191,7 +191,7 @@ public void Test_ConvolveTwoNormalDistributions()
191191
var convolved = EmpiricalDistribution.Convolve(dist1, dist2, 2048);
192192

193193
// Assert number of points
194-
Assert.HasCount(2048, convolved.XValues);
194+
Assert.HasCount(2048, convolved.XValues, "Should have exactly 2048 points");
195195

196196
// Expected: For N(0,1) + N(0,1) = N(0, sqrt(2))
197197
// Mean ≈ 0, StdDev ≈ 1.414
@@ -227,7 +227,7 @@ public void Test_ConvolveDifferentRanges()
227227
var convolved = EmpiricalDistribution.Convolve(dist1, dist2, 500);
228228

229229
// Assert number of points
230-
Assert.HasCount(500, convolved.XValues);
230+
Assert.HasCount(500, convolved.XValues, "Should have exactly 500 points");
231231

232232
// Expected: Range ≈ [5, 25], Mean ≈ 15
233233
Assert.AreEqual(5.0, convolved.Minimum, 0.5, "Minimum should be approximately 5");

Test_Numerics/Distributions/Univariate/Test_GeneralizedExtremeValue.cs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ public void Test_GEV_MOM_Fit()
8484
double true_x = 11012d;
8585
double true_a = 6209.4d;
8686
double true_k = 0.0736d;
87-
Assert.IsLessThan(0.01d,(x - true_x) / true_x );
88-
Assert.IsLessThan(0.01d,(a - true_a) / true_a);
87+
Assert.IsLessThan(0.01d, (x - true_x) / true_x );
88+
Assert.IsLessThan(0.01d, (a - true_a) / true_a );
8989
Assert.IsLessThan(0.01d, (k - true_k) / true_k);
9090
}
9191

@@ -117,9 +117,9 @@ public void Test_GEV_LMOM_Fit()
117117
Assert.AreEqual(k, true_k, 0.001d);
118118
var lmom = GEV.LinearMomentsFromParameters(GEV.GetParameters);
119119
Assert.AreEqual(1648.806d, lmom[0], 0.001d);
120-
Assert.AreEqual(138.2366d, lmom[1], 0.001d);
121-
Assert.AreEqual(0.1030703d, lmom[2], 0.001d);
122-
Assert.AreEqual(0.1277244d, lmom[3], 0.001d);
120+
Assert.AreEqual(138.2366d, lmom[1], 0.001d);
121+
Assert.AreEqual(0.1030703d, lmom[2], 0.001d);
122+
Assert.AreEqual(0.1277244d, lmom[3], 0.001d);
123123
}
124124

125125
/// <summary>
@@ -227,7 +227,7 @@ public void Test_Construction()
227227
var GEV = new GeneralizedExtremeValue();
228228
Assert.AreEqual(100,GEV.Xi);
229229
Assert.AreEqual(10,GEV.Alpha);
230-
Assert.AreEqual(0, GEV.Kappa);
230+
Assert.AreEqual(0,GEV.Kappa);
231231

232232
var GEV2 = new GeneralizedExtremeValue(-100, 1, 1);
233233
Assert.AreEqual(-100,GEV2.Xi);
@@ -258,7 +258,7 @@ public void Test_InvalidParameters()
258258
public void Test_ParametersToString()
259259
{
260260
var GEV = new GeneralizedExtremeValue();
261-
Assert.AreEqual("Location (ξ)",GEV.ParametersToString[0, 0] );
261+
Assert.AreEqual("Location (ξ)", GEV.ParametersToString[0, 0]);
262262
Assert.AreEqual("Scale (α)", GEV.ParametersToString[1, 0]);
263263
Assert.AreEqual("Shape (κ)", GEV.ParametersToString[2, 0]);
264264
Assert.AreEqual("100", GEV.ParametersToString[0, 1]);
@@ -288,13 +288,13 @@ public void Test_Mean()
288288
{
289289
var GEV = new GeneralizedExtremeValue();
290290
var true_val = 100 + 10 * Tools.Euler;
291-
Assert.AreEqual(GEV.Mean, true_val);
291+
Assert.AreEqual(true_val, GEV.Mean);
292292

293293
var GEV2 = new GeneralizedExtremeValue(100, 10, 0.9);
294294
Assert.AreEqual(100.42482, GEV2.Mean, 1e-04);
295295

296296
var GEV3 = new GeneralizedExtremeValue(100, 10, 10);
297-
Assert.AreEqual(double.NaN,GEV3.Mean);
297+
Assert.AreEqual(double.NaN, GEV3.Mean);
298298
}
299299

300300
/// <summary>
@@ -317,10 +317,10 @@ public void Test_Median()
317317
public void Test_Mode()
318318
{
319319
var GEV = new GeneralizedExtremeValue();
320-
Assert.AreEqual(100,GEV.Mode);
320+
Assert.AreEqual(100, GEV.Mode);
321321

322322
var GEV2 = new GeneralizedExtremeValue(100, 10, 1);
323-
Assert.AreEqual(95,GEV2.Mode);
323+
Assert.AreEqual(95, GEV2.Mode);
324324
}
325325

326326
/// <summary>
@@ -336,7 +336,7 @@ public void Test_StandardDeviation()
336336
Assert.AreEqual(9.280898, GEV2.StandardDeviation, 1e-04);
337337

338338
var GEV3 = new GeneralizedExtremeValue(100, 10, 1);
339-
Assert.AreEqual(double.NaN,GEV3.StandardDeviation );
339+
Assert.AreEqual(double.NaN, GEV3.StandardDeviation);
340340
}
341341

342342
/// <summary>
@@ -362,13 +362,13 @@ public void Test_Skewness()
362362
public void Test_Kurtosis()
363363
{
364364
var GEV = new GeneralizedExtremeValue();
365-
Assert.AreEqual(3 + 12d / 5d,GEV.Kurtosis );
365+
Assert.AreEqual(3 + 12d / 5d, GEV.Kurtosis);
366366

367367
var GEV2 = new GeneralizedExtremeValue(100, 10, 0.24);
368368
Assert.AreEqual(2.7659607, GEV2.Kurtosis, 1e-04);
369369

370370
var GEV3 = new GeneralizedExtremeValue(100, 10, 1);
371-
Assert.AreEqual(double.NaN,GEV3.Kurtosis);
371+
Assert.AreEqual(double.NaN, GEV3.Kurtosis);
372372
}
373373

374374
/// <summary>
@@ -423,7 +423,7 @@ public void Test_CDF()
423423

424424
var GEV2 = new GeneralizedExtremeValue(100, 10, 1);
425425
Assert.AreEqual(0.367879, GEV2.CDF(100), 1e-05);
426-
Assert.AreEqual(1,GEV2.CDF(200));
426+
Assert.AreEqual(1, GEV2.CDF(200));
427427
}
428428

429429
/// <summary>
@@ -433,9 +433,9 @@ public void Test_CDF()
433433
public void Test_InverseCDF()
434434
{
435435
var GEV = new GeneralizedExtremeValue();
436-
Assert.AreEqual(double.NegativeInfinity,GEV.InverseCDF(0) );
436+
Assert.AreEqual(double.NegativeInfinity, GEV.InverseCDF(0));
437437
Assert.AreEqual(103.66512, GEV.InverseCDF(0.5), 1e-05);
438-
Assert.AreEqual(double.PositiveInfinity,GEV.InverseCDF(1) );
438+
Assert.AreEqual(double.PositiveInfinity,GEV.InverseCDF(1));
439439
}
440440
}
441441
}

Test_Numerics/Distributions/Univariate/Test_GeneralizedLogistic.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ public void Test_GLO_MOM_Fit()
8484
double true_x = 31892d;
8585
double true_a = 9030d;
8686
double true_k = -0.05515d;
87-
Assert.IsLessThan(0.01d,(x - true_x) / true_x);
88-
Assert.IsLessThan(0.01d,(a - true_a) / true_a);
87+
Assert.IsLessThan(0.01d, (x - true_x) / true_x );
88+
Assert.IsLessThan(0.01d, (a - true_a) / true_a );
8989
Assert.IsLessThan(0.01d, (k - true_k) / true_k);
9090
}
9191

@@ -230,7 +230,7 @@ public void Test_InvalidParameters()
230230
public void Test_ParametersToString()
231231
{
232232
var l = new GeneralizedLogistic();
233-
Assert.AreEqual("Location (ξ)",l.ParametersToString[0, 0] );
233+
Assert.AreEqual("Location (ξ)", l.ParametersToString[0, 0]);
234234
Assert.AreEqual("Scale (α)", l.ParametersToString[1, 0]);
235235
Assert.AreEqual("Shape (κ)", l.ParametersToString[2, 0]);
236236
Assert.AreEqual("100", l.ParametersToString[0, 1]);
@@ -265,7 +265,7 @@ public void Test_Mean()
265265
Assert.AreEqual(9.44703, l2.Mean, 1e-04);
266266

267267
var l3 = new GeneralizedLogistic(100, 10, 1);
268-
Assert.AreEqual(double.NaN,l3.Mean );
268+
Assert.AreEqual(double.NaN, l3.Mean);
269269
}
270270

271271
/// <summary>
@@ -307,7 +307,7 @@ public void Test_StandardDeviation()
307307
Assert.AreEqual(39.76482, l2.StandardDeviation, 1e-04);
308308

309309
var l3 = new GeneralizedLogistic(100, 10, 1);
310-
Assert.AreEqual(double.NaN,l3.StandardDeviation );
310+
Assert.AreEqual(double.NaN, l3.StandardDeviation);
311311
}
312312

313313
/// <summary>
@@ -333,13 +333,13 @@ public void Test_Skewness()
333333
public void Test_Kurtosis()
334334
{
335335
var l = new GeneralizedLogistic();
336-
Assert.AreEqual(21d / 5d,l.Kurtosis);
336+
Assert.AreEqual(21d / 5d, l.Kurtosis);
337337

338338
var l2 = new GeneralizedLogistic(100, 10, 0.24);
339339
Assert.AreEqual(199.733369, l2.Kurtosis, 1e-04);
340340

341341
var l3 = new GeneralizedLogistic(100, 10, 0.25);
342-
Assert.AreEqual(double.NaN,l3.Kurtosis );
342+
Assert.AreEqual(double.NaN, l3.Kurtosis);
343343
}
344344

345345
/// <summary>
@@ -375,7 +375,7 @@ public void Test_Maximum()
375375
public void Test_PDF()
376376
{
377377
var l = new GeneralizedLogistic();
378-
Assert.AreEqual(0.025,l.PDF(100) );
378+
Assert.AreEqual(0.025,l.PDF(100));
379379
Assert.AreEqual(4.5395e-06, l.PDF(0), 1e-10);
380380

381381
var l2 = new GeneralizedLogistic(100, 10, 1);

Test_Numerics/Distributions/Univariate/Test_GeneralizedNormal.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ public void Test_ParametersToString()
202202
Assert.AreEqual("Scale (α)", n.ParametersToString[1, 0]);
203203
Assert.AreEqual("Shape (κ)", n.ParametersToString[2, 0]);
204204
Assert.AreEqual("100", n.ParametersToString[0, 1]);
205-
Assert.AreEqual("10",n.ParametersToString[1, 1]);
205+
Assert.AreEqual("10", n.ParametersToString[1, 1]);
206206
Assert.AreEqual("0", n.ParametersToString[2, 1]);
207207
}
208208

Test_Numerics/Distributions/Univariate/Test_GeneralizedPareto.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ public void Test_GPA_MOM_Fit()
8484
double true_x = 50169.23d;
8585
double true_a = 55443d;
8686
double true_k = 0.0956d;
87-
Assert.IsLessThan(0.01d,(x - true_x) / true_x );
88-
Assert.IsLessThan(0.01d,(a - true_a) / true_a );
87+
Assert.IsLessThan(0.01d, (x - true_x) / true_x );
88+
Assert.IsLessThan(0.01d, (a - true_a) / true_a );
8989
Assert.IsLessThan(0.01d, (k - true_k) / true_k);
9090
}
9191

@@ -364,13 +364,13 @@ public void Test_StandardDeviation()
364364
public void Test_Skewness()
365365
{
366366
var GPA = new GeneralizedPareto();
367-
Assert.AreEqual(2,GPA.Skewness);
367+
Assert.AreEqual(2, GPA.Skewness);
368368

369369
var GPA2 = new GeneralizedPareto(100, 10, 0.3);
370370
Assert.AreEqual(0.932039, GPA2.Skewness, 1e-04);
371371

372372
var GPA3 = new GeneralizedPareto(100, 10, 1);
373-
Assert.AreEqual(double.NaN,GPA3.Skewness );
373+
Assert.AreEqual(double.NaN, GPA3.Skewness);
374374
}
375375

376376
/// <summary>
@@ -424,7 +424,7 @@ public void Test_PDF()
424424

425425
var GPA2 = new GeneralizedPareto(100, 10, 1);
426426
Assert.AreEqual(0,GPA2.PDF(200));
427-
Assert.AreEqual(0,GPA2.PDF(50));
427+
Assert.AreEqual(0, GPA2.PDF(50));
428428
}
429429

430430
/// <summary>

Test_Numerics/Distributions/Univariate/Test_Geometric.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public void Test_InvalidParameters()
126126
public void Test_ParametersToString()
127127
{
128128
var G = new Geometric();
129-
Assert.AreEqual("Probability (p)",G.ParametersToString[0, 0]);
129+
Assert.AreEqual("Probability (p)", G.ParametersToString[0, 0]);
130130
Assert.AreEqual("0.5", G.ParametersToString[0, 1]);
131131
}
132132

@@ -150,7 +150,7 @@ public void Test_Mean()
150150
public void Test_Median()
151151
{
152152
var G = new Geometric(0.0001);
153-
Assert.AreEqual(6931,G.Median);
153+
Assert.AreEqual(6931, G.Median);
154154

155155
var G2 = new Geometric(0.1);
156156
Assert.AreEqual(6, G2.Median);
@@ -195,7 +195,7 @@ public void Test_Skewness()
195195
Assert.AreEqual(2.12132, G.Skewness, 1e-04);
196196

197197
var G2 = new Geometric(0.3);
198-
Assert.AreEqual(2.03188, G2.Skewness, 1e-04);
198+
Assert.AreEqual(2.03188, G2.Skewness, 1e-04);
199199
}
200200

201201
/// <summary>
@@ -205,7 +205,7 @@ public void Test_Skewness()
205205
public void Test_Kurtosis()
206206
{
207207
var G = new Geometric();
208-
Assert.AreEqual(9.5,G.Kurtosis);
208+
Assert.AreEqual(9.5, G.Kurtosis);
209209

210210
var G2 = new Geometric(0.3);
211211
Assert.AreEqual(9.12857, G2.Kurtosis, 1e-04);
@@ -218,7 +218,7 @@ public void Test_Kurtosis()
218218
public void Test_MinMax()
219219
{
220220
var G = new Geometric();
221-
Assert.AreEqual(0,G.Minimum);
221+
Assert.AreEqual(0, G.Minimum);
222222
Assert.AreEqual(double.PositiveInfinity,G.Maximum);
223223

224224
var G2 = new Geometric(0.3);
@@ -233,8 +233,8 @@ public void Test_MinMax()
233233
public void Test_PDF()
234234
{
235235
var G = new Geometric();
236-
Assert.AreEqual(0.5,G.PDF(0));
237-
Assert.AreEqual(0.125,G.PDF(2));
236+
Assert.AreEqual(0.5, G.PDF(0));
237+
Assert.AreEqual(0.125, G.PDF(2));
238238
Assert.AreEqual(0, G.PDF(-1));
239239

240240
var G2 = new Geometric(0.3);
@@ -256,7 +256,7 @@ public void Test_CDF()
256256

257257
var G2 = new Geometric(0.3);
258258
Assert.AreEqual(0.657, G2.CDF(2));
259-
Assert.AreEqual(1,G2.CDF(100), 1e-04);
259+
Assert.AreEqual(1, G2.CDF(100), 1e-04);
260260
}
261261

262262
/// <summary>
@@ -266,11 +266,11 @@ public void Test_CDF()
266266
public void Test_InverseCDF()
267267
{
268268
var G = new Geometric();
269-
Assert.AreEqual(0,G.InverseCDF(0.3));
270-
Assert.AreEqual(1,G.InverseCDF(0.7), 1e-04);
269+
Assert.AreEqual(0, G.InverseCDF(0.3));
270+
Assert.AreEqual(1, G.InverseCDF(0.7), 1e-04);
271271

272272
var G2 = new Geometric(0.3);
273-
Assert.AreEqual(1,G2.InverseCDF(0.5), 1e-04);
273+
Assert.AreEqual(1, G2.InverseCDF(0.5), 1e-04);
274274
Assert.AreEqual(6,G2.InverseCDF(0.9));
275275
}
276276
}

0 commit comments

Comments
 (0)