- Timestamp:
- 02/05/15 18:51:07 (10 years ago)
- Location:
- stable
- Files:
-
- 9 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk/sources merged: 11523-11525,11541,11827-11828
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.DataAnalysis.Symbolic
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic merged: 11523,11827
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views merged: 11523-11525,11541,11828
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views-3.4.csproj
r11920 r11923 99 99 </PropertyGroup> 100 100 <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> 101 106 <Reference Include="System" /> 102 107 <Reference Include="System.Core"> … … 122 127 <DependentUpon>InteractiveSymbolicClassificationSolutionSimplifierView.cs</DependentUpon> 123 128 </Compile> 129 <Compile Include="SymbolicDiscriminantFunctionClassificationSolutionExcelExporter.cs" /> 124 130 <Compile Include="SymbolicClassificationSolutionView.cs"> 125 131 <SubType>UserControl</SubType> -
stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views/3.4/Plugin.cs.frame
r11173 r11923 32 32 [PluginDependency("HeuristicLab.Core", "3.3")] 33 33 [PluginDependency("HeuristicLab.Core.Views", "3.3")] 34 [PluginDependency("HeuristicLab.Data", "3.3")] 34 35 [PluginDependency("HeuristicLab.Encodings.SymbolicExpressionTreeEncoding", "3.4")] 36 [PluginDependency("HeuristicLab.EPPlus", "3.1")] 35 37 [PluginDependency("HeuristicLab.MainForm", "3.3")] 36 38 [PluginDependency("HeuristicLab.MainForm.WindowsForms", "3.3")] -
stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views/3.4/SymbolicDiscriminantFunctionClassificationSolutionExcelExporter.cs
r11525 r11923 6 6 using HeuristicLab.Problems.DataAnalysis.Symbolic.Views; 7 7 using OfficeOpenXml; 8 using OfficeOpenXml.Drawing.Chart; 8 9 9 10 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views { 10 11 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) { 16 21 FileInfo newFile = new FileInfo(fileName); 17 22 if (newFile.Exists) { … … 35 40 36 41 ExcelWorksheet chartsWorksheet = package.Workbook.Worksheets.Add("Charts"); 37 AddCharts(chartsWorksheet );42 AddCharts(chartsWorksheet, solution); 38 43 package.Workbook.Properties.Title = "Excel Export"; 39 44 package.Workbook.Properties.Author = "HEAL"; … … 42 47 package.Save(); 43 48 } 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);52 49 } 53 50 … … 180 177 estimatedWorksheet.Cells[1, 3].Value = "Estimated Values"; // C 181 178 estimatedWorksheet.Cells[1, 4].Value = "Estimated Class Values"; // D 182 estimatedWorksheet.Cells[1, 6].Value = "Error"; // E179 estimatedWorksheet.Cells[1, 6].Value = "Error"; // F 183 180 estimatedWorksheet.Cells[1, 7].Value = "Squared Error"; // G 184 181 estimatedWorksheet.Cells[1, 9].Value = "Unbounded Estimated Values"; // I 185 182 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 188 184 189 185 var thresholds = solution.Model.Thresholds.Where(x => !double.IsInfinity(x)).ToList(); 190 186 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(); 191 195 192 196 int targetIndex = solution.ProblemData.Dataset.VariableNames.ToList().FindIndex(x => x.Equals(solution.ProblemData.TargetVariable)) + 1; … … 195 199 estimatedWorksheet.Cells[i + 2, 2].Formula = datasetWorksheet.Cells[i + 2, targetIndex].FullAddress; // target values 196 200 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 } 197 220 } 198 221 estimatedWorksheet.Cells["B2:B" + (rows + 1)].Style.Numberformat.Format = "0.000"; … … 204 227 estimatedWorksheet.Cells["D2:D" + (rows + 1)].Style.Numberformat.Format = "0.0"; 205 228 206 estimatedWorksheet.Cells["F2:F" + (rows + 1)].Formula = "B2 - D2";229 estimatedWorksheet.Cells["F2:F" + (rows + 1)].Formula = "B2 - C2"; 207 230 estimatedWorksheet.Cells["F2:F" + (rows + 1)].Style.Numberformat.Format = "0.0"; 208 231 … … 213 236 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))"; 214 237 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 } 215 264 } 216 265 217 266 // this method assumes that the thresholds list is sorted in ascending order 218 private st ring GenerateThresholdsFormula(List<double> thresholds) {267 private static string GenerateThresholdsFormula(List<double> thresholds) { 219 268 if (thresholds.Count == 1) { 220 269 return String.Format("IF(J2 < {0}, 0, 1)", thresholds[0]); -
stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views/3.4/SymbolicDiscriminantFunctionClassificationSolutionView.cs
r11170 r11923 25 25 using System.Windows.Forms; 26 26 using HeuristicLab.MainForm; 27 using HeuristicLab.Problems.DataAnalysis.Symbolic.Views;28 27 using HeuristicLab.Problems.DataAnalysis.Views; 29 28 … … 54 53 55 54 private void exportButton_Click(object sender, EventArgs e) { 56 var exporter = new Symbolic SolutionExcelExporter();55 var exporter = new SymbolicDiscriminantFunctionClassificationSolutionExcelExporter(); 57 56 exportFileDialog.Filter = exporter.FileTypeFilter; 58 57 if (exportFileDialog.ShowDialog(this) == DialogResult.OK) { -
stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Views
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Views merged: 11523,11541
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/Exporters/SymbolicSolutionExcelExporter.cs
r11170 r11923 30 30 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views { 31 31 public class SymbolicSolutionExcelExporter : IDataAnalysisSolutionExporter { 32 pr ivateconst string TRAININGSTART = "TrainingStart";33 pr ivateconst string TRAININGEND = "TrainingEnd";34 pr ivateconst string TESTSTART = "TestStart";35 pr ivateconst 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"; 36 36 37 37 … … 44 44 } 45 45 46 public v oid Export(IDataAnalysisSolution solution, string fileName) {46 public virtual void Export(IDataAnalysisSolution solution, string fileName) { 47 47 var symbSolution = solution as ISymbolicDataAnalysisSolution; 48 48 if (symbSolution == null) throw new NotSupportedException("This solution cannot be exported to Excel"); … … 216 216 } 217 217 218 pr ivatestring Indirect(string column, bool training) {218 protected string Indirect(string column, bool training) { 219 219 if (training) { 220 220 return string.Format("INDIRECT(\"'Estimated Values'!{0}\"&{1}+2&\":{0}\"&{2}+1)", column, TRAININGSTART, TRAININGEND); … … 260 260 } 261 261 262 pr ivatevoid AddModelTreePicture(ExcelWorksheet modelWorksheet, ISymbolicDataAnalysisModel model) {262 protected void AddModelTreePicture(ExcelWorksheet modelWorksheet, ISymbolicDataAnalysisModel model) { 263 263 SymbolicExpressionTreeChart modelTreePicture = new SymbolicExpressionTreeChart(); 264 264 modelTreePicture.Tree = model.SymbolicExpressionTree; … … 289 289 estimatedWorksheet.Cells[1, 1, 1, 10].AutoFitColumns(); 290 290 291 // fill in id, target variable and unbounded estimated values 291 292 int targetIndex = solution.ProblemData.Dataset.VariableNames.ToList().FindIndex(x => x.Equals(solution.ProblemData.TargetVariable)) + 1; 292 293 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 296 297 } 297 298 estimatedWorksheet.Cells["B2:B" + (rows + 1)].Style.Numberformat.Format = "0.000"; … … 313 314 } 314 315 315 pr ivatestring PrepareFormula(string[] formulaParts) {316 protected string PrepareFormula(string[] formulaParts) { 316 317 string preparedFormula = formulaParts[0]; 317 318 foreach (var part in formulaParts.Skip(2)) { … … 323 324 } 324 325 325 pr ivatevoid WriteInputSheet(ExcelWorksheet inputsWorksheet, ExcelWorksheet datasetWorksheet, IEnumerable<string> list, Dataset dataset) {326 protected void WriteInputSheet(ExcelWorksheet inputsWorksheet, ExcelWorksheet datasetWorksheet, IEnumerable<string> list, Dataset dataset) { 326 327 //remark the performance of EPPlus drops dramatically 327 328 //if the data is not written row wise (from left to right) due the internal indices used. … … 337 338 } 338 339 339 pr ivatevoid WriteDatasetToExcel(ExcelWorksheet datasetWorksheet, IDataAnalysisProblemData problemData) {340 protected void WriteDatasetToExcel(ExcelWorksheet datasetWorksheet, IDataAnalysisProblemData problemData) { 340 341 //remark the performance of EPPlus drops dramatically 341 342 //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 203 203 stringBuilder.Append(FormatRecursively(node.GetSubtree(1))); 204 204 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)"); 205 261 } else { 206 262 throw new NotImplementedException("Excel export of " + node.Symbol + " is not implemented.");
Note: See TracChangeset
for help on using the changeset viewer.