diff --git a/HEAL.NonlinearRegression.Console/Program.cs b/HEAL.NonlinearRegression.Console/Program.cs index abd8a2f..a8275ac 100644 --- a/HEAL.NonlinearRegression.Console/Program.cs +++ b/HEAL.NonlinearRegression.Console/Program.cs @@ -117,7 +117,7 @@ private static void Evaluate(EvalOptions options) { if (options.Likelihood == LikelihoodEnum.Gaussian) { var yPred = nlr.Predict(x); var ssr = Util.SSR(y, yPred); - var nmse = ssr / y.Length / Util.Variance(y); + var nmse = Util.NMSE(y, yPred); var mae = Util.MAE(y, yPred); System.Console.WriteLine($"SSR: {ssr:g6} MSE: {ssr / y.Length:g6} RMSE: {Math.Sqrt(ssr / y.Length):g6} NMSE: {nmse:g6} R2: {1 - nmse:g4} MAE: {mae:g4} LogLik: {logLik:g6} AIC: {nlr.AIC:f2} AICc: {aicc:f2} BIC: {bic:f2} DL: {dl:f2} DL_lattice: {dlLattice:f2} neg. Evidence: {evidence:f2} DoF: {p.Length} m: {m}"); } diff --git a/HEAL.NonlinearRegression/Util.cs b/HEAL.NonlinearRegression/Util.cs index 8b865c5..7febf5e 100644 --- a/HEAL.NonlinearRegression/Util.cs +++ b/HEAL.NonlinearRegression/Util.cs @@ -12,6 +12,11 @@ public static double SSR(double[] y, double[] yPred) { return ssr; } + public static double MSE(double[] y, double[] yPred) => SSR(y, yPred) / y.Length; + public static double NMSE(double[] y, double[] yPred) => MSE(y, yPred) / Util.Variance(y); + public static double R2(double[] y, double[] yPred) => 1.0 - NMSE(y, yPred); + + public static double MAE(double[] y, double[] yPred) { if (y.Length != yPred.Length) throw new ArgumentException("arrays must have the same length"); var sae = 0.0; @@ -45,5 +50,6 @@ public static double[][] ToColumns(double[,] x) { } return xc; } + } }