Changeset 14710
- Timestamp:
- 03/02/17 14:10:57 (8 years ago)
- Location:
- branches/HeuristicLab.DatastreamAnalysis
- Files:
-
- 4 added
- 13 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.DatastreamAnalysis/HeuristicLab.DatastreamAnalysis.Views/3.4/DataBarSetView.cs
r14588 r14710 119 119 120 120 chart.Series.Clear(); 121 121 122 Series series = chart.Series.Add(seriesName); 122 123 series.IsVisibleInLegend = false; … … 124 125 int i = 0; 125 126 foreach (var bar in Content.Bars) { 126 series.Points.Add(new DataPoint(i, bar.Value) { AxisLabel = bar.Name, Color = bar.BarColor }); 127 var dp = new DataPoint(i, bar.Value) { 128 AxisLabel = bar.Name, 129 ToolTip = bar.Name, 130 Color = bar.BarColor, 131 BorderWidth = 5 132 }; 133 series.Points.Add(dp); 127 134 i++; 128 135 } … … 154 161 for (int i = 0; i < bars.Count; i++) { 155 162 chart.Series[seriesName].Points.ElementAt(i).SetValueY(bars[i].Value); 163 chart.Series[seriesName].Points.ElementAt(i).ToolTip = bars[i].Name + " = " + bars[i].Value; 156 164 } 157 165 … … 163 171 } 164 172 173 public static Color DefaultColor = Color.FromArgb(65, 140, 240); 174 public static Color HighlightColor1 = Color.FromArgb(37, 105, 175); 175 public static Color HighlightColor2 = Color.FromArgb(247, 150, 70); 176 public static Color HighlightColor3 = Color.FromArgb(228, 108, 10); 177 //public static Color HighlightColor1 = Color.FromArgb(45, 120, 200); 178 //public static Color HighlightColor2 = Color.FromArgb(15, 90, 160); 179 //public static Color HighlightColor3 = Color.FromArgb(10, 60, 110); 165 180 private void CheckThresholds() { 166 181 var bars = Content.Bars.ToList(); 182 var winner = 183 !bars.Any() ? -1 : 184 bars 185 .Select((value, index) => new {Value = value, Index = index}) 186 .Aggregate((a, b) => ((a.Value.Value - a.Value.ThresholdUpperBound) > (b.Value.Value - b.Value.ThresholdUpperBound)) ? a : b) 187 .Index; 188 189 // color bars depending on the threshold boundaries they exceed 167 190 for (int i = 0; i < bars.Count; i++) { 168 191 var bar = bars[i]; 169 if (bar.Value > bar.Threshold) { 170 chart.Series[seriesName].Points[i].Color = Color.Orange; 192 if (bar.Value > bar.ThresholdUpperBound) { 193 chart.Series[seriesName].Points[i].Color = HighlightColor2; 194 chart.Series[seriesName].Points[i].BorderColor = HighlightColor2; 195 } else if (bar.Value > bar.ThresholdLowerBound) { 196 chart.Series[seriesName].Points[i].Color = HighlightColor1; 197 chart.Series[seriesName].Points[i].BorderColor = HighlightColor1; 171 198 } else { 172 199 chart.Series[seriesName].Points[i].Color = bar.BarColor; 200 chart.Series[seriesName].Points[i].BorderColor = bar.BarColor; 173 201 } 174 202 } 175 } 176 203 204 // color the winner's border 205 if (winner != -1 && bars[winner].Value > bars[winner].ThresholdUpperBound) { 206 chart.Series[seriesName].Points[winner].BorderColor = HighlightColor3; 207 } 208 } 209 210 211 212 private void AddThresholds() { 213 Series series = chart.Series.Add("Thresholds"); 214 series.IsVisibleInLegend = false; 215 series.ChartType = SeriesChartType.ErrorBar; 216 217 int i = 0; 218 foreach (var bar in Content.Bars) { 219 string desc = string.Format("{0} - Threshold [{1},{2}]", bar.Name, bar.ThresholdLowerBound,bar.ThresholdUpperBound); 220 var threshold = new DataPoint(i, new[] 221 {(bar.ThresholdLowerBound + bar.ThresholdUpperBound)/2, bar.ThresholdLowerBound, bar.ThresholdUpperBound}) { 222 AxisLabel = desc, 223 ToolTip = desc, 224 Color = bar.ThresholdColor, 225 BorderWidth = 1 226 }; 227 series.Points.Add(threshold); 228 i++; 229 } 230 } 177 231 private void AddThresholdsOld() { 178 232 Series series = chart.Series.Add("Thresholds"); … … 183 237 foreach (var bar in Content.Bars) { 184 238 //series.Points.Add(new DataPoint(i, new [] { bar.Threshold, bar.Threshold + 0.05 }) { AxisLabel = bar.Name, Color = Color.Transparent, BorderWidth = 2, BorderColor = bar.ThresholdColor}); 185 series.Points.Add(new DataPoint(i, new[] { bar.Threshold , bar.Threshold + 0.05}) { AxisLabel = bar.Name, Color = bar.ThresholdColor });239 series.Points.Add(new DataPoint(i, new[] { bar.ThresholdLowerBound, bar.ThresholdUpperBound }) { AxisLabel = bar.Name, Color = bar.ThresholdColor }); 186 240 i++; 187 241 } 188 242 } 189 190 private void AddThresholds() { 243 private void AddThresholdsOld2() { 191 244 chart.Annotations.Clear(); 192 245 … … 202 255 annotation.AxisX = chart.ChartAreas[0].AxisX; 203 256 annotation.AxisY = chart.ChartAreas[0].AxisY; 204 annotation.Y = bars[i].Threshold ;257 annotation.Y = bars[i].ThresholdLowerBound; 205 258 206 259 annotation.Alignment = ContentAlignment.MiddleCenter; … … 208 261 209 262 annotation.X = i - 0.4; 210 annotation.Width = 52.0/ bars.Count;263 annotation.Width = (46 - bars.Count) / bars.Count; 211 264 annotation.Name = bars[i].Name; 212 265 annotation.Tag = bars[i].Name; -
branches/HeuristicLab.DatastreamAnalysis/HeuristicLab.DatastreamAnalysis.Views/3.4/DatastreamAnalysisOptimizerView.cs
r14538 r14710 157 157 try { 158 158 var data = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat); 159 if (data is IR egressionEnsembleModel) {160 data = (IR egressionEnsembleModel) data;161 Content.Ensembles.Add((R egressionEnsembleModel) data);159 if (data is IRatedEnsembleModel) { 160 data = (IRatedEnsembleModel) data; 161 Content.Ensembles.Add((RatedEnsembleModel) data); 162 162 } 163 163 } … … 175 175 var data = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat); 176 176 177 if (data is IR egressionEnsembleModel) {177 if (data is IRatedEnsembleModel) { 178 178 if ((e.KeyState & 32) == 32) e.Effect = DragDropEffects.Link; // ALT key 179 179 else if ((e.KeyState & 4) == 4) e.Effect = DragDropEffects.Move; // SHIFT key -
branches/HeuristicLab.DatastreamAnalysis/HeuristicLab.DatastreamAnalysis.Views/3.4/HeuristicLab.DatastreamAnalysis.Views.csproj
r14588 r14710 111 111 <DependentUpon>DatastreamAnalysisOptimizerView.cs</DependentUpon> 112 112 </Compile> 113 <Compile Include="Form1.cs"> 114 <SubType>Form</SubType> 115 </Compile> 116 <Compile Include="Form1.Designer.cs"> 117 <DependentUpon>Form1.cs</DependentUpon> 118 </Compile> 113 119 <Compile Include="Plugin.cs" /> 114 120 <Compile Include="Properties\AssemblyInfo.cs" /> … … 142 148 <DependentUpon>DatastreamAnalysisOptimizerView.cs</DependentUpon> 143 149 </EmbeddedResource> 150 <EmbeddedResource Include="Form1.resx"> 151 <DependentUpon>Form1.cs</DependentUpon> 152 </EmbeddedResource> 144 153 <EmbeddedResource Include="RegressionEnsembleModelView.resx"> 145 154 <DependentUpon>RegressionEnsembleModelView.cs</DependentUpon> -
branches/HeuristicLab.DatastreamAnalysis/HeuristicLab.DatastreamAnalysis.Views/3.4/Plugin.cs
r14588 r14710 23 23 24 24 namespace HeuristicLab.DatastreamAnalysis.Views { 25 [Plugin("HeuristicLab.DatastreamAnalysis.Views", "3.4.14.145 47")]25 [Plugin("HeuristicLab.DatastreamAnalysis.Views", "3.4.14.14588")] 26 26 [PluginFile("HeuristicLab.DatastreamAnalysis.Views-3.4.dll", PluginFileType.Assembly)] 27 27 [PluginDependency("HeuristicLab.Collections", "3.3")] -
branches/HeuristicLab.DatastreamAnalysis/HeuristicLab.DatastreamAnalysis.Views/3.4/Properties/AssemblyInfo.cs
r14588 r14710 54 54 // [assembly: AssemblyVersion("1.0.*")] 55 55 [assembly: AssemblyVersion("3.4.0.0")] 56 [assembly: AssemblyFileVersion("3.4.14.145 47")]56 [assembly: AssemblyFileVersion("3.4.14.14588")] -
branches/HeuristicLab.DatastreamAnalysis/HeuristicLab.DatastreamAnalysis/3.4/DataBar.cs
r14588 r14710 28 28 using HeuristicLab.Common; 29 29 using HeuristicLab.Core; 30 using HeuristicLab.Data; 30 31 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 31 32 … … 38 39 public class DataBar : NamedItem, INotifyPropertyChanged { 39 40 private double value; 41 public static Color DefaultBarColor = Color.FromArgb(65, 140, 240); 40 42 41 43 public double Value { … … 50 52 } 51 53 52 private double threshold ;54 private double thresholdLowerBound; 53 55 54 public double Threshold {55 get { return threshold ; }56 public double ThresholdLowerBound { 57 get { return thresholdLowerBound; } 56 58 set { 59 if (this.value != value) { 60 this.value = value; 61 OnThresholdPropertyChanged("Threshold"); 62 } 63 } 64 } 65 66 private double thresholdUpperBound; 67 68 public double ThresholdUpperBound 69 { 70 get { return thresholdUpperBound; } 71 set 72 { 57 73 if (this.value != value) { 58 74 this.value = value; … … 68 84 set { this.value = value; } 69 85 } 70 [Storable(Name = "Threshold")] 71 private double StorableThreshold { 72 get { return threshold; } 73 set { this.threshold = value; } 86 [Storable(Name = "ThresholdLowerBound")] 87 private double StorableThresholdLowerBound { 88 get { return thresholdLowerBound; } 89 set { this.thresholdLowerBound = value; } 90 } 91 [Storable(Name = "ThresholdUpperBound")] 92 private double StorableThresholdUpperBound 93 { 94 get { return thresholdUpperBound; } 95 set { this.thresholdUpperBound = value; } 74 96 } 75 97 #endregion … … 109 131 protected DataBar(DataBar original, Cloner cloner) : base(original, cloner) { 110 132 this.value = original.value; 111 this.threshold = original.threshold;133 this.thresholdLowerBound = original.thresholdLowerBound; 112 134 this.barColor = original.barColor; 113 135 this.thresholdColor = original.thresholdColor; … … 115 137 116 138 public DataBar() : this("DataBar") { 117 barColor = Color.Empty;118 thresholdColor = Color. Red;139 barColor = DefaultBarColor; 140 thresholdColor = Color.Black; 119 141 } 120 142 121 143 public DataBar(string name) : base(name) { 122 144 if (string.IsNullOrEmpty(name)) throw new ArgumentException("Name of a DataBar cannot be empty", name); 123 barColor = Color.Empty;124 thresholdColor = Color. Red;145 barColor = DefaultBarColor; 146 thresholdColor = Color.Black; 125 147 } 126 148 127 public DataBar(string name, double threshold ) : base(name) {149 public DataBar(string name, double thresholdLowerBound, double thresholdUpperBound) : base(name) { 128 150 if (string.IsNullOrEmpty(name)) throw new ArgumentException("Name of a DataBar cannot be empty", name); 129 this.threshold = threshold; 130 barColor = Color.Empty; 131 thresholdColor = Color.Red; 151 this.thresholdLowerBound = thresholdLowerBound; 152 this.thresholdUpperBound = thresholdUpperBound; 153 barColor = DefaultBarColor; 154 thresholdColor = Color.Black; 132 155 } 133 156 134 157 public DataBar(string name, string description) : base(name, description) { 135 158 if (string.IsNullOrEmpty(name)) throw new ArgumentException("Name of a DataBar cannot be empty", name); 136 barColor = Color.Empty;137 thresholdColor = Color. Red;159 barColor = DefaultBarColor; 160 thresholdColor = Color.Black; 138 161 } 139 162 -
branches/HeuristicLab.DatastreamAnalysis/HeuristicLab.DatastreamAnalysis/3.4/Datastream.cs
r14543 r14710 42 42 protected const string SlidingWindowSizeParameterName = "SlidingWindowSize"; 43 43 protected const string SlidingWindowStepWidthParameterName = "SlidingWindowStepWidth"; 44 protected const string SlidingWindowMovement IntervalParameterName = "SlidingWindowMovementInterval";44 protected const string SlidingWindowMovementDelayParameterName = "SlidingWindowMovementDelay"; 45 45 protected const string FitnessPartitionParameterName = "FitnessPartition"; 46 protected const string SlidingWindowSonarRatioParameterName = "SlidingWindowSonarRatio"; 46 47 47 48 #region parameter properites … … 63 64 } 64 65 65 public IValueParameter<IntValue> SlidingWindowMovementIntervalParameter { 66 get { return (IValueParameter<IntValue>) Parameters[SlidingWindowMovementIntervalParameterName]; } 66 public IValueParameter<IntValue> SlidingWindowMovementDelayParameter { 67 get { return (IValueParameter<IntValue>) Parameters[SlidingWindowMovementDelayParameterName]; } 68 } 69 70 public IValueParameter<DoubleValue> SlidingWindowSonarRatioParameter { 71 get { return (IValueParameter<DoubleValue>) Parameters[SlidingWindowSonarRatioParameterName]; } 67 72 } 68 73 … … 78 83 get { return ProblemDataParameter.Value; } 79 84 set { 80 if(value == null) throw new ArgumentNullException(" problemData", "The provided value for theproblemData is null.");85 if(value == null) throw new ArgumentNullException("ProblemData", "The provided value for problemData is null."); 81 86 ProblemDataParameter.Value = value; 82 87 //OnProblemDataChanged(); … … 100 105 } 101 106 102 public IntValue SlidingWindowMovementInterval { 103 get { return SlidingWindowMovementIntervalParameter.Value; } 104 set { SlidingWindowMovementIntervalParameter.Value = value; } 107 public IntValue SlidingWindowMovementDelay { 108 get { return SlidingWindowMovementDelayParameter.Value; } 109 set { SlidingWindowMovementDelayParameter.Value = value; } 110 } 111 112 public DoubleValue SlidingWindowSonarRatio { 113 get { return SlidingWindowSonarRatioParameter.Value; } 114 set { SlidingWindowSonarRatioParameter.Value = value; } 105 115 } 106 116 … … 181 191 public Datastream() : base() { 182 192 Parameters.Add(new ValueParameter<RegressionProblemData>(ProblemDataParameterName, "ProblemData for analysis with selected ensembles.", null)); 183 Parameters.Add(new FixedValueParameter<IntRange>(InitialSlidingWindowParameterName, "Initial sliding window boundaries", new IntRange(0, 20)));184 Parameters.Add(new FixedValueParameter<IntValue>(SlidingWindowSizeParameterName, "Sliding window size", new IntValue( 20)));193 Parameters.Add(new FixedValueParameter<IntRange>(InitialSlidingWindowParameterName, "Initial sliding window boundaries", new IntRange(0, 100))); 194 Parameters.Add(new FixedValueParameter<IntValue>(SlidingWindowSizeParameterName, "Sliding window size", new IntValue(100))); 185 195 Parameters.Add(new FixedValueParameter<IntValue>(SlidingWindowStepWidthParameterName, "Sliding window step width", new IntValue(1))); 186 Parameters.Add(new FixedValueParameter<IntValue>(SlidingWindowMovementIntervalParameterName, "Sliding window movement interval (milliseconds)", new IntValue(500))); 196 Parameters.Add(new FixedValueParameter<IntValue>(SlidingWindowMovementDelayParameterName, "Sliding window movement delay interval (milliseconds)", new IntValue(0))); 197 Parameters.Add(new FixedValueParameter<DoubleValue>(SlidingWindowSonarRatioParameterName, "Sliding window sonar ratio", new DoubleValue(0.25))); 187 198 RegisterParameterEvents(); 188 199 InitializeState(); -
branches/HeuristicLab.DatastreamAnalysis/HeuristicLab.DatastreamAnalysis/3.4/DatastreamAnalysisOptimizer.cs
r14588 r14710 74 74 } 75 75 76 private double lastStateValue; 77 private double pR2Sum; 78 private int detectionCount; 79 private int evaluationCount; 80 private double exclusivitySum; 81 private double accuracySum; 82 76 83 private CancellationTokenSource cancellationTokenSource; 77 84 private bool stopPending; … … 100 107 } 101 108 102 103 109 [Storable] 104 private IItemList<R egressionEnsembleModel> ensembles;105 106 public IItemList<R egressionEnsembleModel> Ensembles {110 private IItemList<RatedEnsembleModel> ensembles; 111 112 public IItemList<RatedEnsembleModel> Ensembles { 107 113 get { return ensembles; } 108 114 set { 109 115 if (value == null || value == ensembles) 110 116 return; 111 if (!(value is IRegressionEnsembleModel)) throw new ArgumentException("Invaid ensemble model type");117 if (!(value is IRatedEnsembleModel)) throw new ArgumentException("Invaid ensemble model type"); 112 118 DeregisterEnsembleEvents(); 113 119 ensembles = value; … … 145 151 } 146 152 private DataTable ResultsQualities { 147 get { return ((DataTable)Results["Qualities"].Value); } 153 get { return ((DataTable)Results["Qualities 1"].Value); } 154 } 155 156 private DataTable ResultsPeakQualities { 157 get { return ((DataTable) Results["Qualities 2"].Value); } 148 158 } 149 159 … … 155 165 } 156 166 167 private DataTable ResultsStateDetection { 168 get { return ((DataTable) Results["State Detection"].Value);} 169 } 170 157 171 private const string ResultsTargetsReal = "Real"; 158 172 159 private DataBarSet ResultsQualitiesBars { 160 get { return (DataBarSet) Results["Ensemble Comparison"].Value; } 161 } 173 private DataBarSet ResultsSWQualitiesBars { 174 get { return (DataBarSet) Results["Ensemble Comparison [SW-Quality]"].Value; } 175 } 176 177 private DataBarSet ResultsSWVotingBars { 178 get { return (DataBarSet) Results["Ensemble Comparison [SW-Voting]"].Value; } 179 } 180 181 private DataBarSet ResultsSonarQualitiesBars { 182 get { return (DataBarSet)Results["Ensemble Comparison [Sonar-Quality]"].Value; } 183 } 184 185 private DataBarSet ResultsSWPeakQualitiesBars { 186 get { return (DataBarSet)Results["Ensemble Comparison [SW-PeakQuality]"].Value; } 187 } 188 189 private double ResultsMeanPR2 { 190 get { return ((DoubleValue) Results["Mean PR2"].Value).Value; } 191 set { ((DoubleValue)Results["Mean PR2"].Value).Value = value; } 192 } 193 194 private double ResultsDetectionAccuracy { 195 get { return ((DoubleValue)Results["Detection Accuracy"].Value).Value; } 196 set { ((DoubleValue)Results["Detection Accuracy"].Value).Value = value; } 197 } 198 199 private double ResultsDetectionExclusivity { 200 get { return ((DoubleValue)Results["Detection Exclusivity"].Value).Value; } 201 set { ((DoubleValue)Results["Detection Exclusivity"].Value).Value = value; } 202 } 203 204 //private int ResultsTrueDetectionCount { 205 // get { return ((IntValue)Results["True Detection Count"].Value).Value; } 206 // set { ((IntValue)Results["True Detection Count"].Value).Value = value; } 207 //} 208 209 //private int ResultsFalseDetectionCount { 210 // get { return ((IntValue)Results["False Detection Count"].Value).Value; } 211 // set { ((IntValue)Results["False Detection Count"].Value).Value = value; } 212 //} 162 213 163 214 protected void SetupResults() { 215 evaluationCount = 0; 216 lastStateValue = 0.0; 217 pR2Sum = 0.0; 218 exclusivitySum = 0.0; 219 accuracySum = 0.0; 220 detectionCount = 0; 164 221 Results.Clear(); 165 166 222 Results.Add(new Result("Sliding Window Movements", new IntValue(0))); 167 Results.Add(new Result("Qualities", new DataTable("Pearson R²"))); 223 Results.Add(new Result("Qualities 1", new DataTable("Average Pearson R²"))); 224 Results.Add(new Result("Qualities 2", new DataTable("Peak Pearson R²"))); 168 225 Results.Add(new Result("Targets", new DataTable("Targets"))); 169 Results.Add(new Result("Ensemble Comparison", new DataBarSet("Ensemble Comparison"))); 226 Results.Add(new Result("State Detection", new DataTable("State Detection"))); 227 Results.Add(new Result("Ensemble Comparison [SW-Quality]", new DataBarSet("Ensemble Comparison [SW-Quality]"))); 228 Results.Add(new Result("Ensemble Comparison [SW-Voting]", new DataBarSet("Ensemble Comparison [SW-Voting]"))); 229 Results.Add(new Result("Ensemble Comparison [Sonar-Quality]", new DataBarSet("Ensemble Comparison [Sonar-Quality]"))); 230 Results.Add(new Result("Ensemble Comparison [SW-PeakQuality]", new DataBarSet("Ensemble Comparison [SW-PeakQuality]"))); 231 Results.Add(new Result("Mean PR2", new DoubleValue())); 232 Results.Add(new Result("Detection Accuracy", new DoubleValue())); 233 Results.Add(new Result("Detection Exclusivity", new DoubleValue())); 170 234 171 235 ResultsTargets.Rows.Add(new DataRow(ResultsTargetsReal)); … … 174 238 ResultsTargets.Rows.Add(new DataRow(ensemble.Name)); 175 239 240 ResultsStateDetection.Rows.Add(new DataRow(ensemble.Name)); 241 176 242 // qualities (series) 177 243 //ResultsQualities.Rows.Add(new DataRow(ensemble.Name + " - " + ResultsQualitiesMSE)); 178 ResultsQualities.Rows.Add(new DataRow(ensemble.Name + " - " + ResultsQualitiesPR2)); 244 ResultsQualities.Rows.Add(new DataRow(ensemble.Name)); 245 246 ResultsPeakQualities.Rows.Add(new DataRow(ensemble.Name)); 179 247 180 248 // qualities (bars) 181 ResultsQualitiesBars.Bars.Add(new DataBar(ensemble.Name, 0.9)); 249 ResultsSWQualitiesBars.Bars.Add(new DataBar(ensemble.Name, ensemble.QualityThreshold.Start, ensemble.QualityThreshold.End)); 250 251 // voting (bars) 252 ResultsSWVotingBars.Bars.Add(new DataBar(ensemble.Name, ensemble.ConfidenceThreshold.Start, ensemble.ConfidenceThreshold.End)); 253 254 // sonar quality (bars) 255 ResultsSonarQualitiesBars.Bars.Add(new DataBar(ensemble.Name, ensemble.QualityThreshold.Start, ensemble.QualityThreshold.End)); 256 257 // quality peaks (bars) 258 ResultsSWPeakQualitiesBars.Bars.Add(new DataBar(ensemble.Name, ensemble.QualityThreshold.Start, ensemble.QualityThreshold.End)); 182 259 } 183 260 } … … 190 267 log = new Log(); 191 268 results = new ResultCollection(); 192 ensembles = new ItemList<R egressionEnsembleModel>();269 ensembles = new ItemList<RatedEnsembleModel>(); 193 270 datastream = new Datastream(); 194 271 runsCounter = 0; … … 210 287 log = cloner.Clone(original.log); 211 288 results = cloner.Clone(original.results); 212 ensembles = (ItemList<R egressionEnsembleModel>) original.Ensembles.Clone(cloner);289 ensembles = (ItemList<RatedEnsembleModel>) original.Ensembles.Clone(cloner); 213 290 datastream = (Datastream) original.Datastream.Clone(cloner); 214 291 runsCounter = original.runsCounter; … … 373 450 // play and evaluate initial window 374 451 PlayDatastream(); 375 if(Datastream.SlidingWindowEvaluationPossible) Evaluate(); 452 lastStateValue = Datastream.ProblemData.Dataset.GetDoubleValue("h", replayedIndex); 453 if (Datastream.SlidingWindowEvaluationPossible) Evaluate(); 376 454 replayedIndex = Datastream.FitnessPartition.End; 377 455 … … 381 459 382 460 // perform (delayed) window movement 383 Thread.Sleep(Datastream.SlidingWindowMovement Interval.Value);461 Thread.Sleep(Datastream.SlidingWindowMovementDelay.Value); 384 462 Datastream.MoveSlidingWindow(); 385 463 ResultsSlidingWindowMovements++; … … 412 490 } 413 491 } 414 492 415 493 private void Evaluate() { 494 evaluationCount++; 416 495 var problemData = Datastream.ProblemData; 417 496 var dataset = problemData.Dataset; 418 497 var targetVarName = problemData.TargetVariable; 419 498 420 var realRows = Enumerable.Range(Datastream.FitnessPartition.Start, Datastream.FitnessPartition.Size).ToList(); 421 var realValues = dataset.GetDoubleValues(targetVarName, realRows); 422 499 var rows = Enumerable.Range(Datastream.FitnessPartition.Start, Datastream.FitnessPartition.Size); 500 var realValues = dataset.GetDoubleValues(targetVarName, rows); 501 502 int sonarSize = (int)(Datastream.FitnessPartition.Size * Datastream.SlidingWindowSonarRatio.Value); 503 var sonarStart = Datastream.FitnessPartition.End - sonarSize; 504 var sonarRows = Enumerable.Range(sonarStart, sonarSize); 505 var sonarRealValues = dataset.GetDoubleValues(targetVarName, sonarRows); 506 507 var winningEnsembleName = ensembles[0].Name; 508 var winningEnsemblePR2 = 0.0; 509 var winningEnsembleIdx = 0; 510 var ec = 0; 511 bool stateChangeInStep = false; 512 var curDetectionCount = 0; 513 var changeDetectionCount = 0; 514 double curStateValue = 0.0; 423 515 foreach (var ensemble in Ensembles) { 424 516 425 var rows = Enumerable.Range(Datastream.FitnessPartition.Start, Datastream.FitnessPartition.Size); 426 var estimatedValuesPerModelPerRow = ensemble.Models.Select(x => x.GetEstimatedValues(datastream.ProblemData.Dataset, rows).ToArray()); 427 var estimatedValues = Enumerable.Range(0, Datastream.FitnessPartition.Size).Select(r => estimatedValuesPerModelPerRow.Select(e => e[r]).Average()).ToArray(); // per row 517 var sonarEstimatedValuesPerModelPerRow = ensemble.Model.Models.Select(x => x.GetEstimatedValues(datastream.ProblemData.Dataset, sonarRows).ToArray()); 518 var sonarEstimatedValuesPerRow = Enumerable.Range(0, sonarSize).Select(r => sonarEstimatedValuesPerModelPerRow.Select(m => m[r]).Average()).ToArray(); 519 520 var estimatedValuesPerModelPerRow = ensemble.Model.Models.Select(x => x.GetEstimatedValues(datastream.ProblemData.Dataset, rows).ToArray()); 521 var estimatedValuesPerRow = Enumerable.Range(0, Datastream.FitnessPartition.Size).Select(r => estimatedValuesPerModelPerRow.Select(e => e[r]).Average()).ToArray(); // per row 428 522 var averageEstimatedValuesPerModel = estimatedValuesPerModelPerRow.Select(x => x.Average()); // per model 429 523 var averageEstimatedValue = averageEstimatedValuesPerModel.Average(); 430 524 431 // determine quality432 var mse = Math.Pow(averageEstimatedValue - realValues.Average(), 2);525 // calulate quality 526 //var mse = Math.Pow(averageEstimatedValue - realValues.Average(), 2); 433 527 OnlineCalculatorError error; 434 var pR = OnlinePearsonsRCalculator.Calculate(estimatedValues , realValues, out error);528 var pR = OnlinePearsonsRCalculator.Calculate(estimatedValuesPerRow, realValues, out error); 435 529 var pR2 = error == OnlineCalculatorError.None ? pR * pR : 0.0; 436 530 531 var sonarPR = OnlinePearsonsRCalculator.Calculate(sonarEstimatedValuesPerRow, sonarRealValues, out error); 532 var sonarPR2 = error == OnlineCalculatorError.None ? sonarPR * sonarPR : 0.0; 533 534 var estimatedValuesPerModelPerRowArr = estimatedValuesPerModelPerRow.ToArray(); 535 var curPR = 0.0; 536 537 var peakPR = OnlinePearsonsRCalculator.Calculate(estimatedValuesPerModelPerRowArr[0], realValues, out error); 538 for (int i = 1; i < estimatedValuesPerModelPerRow.Count(); i++) { 539 curPR = OnlinePearsonsRCalculator.Calculate(estimatedValuesPerModelPerRowArr[i], realValues, out error); 540 if (curPR > peakPR && error == OnlineCalculatorError.None) { 541 peakPR = curPR; 542 } 543 } 544 var peakPR2 = peakPR * peakPR; 545 546 // calculate confidence 547 var cm1 = CalulateEnsembleConfidenceCM1(ensemble, estimatedValuesPerModelPerRow, realValues); 548 437 549 int replayAmount = Datastream.FitnessPartition.End - replayedIndex; 438 int replayCount = estimatedValues .Length - replayAmount;550 int replayCount = estimatedValuesPerRow.Length - replayAmount; 439 551 440 552 for (int i = replayedIndex; i < Datastream.FitnessPartition.End; i++) { 441 553 //ResultsTargets.Rows[ensemble.Name].Values.Add(averageEstimatedValue); 442 ResultsTargets.Rows[ensemble.Name].Values.Add(estimatedValues [replayCount]);554 ResultsTargets.Rows[ensemble.Name].Values.Add(estimatedValuesPerRow[replayCount]); 443 555 replayCount++; 444 556 445 557 //ResultsQualities.Rows[ensemble.Name + " - " + ResultsQualitiesMSE].Values.Add(mse); 446 ResultsQualities.Rows[ensemble.Name + " - " + ResultsQualitiesPR2].Values.Add(pR2); 447 ResultsQualitiesBars.Bars[ensemble.Name].Value = pR2; 448 } 449 } 558 ResultsQualities.Rows[ensemble.Name].Values.Add(pR2); 559 ResultsPeakQualities.Rows[ensemble.Name].Values.Add(peakPR2); 560 561 double amp = (pR2 > ensemble.QualityThreshold.Start) ? 1.0 : 0.0; 562 ResultsStateDetection.Rows[ensemble.Name].Values.Add(amp); 563 } 564 ResultsSWQualitiesBars.Bars[ensemble.Name].Value = pR2; 565 ResultsSonarQualitiesBars.Bars[ensemble.Name].Value = sonarPR2; 566 ResultsSWVotingBars.Bars[ensemble.Name].Value = cm1; 567 ResultsSWPeakQualitiesBars.Bars[ensemble.Name].Value = peakPR2; 568 569 if (pR2 > ensemble.QualityThreshold.Start) 570 curDetectionCount++; 571 572 if (pR2 > winningEnsemblePR2) { 573 winningEnsemblePR2 = pR2; 574 winningEnsembleName = ensemble.Name; 575 winningEnsembleIdx = ec; 576 } 577 ec++; 578 } 579 580 // quality meassures 581 // ================================================= 582 583 if (winningEnsemblePR2 > ensembles[winningEnsembleIdx].QualityThreshold.Start) { 584 // Mean PR2 585 pR2Sum += winningEnsemblePR2; 586 detectionCount++; 587 ResultsMeanPR2 = pR2Sum/detectionCount; 588 589 // detection exclusivity --> 1.0 - (x - 1) * (1.0 / n) 590 var fraction = 1.0 / ensembles.Count; 591 var curExclusivity = 1.0 - (curDetectionCount - 1) * fraction; 592 exclusivitySum += curExclusivity; 593 ResultsDetectionExclusivity = exclusivitySum / detectionCount; 594 } 595 596 double replCount = 0.0; 597 double accCount = 0.0; 598 for (int i = replayedIndex; i < Datastream.FitnessPartition.End; i++) { 599 replCount++; 600 curStateValue = problemData.Dataset.GetDoubleValue("h", i); 601 if (curStateValue <= 0.5 && winningEnsembleIdx == 0 && winningEnsemblePR2 > ensembles[winningEnsembleIdx].QualityThreshold.Start) { 602 accCount++; 603 } else if (curStateValue > 0.5 && winningEnsembleIdx == 1 && winningEnsemblePR2 > ensembles[winningEnsembleIdx].QualityThreshold.Start) { 604 accCount++; 605 } 606 } 607 accuracySum += accCount / replCount; 608 ResultsDetectionAccuracy = accuracySum / evaluationCount; 609 610 //if (accCount / replCount > 1.0) { 611 // Console.WriteLine(); 612 //} 613 614 //if(accuracySum / evaluationCount > 1.0) { 615 // Console.WriteLine(); 616 //} 617 618 //if (accCount < replCount && !accDiscount) accDiscount = true; 619 //if (accDiscount && accuracySum/evaluationCount >= 1.0) { 620 // Console.WriteLine(); 621 //} 622 623 lastStateValue = curStateValue; 624 625 // detection of state change 626 //for (int i = replayedIndex; i < Datastream.FitnessPartition.End; i++) { 627 // curStateValue = problemData.Dataset.GetDoubleValue("h", i); 628 // if (lastStateValue > curStateValue || lastStateValue < curStateValue) { 629 // stateChangeInStep = true; 630 // changeDetectionCount++; 631 // } 632 //} 633 //lastStateValue = curStateValue; 634 635 // detection accuracy 636 //if (!stateChangeInStep && winningEnsemblePR2 > ensembles[winningEnsembleIdx].QualityThreshold.Start) { 637 // // (stable) state - detected 638 // accuracySum++; 639 //} else if(!stateChangeInStep && winningEnsemblePR2 < ensembles[winningEnsembleIdx].QualityThreshold.Start) { 640 // // (stable) state - not detected 641 // // no accuracy points (or penalty) 642 //} else if (stateChangeInStep && winningEnsemblePR2 < ensembles[winningEnsembleIdx].QualityThreshold.Start) { 643 // // change - detected 644 // accuracySum++; 645 //} else if (stateChangeInStep && winningEnsemblePR2 > ensembles[winningEnsembleIdx].QualityThreshold.Start) { 646 // // change - not detected 647 // // no accuracy points (or penalty) 648 //} 649 } 650 private bool accDiscount = false; 651 652 private double CalulateEnsembleConfidenceCM1(RatedEnsembleModel ensemble, IEnumerable<double[]> estimatedValuesPerModelPerRow, IEnumerable<double> realValues) { 653 int noModels = estimatedValuesPerModelPerRow.Count(); 654 int votes = 0; 655 656 OnlineCalculatorError error; 657 658 foreach(var model in estimatedValuesPerModelPerRow) { 659 var pR = OnlinePearsonsRCalculator.Calculate(model, realValues, out error); 660 var pR2 = error == OnlineCalculatorError.None ? pR * pR : 0.0; 661 if (pR2 >= ensemble.QualityThreshold.End) { 662 votes++; 663 } 664 } 665 666 667 return (double)votes/noModels; 450 668 } 451 669 … … 499 717 500 718 protected virtual void RegisterEnsembleEvents() { 501 ensembles.ItemsAdded += new CollectionItemsChangedEventHandler<IndexedItem<R egressionEnsembleModel>>(Ensembles_ItemsChanged);502 ensembles.ItemsMoved += new CollectionItemsChangedEventHandler<IndexedItem<R egressionEnsembleModel>>(Ensembles_ItemsChanged);503 ensembles.ItemsRemoved += new CollectionItemsChangedEventHandler<IndexedItem<R egressionEnsembleModel>>(Ensembles_ItemsChanged);504 ensembles.ItemsReplaced += new CollectionItemsChangedEventHandler<IndexedItem<R egressionEnsembleModel>>(Ensembles_ItemsChanged);505 ensembles.CollectionReset += new CollectionItemsChangedEventHandler<IndexedItem<R egressionEnsembleModel>>(Ensembles_Reset);719 ensembles.ItemsAdded += new CollectionItemsChangedEventHandler<IndexedItem<RatedEnsembleModel>>(Ensembles_ItemsChanged); 720 ensembles.ItemsMoved += new CollectionItemsChangedEventHandler<IndexedItem<RatedEnsembleModel>>(Ensembles_ItemsChanged); 721 ensembles.ItemsRemoved += new CollectionItemsChangedEventHandler<IndexedItem<RatedEnsembleModel>>(Ensembles_ItemsChanged); 722 ensembles.ItemsReplaced += new CollectionItemsChangedEventHandler<IndexedItem<RatedEnsembleModel>>(Ensembles_ItemsChanged); 723 ensembles.CollectionReset += new CollectionItemsChangedEventHandler<IndexedItem<RatedEnsembleModel>>(Ensembles_Reset); 506 724 } 507 725 508 726 protected virtual void DeregisterEnsembleEvents() { 509 ensembles.ItemsAdded -= new CollectionItemsChangedEventHandler<IndexedItem<R egressionEnsembleModel>>(Ensembles_ItemsChanged);510 ensembles.ItemsMoved -= new CollectionItemsChangedEventHandler<IndexedItem<R egressionEnsembleModel>>(Ensembles_ItemsChanged);511 ensembles.ItemsRemoved -= new CollectionItemsChangedEventHandler<IndexedItem<R egressionEnsembleModel>>(Ensembles_ItemsChanged);512 ensembles.ItemsReplaced -= new CollectionItemsChangedEventHandler<IndexedItem<R egressionEnsembleModel>>(Ensembles_ItemsChanged);513 ensembles.CollectionReset -= new CollectionItemsChangedEventHandler<IndexedItem<R egressionEnsembleModel>>(Ensembles_Reset);727 ensembles.ItemsAdded -= new CollectionItemsChangedEventHandler<IndexedItem<RatedEnsembleModel>>(Ensembles_ItemsChanged); 728 ensembles.ItemsMoved -= new CollectionItemsChangedEventHandler<IndexedItem<RatedEnsembleModel>>(Ensembles_ItemsChanged); 729 ensembles.ItemsRemoved -= new CollectionItemsChangedEventHandler<IndexedItem<RatedEnsembleModel>>(Ensembles_ItemsChanged); 730 ensembles.ItemsReplaced -= new CollectionItemsChangedEventHandler<IndexedItem<RatedEnsembleModel>>(Ensembles_ItemsChanged); 731 ensembles.CollectionReset -= new CollectionItemsChangedEventHandler<IndexedItem<RatedEnsembleModel>>(Ensembles_Reset); 514 732 } 515 733 #endregion -
branches/HeuristicLab.DatastreamAnalysis/HeuristicLab.DatastreamAnalysis/3.4/HeuristicLab.DatastreamAnalysis.csproj
r14588 r14710 110 110 <Compile Include="IAnalysisBase.cs" /> 111 111 <Compile Include="IDatastream.cs" /> 112 <Compile Include="IRatedEnsembleModel.cs" /> 112 113 <Compile Include="Plugin.cs" /> 113 114 <Compile Include="Properties\AssemblyInfo.cs" /> 115 <Compile Include="RatedEnsembleModel.cs" /> 114 116 </ItemGroup> 115 117 <ItemGroup> -
branches/HeuristicLab.DatastreamAnalysis/HeuristicLab.DatastreamAnalysis/3.4/Plugin.cs
r14588 r14710 23 23 24 24 namespace HeuristicLab.DatastreamAnalysis { 25 [Plugin("HeuristicLab.DatastreamAnalysis", "3.4.14.145 47")]25 [Plugin("HeuristicLab.DatastreamAnalysis", "3.4.14.14588")] 26 26 [PluginFile("HeuristicLab.DatastreamAnalysis-3.4.dll", PluginFileType.Assembly)] 27 27 [PluginDependency("HeuristicLab.Collections", "3.3")] -
branches/HeuristicLab.DatastreamAnalysis/HeuristicLab.DatastreamAnalysis/3.4/Properties/AssemblyInfo.cs
r14588 r14710 54 54 // [assembly: AssemblyVersion("1.0.*")] 55 55 [assembly: AssemblyVersion("3.4.0.0")] 56 [assembly: AssemblyFileVersion("3.4.14.145 47")]56 [assembly: AssemblyFileVersion("3.4.14.14588")] -
branches/HeuristicLab.DatastreamAnalysis/HeuristicLab.Problems.DataAnalysis/3.4/HeuristicLab.Problems.DataAnalysis-3.4.csproj
r14491 r14710 173 173 <Compile Include="Implementation\Regression\ConstantRegressionModel.cs" /> 174 174 <Compile Include="Implementation\Regression\ConstantRegressionSolution.cs" /> 175 <Compile Include="Implementation\Regression\RatedRegressionEnsembleModel.cs" /> 175 176 <Compile Include="Implementation\Regression\RegressionEnsembleProblemData.cs" /> 176 177 <Compile Include="Implementation\Regression\RegressionEnsembleModel.cs"> -
branches/HeuristicLab.DatastreamAnalysis/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RatedRegressionEnsembleModel.cs
r14538 r14710 25 25 using HeuristicLab.Common; 26 26 using HeuristicLab.Core; 27 using HeuristicLab.Data; 27 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 29 … … 32 33 /// </summary> 33 34 [StorableClass] 34 [Item("R egression Ensemble Model", "A regression model that contains an ensemble of multiple regression models")]35 [Item("Rated Regression Ensemble Model", "A regression model that contains an ensemble of multiple regression models")] 35 36 [Creatable(CreatableAttribute.Categories.DataAnalysisEnsembles, Priority = 100)] 36 public sealed class R egressionEnsembleModel : RegressionModel, IRegressionEnsembleModel {37 public sealed class RatedRegressionEnsembleModel : RegressionModel, IRegressionEnsembleModel { 37 38 public override IEnumerable<string> VariablesUsedForPrediction { 38 39 get { return models.SelectMany(x => x.VariablesUsedForPrediction).Distinct().OrderBy(x => x); } … … 59 60 get { return modelWeights; } 60 61 set { modelWeights = value.ToList(); } 62 } 63 64 private DoubleRange qualityThreshold; 65 public DoubleRange QualityThreshold { 66 get { return qualityThreshold; } 67 set { qualityThreshold = value; } 68 } 69 [Storable(Name = "QualityThreshold")] 70 private DoubleRange StorableQualityThreshold { 71 get { return qualityThreshold; } 72 set { qualityThreshold = value; } 73 } 74 75 private DoubleRange confidenceThreshold; 76 public DoubleRange ConfidenceThreshold 77 { 78 get { return confidenceThreshold; } 79 set { confidenceThreshold = value; } 80 } 81 [Storable(Name = "QualityThreshold")] 82 private DoubleRange StorableConfidenceThreshold 83 { 84 get { return confidenceThreshold; } 85 set { confidenceThreshold = value; } 61 86 } 62 87 … … 90 115 91 116 [StorableConstructor] 92 private R egressionEnsembleModel(bool deserializing) : base(deserializing) { }93 private R egressionEnsembleModel(RegressionEnsembleModel original, Cloner cloner)117 private RatedRegressionEnsembleModel(bool deserializing) : base(deserializing) { } 118 private RatedRegressionEnsembleModel(RatedRegressionEnsembleModel original, Cloner cloner) 94 119 : base(original, cloner) { 95 120 this.models = original.Models.Select(cloner.Clone).ToList(); 96 121 this.modelWeights = new List<double>(original.ModelWeights); 122 this.qualityThreshold = cloner.Clone(original.qualityThreshold); 123 this.confidenceThreshold = cloner.Clone(original.confidenceThreshold); 97 124 this.averageModelEstimates = original.averageModelEstimates; 98 125 } 99 126 public override IDeepCloneable Clone(Cloner cloner) { 100 return new R egressionEnsembleModel(this, cloner);101 } 102 103 public R egressionEnsembleModel() : this(Enumerable.Empty<IRegressionModel>()) { }104 public R egressionEnsembleModel(IEnumerable<IRegressionModel> models) : this(models, models.Select(m => 1.0)) { }105 public R egressionEnsembleModel(IEnumerable<IRegressionModel> models, IEnumerable<double> modelWeights)127 return new RatedRegressionEnsembleModel(this, cloner); 128 } 129 130 public RatedRegressionEnsembleModel() : this(Enumerable.Empty<IRegressionModel>()) { } 131 public RatedRegressionEnsembleModel(IEnumerable<IRegressionModel> models) : this(models, models.Select(m => 1.0)) { } 132 public RatedRegressionEnsembleModel(IEnumerable<IRegressionModel> models, IEnumerable<double> modelWeights) 106 133 : base(string.Empty) { 107 134 this.name = ItemName; -
branches/HeuristicLab.DatastreamAnalysis/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionEnsembleModel.cs
r14538 r14710 33 33 [StorableClass] 34 34 [Item("Regression Ensemble Model", "A regression model that contains an ensemble of multiple regression models")] 35 [Creatable(CreatableAttribute.Categories.DataAnalysisEnsembles, Priority = 100)]36 35 public sealed class RegressionEnsembleModel : RegressionModel, IRegressionEnsembleModel { 37 36 public override IEnumerable<string> VariablesUsedForPrediction {
Note: See TracChangeset
for help on using the changeset viewer.