source: branches/MathNetNumerics-Exploration-2789/Main/Program.cs @ 15449

Last change on this file since 15449 was 15449, checked in by gkronber, 4 years ago

#2789 created x64 build of CUBGCV algorithm, fixed some bugs

File size: 2.3 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Globalization;
4using System.Linq;
5using System.Text;
6using System.Threading;
7using System.Threading.Tasks;
8using HeuristicLab.Algorithms.DataAnalysis.Experimental;
9using HeuristicLab.Problems.DataAnalysis;
10
11namespace Main {
12  class Program {
13    static void Main(string[] args) {
14      var xs = HeuristicLab.Common.SequenceGenerator.GenerateSteps(-3.5, 3.5, 0.1, includeEnd: true).ToList();
15      var ys = xs.Select(xi => 1.0 / Math.Sqrt(2 * Math.PI) * Math.Exp(-0.5 * xi * xi)).ToArray(); // 1.0 / (Math.Sqrt(2 * Math.PI) * Math.Exp(-0.5 * xi * xi))).ToArray();
16
17      int n = xs.Count();
18      alglib.hqrndstate state;
19      alglib.hqrndseed(1234, 5678, out state);
20      var ys_noise = ys.Select(yi => yi + alglib.hqrndnormal(state) * 0.1).ToList();
21
22      CubicSplineGCV.CubGcvReport report;
23      var model = CubicSplineGCV.CalculateCubicSpline(
24        xs.ToArray(), ys_noise.ToArray(), "y", new string[] { "x" }, out report);
25
26      Console.WriteLine("Smoothing Parameter (= RHO/(RHO + 1) {0}", report.smoothingParameter);
27      Console.WriteLine("Estimated DOF of RSS {0}", report.estimatedRSSDegreesOfFreedom);
28      Console.WriteLine("GCV {0}", report.generalizedCrossValidation);
29      Console.WriteLine("Mean squared residual {0}", report.meanSquareResiudal);
30      Console.WriteLine("Estimate of true MSE at data points {0}", report.estimatedTrueMeanSquaredErrorAtDataPoints);
31      Console.WriteLine("Estimate of error variance {0}", report.estimatedErrorVariance);
32      Console.WriteLine("Mean square value of DF(I) {0}", report.meanSquareOfDf);
33
34      OnlineCalculatorError error;
35      var ys_smoothed = xs.Select(xi => model.GetEstimatedValue(xi)).ToArray();
36      var mse = OnlineMeanSquaredErrorCalculator.Calculate(ys, ys_smoothed, out error);
37      Console.WriteLine("MSE(ys, ys_smooth) = {0}", mse);
38      mse = OnlineMeanSquaredErrorCalculator.Calculate(ys, ys_noise, out error);
39      Console.WriteLine("MSE(ys, ys_noise) = {0}", mse);
40
41      Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
42
43      for (int i = 0; i < n; i++) {
44        Console.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}\t{5}",
45          xs[i], ys[i], ys_smoothed[i], ys_noise[i], ys_smoothed[i] + 1.96 * report.se[i], ys_smoothed[i] - 1.96 * report.se[i]);
46      }
47    }
48  }
49}
Note: See TracBrowser for help on using the repository browser.