- Timestamp:
- 08/19/11 11:12:25 (13 years ago)
- Location:
- trunk/sources
- Files:
-
- 7 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/ClassificationEnsembleSolutionEstimatedClassValuesView.Designer.cs
r6661 r6672 20 20 #endregion 21 21 namespace HeuristicLab.Problems.DataAnalysis.Views { 22 partial class DiscriminantFunctionClassificationSolutionEstimatedClassValuesView {22 partial class ClassificationEnsembleSolutionEstimatedClassValuesView { 23 23 /// <summary> 24 24 /// Required designer variable. … … 44 44 /// </summary> 45 45 private void InitializeComponent() { 46 this.problemView1 = new HeuristicLab.Optimization.Views.ProblemView(); 47 this.SamplesComboBox = new System.Windows.Forms.ComboBox(); 46 48 this.SuspendLayout(); 47 49 // 48 // EstimatedValuesView50 // matrixView 49 51 // 50 this.AllowDrop = true; 52 this.matrixView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 53 | System.Windows.Forms.AnchorStyles.Left) 54 | System.Windows.Forms.AnchorStyles.Right))); 55 this.matrixView.Dock = System.Windows.Forms.DockStyle.None; 56 this.matrixView.Location = new System.Drawing.Point(3, 31); 57 this.matrixView.Size = new System.Drawing.Size(304, 251); 58 // 59 // problemView1 60 // 61 this.problemView1.Caption = "Problem View"; 62 this.problemView1.Content = null; 63 this.problemView1.Location = new System.Drawing.Point(1147, 687); 64 this.problemView1.Name = "problemView1"; 65 this.problemView1.ReadOnly = false; 66 this.problemView1.Size = new System.Drawing.Size(490, 353); 67 this.problemView1.TabIndex = 1; 68 // 69 // SamplesComboBox 70 // 71 this.SamplesComboBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 72 | System.Windows.Forms.AnchorStyles.Right))); 73 this.SamplesComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; 74 this.SamplesComboBox.FormattingEnabled = true; 75 this.SamplesComboBox.Location = new System.Drawing.Point(4, 4); 76 this.SamplesComboBox.Name = "SamplesComboBox"; 77 this.SamplesComboBox.Size = new System.Drawing.Size(303, 21); 78 this.SamplesComboBox.TabIndex = 2; 79 this.SamplesComboBox.SelectedIndexChanged += new System.EventHandler(this.SamplesComboBox_SelectedIndexChanged); 80 // 81 // ClassificationEnsembleSolutionEstimatedClassValuesView 82 // 51 83 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 52 84 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 53 this.Name = "EstimatedValuesView"; 54 this.Size = new System.Drawing.Size(310, 285); 85 this.Controls.Add(this.SamplesComboBox); 86 this.Controls.Add(this.problemView1); 87 this.Name = "ClassificationEnsembleSolutionEstimatedClassValuesView"; 88 this.Controls.SetChildIndex(this.matrixView, 0); 89 this.Controls.SetChildIndex(this.problemView1, 0); 90 this.Controls.SetChildIndex(this.SamplesComboBox, 0); 55 91 this.ResumeLayout(false); 56 92 … … 59 95 #endregion 60 96 97 private Optimization.Views.ProblemView problemView1; 98 private System.Windows.Forms.ComboBox SamplesComboBox; 99 61 100 } 62 101 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/ClassificationEnsembleSolutionEstimatedClassValuesView.cs
r6661 r6672 20 20 #endregion 21 21 using System; 22 using System.Collections.Generic; 22 23 using System.Linq; 23 24 using System.Windows.Forms; … … 28 29 namespace HeuristicLab.Problems.DataAnalysis.Views { 29 30 [View("Estimated Class Values")] 30 [Content(typeof(IDiscriminantFunctionClassificationSolution))] 31 public partial class DiscriminantFunctionClassificationSolutionEstimatedClassValuesView : ClassificationSolutionEstimatedClassValuesView { 32 private const string TargetClassValuesSeriesname = "TargetVariable"; 33 private const string EstimatedClassValuesSeriesName = "EstimatedClassValues"; 34 private const string EstimatedValuesSeriesName = "EstimatedValues"; 31 [Content(typeof(ClassificationEnsembleSolution))] 32 public partial class ClassificationEnsembleSolutionEstimatedClassValuesView : 33 ClassificationSolutionEstimatedClassValuesView { 34 private const string RowColumnName = "Row"; 35 private const string TargetClassValuesColumnName = "TargetVariable"; 36 private const string EstimatedClassValuesColumnName = "EstimatedClassValues"; 37 private const string ConfidenceColumnName = "Confidence"; 35 38 36 public new IDiscriminantFunctionClassificationSolution Content { 37 get { return (IDiscriminantFunctionClassificationSolution)base.Content; } 39 private const string SamplesComboBoxAllSamples = "All Samples"; 40 private const string SamplesComboBoxTrainingSamples = "Training Samples"; 41 private const string SamplesComboBoxTestSamples = "Test Samples"; 42 43 public new ClassificationEnsembleSolution Content { 44 get { return (ClassificationEnsembleSolution)base.Content; } 38 45 set { base.Content = value; } 39 46 } 40 47 41 public DiscriminantFunctionClassificationSolutionEstimatedClassValuesView()48 public ClassificationEnsembleSolutionEstimatedClassValuesView() 42 49 : base() { 43 50 InitializeComponent(); 51 SamplesComboBox.Items.AddRange(new string[] { SamplesComboBoxAllSamples, SamplesComboBoxTrainingSamples, SamplesComboBoxTestSamples }); 52 SamplesComboBox.SelectedIndex = 0; 53 } 54 55 private void SamplesComboBox_SelectedIndexChanged(object sender, EventArgs e) { 56 UpdateEstimatedValues(); 44 57 } 45 58 46 59 protected override void UpdateEstimatedValues() { 47 if (InvokeRequired) Invoke((Action)UpdateEstimatedValues); 48 else { 49 StringMatrix matrix = null; 50 if (Content != null) { 51 string[,] values = new string[Content.ProblemData.Dataset.Rows, 4]; 60 if (InvokeRequired) { 61 Invoke((Action)UpdateEstimatedValues); 62 return; 63 } 64 if (Content == null) { 65 matrixView.Content = null; 66 return; 67 } 52 68 53 double[] target = Content.ProblemData.Dataset.GetVariableValues(Content.ProblemData.TargetVariable);54 double[] estimatedClassValues = Content.EstimatedClassValues.ToArray();55 double[] estimatedValues = Content.EstimatedValues.ToArray(); 56 for (int row = 0; row < target.Length; row++) {57 values[row, 0] = row.ToString();58 values[row, 1] = target[row].ToString();59 values[row, 2] = estimatedClassValues[row].ToString();60 values[row, 3] = estimatedValues[row].ToString();69 int[] indizes; 70 double[] estimatedClassValues; 71 72 switch (SamplesComboBox.SelectedItem.ToString()) { 73 case SamplesComboBoxAllSamples: { 74 indizes = Enumerable.Range(0, Content.ProblemData.Dataset.Rows).ToArray(); 75 estimatedClassValues = Content.EstimatedClassValues.ToArray(); 76 break; 61 77 } 78 case SamplesComboBoxTrainingSamples: { 79 indizes = Content.ProblemData.TrainingIndizes.ToArray(); 80 estimatedClassValues = Content.EstimatedTrainingClassValues.ToArray(); 81 break; 82 } 83 case SamplesComboBoxTestSamples: { 84 indizes = Content.ProblemData.TestIndizes.ToArray(); 85 estimatedClassValues = Content.EstimatedTestClassValues.ToArray(); 86 break; 87 } 88 default: 89 throw new ArgumentException(); 90 } 62 91 63 matrix = new StringMatrix(values); 64 matrix.ColumnNames = new string[] { "Id", TargetClassValuesSeriesname, EstimatedClassValuesSeriesName, EstimatedValuesSeriesName }; 65 matrix.SortableView = true; 92 int classValuesCount = Content.ProblemData.ClassValues.Count; 93 int modelCount = Content.Model.Models.Count(); 94 string[,] values = new string[indizes.Length, 4 + classValuesCount + modelCount]; 95 double[] target = Content.ProblemData.Dataset.GetVariableValues(Content.ProblemData.TargetVariable); 96 List<List<double?>> estimatedValuesVector = GetEstimatedValues(SamplesComboBox.SelectedItem.ToString(), indizes, 97 Content.ClassificationSolutions); 98 99 for (int i = 0; i < indizes.Length; i++) { 100 int row = indizes[i]; 101 values[i, 0] = row.ToString(); 102 values[i, 1] = target[i].ToString(); 103 values[i, 2] = estimatedClassValues[i].ToString(); 104 var groups = estimatedValuesVector[i].GroupBy(x => x).Select(g => new { Key = g.Key, Count = g.Count() }).ToList(); 105 var estimationCount = groups.Where(g => g.Key != null).Select(g => g.Count).Sum(); 106 values[i, 3] = (((double)groups.Where(g => g.Key == estimatedClassValues[i]).Single().Count) / estimationCount).ToString(); 107 for (int classIndex = 0; classIndex < Content.ProblemData.ClassValues.Count; classIndex++) { 108 var group = groups.Where(g => g.Key == Content.ProblemData.ClassValues[classIndex]).SingleOrDefault(); 109 if (group == null) values[i, 4 + classIndex] = 0.ToString(); 110 else values[i, 4 + classIndex] = group.Count.ToString(); 66 111 } 67 matrixView.Content = matrix; 112 for (int modelIndex = 0; modelIndex < estimatedValuesVector[i].Count; modelIndex++) { 113 values[i, 4 + classValuesCount + modelIndex] = estimatedValuesVector[i][modelIndex] == null 114 ? string.Empty 115 : estimatedValuesVector[i][modelIndex].ToString(); 116 } 117 68 118 } 119 120 StringMatrix matrix = new StringMatrix(values); 121 List<string> columnNames = new List<string>() { "Id", TargetClassValuesColumnName, EstimatedClassValuesColumnName, ConfidenceColumnName }; 122 columnNames.AddRange(Content.ProblemData.ClassNames); 123 columnNames.AddRange(Content.Model.Models.Select(m => m.Name)); 124 matrix.ColumnNames = columnNames; 125 matrix.SortableView = true; 126 matrixView.Content = matrix; 69 127 } 128 129 private List<List<double?>> GetEstimatedValues(string samplesSelection, int[] rows, IEnumerable<IClassificationSolution> solutions) { 130 List<List<double?>> values = new List<List<double?>>(); 131 int solutionIndex = 0; 132 foreach (var solution in solutions) { 133 double[] estimation = solution.GetEstimatedClassValues(rows).ToArray(); 134 for (int i = 0; i < rows.Length; i++) { 135 var row = rows[i]; 136 if (solutionIndex == 0) values.Add(new List<double?>()); 137 138 if (samplesSelection == SamplesComboBoxAllSamples) 139 values[i].Add(estimation[i]); 140 else if (samplesSelection == SamplesComboBoxTrainingSamples && solution.ProblemData.IsTrainingSample(row)) 141 values[i].Add(estimation[i]); 142 else if (samplesSelection == SamplesComboBoxTestSamples && solution.ProblemData.IsTestSample(row)) 143 values[i].Add(estimation[i]); 144 else 145 values[i].Add(null); 146 } 147 solutionIndex++; 148 } 149 return values; 150 } 151 152 153 70 154 } 71 155 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/HeuristicLab.Problems.DataAnalysis.Views-3.4.csproj
r6666 r6672 110 110 </ItemGroup> 111 111 <ItemGroup> 112 <Compile Include="Classification\ClassificationEnsembleSolutionEstimatedClassValuesView.cs"> 113 <SubType>UserControl</SubType> 114 </Compile> 115 <Compile Include="Classification\ClassificationEnsembleSolutionEstimatedClassValuesView.Designer.cs"> 116 <DependentUpon>ClassificationEnsembleSolutionEstimatedClassValuesView.cs</DependentUpon> 117 </Compile> 112 118 <Compile Include="Classification\ClassificationEnsembleSolutionModelView.cs"> 113 119 <SubType>UserControl</SubType> -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationEnsembleProblemData.cs
r6666 r6672 21 21 22 22 using System.Collections.Generic; 23 using System.Linq;24 23 using HeuristicLab.Common; 25 24 using HeuristicLab.Core; … … 33 32 public class ClassificationEnsembleProblemData : ClassificationProblemData { 34 33 35 public override IEnumerable<int> TrainingIndizes { 36 get { return Enumerable.Range(TrainingPartition.Start, TrainingPartition.End - TrainingPartition.Start); } 37 } 38 public override IEnumerable<int> TestIndizes { 39 get { return Enumerable.Range(TestPartition.Start, TestPartition.End - TestPartition.Start); } 34 public override bool IsTrainingSample(int index) { 35 return index >= 0 && index < Dataset.Rows && 36 TrainingPartition.Start <= index && index < TrainingPartition.End; 40 37 } 41 38 42 private static ClassificationEnsembleProblemData emptyProblemData; 39 public override bool IsTestSample(int index) { 40 return index >= 0 && index < Dataset.Rows && 41 TestPartition.Start <= index && index < TestPartition.End; 42 } 43 44 private static readonly ClassificationEnsembleProblemData emptyProblemData; 43 45 public static ClassificationEnsembleProblemData EmptyProblemData { 44 46 get { return emptyProblemData; } -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationProblemData.cs
r6666 r6672 171 171 {1176881,7,5,3,7,4,10,7,5,5,4 } 172 172 }; 173 private static Dataset defaultDataset;174 private static IEnumerable<string> defaultAllowedInputVariables;175 private static string defaultTargetVariable;176 177 private static ClassificationProblemData emptyProblemData;173 private static readonly Dataset defaultDataset; 174 private static readonly IEnumerable<string> defaultAllowedInputVariables; 175 private static readonly string defaultTargetVariable; 176 177 private static readonly ClassificationProblemData emptyProblemData; 178 178 public static ClassificationProblemData EmptyProblemData { 179 179 get { return EmptyProblemData; } -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/DataAnalysisProblemData.cs
r6666 r6672 78 78 get { 79 79 return Enumerable.Range(TrainingPartition.Start, TrainingPartition.End - TrainingPartition.Start) 80 .Where( i => i >= 0 && i < Dataset.Rows && (i < TestPartition.Start || TestPartition.End <= i));80 .Where(IsTrainingSample); 81 81 } 82 82 } … … 84 84 get { 85 85 return Enumerable.Range(TestPartition.Start, TestPartition.End - TestPartition.Start) 86 .Where( i => i >= 0 && i < Dataset.Rows);86 .Where(IsTestSample); 87 87 } 88 } 89 90 public virtual bool IsTrainingSample(int index) { 91 return index >= 0 && index < Dataset.Rows && 92 TrainingPartition.Start <= index && index < TrainingPartition.End && 93 (index < TestPartition.Start || TestPartition.End <= index); 94 } 95 96 public virtual bool IsTestSample(int index) { 97 return index >= 0 && index < Dataset.Rows && 98 TestPartition.Start <= index && index < TestPartition.End; 88 99 } 89 100 #endregion -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionEnsembleProblemData.cs
r6666 r6672 21 21 22 22 using System.Collections.Generic; 23 using System.Linq;24 23 using HeuristicLab.Common; 25 24 using HeuristicLab.Core; … … 33 32 public sealed class RegressionEnsembleProblemData : RegressionProblemData { 34 33 35 public override IEnumerable<int> TrainingIndizes { 36 get { 37 return Enumerable.Range(TrainingPartition.Start, TrainingPartition.End - TrainingPartition.Start); 38 } 34 public override bool IsTrainingSample(int index) { 35 return index >= 0 && index < Dataset.Rows && 36 TrainingPartition.Start <= index && index < TrainingPartition.End; 39 37 } 40 38 41 public override IEnumerable<int> TestIndizes { 42 get { 43 return Enumerable.Range(TestPartition.Start, TestPartition.End - TestPartition.Start); 44 } 39 public override bool IsTestSample(int index) { 40 return index >= 0 && index < Dataset.Rows && 41 TestPartition.Start <= index && index < TestPartition.End; 45 42 } 46 43 47 private static RegressionEnsembleProblemData emptyProblemData;44 private static readonly RegressionEnsembleProblemData emptyProblemData; 48 45 public new static RegressionEnsembleProblemData EmptyProblemData { 49 46 get { return emptyProblemData; } -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionProblemData.cs
r6666 r6672 64 64 {0.83763905, 0.468046718} 65 65 }; 66 private static Dataset defaultDataset;67 private static IEnumerable<string> defaultAllowedInputVariables;68 private static string defaultTargetVariable;66 private static readonly Dataset defaultDataset; 67 private static readonly IEnumerable<string> defaultAllowedInputVariables; 68 private static readonly string defaultTargetVariable; 69 69 70 private static RegressionProblemData emptyProblemData;70 private static readonly RegressionProblemData emptyProblemData; 71 71 public static RegressionProblemData EmptyProblemData { 72 72 get { return emptyProblemData; } -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IDataAnalysisProblemData.cs
r6666 r6672 39 39 IEnumerable<int> TestIndizes { get; } 40 40 41 bool IsTrainingSample(int index); 42 bool IsTestSample(int index); 43 41 44 event EventHandler Changed; 42 45 }
Note: See TracChangeset
for help on using the changeset viewer.