Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/03/17 20:28:37 (7 years ago)
Author:
gkronber
Message:

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

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

Legend:

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

    r15443 r15449  
    2323    <ErrorReport>prompt</ErrorReport>
    2424    <WarningLevel>4</WarningLevel>
     25    <Prefer32Bit>false</Prefer32Bit>
    2526  </PropertyGroup>
    2627  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
     
    4041      <HintPath>..\..\..\trunk\sources\bin\HeuristicLab.Common-3.3.dll</HintPath>
    4142    </Reference>
     43    <Reference Include="HeuristicLab.Core-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec" />
    4244    <Reference Include="HeuristicLab.Problems.DataAnalysis-3.4, Version=3.4.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    4345      <SpecificVersion>False</SpecificVersion>
  • branches/MathNetNumerics-Exploration-2789/Main/Program.cs

    r15443 r15449  
    1313    static void Main(string[] args) {
    1414      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();
     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();
    1616
     17      int n = xs.Count();
    1718      alglib.hqrndstate state;
    1819      alglib.hqrndseed(1234, 5678, out state);
    1920      var ys_noise = ys.Select(yi => yi + alglib.hqrndnormal(state) * 0.1).ToList();
    2021
    21       int n = xs.Count;
    22       double[] ys_smoothed = new double[n];
    23       double[] df = Enumerable.Repeat(1.0, n).ToArray();   // set each df if actual standard deviation of data points is not known
    24       double[,] c = new double[n - 1, 3];
    25       double var = -99.0;
    26       int ic = n - 1;
    27       int job = 1; // calc estimates of standard errors in points
    28       double[] se = new double[n]; // standard errors in points
    29       double[,] wk = new double[7, (n + 2)]; // work array;
    30       int ier = -99;
    31       if (Environment.Is64BitProcess) {
    32         // CubicSplineGCV.cubgcv_x64(xs.ToArray(), f, df, ref n, ys_noise.ToArray(), c, ref ic, ref var, ref job, se, wk);
    33         Console.WriteLine("x64 version not supported");
    34       } else {
    35         CubicSplineGCV.cubgcv_x86(xs.ToArray(), ys_noise.ToArray(), df, ref n, ys_smoothed,
    36           c, ref ic, ref var, ref job, se, wk, ref ier);
     22      CubicSplineGCV.CubGcvReport report;
     23      var model = CubicSplineGCV.CalculateCubicSpline(
     24        xs.ToArray(), ys_noise.ToArray(), "y", new string[] { "x" }, out report);
    3725
     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);
    3833
    39         //                           WK(1) = SMOOTHING PARAMETER (= RHO/(RHO + 1))
    40         //                           WK(2) = ESTIMATE OF THE NUMBER OF DEGREES OF
    41         //                                   FREEDOM OF THE RESIDUAL SUM OF SQUARES
    42         //                           WK(3) = GENERALIZED CROSS VALIDATION
    43         //                           WK(4) = MEAN SQUARE RESIDUAL
    44         //                           WK(5) = ESTIMATE OF THE TRUE MEAN SQUARE ERROR
    45         //                                   AT THE DATA POINTS
    46         //                           WK(6) = ESTIMATE OF THE ERROR VARIANCE
    47         //                           WK(7) = MEAN SQUARE VALUE OF THE DF(I)
     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);
    4840
    49         Console.WriteLine("Smoothing Parameter (= RHO/(RHO + 1) {0}", wk[0, 0]);
    50         Console.WriteLine("Estimated DOF of RSS {0}", wk[0, 1]);
    51         Console.WriteLine("GCV {0}", wk[0, 2]);
    52         Console.WriteLine("Mean squared residual {0}", wk[0, 3]);
    53         Console.WriteLine("Estimate of true MSE at data points {0}", wk[0, 4]);
    54         Console.WriteLine("Estimate of error variance {0}", wk[0, 5]);
    55         Console.WriteLine("Mean square value of DF(I) {0}", wk[0, 6]);
     41      Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
    5642
    57         OnlineCalculatorError error;
    58         var mse = OnlineMeanSquaredErrorCalculator.Calculate(ys, ys_smoothed, out error);
    59         Console.WriteLine("MSE(ys, ys_smooth) = {0}", mse);
    60         mse = OnlineMeanSquaredErrorCalculator.Calculate(ys, ys_noise, out error);
    61         Console.WriteLine("MSE(ys, ys_noise) = {0}", mse);
    62 
    63         Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
    64 
    65         for (int i=0;i<n;i++) {
    66           Console.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}\t{5}",
    67             xs[i], ys[i], ys_smoothed[i], ys_noise[i], ys_smoothed[i] + 1.96 * se[i], ys_smoothed[i] - 1.96 * se[i]);
    68         }
     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]);
    6946      }
    7047    }
Note: See TracChangeset for help on using the changeset viewer.