diff --git a/README.md b/README.md index 8ad0e03..3f97ed9 100644 --- a/README.md +++ b/README.md @@ -24,21 +24,21 @@ dotnet test --filter "FullyQualifiedName~Fit" ``` Starting test execution, please wait... Deviance: 1.0000e+001, BIC: 96.91 -pred: 50.56597777048287, low: 41.54374721579106, high: 59.588208325174676 +pred: 50.56597777048287, low: 41.54374721579334, high: 59.588208325172396 p_opt: 1.10421e+002 1.03488e+002 Successful: True, NumIters: 1, NumFuncEvals: 11, NumJacEvals: 11 -SSR: 9.5471e+003 s: 3.0898e+001 RMSE: 3.0898e+001 AICc: 123.4 BIC: 121.8 DL: 67.3 DL (lattice): 58.7 +SSR: 9.5471e+003 s: 3.0898e+001 RMSE: 3.0898e+001 AICc: 123.4 BIC: 121.8 DL: 67.33 DL (lattice): 58.69 neg. Evidence: 41.93 Para Estimate Std. error z Score Lower Upper Correlation matrix 0 1.1042e+002 2.3371e+001 4.72e+000 5.8347e+001 1.6249e+002 1.00 1 1.0349e+002 1.2024e+001 8.61e+000 7.6697e+001 1.3028e+002 -0.67 1.00 -Optimized: ((110.4 * x0) + 103.5) +Optimized: 110.42108 * x0 + 103.48806 p_opt: 1.38378e+000 4.84833e-002 5.24299e-001 3.52511e-001 -6.84851e-002 -1.11809e+001 -Successful: True, NumIters: 1, NumFuncEvals: 3, NumJacEvals: 3 -Deviance: 7.8438e+002 AICc: 796.5 BIC: 825.6 DL: 458.2 DL (lattice): 455.8 +Successful: True, NumIters: 3, NumFuncEvals: 43, NumJacEvals: 43 +Deviance: 7.8438e+002 AICc: 796.5 BIC: 825.6 DL: 458 DL (lattice): 456 neg. Evidence: 389.84 Para Estimate Std. error z Score Lower Upper Correlation matrix 0 1.3838e+000 1.7042e-001 8.12e+000 1.0493e+000 1.7182e+000 1.00 1 4.8483e-002 7.5999e-003 6.38e+000 3.3569e-002 6.3398e-002 -0.04 1.00 @@ -47,21 +47,21 @@ Para Estimate Std. error z Score Lower Upper Co 4 -6.8485e-002 2.4032e-001 -2.85e-001 -5.4009e-001 4.0312e-001 -0.04 0.00 0.02 -0.10 1.00 5 -1.1181e+001 1.0533e+000 -1.06e+001 -1.3248e+001 -9.1140e+000 -0.60 -0.38 -0.11 0.12 -0.62 1.00 -Optimized: Logistic(((((((1.384 * BI_RADS) + (0.04848 * Age)) + (0.5243 * Shape)) + (0.3525 * Margin)) + (-0.06849 * Density)) + -11.18)) +Optimized: logistic(1.3837835 * BI_RADS + 0.048483267 * Age + 0.5242994 * Shape + 0.35251072 * Margin + -0.068485134 * Density + -11.180916) p_opt: 6.41213e-002 2.12684e+002 Successful: True, NumIters: 1, NumFuncEvals: 21, NumJacEvals: 21 -SSR: 1.1954e+003 s: 1.0934e+001 RMSE: 1.0934e+001 AICc: 98.5 BIC: 96.9 DL: 61.2 DL (lattice): 59.1 +SSR: 1.1954e+003 s: 1.0934e+001 RMSE: 1.0934e+001 AICc: 98.5 BIC: 96.9 DL: 61.23 DL (lattice): 59.14 neg. Evidence: 33.06 Para Estimate Std. error z Score Lower Upper Correlation matrix 0 6.4121e-002 8.7112e-003 7.36e+000 4.4711e-002 8.3531e-002 1.00 1 2.1268e+002 7.1607e+000 2.97e+001 1.9673e+002 2.2864e+002 0.78 1.00 -Optimized: ((x0 / (0.06412 + x0)) * 212.7) +Optimized: x0 / (0.064121282 + x0) * 212.68374 -Passed! - Failed: 0, Passed: 5, Skipped: 0, Total: 5, Duration: 423 ms - HEAL.NonlinearRegression.Console.Tests.dll (net6.0) +Passed! - Failed: 0, Passed: 5, Skipped: 0, Total: 5, Duration: 705 ms ``` Run the tests for profile likelihood confidence intervals: @@ -80,19 +80,19 @@ p4 -6.8485e-002 -5.3640e-001 4.0944e-001 p5 -1.1181e+001 -1.3314e+001 -9.1744e+000 - Passed ProfileMammography [3 s] + Passed ProfileMammography [8 s] profile-based marginal confidence intervals (alpha=0.05) p0 6.4121e-002 4.6920e-002 8.6157e-002 p1 2.1268e+002 1.9730e+002 2.2929e+002 -NUnit Adapter 4.4.0.0: Test execution complete - Passed ProfilePuromycin [13 ms] +NUnit Adapter 4.5.0.0: Test execution complete + Passed ProfilePuromycin [22 ms] Test Run Successful. Total tests: 2 Passed: 2 - Total time: 4,7091 Seconds + Total time: 9,2968 Seconds ``` # Usage @@ -103,14 +103,19 @@ var x = new double[,] { { 0.02 }, { 0.02 }, { 0.06 }, { 0.06 }, { 0.11 }, { 0.11 var y = new double[] {76, 47, 97, 107, 123, 139, 159, 152, 191, 201, 207, 200 }; var nlr = new NonlinearRegression(); -var likelihood = new SimpleGaussianLikelihood(x, y, (p, x) => p[0] * x[0] / (1.0 + p[1] * x[0])); -nlr.Fit(p: new double[] {0.1, 0.1 }, likelihood); // initial values for parameters +var modelExpr = "0.1 * x0 / (1.0f + 0.1 * x0)"; +var parser = new HEAL.Expressions.Parser.ExprParser(modelExpr, + new[] { "x0" }, + System.Linq.Expressions.Expression.Parameter(typeof(double[]), "x"), + System.Linq.Expressions.Expression.Parameter(typeof(double[]), "p")); +var likelihood = new SimpleGaussianLikelihood(x, y, parser.Parse()); +nlr.Fit(parser.ParameterValues, likelihood); nlr.WriteStatistics(); ``` Output: ``` -SSR: 1.1954e+003 s: 1.0934e+001 RMSE: 1.0934e+001 AICc: 98.5 BIC: 96.9 DL: 66.3 DL (lattice): 54.8 +SSR: 1.1954e+003 s: 1.0934e+001 RMSE: 1.0934e+001 AICc: 98.5 BIC: 96.9 DL: 66.34 DL (lattice): 54.81 neg. Evidence: 33.06 Para Estimate Std. error z Score Lower Upper Correlation matrix 0 3.3169e+003 3.7006e+002 8.96e+000 2.4924e+003 4.1414e+003 1.00 1 1.5595e+001 2.1187e+000 7.36e+000 1.0875e+001 2.0316e+001 0.98 1.00