@@ -29,7 +29,7 @@ public UncertainMeasurementSample () {
29
29
/// </summary>
30
30
/// <param name="datum">The data point.</param>
31
31
public void Add ( UncertainMeasurement < T > datum ) {
32
- if ( datum == null ) throw new ArgumentNullException ( " datum" ) ;
32
+ if ( datum == null ) throw new ArgumentNullException ( nameof ( datum ) ) ;
33
33
data . Add ( datum ) ;
34
34
}
35
35
@@ -48,7 +48,7 @@ public void Add (T x, double y, double dy) {
48
48
/// </summary>
49
49
/// <param name="data">The data points.</param>
50
50
public void Add ( IEnumerable < UncertainMeasurement < T > > data ) {
51
- if ( data == null ) throw new ArgumentNullException ( " data" ) ;
51
+ if ( data == null ) throw new ArgumentNullException ( nameof ( data ) ) ;
52
52
foreach ( UncertainMeasurement < T > datum in data ) {
53
53
this . data . Add ( datum ) ;
54
54
}
@@ -100,7 +100,7 @@ public int Count {
100
100
/// <exception cref="InsufficientDataException">There are fewer data points than fit parameters.</exception>
101
101
public FitResult FitToLinearFunction ( Func < T , double > [ ] functions ) {
102
102
103
- if ( functions == null ) throw new ArgumentNullException ( " functions" ) ;
103
+ if ( functions == null ) throw new ArgumentNullException ( nameof ( functions ) ) ;
104
104
if ( functions . Length > data . Count ) throw new InsufficientDataException ( ) ;
105
105
106
106
// construct the design matrix
@@ -176,11 +176,13 @@ public FitResult FitToLinearFunction (Func<T, double>[] functions) {
176
176
/// <param name="start">An initial guess at the parameters.</param>
177
177
/// <returns>A fit result containing the best-fitting function parameters
178
178
/// and a χ<sup>2</sup> test of the quality of the fit.</returns>
179
- /// <exception cref="ArgumentNullException"><paramref name="function"/> or <paramref name="start"/> are null.</exception>
179
+ /// <exception cref="ArgumentNullException"><paramref name="function"/> or <paramref name="start"/> are <see langword=" null"/> .</exception>
180
180
/// <exception cref="InsufficientDataException">There are fewer data points than fit parameters.</exception>
181
+ /// <exception cref="DivideByZeroException">The curvature matrix is singular, indicating that the data is independent of
182
+ /// one or more parameters, or that two or more parameters are linearly dependent.</exception>
181
183
public FitResult FitToFunction ( Func < double [ ] , T , double > function , double [ ] start ) {
182
- if ( function == null ) throw new ArgumentNullException ( " function" ) ;
183
- if ( start == null ) throw new ArgumentNullException ( " start" ) ;
184
+ if ( function == null ) throw new ArgumentNullException ( nameof ( function ) ) ;
185
+ if ( start == null ) throw new ArgumentNullException ( nameof ( start ) ) ;
184
186
185
187
// you can't do a fit with less data than parameters
186
188
if ( this . Count < start . Length ) throw new InsufficientDataException ( ) ;
@@ -201,6 +203,7 @@ public FitResult FitToFunction (Func<double[], T, double> function, double[] sta
201
203
// compute the covariance (Hessian) matrix by inverting the curvature matrix
202
204
SymmetricMatrix A = 0.5 * minimum . Curvature ( ) ;
203
205
CholeskyDecomposition CD = A . CholeskyDecomposition ( ) ; // should not return null if we were at a minimum
206
+ if ( CD == null ) throw new DivideByZeroException ( ) ;
204
207
SymmetricMatrix C = CD . Inverse ( ) ;
205
208
206
209
// package up the results and return them
@@ -228,7 +231,7 @@ bool ICollection<UncertainMeasurement<T>>.IsReadOnly {
228
231
}
229
232
230
233
void ICollection < UncertainMeasurement < T > > . CopyTo ( UncertainMeasurement < T > [ ] array , int offset ) {
231
- if ( array == null ) throw new ArgumentNullException ( " array" ) ;
234
+ if ( array == null ) throw new ArgumentNullException ( nameof ( array ) ) ;
232
235
data . CopyTo ( array , offset ) ;
233
236
}
234
237
@@ -262,7 +265,7 @@ public UncertainMeasurementSample ()
262
265
/// <param name="data">An enumerator over the <see cref="UncertainMeasurement{Double}" />s to place in the set.</param>
263
266
public UncertainMeasurementSample ( IEnumerable < UncertainMeasurement < double > > data )
264
267
: base ( ) {
265
- if ( data == null ) throw new ArgumentNullException ( " data" ) ;
268
+ if ( data == null ) throw new ArgumentNullException ( nameof ( data ) ) ;
266
269
foreach ( UncertainMeasurement < double > datum in data ) {
267
270
Add ( datum ) ;
268
271
}
@@ -273,6 +276,7 @@ public UncertainMeasurementSample (IEnumerable<UncertainMeasurement<double>> dat
273
276
/// </summary>
274
277
/// <returns>A fit result containing the best combined value and a χ<sup>2</sup> test of the quality of the fit.</returns>
275
278
/// <remarks><para>This method provides a simple way to </para></remarks>
279
+ /// <exception cref="InsufficientDataException">There are fewer than one data points.</exception>
276
280
public FitResult FitToConstant ( ) {
277
281
278
282
if ( Count < 1 ) throw new InsufficientDataException ( ) ;
@@ -310,6 +314,7 @@ public FitResult FitToConstant () {
310
314
/// </summary>
311
315
/// <returns>A fit result containing the best-fit proportionality constant parameter and a χ<sup>2</sup> test of the
312
316
/// quality of the fit.</returns>
317
+ /// <exception cref="InsufficientDataException">There are fewer than one data points.</exception>
313
318
public FitResult FitToProportionality ( ) {
314
319
315
320
if ( Count < 1 ) throw new InsufficientDataException ( ) ;
@@ -350,6 +355,7 @@ public FitResult FitToProportionality () {
350
355
/// </summary>
351
356
/// <returns>A fit result containing the best-fit intercept and slope parameters and a χ<sup>2</sup> test of
352
357
/// the quality of the fit.</returns>
358
+ /// <exception cref="InsufficientDataException">There are fewer than two data points.</exception>
353
359
public FitResult FitToLine ( ) {
354
360
355
361
if ( Count < 2 ) throw new InsufficientDataException ( ) ;
@@ -404,11 +410,12 @@ public FitResult FitToLine () {
404
410
/// <param name="order">The order of the polynomial to fit.</param>
405
411
/// <returns>A fit result containg the best-fit polynomial coefficients, in order of ascending power from 0 to <paramref name="order"/>,
406
412
/// and a χ<sup>2</sup> test of the quality of the fit.</returns>
407
- /// <exception cref="InvalidOperationException">There are more polynomial coefficients than data points.</exception>
413
+ /// <exception cref="ArgumentOutOfRangeException"><paramref name="order"/> is negative.</exception>
414
+ /// <exception cref="InsufficientDataException">There are more polynomial coefficients than data points.</exception>
408
415
public FitResult FitToPolynomial ( int order ) {
409
416
410
- if ( order < 0 ) throw new ArgumentOutOfRangeException ( " order" ) ;
411
- if ( Count < order ) throw new InvalidOperationException ( ) ;
417
+ if ( order < 0 ) throw new ArgumentOutOfRangeException ( nameof ( order ) ) ;
418
+ if ( Count < order ) throw new InsufficientDataException ( ) ;
412
419
413
420
// create the functions
414
421
Func < double , double > [ ] functions = new Func < double , double > [ order + 1 ] ;
0 commit comments