Skip to content

Bugfixes and enhancements#132

Closed
HadenSmith wants to merge 61 commits intomainfrom
bugfixes-and-enhancements
Closed

Bugfixes and enhancements#132
HadenSmith wants to merge 61 commits intomainfrom
bugfixes-and-enhancements

Conversation

@HadenSmith
Copy link
Copy Markdown
Collaborator

Merging a branch with several bug fixes and minor enhancements. The branch also includes significant improvements to the technical documentation.

Brennan1994 and others added 30 commits September 18, 2025 16:01
Updates the Numerics project settings to build better NuGets
hash cleanups

compiler warnings addressed. rethrow exceptions excape special chars in xml
To prevent future issues with unwanted files showing up in the repo

Remove all packages committed to vc
compiler warnings test - unused variables and nullables
Replace BinaryFormatter with System.Text.Json serialization

Switched serialization in UncertaintyAnalysisResults, MCMCResults, ParameterResults, and related classes from BinaryFormatter to System.Text.Json for improved security and compatibility. Added JsonInclude attributes to private setters for correct serialization. Updated project file to include System.Text.Json package and removed obsolete [Serializable] attributes.

Reimplement binary formatter for reading legacy saved data.
Update Integration.yml
readonly and never set. would always return an empty readonly collection
- Mixture.cs: Fix ParametersToString loop to include all weights/distributions (was skipping first and last)
- Linear.cs: Fix division-by-zero check in Extrapolate to check (x2-x1) instead of (y2-y1)
- Triangular.cs: Remove unreachable code in InverseCDF
- Brent.cs: Remove duplicate bounds check in Bracket method
- MCMCSampler.cs: Add MAPInitializationFailed property to track when MAP falls back to random init
In MSTest, Assert.AreEqual expects (expected, actual) order.
Fixed multiple test files where actual and expected values were swapped:

- Test_Triangular.cs: Fixed ~30 assertions
- Test_Normal.cs: Fixed 6 assertions
- Test_Exponential.cs: Fixed 7 assertions
- Test_Statistics.cs: Fixed ~40 assertions
- Test_Tools.cs: Fixed 3 assertions
Corrected the argument order in Assert.AreEqual calls throughout the
univariate distribution tests. In MSTest, the correct order is
Assert.AreEqual(expected, actual, delta). This fix ensures error
messages will correctly show expected vs actual values when tests fail.

Affected files:
- Test_Bernoulli.cs, Test_Beta.cs, Test_ChiSquared.cs
- Test_GammaDistribution.cs, Test_GeneralizedBeta.cs
- Test_GeneralizedExtremeValue.cs, Test_GeneralizedLogistic.cs
- Test_GeneralizedNormal.cs, Test_GeneralizedPareto.cs
- Test_Gumbel.cs, Test_LnNormal.cs, Test_Logistic.cs
- Test_Pareto.cs, Test_PearsonTypeIII.cs, Test_Pert.cs
- Test_Poisson.cs, Test_Rayleigh.cs, Test_StudentT.cs
- Test_TruncatedDistribution.cs, Test_TruncatedNormal.cs
- Test_Uniform.cs, Test_Weibull.cs
Comprehensive scope document outlining plan for numerics-python-examples
repository including:
- Repository structure with 10 Jupyter notebooks
- 3 standalone Python examples (flood frequency, reliability, Bayesian regression)
- Helper module and documentation files
- Phased release plan (MVP through full suite)
- Success metrics for evaluating wrapper development
Draft manuscript for Journal of Open Source Software submission describing
the Numerics library - a .NET numerical computing library for statistical
analysis and risk assessment developed by USACE-RMC.
- paper.tex: Full manuscript in official JOSS LaTeX format
- joss.sty: JOSS style file for document formatting
## Changes to hypothesis-tests.md:
- Fix critical API mismatch: all HypothesisTests methods return p-values,
  not test statistics. Updated all code examples to correctly show p-value
  returns and interpretation
- Add comprehensive hydrologic application examples:
  - Testing for stationarity in annual maximum floods
  - Comparing flood records between time periods
  - Testing normality of log-transformed flood data
- Add test selection guide table
- Add best practices section
- Update references to authoritative hydrology sources (USGS, Hirsch et al.)

## Navigation fixes:
- goodness-of-fit.md: Fix "Next" link to point to hypothesis-tests.md
  instead of mcmc.md
- mcmc.md: Fix "Previous" link to point to hypothesis-tests.md
  instead of goodness-of-fit.md

These changes ensure documentation accuracy for JOSS article submission.
This commit addresses all issues found in comprehensive documentation review:

## index.md
- Remove internal status legend and status column (meta-commentary)
- Fix placeholder comment in MCMC example

## getting-started.md
- Standardize package name to RMC.Numerics
- Remove placeholder version number

## Mathematics docs
- optimization.md: Fix navigation to point to root-finding.md
- linear-algebra.md: Fix navigation consistency (add Previous link)
- root-finding.md: Fix Erf function reference (use Erf.Function())
- integration.md: Change misleading "Error" labels to "Accuracy"/"Convergence Rate"
- ode-solvers.md: Remove dead code with meta-commentary

## Distributions docs
- copulas.md: Add missing "Next: Multivariate" navigation link
- copulas.md: Replace placeholder code with actual working examples
- copulas.md: Remove meta-commentary, simplify vine copulas section
- parameter-estimation.md: Fix 10n rule inconsistency between docs and code

## Sampling docs
- convergence-diagnostics.md: Replace placeholder code with actual API calls
- convergence-diagnostics.md: Use sampler.MarkovChains.ToList() instead of undefined ExtractChains()

## Data docs
- interpolation.md: Replace incomplete contour code with working transect example

## Machine Learning docs
- overview.md: Replace undefined LoadIris* functions with inline data
- overview.md: Replace placeholder ellipsis with actual cross-validation code
- overview.md: Fix model comparison with complete implementation

All documentation is now publication-ready for JOSS submission.
JOSS requires markdown (paper.md) not LaTeX for submissions.
Add ToXElement() to ILinkFunction interface, all 5 concrete link classes,
LinkFunctionFactory (CreateFromXElement), and LinkController. Change
LinkController._links to public Links property with private set. Add
parameterless constructor and XElement constructor for deserialization.
Add round-trip serialization tests for all types.
…tests

The Numerics test project uses Assert.Throws<T>() for exception testing,
not the [ExpectedException] attribute.
…t, studentTcopula, von mises distributions. Improved parameter estimation for bivariate copulas. Added Bessel special functions. Updating JOSS paper. Updated unit testing for all new classes.
…t, studentTcopula, von mises distributions. Improved parameter estimation for bivariate copulas. Added Bessel special functions. Updating JOSS paper. Updating technical documentation. Updated unit testing for all new classes.
… a bug in mixture.cs. Updated unit test for mixtures and competing risks. Changed namespace for JsonConverterDemo.
…ents

# Conflicts:
#	Numerics/Data/Interpolation/CubicSpline.cs
#	Numerics/Data/Paired Data/OrderedPairedData.cs
#	Numerics/Data/Paired Data/UncertainOrderedPairedData.cs
#	Numerics/Data/Paired Data/UncertainOrdinate.cs
#	Numerics/Data/Regression/LinearRegression.cs
#	Numerics/Data/Statistics/Autocorrelation.cs
#	Numerics/Data/Statistics/Histogram.cs
#	Numerics/Data/Statistics/HypothesisTests.cs
#	Numerics/Data/Time Series/Support/Series.cs
#	Numerics/Data/Time Series/Support/SeriesOrdinate.cs
#	Numerics/Data/Time Series/Support/TimeSeriesDownload.cs
#	Numerics/Data/Time Series/TimeSeries.cs
#	Numerics/Distributions/Bivariate Copulas/Base/BivariateCopula.cs
#	Numerics/Distributions/Multivariate/BivariateEmpirical.cs
#	Numerics/Distributions/Multivariate/MultivariateNormal.cs
#	Numerics/Distributions/Univariate/Base/UnivariateDistributionFactory.cs
#	Numerics/Distributions/Univariate/CompetingRisks.cs
#	Numerics/Distributions/Univariate/EmpiricalDistribution.cs
#	Numerics/Distributions/Univariate/KernelDensity.cs
#	Numerics/Distributions/Univariate/Mixture.cs
#	Numerics/Distributions/Univariate/PertPercentile.cs
#	Numerics/Distributions/Univariate/PertPercentileZ.cs
#	Numerics/Distributions/Univariate/TruncatedDistribution.cs
#	Numerics/Distributions/Univariate/Uncertainty Analysis/BootstrapAnalysis.cs
#	Numerics/Distributions/Univariate/Uncertainty Analysis/UncertaintyAnalysisResults.cs
#	Numerics/Machine Learning/Supervised/GeneralizedLinearModel.cs
#	Numerics/Machine Learning/Supervised/NaiveBayes.cs
#	Numerics/Machine Learning/Support/DecisionNode.cs
#	Numerics/Machine Learning/Unsupervised/GaussianMixtureModel.cs
#	Numerics/Mathematics/Integration/Miser.cs
#	Numerics/Mathematics/Linear Algebra/Support/Matrix.cs
#	Numerics/Mathematics/Linear Algebra/Support/Vector.cs
#	Numerics/Mathematics/Optimization/Dynamic/Dijkstra.cs
#	Numerics/Mathematics/Optimization/Global/MLSL.cs
#	Numerics/Mathematics/Optimization/Global/MultiStart.cs
#	Numerics/Mathematics/Optimization/Local/ADAM.cs
#	Numerics/Mathematics/Optimization/Local/BFGS.cs
#	Numerics/Mathematics/Optimization/Local/GradientDescent.cs
#	Numerics/Mathematics/Optimization/Support/Optimizer.cs
#	Numerics/Mathematics/Optimization/Support/ParameterSet.cs
#	Numerics/Sampling/Bootstrap/Bootstrap.cs
#	Numerics/Sampling/MCMC/ARWMH.cs
#	Numerics/Sampling/MCMC/Base/MCMCSampler.cs
#	Numerics/Sampling/MCMC/Support/MCMCResults.cs
#	Numerics/Sampling/MCMC/Support/ParameterResults.cs
#	Numerics/Sampling/SobolSequence.cs
#	Numerics/Sampling/StratificationBin.cs
#	Numerics/Sampling/Stratify.cs
#	Numerics/Utilities/JsonConverters.cs
#	Numerics/Utilities/SafeProgressReporter.cs
#	Test_Numerics/Data/Interpolation/Test_Bilinear.cs
#	Test_Numerics/Data/Interpolation/Test_CubicSpline.cs
#	Test_Numerics/Data/Interpolation/Test_Linear.cs
#	Test_Numerics/Data/Interpolation/Test_Polynomial.cs
#	Test_Numerics/Data/Paired Data/Test_Ordinate.cs
#	Test_Numerics/Data/Paired Data/Test_PairedDataInterpolation.cs
#	Test_Numerics/Data/Statistics/Test_BoxCox.cs
#	Test_Numerics/Data/Statistics/Test_HypothesisTests.cs
#	Test_Numerics/Distributions/Multivariate/Test_MultivariateNormal.cs
#	Test_Numerics/Distributions/Univariate/Test_GammaDistribution.cs
#	Test_Numerics/Distributions/Univariate/Test_GeneralizedLogistic.cs
#	Test_Numerics/Distributions/Univariate/Test_Gumbel.cs
#	Test_Numerics/Distributions/Univariate/Test_LogPearsonTypeIII.cs
#	Test_Numerics/Distributions/Univariate/Test_PearsonTypeIII.cs
#	Test_Numerics/Distributions/Univariate/Test_Rayleigh.cs
#	Test_Numerics/Distributions/Univariate/Test_StudentT.cs
#	Test_Numerics/Distributions/Univariate/Test_Triangular.cs
#	Test_Numerics/Distributions/Univariate/Test_TruncatedDistribution.cs
#	Test_Numerics/Distributions/Univariate/Test_TruncatedNormal.cs
#	Test_Numerics/Distributions/Univariate/Test_Uniform.cs
#	Test_Numerics/Distributions/Univariate/Test_UniformDiscrete.cs
#	Test_Numerics/Distributions/Univariate/Test_Weibull.cs
#	Test_Numerics/Functions/Test_Functions.cs
#	Test_Numerics/Mathematics/Linear Algebra/Test_GaussJordanElimination.cs
#	Test_Numerics/Sampling/Test_Stratification.cs
…ixes-and-enhancements

# Conflicts:
#	.github/workflows/Integration.yml
#	.github/workflows/Release.yml
#	.github/workflows/Snapshot.yml
#	.gitignore
#	Numerics/Data/Paired Data/OrderedPairedData.cs
#	Numerics/Data/Paired Data/Ordinate.cs
#	Numerics/Data/Paired Data/UncertainOrderedPairedData.cs
#	Numerics/Data/Paired Data/UncertainOrdinate.cs
#	Numerics/Data/Statistics/Histogram.cs
#	Numerics/Distributions/Univariate/Base/UnivariateDistributionBase.cs
#	Numerics/Distributions/Univariate/KernelDensity.cs
#	Numerics/Numerics.csproj
#	Numerics/Sampling/MCMC/Support/MCMCResults.cs
#	Numerics/Sampling/MCMC/Support/ParameterResults.cs
#	Numerics/Utilities/JsonConverters.cs
#	Test_Numerics/Serialization/JsonConverterDemo.cs
#	Test_Numerics/Serialization/Test_JsonSerialization.cs
#	Test_Numerics/Test_Numerics.csproj
HadenSmith and others added 29 commits March 6, 2026 15:16
…es-and-enhancements

# Conflicts:
#	docs/distributions/copulas.md
#	docs/getting-started.md
#	docs/index.md
…roved content and examples. Updated references.
Updated the paper to replace hydrology and risk assessment topics with machine learning and optimization. Revised sections to enhance clarity and detail on the capabilities of the Numerics library.
…hancements

Phase 1 - Critical correctness fixes:
- Fix InverseChiSquared CDF and InverseCDF formulas (was computing survival function)
- Fix NormalCopula CDF computing survival copula instead of copula
- Fix AMH, Frank, and Normal copula ValidateParameter returning non-null for valid params
- Fix MultipleGrubbsBeckTest static mutable fields (thread safety)
- Fix TimeSeries OneQuarter interval off by factor of 4
- Fix Search.Hunt always assuming descending order for OrderedPairedData overload
- Fix Bilinear UseSmartSearch copy-paste bug (X2LI never set)
- Fix KMeans++ initialization always using centroid[0]
- Fix SNIS weight filter wrong boolean operator (|| vs &&)
- Fix KNearestNeighbors multi-row GetNeighbors overwriting results

Phase 2 - High-priority fixes:
- Fix TimeSeries StartDate/EndDate crash on empty series
- Fix TimeSeries InterpolateMissingData index -1 crash
- Fix TimeSeries CumulativeSum NaN vs zero confusion
- Fix TimeSeries Divide silent infinity on zero divisor
- Fix TimeSeries StandardDeviation/Duration/SummaryPercentiles NaN handling
- Fix LogPearsonTypeIII Clone() dropping Base parameter
- Fix ChiSquared PDF overflow for large degrees of freedom (log-space)
- Fix Bernoulli Skewness/Kurtosis division by zero at p=0,1
- Fix Binomial InverseCDF off-by-one (never returns NumberOfTrials)
- Fix Rayleigh MoM wrong estimator
- Fix UniformDiscrete StandardDeviation wrong formula (continuous vs discrete)
- Fix GeneralizedBeta Mode 0/0 at Alpha=Beta=1
- Fix TruncatedNormal ValidateParameters reading property instead of parameter
- Fix EmpiricalDistribution/KernelDensity GetParameters NotImplementedException
- Fix Statistics HarmonicMean missing zero guard
- Fix GoodnessOfFit RSR using N instead of N-1
- Fix Histogram multiple issues (BinWidth=0, swapped args, empty guard)
- Fix MCMCDiagnostics GelmanRubin wrong denominator with warmup
- Fix GLM bounds inversion for negative intercept
- Fix HMC boundary enforcement (add momentum reflection)
- Fix NaiveBayes NaN for singleton classes
- Fix JenksCluster numerically unstable variance (Welford's algorithm)
- Fix ARWMH ProposalSigma division by zero when N=1
- Fix PowerFunction MinimumOfParameters/MaximumOfParameters wrong array length
- Fix LinearFunction/PowerFunction SetParameters not updating _normal
- Fix LinearFunction InverseFunction division by zero when Beta=0
- Fix MCMCSampler AcceptanceRates/ProgressChanged division by zero
- Fix DEMCz infinite loop when PopulationMatrix.Count=1
- Fix Autocorrelation/Correlation division by zero for constant series
- Fix HypothesisTests division-by-zero issues
- Fix BoxCox/GrubbsBeckTest non-positive values not guarded
- Remove VonMises Kurtosis dead computation

Phase 3 - Security (TimeSeriesDownload):
- Use static HttpClient instances (prevent socket exhaustion)
- Add CancellationToken support to all public async methods
- Validate redirect URLs against expected domains
- Remove UseProxy=false bypass
- Replace browser User-Agent with library identifier
- Replace Google.com connectivity check with target endpoint
- Sanitize GHCN station numbers
- Fix temp file leak on error
- Add explicit timeouts and retry logic with exponential backoff
- Use automatic gzip decompression

Phase 4 - Robustness:
- Fix Brent.Solve returning 0 instead of last iterate on failure
- Fix Series.SyncRoot returning unstable object
- Fix FrankCopula generator division by zero at Theta=0
- Fix TruncatedDistribution ValidateParameters exact float equality
- Fix Mixture EM convergence check placement
- Fix Deterministic/Binomial wrong parameter names in exceptions
- Fix JsonConverters silent zero-fill on malformed input
- Fix SafeProgressReporter MessageCount thread safety
- Fix ExtensionMethods.NextDoubles exact type check (use 'is')
- Fix TimeSeries FillMissingDates O(n^2) to O(n)
- Fix TimeSeries ResampleWithKNN index exceeding neighbor count
- Fix AdaptiveGaussKronrod wrong exception type

Phase 5 - Code quality:
- Remove useless catch/throw blocks (SobolSequence)
- Remove unused Microsoft.VisualBasic using (Gamma.cs)
- Fix CubicSpline XML doc saying "linear interpolation"
- Remove dead code (HypothesisTests, Search, YeoJohnson, DEMCzs)
- Fix KernelDensity typo GuassianKernel -> GaussianKernel
- Fix bitwise | vs logical || (Ordinate, Search)
- Remove unused NUnit references from test project
- Fix KNN XML doc "clusters" -> "nearest neighbors"
- Fix PowerFunction.Minimum setter no-op -> NotSupportedException
- Enable CS1591 (missing XML doc) warning and add missing XML docs
- Add XML docs for BinaryHeap, Network, SafeProgressReporter,
  MCMCSampler, MultivariateNormal, KernelDensity, SimulatedAnnealing,
  TimeSeries.FillMissingDates

Phase 6 - Unit tests with Python-verified reference values:
- Update InverseChiSquared tests for corrected CDF/InverseCDF
- Add InverseChiSquared CDF/InverseCDF roundtrip test
- Add NormalCopula CDF asymmetric inputs test
- Add Bernoulli boundary skewness/kurtosis test
- Add Binomial InverseCDF boundary test
- Add ChiSquared PDF large DoF test
- Add GeneralizedBeta Mode uniform case test
- Add Rayleigh MoM estimation test
- Add UniformDiscrete StandardDeviation test
- Add Statistics HarmonicMean zero value test
- Add KNN multi-row GetNeighbors test
- Add MCMCDiagnostics GelmanRubin warmup test
- Add HMC non-finite gradient crash test
- Fix MSTEST0037 analyzer warnings across test project
- Revert RSR denominator from N-1 back to N (ensures RSR=1.0 for
  constant-at-mean predictions); fix misleading comment
- Fix assertion argument order in Test_InverseChiSquared,
  Test_TimeSeries, Test_kNN, and Test_MCMCDiagnostics
- Replace 120-line private ZBrent method in NoncentralT with a single
  call to Brent.Solve, using Math.Min/Max for bracket ordering
…ll 4 TFMs, runs tests, and pushes to nuget.org
…gence in mixture and GMM expectation-maximization method. Made degrees of freedom in student-t and noncentral-t doubles.
@HadenSmith HadenSmith closed this Mar 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants