Free cookie consent management tool by TermsFeed Policy Generator

Changeset 14373


Ignore:
Timestamp:
11/05/16 09:06:31 (7 years ago)
Author:
gkronber
Message:

#745:

  • using a line chart (IndexedDataTable) instead of a scatter plot
  • added number of variables (non-zero coefficients) to the line chart
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Algorithms.DataAnalysis.Glmnet/3.4/ElasticNetLinearRegression.cs

    r14370 r14373  
    140140      var dataRows = new DataRow[nCoeff];
    141141      var allowedVars = Problem.ProblemData.AllowedInputVariables.ToArray();
     142      var numNonZeroCoeffs = new int[nLambdas];
    142143      for (int i = 0; i < nCoeff; i++) {
    143144        var coeffId = allowedVars[i];
     
    147148        coeffTable.Rows.Add(dataRows[i]);
    148149      }
     150      for (int i = 0; i < coeff.GetLength(0); i++) {
     151        for (int j = 0; j < coeff.GetLength(1); j++) {
     152          if (!coeff[i, j].IsAlmost(0.0)) {
     153            numNonZeroCoeffs[i]++;
     154          }
     155        }
     156      }
    149157
    150158      Results.Add(new Result(coeffTable.Name, coeffTable.Description, coeffTable));
    151159
    152       var nmsePlot = new ScatterPlot("NMSE", "Path of NMSE values over different lambda values");
     160      var nmsePlot = new IndexedDataTable<double>("NMSE", "Path of NMSE values over different lambda values");
    153161      nmsePlot.VisualProperties.YAxisMaximumAuto = false;
    154162      nmsePlot.VisualProperties.YAxisMinimumAuto = false;
     
    158166      nmsePlot.VisualProperties.YAxisMinimumFixedValue = 0;
    159167      nmsePlot.VisualProperties.YAxisMaximumFixedValue = 1.0;
     168      nmsePlot.VisualProperties.XAxisLogScale = true;
    160169      nmsePlot.VisualProperties.XAxisTitle = "Log10(Lambda)";
    161170      nmsePlot.VisualProperties.YAxisTitle = "Normalized mean of squared errors (NMSE)";
    162       nmsePlot.Rows.Add(new ScatterPlotDataRow("NMSE (train)", "Path of NMSE values over different lambda values", lambda.Zip(trainNMSE, (l, v) => new Point2D<double>(Math.Log10(l), v))));
    163       nmsePlot.Rows.Add(new ScatterPlotDataRow("NMSE (test)", "Path of NMSE values over different lambda values", lambda.Zip(testNMSE, (l, v) => new Point2D<double>(Math.Log10(l), v))));
     171      nmsePlot.VisualProperties.SecondYAxisTitle= "Number of variables";
     172      nmsePlot.Rows.Add(new IndexedDataRow<double>("NMSE (train)", "Path of NMSE values over different lambda values", lambda.Zip(trainNMSE, (l, v) => Tuple.Create(l, v))));
     173      nmsePlot.Rows.Add(new IndexedDataRow<double>("NMSE (test)", "Path of NMSE values over different lambda values", lambda.Zip(testNMSE, (l, v) => Tuple.Create(l, v))));
     174      nmsePlot.Rows.Add(new IndexedDataRow<double>("Number of variables", "The number of non-zero coefficients for each step in the path", lambda.Zip(numNonZeroCoeffs, (l, v) => Tuple.Create(l, (double)v))));
    164175      if (lambda.Length > 2) {
    165         nmsePlot.VisualProperties.XAxisMinimumFixedValue = Math.Floor(Math.Log10(lambda.Last()));
    166         nmsePlot.VisualProperties.XAxisMaximumFixedValue = Math.Ceiling(Math.Log10(lambda.Skip(1).First()));
    167       }
    168       nmsePlot.Rows["NMSE (train)"].VisualProperties.PointSize = 5;
    169       nmsePlot.Rows["NMSE (test)"].VisualProperties.PointSize = 5;
     176        nmsePlot.VisualProperties.XAxisMinimumFixedValue = Math.Pow(10, Math.Floor(Math.Log10(lambda.Last())));
     177        nmsePlot.VisualProperties.XAxisMaximumFixedValue = Math.Pow(10, Math.Ceiling(Math.Log10(lambda.Skip(1).First())));
     178      }
     179      nmsePlot.Rows["NMSE (train)"].VisualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Points;
     180      nmsePlot.Rows["NMSE (test)"].VisualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Points;
     181      nmsePlot.Rows["Number of variables"].VisualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Points;
     182      nmsePlot.Rows["Number of variables"].VisualProperties.SecondYAxis = true;
     183
    170184
    171185      Results.Add(new Result(nmsePlot.Name, nmsePlot.Description, nmsePlot));
Note: See TracChangeset for help on using the changeset viewer.