Changeset 8487
- Timestamp:
- 08/14/12 14:31:44 (12 years ago)
- Location:
- branches/HeuristicLab.TimeSeries
- Files:
-
- 6 deleted
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Views/3.4/HeuristicLab.Problems.DataAnalysis.Views-3.4.csproj
r8486 r8487 278 278 <DependentUpon>RegressionSolutionView.cs</DependentUpon> 279 279 </Compile> 280 <Compile Include="TimeSeriesPrognosis\TimeSeriesPrognosisSolutionErrorCharacteristicsCurveView.cs"> 281 <SubType>UserControl</SubType> 282 </Compile> 283 <Compile Include="TimeSeriesPrognosis\TimeSeriesPrognosisSolutionErrorCharacteristicsCurveView.Designer.cs"> 284 <DependentUpon>TimeSeriesPrognosisSolutionErrorCharacteristicsCurveView.cs</DependentUpon> 285 </Compile> 280 286 <None Include="HeuristicLab.snk" /> 281 287 <None Include="Plugin.cs.frame" /> … … 300 306 </BootstrapperPackage> 301 307 </ItemGroup> 302 <ItemGroup> 303 <Folder Include="TimeSeriesPrognosis\" /> 304 </ItemGroup> 308 <ItemGroup /> 305 309 <ItemGroup> 306 310 <ProjectReference Include="..\..\HeuristicLab.Problems.DataAnalysis\3.4\HeuristicLab.Problems.DataAnalysis-3.4.csproj"> -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Views/3.4/TimeSeriesPrognosis/TimeSeriesPrognosisSolutionErrorCharacteristicsCurveView.Designer.cs
r7099 r8487 25 25 private void InitializeComponent() { 26 26 this.components = new System.ComponentModel.Container(); 27 System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();28 System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend();29 this.chart = new HeuristicLab.Visualization.ChartControlsExtensions.EnhancedChart();30 this.label1 = new System.Windows.Forms.Label();31 this.cmbSamples = new System.Windows.Forms.ComboBox();32 27 ((System.ComponentModel.ISupportInitialize)(this.chart)).BeginInit(); 33 28 this.SuspendLayout(); 34 //35 // chart36 //37 this.chart.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)38 | System.Windows.Forms.AnchorStyles.Left)39 | System.Windows.Forms.AnchorStyles.Right)));40 chartArea1.Name = "ChartArea1";41 this.chart.ChartAreas.Add(chartArea1);42 legend1.Alignment = System.Drawing.StringAlignment.Center;43 legend1.Docking = System.Windows.Forms.DataVisualization.Charting.Docking.Top;44 legend1.Name = "Legend1";45 this.chart.Legends.Add(legend1);46 this.chart.Location = new System.Drawing.Point(6, 28);47 this.chart.Name = "chart";48 this.chart.Size = new System.Drawing.Size(366, 202);49 this.chart.TabIndex = 0;50 this.chart.Text = "chart";51 //52 // label153 //54 this.label1.AutoSize = true;55 this.label1.Location = new System.Drawing.Point(3, 6);56 this.label1.Name = "label1";57 this.label1.Size = new System.Drawing.Size(47, 13);58 this.label1.TabIndex = 4;59 this.label1.Text = "Samples";60 //61 // cmbSamples62 //63 this.cmbSamples.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;64 this.cmbSamples.FormattingEnabled = true;65 this.cmbSamples.Location = new System.Drawing.Point(56, 3);66 this.cmbSamples.Name = "cmbSamples";67 this.cmbSamples.Size = new System.Drawing.Size(121, 21);68 this.cmbSamples.TabIndex = 3;69 this.cmbSamples.SelectedIndexChanged += new System.EventHandler(this.cmbSamples_SelectedIndexChanged);70 29 // 71 30 // TimeSeriesPrognosisSolutionErrorCharacteristicsCurveView … … 73 32 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 74 33 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 75 this.Controls.Add(this.label1);76 this.Controls.Add(this.cmbSamples);77 this.Controls.Add(this.chart);78 34 this.Name = "TimeSeriesPrognosisSolutionErrorCharacteristicsCurveView"; 79 this.Size = new System.Drawing.Size(366, 230);80 35 ((System.ComponentModel.ISupportInitialize)(this.chart)).EndInit(); 81 36 this.ResumeLayout(false); … … 85 40 86 41 #endregion 87 88 protected HeuristicLab.Visualization.ChartControlsExtensions.EnhancedChart chart;89 protected System.Windows.Forms.Label label1;90 protected System.Windows.Forms.ComboBox cmbSamples;91 42 } 92 43 } -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Views/3.4/TimeSeriesPrognosis/TimeSeriesPrognosisSolutionErrorCharacteristicsCurveView.cs
r7099 r8487 20 20 #endregion 21 21 22 using System;23 22 using System.Collections.Generic; 24 23 using System.Linq; 25 24 using System.Windows.Forms; 26 using System.Windows.Forms.DataVisualization.Charting;27 25 using HeuristicLab.MainForm; 28 26 using HeuristicLab.MainForm.WindowsForms; … … 30 28 [View("Error Characteristics Curve")] 31 29 [Content(typeof(ITimeSeriesPrognosisSolution))] 32 public partial class TimeSeriesPrognosisSolutionErrorCharacteristicsCurveView : DataAnalysisSolutionEvaluationView { 33 protected const string TrainingSamples = "Training"; 34 protected const string TestSamples = "Test"; 35 protected const string AllSamples = "All Samples"; 30 public partial class TimeSeriesPrognosisSolutionErrorCharacteristicsCurveView : RegressionSolutionErrorCharacteristicsCurveView { 31 36 32 37 33 public TimeSeriesPrognosisSolutionErrorCharacteristicsCurveView() 38 34 : base() { 39 35 InitializeComponent(); 40 41 cmbSamples.Items.Add(TrainingSamples);42 cmbSamples.Items.Add(TestSamples);43 cmbSamples.Items.Add(AllSamples);44 45 cmbSamples.SelectedIndex = 0;46 47 chart.CustomizeAllChartAreas();48 chart.ChartAreas[0].AxisX.Title = "Absolute Error";49 chart.ChartAreas[0].AxisX.Minimum = 0.0;50 chart.ChartAreas[0].AxisX.Maximum = 1.0;51 chart.ChartAreas[0].AxisX.IntervalAutoMode = IntervalAutoMode.VariableCount;52 chart.ChartAreas[0].CursorX.Interval = 0.01;53 54 chart.ChartAreas[0].AxisY.Title = "Number of Samples";55 chart.ChartAreas[0].AxisY.Minimum = 0.0;56 chart.ChartAreas[0].AxisY.Maximum = 1.0;57 chart.ChartAreas[0].AxisY.MajorGrid.Interval = 0.2;58 chart.ChartAreas[0].CursorY.Interval = 0.01;59 36 } 60 37 … … 63 40 set { base.Content = value; } 64 41 } 65 public ITimeSeriesPrognosisProblemData ProblemData {42 public new ITimeSeriesPrognosisProblemData ProblemData { 66 43 get { 67 44 if (Content == null) return null; … … 70 47 } 71 48 72 protected override void RegisterContentEvents() { 73 base.RegisterContentEvents(); 74 Content.ModelChanged += new EventHandler(Content_ModelChanged); 75 Content.ProblemDataChanged += new EventHandler(Content_ProblemDataChanged); 76 } 77 protected override void DeregisterContentEvents() { 78 base.DeregisterContentEvents(); 79 Content.ModelChanged -= new EventHandler(Content_ModelChanged); 80 Content.ProblemDataChanged -= new EventHandler(Content_ProblemDataChanged); 81 } 49 protected override void UpdateChart() { 50 base.UpdateChart(); 51 if (Content == null) return; 52 var movingAverageModel = new TimeSeriesPrognosisMovingAverageModel(10, Content.ProblemData.TargetVariable).CreateTimeSeriesPrognosisSolution(ProblemData); 53 movingAverageModel.Name = "Moving average Model"; 54 AddRegressionSolution(movingAverageModel); 82 55 83 protected virtual void Content_ModelChanged(object sender, EventArgs e) { 84 if (InvokeRequired) Invoke((Action<object, EventArgs>)Content_ModelChanged, sender, e); 85 else UpdateChart(); 86 } 87 protected virtual void Content_ProblemDataChanged(object sender, EventArgs e) { 88 if (InvokeRequired) Invoke((Action<object, EventArgs>)Content_ProblemDataChanged, sender, e); 89 else { 90 UpdateChart(); 91 } 92 } 93 protected override void OnContentChanged() { 94 base.OnContentChanged(); 95 UpdateChart(); 96 } 97 98 protected virtual void UpdateChart() { 99 chart.Series.Clear(); 100 chart.Annotations.Clear(); 101 if (Content == null) return; 102 103 var originalValues = GetOriginalValues(); 104 var meanModelEstimatedValues = GetMeanModelEstimatedValues(originalValues); 105 var meanModelResiduals = GetResiduals(originalValues, meanModelEstimatedValues); 106 107 meanModelResiduals.Sort(); 108 chart.ChartAreas[0].AxisX.Maximum = Math.Ceiling(meanModelResiduals.Last()); 109 chart.ChartAreas[0].CursorX.Interval = meanModelResiduals.First() / 100; 110 111 Series meanModelSeries = new Series("Mean Model"); 112 meanModelSeries.ChartType = SeriesChartType.FastLine; 113 UpdateSeries(meanModelResiduals, meanModelSeries); 114 meanModelSeries.ToolTip = "Area over Curve: " + CalculateAreaOverCurve(meanModelSeries); 115 chart.Series.Add(meanModelSeries); 116 117 AddTimeSeriesPrognosisSolution(Content); 118 } 119 120 protected void AddTimeSeriesPrognosisSolution(ITimeSeriesPrognosisSolution solution) { 121 if (chart.Series.Any(s => s.Name == solution.Name)) return; 122 123 Series solutionSeries = new Series(solution.Name); 124 solutionSeries.Tag = solution; 125 solutionSeries.ChartType = SeriesChartType.FastLine; 126 var estimatedValues = GetResiduals(GetOriginalValues(), GetPrognosedValues(solution)); 127 UpdateSeries(estimatedValues, solutionSeries); 128 solutionSeries.ToolTip = "Area over Curve: " + CalculateAreaOverCurve(solutionSeries); 129 chart.Series.Add(solutionSeries); 130 } 131 132 protected void UpdateSeries(List<double> residuals, Series series) { 133 series.Points.Clear(); 134 residuals.Sort(); 135 136 series.Points.AddXY(0, 0); 137 for (int i = 0; i < residuals.Count; i++) { 138 var point = new DataPoint(); 139 if (residuals[i] > chart.ChartAreas[0].AxisX.Maximum) { 140 point.XValue = chart.ChartAreas[0].AxisX.Maximum; 141 point.YValues[0] = ((double)i) / residuals.Count; 142 point.ToolTip = "Error: " + point.XValue + "\n" + "Samples: " + point.YValues[0]; 143 series.Points.Add(point); 144 break; 145 } 146 147 point.XValue = residuals[i]; 148 point.YValues[0] = ((double)i + 1) / residuals.Count; 149 point.ToolTip = "Error: " + point.XValue + "\n" + "Samples: " + point.YValues[0]; 150 series.Points.Add(point); 151 } 152 153 if (series.Points.Last().XValue < chart.ChartAreas[0].AxisX.Maximum) { 154 var point = new DataPoint(); 155 point.XValue = chart.ChartAreas[0].AxisX.Maximum; 156 point.YValues[0] = 1; 157 point.ToolTip = "Error: " + point.XValue + "\n" + "Samples: " + point.YValues[0]; 158 series.Points.Add(point); 159 } 160 } 161 162 protected IEnumerable<double> GetOriginalValues() { 163 IEnumerable<double> originalValues; 164 switch (cmbSamples.SelectedItem.ToString()) { 165 case TrainingSamples: 166 originalValues = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndizes); 167 break; 168 case TestSamples: 169 originalValues = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TestIndizes); 170 break; 171 case AllSamples: 172 originalValues = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable); 173 break; 174 default: 175 throw new NotSupportedException(); 176 } 177 return originalValues; 178 } 179 180 protected IEnumerable<double> GetPrognosedValues(ITimeSeriesPrognosisSolution solution) { 181 IEnumerable<double> prognosedValues; 182 switch (cmbSamples.SelectedItem.ToString()) { 183 case TrainingSamples: 184 prognosedValues = solution.PrognosedTrainingValues; 185 break; 186 case TestSamples: 187 prognosedValues = solution.PrognosedTestValues; 188 break; 189 case AllSamples: 190 prognosedValues = solution.PrognosedValues; 191 break; 192 default: 193 throw new NotSupportedException(); 194 } 195 return prognosedValues; 196 } 197 198 protected IEnumerable<double> GetMeanModelEstimatedValues(IEnumerable<double> originalValues) { 199 double averageTrainingTarget = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndizes).Average(); 200 return Enumerable.Repeat(averageTrainingTarget, originalValues.Count()); 201 } 202 203 protected virtual List<double> GetResiduals(IEnumerable<double> originalValues, IEnumerable<double> estimatedValues) { 204 return originalValues.Zip(estimatedValues, (x, y) => Math.Abs(x - y)).ToList(); 205 } 206 207 private double CalculateAreaOverCurve(Series series) { 208 if (series.Points.Count < 1) throw new ArgumentException("Could not calculate area under curve if less than 1 data points were given."); 209 210 double auc = 0.0; 211 for (int i = 1; i < series.Points.Count; i++) { 212 double width = series.Points[i].XValue - series.Points[i - 1].XValue; 213 double y1 = 1 - series.Points[i - 1].YValues[0]; 214 double y2 = 1 - series.Points[i].YValues[0]; 215 216 auc += (y1 + y2) * width / 2; 217 } 218 219 return auc; 220 } 221 222 protected void cmbSamples_SelectedIndexChanged(object sender, EventArgs e) { 223 if (InvokeRequired) Invoke((Action<object, EventArgs>)cmbSamples_SelectedIndexChanged, sender, e); 224 else UpdateChart(); 56 //AR1 model 57 double alpha, beta; 58 OnlineCalculatorError errorState; 59 IEnumerable<double> trainingStartValues = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndices.Select(r => r - 1).Where(r => r > 0)).ToList(); 60 OnlineLinearScalingParameterCalculator.Calculate(ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndices.Where(x => x > 0)), trainingStartValues, out alpha, out beta, out errorState); 61 var AR1model = new TimeSeriesPrognosisAutoRegressiveModel(ProblemData.TargetVariable, new double[] { beta }, alpha).CreateTimeSeriesPrognosisSolution(ProblemData); 62 AR1model.Name = "AR(1) Model"; 63 AddRegressionSolution(AR1model); 225 64 } 226 65 } -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/Models/TimeSeriesPrognosisAutoRegressiveModel.cs
r8486 r8487 52 52 } 53 53 public TimeSeriesPrognosisAutoRegressiveModel(string targetVariable, double[] phi, double constant) 54 : base( ) {54 : base("AR(1) Model") { 55 55 Phi = (double[])phi.Clone(); 56 56 Constant = constant; -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/Models/TimeSeriesPrognosisMovingAverageModel.cs
r8486 r8487 47 47 } 48 48 public TimeSeriesPrognosisMovingAverageModel(int windowSize, string targetVariable) 49 : base( ) {49 : base("Moving Average Model") { 50 50 TargetVariable = targetVariable; 51 51 WindowSize = Math.Abs(windowSize);
Note: See TracChangeset
for help on using the changeset viewer.