Free cookie consent management tool by TermsFeed Policy Generator

Changeset 11923


Ignore:
Timestamp:
02/05/15 18:51:07 (9 years ago)
Author:
mkommend
Message:

#2098: Merged r11523, r11524, r11525, r11541, r11827 and r11828 into stable.

Location:
stable
Files:
9 edited
1 copied

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Problems.DataAnalysis.Symbolic

  • stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views

  • stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views-3.4.csproj

    r11920 r11923  
    9999  </PropertyGroup>
    100100  <ItemGroup>
     101    <Reference Include="EPPlus-3.1.3, Version=3.1.3.0, Culture=neutral, PublicKeyToken=ea159fdaa78159a1, processorArchitecture=MSIL">
     102      <SpecificVersion>False</SpecificVersion>
     103      <HintPath>..\..\bin\EPPlus-3.1.3.dll</HintPath>
     104      <Private>False</Private>
     105    </Reference>
    101106    <Reference Include="System" />
    102107    <Reference Include="System.Core">
     
    122127      <DependentUpon>InteractiveSymbolicClassificationSolutionSimplifierView.cs</DependentUpon>
    123128    </Compile>
     129    <Compile Include="SymbolicDiscriminantFunctionClassificationSolutionExcelExporter.cs" />
    124130    <Compile Include="SymbolicClassificationSolutionView.cs">
    125131      <SubType>UserControl</SubType>
  • stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views/3.4/Plugin.cs.frame

    r11173 r11923  
    3232  [PluginDependency("HeuristicLab.Core", "3.3")]
    3333  [PluginDependency("HeuristicLab.Core.Views", "3.3")]
     34  [PluginDependency("HeuristicLab.Data", "3.3")]
    3435  [PluginDependency("HeuristicLab.Encodings.SymbolicExpressionTreeEncoding", "3.4")]
     36  [PluginDependency("HeuristicLab.EPPlus", "3.1")]
    3537  [PluginDependency("HeuristicLab.MainForm", "3.3")]
    3638  [PluginDependency("HeuristicLab.MainForm.WindowsForms", "3.3")]
  • stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views/3.4/SymbolicDiscriminantFunctionClassificationSolutionExcelExporter.cs

    r11525 r11923  
    66using HeuristicLab.Problems.DataAnalysis.Symbolic.Views;
    77using OfficeOpenXml;
     8using OfficeOpenXml.Drawing.Chart;
    89
    910namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views {
    1011  public class SymbolicDiscriminantFunctionClassificationSolutionExcelExporter : SymbolicSolutionExcelExporter {
    11     protected override void ExportChart(string fileName, ISymbolicDataAnalysisSolution solution, string formula) {
    12       ExportChart(fileName, solution as ISymbolicClassificationSolution, formula);
    13     }
    14 
    15     private void ExportChart(string fileName, ISymbolicClassificationSolution solution, string formula) {
     12    public override void Export(IDataAnalysisSolution solution, string fileName) {
     13      var symbDiscriminantSolution = solution as SymbolicDiscriminantFunctionClassificationSolution;
     14      if (symbDiscriminantSolution == null) throw new NotSupportedException("This solution cannot be exported to Excel");
     15      var formatter = new SymbolicDataAnalysisExpressionExcelFormatter();
     16      var formula = formatter.Format(symbDiscriminantSolution.Model.SymbolicExpressionTree, solution.ProblemData.Dataset);
     17      ExportChart(fileName, symbDiscriminantSolution, formula);
     18    }
     19
     20    private void ExportChart(string fileName, SymbolicDiscriminantFunctionClassificationSolution solution, string formula) {
    1621      FileInfo newFile = new FileInfo(fileName);
    1722      if (newFile.Exists) {
     
    3540
    3641        ExcelWorksheet chartsWorksheet = package.Workbook.Worksheets.Add("Charts");
    37         AddCharts(chartsWorksheet);
     42        AddCharts(chartsWorksheet, solution);
    3843        package.Workbook.Properties.Title = "Excel Export";
    3944        package.Workbook.Properties.Author = "HEAL";
     
    4247        package.Save();
    4348      }
    44     }
    45 
    46     protected void WriteEstimatedWorksheet(ExcelWorksheet estimatedWorksheet, ExcelWorksheet datasetWorksheet, string[] formulaParts, ISymbolicDataAnalysisSolution solution) {
    47       WriteEstimatedWorksheet(estimatedWorksheet, datasetWorksheet, formulaParts, solution as SymbolicDiscriminantFunctionClassificationSolution);
    48     }
    49 
    50     protected override void FormatModelSheet(ExcelWorksheet modelWorksheet, ISymbolicDataAnalysisSolution solution, IEnumerable<string> formulaParts) {
    51       FormatModelSheet(modelWorksheet, solution as SymbolicDiscriminantFunctionClassificationSolution, formulaParts);
    5249    }
    5350
     
    180177      estimatedWorksheet.Cells[1, 3].Value = "Estimated Values"; // C
    181178      estimatedWorksheet.Cells[1, 4].Value = "Estimated Class Values"; // D
    182       estimatedWorksheet.Cells[1, 6].Value = "Error"; // E
     179      estimatedWorksheet.Cells[1, 6].Value = "Error"; // F
    183180      estimatedWorksheet.Cells[1, 7].Value = "Squared Error"; // G
    184181      estimatedWorksheet.Cells[1, 9].Value = "Unbounded Estimated Values"; // I
    185182      estimatedWorksheet.Cells[1, 10].Value = "Bounded Estimated Values"; // J
    186 
    187       estimatedWorksheet.Cells[1, 1, 1, 10].AutoFitColumns();
     183      estimatedWorksheet.Cells[1, 11].Value = "Random Key"; // K
    188184
    189185      var thresholds = solution.Model.Thresholds.Where(x => !double.IsInfinity(x)).ToList();
    190186      var thresholdsFormula = GenerateThresholdsFormula(thresholds);
     187
     188      const int columnIndex = 13; // index of beginning columns for class values
     189      for (int i = 0; i <= thresholds.Count; ++i) {
     190        estimatedWorksheet.Cells[1, i + columnIndex].Value = "Class " + i;
     191        if (i < thresholds.Count)
     192          estimatedWorksheet.Cells[1, i + columnIndex + thresholds.Count + 1].Value = "Threshold " + i;
     193      }
     194      estimatedWorksheet.Cells[1, 1, 1, 10].AutoFitColumns();
    191195
    192196      int targetIndex = solution.ProblemData.Dataset.VariableNames.ToList().FindIndex(x => x.Equals(solution.ProblemData.TargetVariable)) + 1;
     
    195199        estimatedWorksheet.Cells[i + 2, 2].Formula = datasetWorksheet.Cells[i + 2, targetIndex].FullAddress; // target values
    196200        estimatedWorksheet.Cells[i + 2, 9].Formula = string.Format(preparedFormula, i + 2); // formula (estimated) values
     201
     202        string condition = string.Empty;
     203        string rowRef = "C" + (i + 2);
     204
     205        int nClasses = thresholds.Count + 1;
     206        for (int j = columnIndex; j < columnIndex + nClasses; ++j) {
     207          int idx = j - columnIndex + 5; // row index for the threshold values
     208          if (j == columnIndex) {
     209            condition = rowRef + " < Model!$B$" + idx;
     210          } else if (j > columnIndex && j < columnIndex + thresholds.Count) {
     211            condition = "AND(" + rowRef + "> Model!$B$" + (idx - 1) + ", " + rowRef + " < Model!$B$" + idx + ")";
     212          } else if (j == columnIndex + thresholds.Count) {
     213            condition = rowRef + " > Model!$B$" + (idx - 1);
     214          }
     215          estimatedWorksheet.Cells[i + 2, j].Formula = "IF(" + condition + ", " + rowRef + ", #N/A)";
     216
     217          if (j < columnIndex + thresholds.Count)
     218            estimatedWorksheet.Cells[i + 2, j + nClasses].Formula = "Model!$B$" + idx;
     219        }
    197220      }
    198221      estimatedWorksheet.Cells["B2:B" + (rows + 1)].Style.Numberformat.Format = "0.000";
     
    204227      estimatedWorksheet.Cells["D2:D" + (rows + 1)].Style.Numberformat.Format = "0.0";
    205228
    206       estimatedWorksheet.Cells["F2:F" + (rows + 1)].Formula = "B2 - D2";
     229      estimatedWorksheet.Cells["F2:F" + (rows + 1)].Formula = "B2 - C2";
    207230      estimatedWorksheet.Cells["F2:F" + (rows + 1)].Style.Numberformat.Format = "0.0";
    208231
     
    213236      estimatedWorksheet.Cells["J2:J" + (rows + 1)].Formula = "IFERROR(IF(I2 > Model!EstimationLimitUpper, Model!EstimationLimitUpper, IF(I2 < Model!EstimationLimitLower, Model!EstimationLimitLower, I2)), AVERAGE(Model!EstimationLimitLower, Model!EstimationLimitUpper))";
    214237      estimatedWorksheet.Cells["J2:J" + (rows + 1)].Style.Numberformat.Format = "0.000";
     238
     239      estimatedWorksheet.Cells["K2:K" + (rows + 1)].Formula = "RAND()";
     240      estimatedWorksheet.Cells["K2:K" + (rows + 1)].Style.Numberformat.Format = "0.000";
     241    }
     242
     243    private void AddCharts(ExcelWorksheet chartsWorksheet, DiscriminantFunctionClassificationSolution solution) {
     244      List<char> columns = new List<char> { 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };
     245      var scatterPlot = chartsWorksheet.Drawings.AddChart("scatterPlot", eChartType.XYScatter);
     246      scatterPlot.SetSize(800, 400);
     247      scatterPlot.SetPosition(0, 0);
     248      scatterPlot.Title.Text = "Scatter Plot";
     249      var thresholds = solution.Model.Thresholds.Where(x => !double.IsInfinity(x)).ToList();
     250      chartsWorksheet.Names.AddFormula("XKey", "OFFSET('Estimated Values'!$K$1,1,0, COUNTA('Estimated Values'!$K:$K)-1)");
     251
     252      for (int i = 0; i <= thresholds.Count; ++i) {
     253        string header = "Class" + i;
     254        chartsWorksheet.Names.AddFormula(header, String.Format("OFFSET('Estimated Values'!${0}$1, 1, 0, COUNTA('Estimated Values'!${0}:${0})-1)", columns[i]));
     255        var series = scatterPlot.Series.Add(header, "XKey");
     256        series.Header = header;
     257
     258        if (i < thresholds.Count) {
     259          chartsWorksheet.Names.AddFormula("Threshold" + i, String.Format("OFFSET('Estimated Values'!${0}$1, 1, 0, COUNTA('Estimated Values'!${0}:${0})-1)", columns[i + thresholds.Count + 1]));
     260          var s = scatterPlot.Series.Add("Threshold" + i, "XKey");
     261          s.Header = "Threshold" + i;
     262        }
     263      }
    215264    }
    216265
    217266    // this method assumes that the thresholds list is sorted in ascending order
    218     private string GenerateThresholdsFormula(List<double> thresholds) {
     267    private static string GenerateThresholdsFormula(List<double> thresholds) {
    219268      if (thresholds.Count == 1) {
    220269        return String.Format("IF(J2 < {0}, 0, 1)", thresholds[0]);
  • stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views/3.4/SymbolicDiscriminantFunctionClassificationSolutionView.cs

    r11170 r11923  
    2525using System.Windows.Forms;
    2626using HeuristicLab.MainForm;
    27 using HeuristicLab.Problems.DataAnalysis.Symbolic.Views;
    2827using HeuristicLab.Problems.DataAnalysis.Views;
    2928
     
    5453
    5554    private void exportButton_Click(object sender, EventArgs e) {
    56       var exporter = new SymbolicSolutionExcelExporter();
     55      var exporter = new SymbolicDiscriminantFunctionClassificationSolutionExcelExporter();
    5756      exportFileDialog.Filter = exporter.FileTypeFilter;
    5857      if (exportFileDialog.ShowDialog(this) == DialogResult.OK) {
  • stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Views

  • stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/Exporters/SymbolicSolutionExcelExporter.cs

    r11170 r11923  
    3030namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views {
    3131  public class SymbolicSolutionExcelExporter : IDataAnalysisSolutionExporter {
    32     private const string TRAININGSTART = "TrainingStart";
    33     private const string TRAININGEND = "TrainingEnd";
    34     private const string TESTSTART = "TestStart";
    35     private const string TESTEND = "TestEnd";
     32    protected const string TRAININGSTART = "TrainingStart";
     33    protected const string TRAININGEND = "TrainingEnd";
     34    protected const string TESTSTART = "TestStart";
     35    protected const string TESTEND = "TestEnd";
    3636
    3737
     
    4444    }
    4545
    46     public void Export(IDataAnalysisSolution solution, string fileName) {
     46    public virtual void Export(IDataAnalysisSolution solution, string fileName) {
    4747      var symbSolution = solution as ISymbolicDataAnalysisSolution;
    4848      if (symbSolution == null) throw new NotSupportedException("This solution cannot be exported to Excel");
     
    216216    }
    217217
    218     private string Indirect(string column, bool training) {
     218    protected string Indirect(string column, bool training) {
    219219      if (training) {
    220220        return string.Format("INDIRECT(\"'Estimated Values'!{0}\"&{1}+2&\":{0}\"&{2}+1)", column, TRAININGSTART, TRAININGEND);
     
    260260    }
    261261
    262     private void AddModelTreePicture(ExcelWorksheet modelWorksheet, ISymbolicDataAnalysisModel model) {
     262    protected void AddModelTreePicture(ExcelWorksheet modelWorksheet, ISymbolicDataAnalysisModel model) {
    263263      SymbolicExpressionTreeChart modelTreePicture = new SymbolicExpressionTreeChart();
    264264      modelTreePicture.Tree = model.SymbolicExpressionTree;
     
    289289      estimatedWorksheet.Cells[1, 1, 1, 10].AutoFitColumns();
    290290
     291      // fill in id, target variable and unbounded estimated values
    291292      int targetIndex = solution.ProblemData.Dataset.VariableNames.ToList().FindIndex(x => x.Equals(solution.ProblemData.TargetVariable)) + 1;
    292293      for (int i = 0; i < rows; i++) {
    293         estimatedWorksheet.Cells[i + 2, 1].Value = i;
    294         estimatedWorksheet.Cells[i + 2, 2].Formula = datasetWorksheet.Cells[i + 2, targetIndex].FullAddress;
    295         estimatedWorksheet.Cells[i + 2, 9].Formula = string.Format(preparedFormula, i + 2);
     294        estimatedWorksheet.Cells[i + 2, 1].Value = i; // id
     295        estimatedWorksheet.Cells[i + 2, 2].Formula = datasetWorksheet.Cells[i + 2, targetIndex].FullAddress; // target variable
     296        estimatedWorksheet.Cells[i + 2, 9].Formula = string.Format(preparedFormula, i + 2); // unbounded estimated values
    296297      }
    297298      estimatedWorksheet.Cells["B2:B" + (rows + 1)].Style.Numberformat.Format = "0.000";
     
    313314    }
    314315
    315     private string PrepareFormula(string[] formulaParts) {
     316    protected string PrepareFormula(string[] formulaParts) {
    316317      string preparedFormula = formulaParts[0];
    317318      foreach (var part in formulaParts.Skip(2)) {
     
    323324    }
    324325
    325     private void WriteInputSheet(ExcelWorksheet inputsWorksheet, ExcelWorksheet datasetWorksheet, IEnumerable<string> list, Dataset dataset) {
     326    protected void WriteInputSheet(ExcelWorksheet inputsWorksheet, ExcelWorksheet datasetWorksheet, IEnumerable<string> list, Dataset dataset) {
    326327      //remark the performance of EPPlus drops dramatically
    327328      //if the data is not written row wise (from left to right) due the internal indices used.
     
    337338    }
    338339
    339     private void WriteDatasetToExcel(ExcelWorksheet datasetWorksheet, IDataAnalysisProblemData problemData) {
     340    protected void WriteDatasetToExcel(ExcelWorksheet datasetWorksheet, IDataAnalysisProblemData problemData) {
    340341      //remark the performance of EPPlus drops dramatically
    341342      //if the data is not written row wise (from left to right) due the internal indices used.
  • stable/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionExcelFormatter.cs

    r11170 r11923  
    203203        stringBuilder.Append(FormatRecursively(node.GetSubtree(1)));
    204204        stringBuilder.Append(",0))");
     205      } else if (symbol is IfThenElse) {
     206        stringBuilder.Append("IF(");
     207        stringBuilder.Append("(" + FormatRecursively(node.GetSubtree(0)) + " ) > 0");
     208        stringBuilder.Append(",");
     209        stringBuilder.Append(FormatRecursively(node.GetSubtree(1)));
     210        stringBuilder.Append(",");
     211        stringBuilder.Append(FormatRecursively(node.GetSubtree(2)));
     212        stringBuilder.Append(")");
     213      } else if (symbol is VariableCondition) {
     214        VariableConditionTreeNode variableConditionTreeNode = node as VariableConditionTreeNode;
     215        double threshold = variableConditionTreeNode.Threshold;
     216        double slope = variableConditionTreeNode.Slope;
     217        string p = "(1 / (1 + EXP(-" + slope.ToString(CultureInfo.InvariantCulture) + " * (" + GetColumnToVariableName(variableConditionTreeNode.VariableName) + "-" + threshold.ToString(CultureInfo.InvariantCulture) + "))))";
     218        stringBuilder.Append("((");
     219        stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
     220        stringBuilder.Append("*");
     221        stringBuilder.Append(p);
     222        stringBuilder.Append(") + (");
     223        stringBuilder.Append(FormatRecursively(node.GetSubtree(1)));
     224        stringBuilder.Append("*(");
     225        stringBuilder.Append("1 - " + p + ")");
     226        stringBuilder.Append("))");
     227      } else if (symbol is Xor) {
     228        stringBuilder.Append("IF(");
     229        stringBuilder.Append("XOR(");
     230        stringBuilder.Append("(" + FormatRecursively(node.GetSubtree(0)) + ") > 0,");
     231        stringBuilder.Append("(" + FormatRecursively(node.GetSubtree(1)) + ") > 0");
     232        stringBuilder.Append("), 1.0, -1.0)");
     233      } else if (symbol is Or) {
     234        stringBuilder.Append("IF(");
     235        stringBuilder.Append("OR(");
     236        stringBuilder.Append("(" + FormatRecursively(node.GetSubtree(0)) + ") > 0,");
     237        stringBuilder.Append("(" + FormatRecursively(node.GetSubtree(1)) + ") > 0");
     238        stringBuilder.Append("), 1.0, -1.0)");
     239      } else if (symbol is And) {
     240        stringBuilder.Append("IF(");
     241        stringBuilder.Append("AND(");
     242        stringBuilder.Append("(" + FormatRecursively(node.GetSubtree(0)) + ") > 0,");
     243        stringBuilder.Append("(" + FormatRecursively(node.GetSubtree(1)) + ") > 0");
     244        stringBuilder.Append("), 1.0, -1.0)");
     245      } else if (symbol is Not) {
     246        stringBuilder.Append("IF(");
     247        stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
     248        stringBuilder.Append(" > 0, -1.0, 1.0)");
     249      } else if (symbol is GreaterThan) {
     250        stringBuilder.Append("IF((");
     251        stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
     252        stringBuilder.Append(") > (");
     253        stringBuilder.Append(FormatRecursively(node.GetSubtree(1)));
     254        stringBuilder.Append("), 1.0, -1.0)");
     255      } else if (symbol is LessThan) {
     256        stringBuilder.Append("IF((");
     257        stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
     258        stringBuilder.Append(") < (");
     259        stringBuilder.Append(FormatRecursively(node.GetSubtree(1)));
     260        stringBuilder.Append("), 1.0, -1.0)");
    205261      } else {
    206262        throw new NotImplementedException("Excel export of " + node.Symbol + " is not implemented.");
Note: See TracChangeset for help on using the changeset viewer.