- Timestamp:
- 09/14/18 11:47:37 (6 years ago)
- Location:
- branches/2817-BinPackingSpeedup
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2817-BinPackingSpeedup
- Property svn:mergeinfo changed
-
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.DataAnalysis.Views
- Property svn:mergeinfo changed
-
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/ClassificationSolutionVariableImpactsView.Designer.cs
r16140 r16141 54 54 this.sortByLabel = new System.Windows.Forms.Label(); 55 55 this.sortByComboBox = new System.Windows.Forms.ComboBox(); 56 this.backgroundWorker = new System.ComponentModel.BackgroundWorker(); 56 57 this.SuspendLayout(); 57 58 // … … 185 186 this.Name = "ClassificationSolutionVariableImpactsView"; 186 187 this.Size = new System.Drawing.Size(668, 365); 188 this.VisibleChanged += new System.EventHandler(this.ClassificationSolutionVariableImpactsView_VisibleChanged); 187 189 this.ResumeLayout(false); 188 190 this.PerformLayout(); … … 202 204 private System.Windows.Forms.Label sortByLabel; 203 205 private System.Windows.Forms.ComboBox sortByComboBox; 206 private System.ComponentModel.BackgroundWorker backgroundWorker; 204 207 } 205 208 } -
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/ClassificationSolutionVariableImpactsView.cs
r16140 r16141 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using System.Threading; 25 26 using System.Threading.Tasks; 26 27 using HeuristicLab.Common; … … 32 33 [Content(typeof(IClassificationSolution))] 33 34 public partial class ClassificationSolutionVariableImpactsView : DataAnalysisSolutionEvaluationView { 35 #region Nested Types 34 36 private enum SortingCriteria { 35 37 ImpactValue, … … 37 39 VariableName 38 40 } 39 41 #endregion 42 43 #region Fields 40 44 private Dictionary<string, double> rawVariableImpacts = new Dictionary<string, double>(); 41 45 private Thread thread; 46 #endregion 47 48 #region Getter/Setter 42 49 public new IClassificationSolution Content { 43 50 get { return (IClassificationSolution)base.Content; } … … 46 53 } 47 54 } 48 55 #endregion 56 57 #region Ctor 49 58 public ClassificationSolutionVariableImpactsView() 50 59 : base() { … … 55 64 this.sortByComboBox.SelectedItem = SortingCriteria.ImpactValue; 56 65 66 //Set the default values 57 67 this.dataPartitionComboBox.SelectedIndex = 0; 58 68 this.replacementComboBox.SelectedIndex = 0; 59 69 this.factorVarReplComboBox.SelectedIndex = 0; 60 70 } 61 62 #region events 71 #endregion 72 73 #region Events 63 74 protected override void RegisterContentEvents() { 64 75 base.RegisterContentEvents(); … … 86 97 variableImactsArrayView.Content = null; 87 98 } else { 88 UpdateVariableImpacts(); 89 } 99 UpdateVariableImpact(); 100 } 101 } 102 103 private void ClassificationSolutionVariableImpactsView_VisibleChanged(object sender, EventArgs e) { 104 if (thread == null) { return; } 105 106 if (thread.IsAlive) { thread.Abort(); } 107 thread = null; 90 108 } 91 109 92 110 93 111 private void dataPartitionComboBox_SelectedIndexChanged(object sender, EventArgs e) { 94 UpdateVariableImpact s();112 UpdateVariableImpact(); 95 113 } 96 114 97 115 private void replacementComboBox_SelectedIndexChanged(object sender, EventArgs e) { 98 UpdateVariableImpact s();116 UpdateVariableImpact(); 99 117 } 100 118 … … 123 141 UpdateDataOrdering(); 124 142 } 125 #endregion 126 127 #region Helper Methods 128 private void UpdateVariableImpacts() { 143 144 #endregion 145 146 #region Helper Methods 147 private void UpdateVariableImpact() { 148 //Check if the selection is valid 129 149 if (Content == null) { return; } 130 150 if (replacementComboBox.SelectedIndex < 0) { return; } … … 132 152 if (factorVarReplComboBox.SelectedIndex < 0) { return; } 133 153 134 variableImactsArrayView.Caption = Content.Name + " Variable Impacts"; 135 154 //Prepare arguments 136 155 var mainForm = (MainForm.WindowsForms.MainForm)MainFormManager.MainForm; 137 156 var replMethod = (ClassificationSolutionVariableImpactsCalculator.ReplacementMethodEnum)replacementComboBox.Items[replacementComboBox.SelectedIndex]; … … 139 158 var dataPartition = (ClassificationSolutionVariableImpactsCalculator.DataPartitionEnum)dataPartitionComboBox.SelectedItem; 140 159 160 variableImactsArrayView.Caption = Content.Name + " Variable Impacts"; 161 162 mainForm.AddOperationProgressToView(this, "Calculating variable impacts for " + Content.Name); 163 141 164 Task.Factory.StartNew(() => { 142 try { 143 mainForm.AddOperationProgressToView(this, "Calculating variable impacts for " + Content.Name); 144 145 //Remember the original ordering of the variables 146 var impacts = ClassificationSolutionVariableImpactsCalculator.CalculateImpacts(Content, dataPartition, replMethod, factorReplMethod); 147 var problemData = Content.ProblemData; 148 var inputvariables = new HashSet<string>(problemData.AllowedInputVariables.Union(Content.Model.VariablesUsedForPrediction)); 149 var originalVariableOrdering = problemData.Dataset.VariableNames.Where(v => inputvariables.Contains(v)).Where(problemData.Dataset.VariableHasType<double>).ToList(); 150 rawVariableImpacts.Clear(); 151 originalVariableOrdering.ForEach(v => rawVariableImpacts.Add(v, impacts.First(vv => vv.Item1 == v).Item2)); 152 UpdateDataOrdering(); 153 } finally { 154 mainForm.RemoveOperationProgressFromView(this); 155 } 156 }); 165 thread = Thread.CurrentThread; 166 //Remember the original ordering of the variables 167 var impacts = ClassificationSolutionVariableImpactsCalculator.CalculateImpacts(Content, dataPartition, replMethod, factorReplMethod); 168 var problemData = Content.ProblemData; 169 var inputvariables = new HashSet<string>(problemData.AllowedInputVariables.Union(Content.Model.VariablesUsedForPrediction)); 170 var originalVariableOrdering = problemData.Dataset.VariableNames.Where(v => inputvariables.Contains(v)).Where(problemData.Dataset.VariableHasType<double>).ToList(); 171 172 rawVariableImpacts.Clear(); 173 originalVariableOrdering.ForEach(v => rawVariableImpacts.Add(v, impacts.First(vv => vv.Item1 == v).Item2)); 174 }).ContinueWith((o) => { 175 UpdateDataOrdering(); 176 mainForm.RemoveOperationProgressFromView(this); 177 thread = null; 178 }, TaskScheduler.FromCurrentSynchronizationContext()); 157 179 } 158 180 … … 193 215 ElementNames = orderedEntries.Select(i => i.Key) 194 216 }; 195 variableImactsArrayView.Content = (DoubleArray)impactArray.AsReadOnly(); 196 } 197 #endregion 217 218 //Could be, if the View was closed 219 if (!variableImactsArrayView.IsDisposed) { 220 variableImactsArrayView.Content = (DoubleArray)impactArray.AsReadOnly(); 221 } 222 } 223 #endregion 198 224 } 199 225 } -
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.DataAnalysis.Views/3.4/Controls/FactorPartialDependencePlot.cs
r16140 r16141 143 143 // Configure axis 144 144 chart.CustomizeAllChartAreas(); 145 chart.ChartAreas[0].CursorX.IsUserSelectionEnabled = true; 146 chart.ChartAreas[0].AxisX.ScaleView.Zoomable = true; 147 chart.ChartAreas[0].CursorX.Interval = 0; 148 149 chart.ChartAreas[0].CursorY.IsUserSelectionEnabled = true; 150 chart.ChartAreas[0].AxisY.ScaleView.Zoomable = true; 151 chart.ChartAreas[0].CursorY.Interval = 0; 145 chart.ChartAreas[0].CursorX.IsUserSelectionEnabled = false; 146 chart.ChartAreas[0].CursorY.IsUserSelectionEnabled = false; 147 148 chart.ChartAreas[0].Axes.ToList().ForEach(x => { x.ScaleView.Zoomable = false; }); 152 149 153 150 Disposed += Control_Disposed; -
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.DataAnalysis.Views/3.4/Controls/PartialDependencePlot.cs
r16140 r16141 215 215 // Configure axis 216 216 chart.CustomizeAllChartAreas(); 217 chart.ChartAreas[0].CursorX.IsUserSelectionEnabled = true; 218 chart.ChartAreas[0].AxisX.ScaleView.Zoomable = true; 219 chart.ChartAreas[0].CursorX.Interval = 0; 220 221 chart.ChartAreas[0].CursorY.IsUserSelectionEnabled = true; 222 chart.ChartAreas[0].AxisY.ScaleView.Zoomable = true; 223 chart.ChartAreas[0].CursorY.Interval = 0; 217 chart.ChartAreas[0].CursorX.IsUserSelectionEnabled = false; 218 chart.ChartAreas[0].CursorY.IsUserSelectionEnabled = false; 219 220 chart.ChartAreas[0].Axes.ToList().ForEach(x => { x.ScaleView.Zoomable = false; }); 224 221 225 222 configToolStripMenuItem = new ToolStripMenuItem("Configuration"); … … 351 348 352 349 private void RecalculateTrainingLimits(bool initializeAxisRanges) { 353 trainingMin = solutions.Select(s => s.ProblemData.Dataset.GetDoubleValues(freeVariable, s.ProblemData.TrainingIndices). Min()).Max();354 trainingMax = solutions.Select(s => s.ProblemData.Dataset.GetDoubleValues(freeVariable, s.ProblemData.TrainingIndices). Max()).Min();350 trainingMin = solutions.Select(s => s.ProblemData.Dataset.GetDoubleValues(freeVariable, s.ProblemData.TrainingIndices).Where(x => !double.IsNaN(x)).Min()).Max(); 351 trainingMax = solutions.Select(s => s.ProblemData.Dataset.GetDoubleValues(freeVariable, s.ProblemData.TrainingIndices).Where(x => !double.IsNaN(x)).Max()).Min(); 355 352 356 353 if (initializeAxisRanges) { … … 702 699 private void config_Click(object sender, EventArgs e) { 703 700 configurationDialog.ShowDialog(this); 701 OnZoomChanged(this, EventArgs.Empty); 704 702 } 705 703 -
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionErrorCharacteristicsCurveView.cs
r16140 r16141 249 249 protected virtual List<double> GetResiduals(IEnumerable<double> originalValues, IEnumerable<double> estimatedValues) { 250 250 switch (residualComboBox.SelectedItem.ToString()) { 251 case "Absolute error": return originalValues.Zip(estimatedValues, (x, y) => Math.Abs(x - y)).ToList(); 252 case "Squared error": return originalValues.Zip(estimatedValues, (x, y) => (x - y) * (x - y)).ToList(); 253 case "Relative error": return originalValues.Zip(estimatedValues, (x, y) => x.IsAlmost(0.0) ? -1 : Math.Abs((x - y) / x)) 254 .Where(x => x > 0) // remove entries where the original value is 0 255 .ToList(); 251 case "Absolute error": return originalValues.Zip(estimatedValues, (x, y) => Math.Abs(x - y)) 252 .Where(r => !double.IsNaN(r) && !double.IsInfinity(r)).ToList(); 253 case "Squared error": return originalValues.Zip(estimatedValues, (x, y) => (x - y) * (x - y)) 254 .Where(r => !double.IsNaN(r) && !double.IsInfinity(r)).ToList(); 255 case "Relative error": 256 return originalValues.Zip(estimatedValues, (x, y) => x.IsAlmost(0.0) ? -1 : Math.Abs((x - y) / x)) 257 .Where(r => r > 0 && !double.IsNaN(r) && !double.IsInfinity(r)) // remove entries where the original value is 0 258 .ToList(); 256 259 default: throw new NotSupportedException(); 257 260 } -
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionLineChartViewBase.cs
r16140 r16141 20 20 #endregion 21 21 using System; 22 using System.Collections.Generic;23 22 using System.Drawing; 24 23 using System.Linq; … … 72 71 this.chart.Series[TARGETVARIABLE_SERIES_NAME].LegendText = TARGETVARIABLE_SERIES_NAME; 73 72 this.chart.Series[TARGETVARIABLE_SERIES_NAME].ChartType = SeriesChartType.FastLine; 74 this.chart.Series[TARGETVARIABLE_SERIES_NAME].Points.DataBindXY(Enumerable.Range(0, Content.ProblemData.Dataset.Rows).ToArray(), 75 Content.ProblemData.Dataset.GetDoubleValues(Content.ProblemData.TargetVariable).ToArray()); 73 74 var rows = Enumerable.Range(0, Content.ProblemData.Dataset.Rows).ToArray(); 75 var targetValues = Content.ProblemData.Dataset.GetDoubleValues(Content.ProblemData.TargetVariable); 76 77 78 this.chart.Series[TARGETVARIABLE_SERIES_NAME].Points.DataBindXY(rows.ToArray(), targetValues.Select(v => double.IsInfinity(v) ? double.NaN : v).ToArray()); 76 79 // training series 77 80 this.chart.Series.Add(ESTIMATEDVALUES_TRAINING_SERIES_NAME); … … 161 164 var targetValues = this.chart.Series[TARGETVARIABLE_SERIES_NAME].Points.Select(x => x.YValues[0]).DefaultIfEmpty(1.0); 162 165 double estimatedValuesRange = estimatedValues.Max() - estimatedValues.Min(); 163 double targetValuesRange = targetValues.Max() - targetValues.Min(); 166 double targetValuesRange = targetValues.Where(v => !double.IsInfinity(v) && !double.IsNaN(v)).Max() - 167 targetValues.Where(v => !double.IsInfinity(v) && !double.IsNaN(v)).Min(); 164 168 double interestingValuesRange = Math.Min(Math.Max(targetValuesRange, 1.0), Math.Max(estimatedValuesRange, 1.0)); 165 169 double digits = (int)Math.Log10(interestingValuesRange) - 3; -
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionResidualAnalysisView.cs
r16140 r16141 89 89 var runs = new RunCollection(); 90 90 // determine relevant variables (at least two different values) 91 var doubleVars = ds.DoubleVariables.Where(vn => ds.GetDoubleValues(vn). Max() > ds.GetDoubleValues(vn).Min()).ToArray();91 var doubleVars = ds.DoubleVariables.Where(vn => ds.GetDoubleValues(vn).Distinct().Skip(1).Any()).ToArray(); 92 92 var stringVars = ds.StringVariables.Where(vn => ds.GetStringValues(vn).Distinct().Skip(1).Any()).ToArray(); 93 93 var dateTimeVars = ds.DateTimeVariables.Where(vn => ds.GetDateTimeValues(vn).Distinct().Skip(1).Any()).ToArray(); -
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionResidualHistogram.cs
r16140 r16141 126 126 127 127 for (int i = 0; i < solution.ProblemData.Dataset.Rows; i++) { 128 if (double.IsNaN(estimatedValues[i]) || double.IsInfinity(estimatedValues[i])) continue; 129 if (double.IsNaN(targetValues[i]) || double.IsInfinity(targetValues[i])) continue; 128 130 double residual = estimatedValues[i] - targetValues[i]; 129 131 residuals.Add(residual); -
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionResidualsLineChartView.cs
r16140 r16141 38 38 var target = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, idx).ToArray(); 39 39 for (int i = 0; i < idx.Length; i++) { 40 x[i] = target[i] - x[i]; 40 if (!double.IsInfinity(target[i]) && !double.IsNaN(target[i]) && 41 !double.IsInfinity(x[i]) && !double.IsNaN(x[i])) { 42 x[i] = target[i] - x[i]; 43 } else { 44 x[i] = 0.0; 45 } 41 46 } 42 47 } -
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionScatterPlotView.cs
r16140 r16141 166 166 this.chart.Series[TEST_SERIES].Points.DataBindXY(dataset.GetDoubleValues(targetVariableName, Content.ProblemData.TestIndices).ToArray(), "", 167 167 Content.EstimatedTestValues.ToArray(), ""); 168 double max = Content.EstimatedTrainingValues.Concat(Content.EstimatedTestValues.Concat(Content.EstimatedValues.Concat(dataset.GetDoubleValues(targetVariableName)))).Max(); 169 double min = Content.EstimatedTrainingValues.Concat(Content.EstimatedTestValues.Concat(Content.EstimatedValues.Concat(dataset.GetDoubleValues(targetVariableName)))).Min(); 168 double max = Content.EstimatedTrainingValues 169 .Concat(Content.EstimatedTestValues 170 .Concat(Content.EstimatedValues 171 .Concat(dataset.GetDoubleValues(targetVariableName)))) 172 .Where(v => !double.IsNaN(v) && !double.IsInfinity(v)).Max(); 173 double min = Content.EstimatedTrainingValues 174 .Concat(Content.EstimatedTestValues 175 .Concat(Content.EstimatedValues 176 .Concat(dataset.GetDoubleValues(targetVariableName)))) 177 .Where(v => !double.IsNaN(v) && !double.IsInfinity(v)).Min(); 170 178 171 179 double axisMin, axisMax, axisInterval; -
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionVariableImpactsView.Designer.cs
r16140 r16141 19 19 */ 20 20 #endregion 21 21 22 22 23 namespace HeuristicLab.Problems.DataAnalysis.Views { … … 81 82 this.sortByComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; 82 83 this.sortByComboBox.FormattingEnabled = true; 84 this.sortByComboBox.Items.AddRange(new object[] { 85 HeuristicLab.Problems.DataAnalysis.Views.RegressionSolutionVariableImpactsView.SortingCriteria.ImpactValue, 86 HeuristicLab.Problems.DataAnalysis.Views.RegressionSolutionVariableImpactsView.SortingCriteria.Occurrence, 87 HeuristicLab.Problems.DataAnalysis.Views.RegressionSolutionVariableImpactsView.SortingCriteria.VariableName}); 83 88 this.sortByComboBox.Location = new System.Drawing.Point(407, 3); 84 89 this.sortByComboBox.Name = "sortByComboBox"; … … 159 164 // variableImactsArrayView 160 165 // 161 this.variableImactsArrayView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 162 | System.Windows.Forms.AnchorStyles.Left) 166 this.variableImactsArrayView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 167 | System.Windows.Forms.AnchorStyles.Left) 163 168 | System.Windows.Forms.AnchorStyles.Right))); 164 169 this.variableImactsArrayView.Caption = "StringConvertibleArray View"; … … 186 191 this.Name = "RegressionSolutionVariableImpactsView"; 187 192 this.Size = new System.Drawing.Size(712, 365); 193 this.VisibleChanged += new System.EventHandler(this.RegressionSolutionVariableImpactsView_VisibleChanged); 188 194 this.ResumeLayout(false); 189 195 this.PerformLayout(); -
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionVariableImpactsView.cs
r16140 r16141 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using System.Threading; 25 26 using System.Threading.Tasks; 26 27 using HeuristicLab.Common; … … 32 33 [Content(typeof(IRegressionSolution))] 33 34 public partial class RegressionSolutionVariableImpactsView : DataAnalysisSolutionEvaluationView { 35 private CancellationTokenSource cancellationToken = new CancellationTokenSource(); 34 36 private enum SortingCriteria { 35 37 ImpactValue, … … 37 39 VariableName 38 40 } 39 40 private Dictionary<string, double> rawVariableImpacts = new Dictionary<string, double>(); 41 private List<Tuple<string, double>> rawVariableImpacts = new List<Tuple<string, double>>(); 41 42 42 43 public new IRegressionSolution Content { … … 51 52 InitializeComponent(); 52 53 53 //Little workaround. If you fill the ComboBox-Items in the other partial class, the UI-Designer will moan. 54 this.sortByComboBox.Items.AddRange(Enum.GetValues(typeof(SortingCriteria)).Cast<object>().ToArray()); 54 //Set the default values 55 this.dataPartitionComboBox.SelectedIndex = 0; 56 this.replacementComboBox.SelectedIndex = 3; 57 this.factorVarReplComboBox.SelectedIndex = 0; 55 58 this.sortByComboBox.SelectedItem = SortingCriteria.ImpactValue; 56 57 this.dataPartitionComboBox.SelectedIndex = 0; 58 this.replacementComboBox.SelectedIndex = 0; 59 this.factorVarReplComboBox.SelectedIndex = 0; 60 } 61 62 #region events 59 } 60 63 61 protected override void RegisterContentEvents() { 64 62 base.RegisterContentEvents(); … … 86 84 variableImactsArrayView.Content = null; 87 85 } else { 88 UpdateVariableImpacts(); 89 } 86 UpdateVariableImpact(); 87 } 88 } 89 90 private void RegressionSolutionVariableImpactsView_VisibleChanged(object sender, EventArgs e) { 91 cancellationToken.Cancel(); 90 92 } 91 93 92 94 93 95 private void dataPartitionComboBox_SelectedIndexChanged(object sender, EventArgs e) { 94 UpdateVariableImpact s();96 UpdateVariableImpact(); 95 97 } 96 98 97 99 private void replacementComboBox_SelectedIndexChanged(object sender, EventArgs e) { 98 UpdateVariableImpact s();100 UpdateVariableImpact(); 99 101 } 100 102 … … 102 104 //Update the default ordering (asc,desc), but remove the eventHandler beforehand (otherwise the data would be ordered twice) 103 105 ascendingCheckBox.CheckedChanged -= ascendingCheckBox_CheckedChanged; 104 switch ((SortingCriteria)sortByComboBox.SelectedItem) { 105 case SortingCriteria.ImpactValue: 106 ascendingCheckBox.Checked = false; 107 break; 108 case SortingCriteria.Occurrence: 109 ascendingCheckBox.Checked = true; 110 break; 111 case SortingCriteria.VariableName: 112 ascendingCheckBox.Checked = true; 113 break; 114 default: 115 throw new NotImplementedException("Ordering for selected SortingCriteria not implemented"); 116 } 106 ascendingCheckBox.Checked = (SortingCriteria)sortByComboBox.SelectedItem != SortingCriteria.ImpactValue; 117 107 ascendingCheckBox.CheckedChanged += ascendingCheckBox_CheckedChanged; 118 108 119 Update DataOrdering();109 UpdateOrdering(); 120 110 } 121 111 122 112 private void ascendingCheckBox_CheckedChanged(object sender, EventArgs e) { 123 UpdateDataOrdering(); 124 } 125 #endregion 126 127 #region Helper Methods 128 private void UpdateVariableImpacts() { 113 UpdateOrdering(); 114 } 115 116 117 private async void UpdateVariableImpact() { 118 IProgress progress; 119 120 //Check if the selection is valid 129 121 if (Content == null) { return; } 130 122 if (replacementComboBox.SelectedIndex < 0) { return; } … … 132 124 if (factorVarReplComboBox.SelectedIndex < 0) { return; } 133 125 134 variableImactsArrayView.Caption = Content.Name + " Variable Impacts"; 135 126 //Prepare arguments 136 127 var mainForm = (MainForm.WindowsForms.MainForm)MainFormManager.MainForm; 137 128 var replMethod = (RegressionSolutionVariableImpactsCalculator.ReplacementMethodEnum)replacementComboBox.Items[replacementComboBox.SelectedIndex]; … … 139 130 var dataPartition = (RegressionSolutionVariableImpactsCalculator.DataPartitionEnum)dataPartitionComboBox.SelectedItem; 140 131 141 Task.Factory.StartNew(() => { 142 try { 143 mainForm.AddOperationProgressToView(this, "Calculating variable impacts for " + Content.Name); 144 145 //Remember the original ordering of the variables 146 var impacts = RegressionSolutionVariableImpactsCalculator.CalculateImpacts(Content, dataPartition, replMethod, factorReplMethod); 147 var problemData = Content.ProblemData; 148 var inputvariables = new HashSet<string>(problemData.AllowedInputVariables.Union(Content.Model.VariablesUsedForPrediction)); 149 var originalVariableOrdering = problemData.Dataset.VariableNames.Where(v => inputvariables.Contains(v)).Where(problemData.Dataset.VariableHasType<double>).ToList(); 150 rawVariableImpacts.Clear(); 151 originalVariableOrdering.ForEach(v => rawVariableImpacts.Add(v, impacts.First(vv => vv.Item1 == v).Item2)); 152 UpdateDataOrdering(); 153 } finally { 154 mainForm.RemoveOperationProgressFromView(this); 155 } 156 }); 132 variableImactsArrayView.Caption = Content.Name + " Variable Impacts"; 133 progress = mainForm.AddOperationProgressToView(this, "Calculating variable impacts for " + Content.Name); 134 progress.ProgressValue = 0; 135 136 cancellationToken = new CancellationTokenSource(); 137 //Remember the original ordering of the variables 138 try { 139 var impacts = await Task.Run(() => RegressionSolutionVariableImpactsCalculator.CalculateImpacts(Content, dataPartition, replMethod, factorReplMethod, 140 (i, s) => { 141 progress.ProgressValue = i; 142 progress.Status = s; 143 return cancellationToken.Token.IsCancellationRequested; 144 }), cancellationToken.Token); 145 146 if (cancellationToken.Token.IsCancellationRequested) { return; } 147 var problemData = Content.ProblemData; 148 var inputvariables = new HashSet<string>(problemData.AllowedInputVariables.Union(Content.Model.VariablesUsedForPrediction)); 149 var originalVariableOrdering = problemData.Dataset.VariableNames 150 .Where(v => inputvariables.Contains(v)) 151 .Where(v => problemData.Dataset.VariableHasType<double>(v) || problemData.Dataset.VariableHasType<string>(v)) 152 .ToList(); 153 154 rawVariableImpacts.Clear(); 155 originalVariableOrdering.ForEach(v => rawVariableImpacts.Add(new Tuple<string, double>(v, impacts.First(vv => vv.Item1 == v).Item2))); 156 UpdateOrdering(); 157 } finally { 158 ((MainForm.WindowsForms.MainForm)MainFormManager.MainForm).RemoveOperationProgressFromView(this); 159 } 157 160 } 158 161 … … 161 164 /// The default is "Descending" by "VariableImpact" (as in previous versions) 162 165 /// </summary> 163 private void Update DataOrdering() {166 private void UpdateOrdering() { 164 167 //Check if valid sortingCriteria is selected and data exists 165 168 if (sortByComboBox.SelectedIndex == -1) { return; } … … 170 173 bool ascending = ascendingCheckBox.Checked; 171 174 172 IEnumerable< KeyValuePair<string, double>> orderedEntries = null;175 IEnumerable<Tuple<string, double>> orderedEntries = null; 173 176 174 177 //Sort accordingly 175 178 switch (selectedItem) { 176 179 case SortingCriteria.ImpactValue: 177 orderedEntries = rawVariableImpacts.OrderBy(v => v. Value);180 orderedEntries = rawVariableImpacts.OrderBy(v => v.Item2); 178 181 break; 179 182 case SortingCriteria.Occurrence: … … 181 184 break; 182 185 case SortingCriteria.VariableName: 183 orderedEntries = rawVariableImpacts.OrderBy(v => v. Key, new NaturalStringComparer());186 orderedEntries = rawVariableImpacts.OrderBy(v => v.Item1, new NaturalStringComparer()); 184 187 break; 185 188 default: … … 190 193 191 194 //Write the data back 192 var impactArray = new DoubleArray(orderedEntries.Select(i => i. Value).ToArray()) {193 ElementNames = orderedEntries.Select(i => i. Key)195 var impactArray = new DoubleArray(orderedEntries.Select(i => i.Item2).ToArray()) { 196 ElementNames = orderedEntries.Select(i => i.Item1) 194 197 }; 195 variableImactsArrayView.Content = (DoubleArray)impactArray.AsReadOnly(); 196 } 197 #endregion 198 199 //Could be, if the View was closed 200 if (!variableImactsArrayView.IsDisposed) { 201 variableImactsArrayView.Content = (DoubleArray)impactArray.AsReadOnly(); 202 } 203 } 198 204 } 199 205 } -
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.DataAnalysis.Views/3.4/TimeSeriesPrognosis/TimeSeriesPrognosisResidualsLineChartView.cs
r16140 r16141 20 20 #endregion 21 21 22 using System;23 22 using System.Linq; 24 using System.Windows.Forms.DataVisualization.Charting;25 23 using HeuristicLab.MainForm; 26 24
Note: See TracChangeset
for help on using the changeset viewer.