@@ -420,6 +420,49 @@ public static double CDF(double shape, double scale, double x)
420
420
return - SpecialFunctions . ExponentialMinusOne ( - Math . Pow ( x , shape ) * Math . Pow ( scale , - shape ) ) ;
421
421
}
422
422
423
+ /// <summary>
424
+ /// Implemented according to: Parameter estimation of the Weibull probability distribution, 1994, Hongzhu Qiao, Chris P. Tsokos
425
+ /// </summary>
426
+ /// <param name="samples"></param>
427
+ /// <param name="randomSource"></param>
428
+ /// <returns>Returns a Weibull distribution.</returns>
429
+ public static Weibull Estimate ( IEnumerable < double > samples , System . Random randomSource = null )
430
+ {
431
+ var samp = samples as double [ ] ?? samples . ToArray ( ) ;
432
+ double n = samp . Count ( ) , s1 = 0 , s2 = 0 , s3 = 0 , previousC = Int32 . MinValue , QofC = 0 ;
433
+
434
+ if ( n <= 1 ) throw new Exception ( "Observations not sufficient" ) ;
435
+
436
+ // Start values
437
+ double c = 10 ; double b = 0 ;
438
+
439
+ while ( Math . Abs ( c - previousC ) >= 0.0001 )
440
+ {
441
+ s1 = s2 = s3 = 0 ;
442
+ foreach ( double x in samp )
443
+ {
444
+ if ( x > 0 )
445
+ {
446
+ s1 += Math . Log ( x ) ;
447
+ s2 += Math . Pow ( x , c ) ;
448
+ s3 += Math . Pow ( x , c ) * Math . Log ( x ) ;
449
+ }
450
+ }
451
+ QofC = n * s2 / ( n * s3 - s1 * s2 ) ;
452
+
453
+ previousC = c ;
454
+ c = ( c + QofC ) / 2 ;
455
+ }
456
+
457
+ foreach ( double x in samp )
458
+ if ( x > 0 )
459
+ b += Math . Pow ( x , c ) ;
460
+
461
+ b = Math . Pow ( b / n , 1 / c ) ;
462
+
463
+ return new Weibull ( c , b , randomSource ) ;
464
+ }
465
+
423
466
/// <summary>
424
467
/// Generates a sample from the Weibull distribution.
425
468
/// </summary>
0 commit comments