Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/06/17 13:12:41 (6 years ago)
Author:
gkronber
Message:

#2789 more tests with CV and automatic determination of smoothing parameter

Location:
branches/MathNetNumerics-Exploration-2789/Main
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/MathNetNumerics-Exploration-2789/Main/Main.csproj

    r15449 r15450  
    3838      <HintPath>..\..\..\trunk\sources\bin\ALGLIB-3.7.0.dll</HintPath>
    3939    </Reference>
     40    <Reference Include="HeuristicLab.Algorithms.DataAnalysis-3.4, Version=3.4.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     41      <SpecificVersion>False</SpecificVersion>
     42      <HintPath>..\..\..\trunk\sources\bin\HeuristicLab.Algorithms.DataAnalysis-3.4.dll</HintPath>
     43    </Reference>
     44    <Reference Include="HeuristicLab.Collections-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec" />
    4045    <Reference Include="HeuristicLab.Common-3.3">
    4146      <HintPath>..\..\..\trunk\sources\bin\HeuristicLab.Common-3.3.dll</HintPath>
    4247    </Reference>
    4348    <Reference Include="HeuristicLab.Core-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec" />
     49    <Reference Include="HeuristicLab.Optimization-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec" />
    4450    <Reference Include="HeuristicLab.Problems.DataAnalysis-3.4, Version=3.4.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    4551      <SpecificVersion>False</SpecificVersion>
    4652      <HintPath>..\..\..\trunk\sources\bin\HeuristicLab.Problems.DataAnalysis-3.4.dll</HintPath>
     53    </Reference>
     54    <Reference Include="HeuristicLab.Problems.Instances-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     55      <SpecificVersion>False</SpecificVersion>
     56      <HintPath>..\..\..\trunk\sources\bin\HeuristicLab.Problems.Instances-3.3.dll</HintPath>
     57    </Reference>
     58    <Reference Include="HeuristicLab.Problems.Instances.DataAnalysis-3.3">
     59      <HintPath>..\..\..\trunk\sources\bin\HeuristicLab.Problems.Instances.DataAnalysis-3.3.dll</HintPath>
    4760    </Reference>
    4861    <Reference Include="System" />
  • branches/MathNetNumerics-Exploration-2789/Main/Program.cs

    r15449 r15450  
    1212  class Program {
    1313    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();
     14      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.VariousInstanceProvider();
     15      var problemData = provider.LoadData(provider.GetDataDescriptors().First(dd => dd.Name.Contains("Poly")));
     16      // var provider = new HeuristicLab.Problems.Instances.DataAnalysis.RegressionRealWorldInstanceProvider();
     17      // var problemData = provider.LoadData(provider.GetDataDescriptors().First(dd => dd.Name.Contains("Chem")));
    1618
    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();
     19      var gam = new GAM();
     20      gam.MaxIterations = 10;
     21      gam.MaxInteractions = 3;
     22      gam.Problem.ProblemData = problemData;
     23      gam.Start();
    2124
    22       CubicSplineGCV.CubGcvReport report;
    23       var model = CubicSplineGCV.CalculateCubicSpline(
    24         xs.ToArray(), ys_noise.ToArray(), "y", new string[] { "x" }, out report);
     25      var solution = (IRegressionSolution)gam.Results["Ensemble solution"].Value;
    2526
    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       }
     27      Console.WriteLine("RMSE (train) {0}", solution.TrainingRootMeanSquaredError);
     28      Console.WriteLine("RMSE (test) {0}", solution.TestRootMeanSquaredError);
    4729    }
    4830  }
Note: See TracChangeset for help on using the changeset viewer.