Changeset 4631
- Timestamp:
- 10/21/10 02:58:15 (14 years ago)
- Location:
- trunk/sources
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Analysis.Views/3.3/AlleleFrequencyArrayView.Designer.cs
r4623 r4631 47 47 System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); 48 48 System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend(); 49 System.Windows.Forms.DataVisualization.Charting. Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series();50 this.chart = new System.Windows.Forms.DataVisualization.Charting.Chart();49 System.Windows.Forms.DataVisualization.Charting.Title title1 = new System.Windows.Forms.DataVisualization.Charting.Title(); 50 this.chart = new HeuristicLab.Visualization.ChartControlsExtensions.EnhancedChart(); 51 51 ((System.ComponentModel.ISupportInitialize)(this.chart)).BeginInit(); 52 52 this.SuspendLayout(); … … 59 59 this.chart.BorderlineColor = System.Drawing.Color.Black; 60 60 this.chart.BorderlineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Solid; 61 chartArea1.AxisX.IntervalAutoMode = System.Windows.Forms.DataVisualization.Charting.IntervalAutoMode.VariableCount; 62 chartArea1.AxisX.LabelAutoFitStyle = ((System.Windows.Forms.DataVisualization.Charting.LabelAutoFitStyles)((System.Windows.Forms.DataVisualization.Charting.LabelAutoFitStyles.IncreaseFont | System.Windows.Forms.DataVisualization.Charting.LabelAutoFitStyles.DecreaseFont))); 63 chartArea1.AxisX.LabelStyle.Angle = 90; 64 chartArea1.AxisX.Title = "Alleles"; 65 chartArea1.AxisY.Maximum = 1D; 66 chartArea1.AxisY.Minimum = 0D; 67 chartArea1.AxisY.Title = "Relative Frequency"; 68 chartArea1.AxisY2.Title = "Average Solution Quality"; 61 69 chartArea1.CursorX.IsUserEnabled = true; 62 70 chartArea1.CursorX.IsUserSelectionEnabled = true; 63 71 chartArea1.CursorY.IsUserEnabled = true; 64 72 chartArea1.CursorY.IsUserSelectionEnabled = true; 65 chartArea1.Name = " ChartArea1";73 chartArea1.Name = "Default"; 66 74 this.chart.ChartAreas.Add(chartArea1); 67 75 legend1.Docking = System.Windows.Forms.DataVisualization.Charting.Docking.Top; 68 legend1.Name = " Legend1";76 legend1.Name = "Default"; 69 77 this.chart.Legends.Add(legend1); 70 78 this.chart.Location = new System.Drawing.Point(0, 0); 71 79 this.chart.Name = "chart"; 72 series1.ChartArea = "ChartArea1";73 series1.Legend = "Legend1";74 series1.Name = "Series1";75 this.chart.Series.Add(series1);76 80 this.chart.Size = new System.Drawing.Size(498, 359); 77 this.chart.TabIndex = 4; 78 this.chart.Text = "chart1"; 81 this.chart.TabIndex = 0; 82 this.chart.Text = "chart"; 83 title1.Name = "Default"; 84 title1.Text = "Allele Frequencies"; 85 this.chart.Titles.Add(title1); 86 this.chart.CustomizeLegend += new System.EventHandler<System.Windows.Forms.DataVisualization.Charting.CustomizeLegendEventArgs>(this.chart_CustomizeLegend); 87 this.chart.MouseDown += new System.Windows.Forms.MouseEventHandler(this.chart_MouseDown); 88 this.chart.MouseMove += new System.Windows.Forms.MouseEventHandler(this.chart_MouseMove); 79 89 // 80 90 // AlleleFrequencyArrayView … … 92 102 #endregion 93 103 94 pr ivate System.Windows.Forms.DataVisualization.Charting.Chart chart;104 protected HeuristicLab.Visualization.ChartControlsExtensions.EnhancedChart chart; 95 105 96 106 } -
trunk/sources/HeuristicLab.Analysis.Views/3.3/AlleleFrequencyArrayView.cs
r4623 r4631 20 20 #endregion 21 21 22 using System.Collections.Generic; 23 using System.Drawing; 24 using System.Linq; 22 25 using System.Windows.Forms; 23 26 using System.Windows.Forms.DataVisualization.Charting; … … 29 32 [Content(typeof(AlleleFrequencyArray), true)] 30 33 public partial class AlleleFrequencyArrayView : ItemView { 34 private List<Series> invisibleSeries; 35 31 36 public new AlleleFrequencyArray Content { 32 37 get { return (AlleleFrequencyArray)base.Content; } … … 36 41 public AlleleFrequencyArrayView() { 37 42 InitializeComponent(); 38 } 39 40 protected override void DeregisterContentEvents() { 41 // ... 42 base.DeregisterContentEvents(); 43 } 44 45 protected override void RegisterContentEvents() { 46 base.RegisterContentEvents(); 47 // ... 43 invisibleSeries = new List<Series>(); 48 44 } 49 45 50 46 protected override void OnContentChanged() { 51 47 base.OnContentChanged(); 52 chart.Titles.Clear(); 53 chart.Series.Clear(); 54 chart.DataSource = null; 55 if (Content != null) 56 PopulateChart(); 48 if (Content == null) { 49 chart.Series.Clear(); 50 chart.DataSource = null; 51 invisibleSeries.Clear(); 52 } else { 53 if (chart.Series.Count == 0) CreateSeries(); 54 chart.DataSource = Content.Select(x => new { 55 Id = x.Id, 56 BestKnownFrequency = x.ContainedInBestKnownSolution ? x.Frequency : 0, 57 Frequency = !x.ContainedInBestKnownSolution ? x.Frequency : 0, 58 Quality = x.AverageSolutionQuality, 59 Impact = x.AverageImpact 60 }).OrderBy(x => x.Impact).ToArray(); 61 UpdateSeries(); 62 } 57 63 } 58 64 … … 62 68 } 63 69 64 private void PopulateChart() { 65 chart.Titles.Add(new Title("Allele Frequencies", Docking.Top)); 66 chart.DataSource = Content; 67 Series frequencies = new Series("Frequencies"); 68 frequencies.ChartType = SeriesChartType.Column; 69 frequencies.XValueMember = "Id"; 70 frequencies.XValueType = ChartValueType.String; 71 frequencies.YValueMembers = "Frequency"; 72 frequencies.YValueType = ChartValueType.Double; 73 frequencies.YAxisType = AxisType.Primary; 74 frequencies.ToolTip = "X = #INDEX, Y = #VAL"; 75 chart.Series.Add(frequencies); 70 protected virtual void CreateSeries() { 71 Series bestKnown = new Series("Alleles of Best Known Solution"); 72 bestKnown.ChartType = SeriesChartType.StackedColumn; 73 bestKnown.XValueMember = "Id"; 74 bestKnown.XValueType = ChartValueType.String; 75 bestKnown.YValueMembers = "BestKnownFrequency"; 76 bestKnown.YValueType = ChartValueType.Double; 77 bestKnown.YAxisType = AxisType.Primary; 78 bestKnown.ToolTip = "X = #LABEL, Y = #VAL"; 79 chart.Series.Add(bestKnown); 80 81 Series others = new Series("Other Alleles"); 82 others.ChartType = SeriesChartType.StackedColumn; 83 others.XValueMember = "Id"; 84 others.XValueType = ChartValueType.String; 85 others.YValueMembers = "Frequency"; 86 others.YValueType = ChartValueType.Double; 87 others.YAxisType = AxisType.Primary; 88 others.ToolTip = "X = #LABEL, Y = #VAL"; 89 chart.Series.Add(others); 90 76 91 Series qualities = new Series("Average Solution Qualities"); 77 92 qualities.ChartType = SeriesChartType.FastLine; 78 93 qualities.XValueMember = "Id"; 79 94 qualities.XValueType = ChartValueType.String; 80 qualities.YValueMembers = " AverageSolutionQuality";95 qualities.YValueMembers = "Quality"; 81 96 qualities.YValueType = ChartValueType.Double; 82 97 qualities.YAxisType = AxisType.Secondary; 83 qualities.ToolTip = "X = # INDEX, Y = #VAL";98 qualities.ToolTip = "X = #LABEL, Y = #VAL"; 84 99 chart.Series.Add(qualities); 100 101 Series impacts = new Series("Average Impact"); 102 impacts.ChartType = SeriesChartType.FastLine; 103 impacts.XValueMember = "Id"; 104 impacts.XValueType = ChartValueType.String; 105 impacts.YValueMembers = "Impact"; 106 impacts.YValueType = ChartValueType.Double; 107 impacts.YAxisType = AxisType.Secondary; 108 impacts.ToolTip = "X = #LABEL, Y = #VAL"; 109 chart.Series.Add(impacts); 85 110 } 111 112 protected virtual void UpdateSeries() { 113 chart.DataBind(); 114 115 if (invisibleSeries.Contains(chart.Series["Alleles of Best Known Solution"])) 116 chart.Series["Alleles of Best Known Solution"].Points.Clear(); 117 chart.DataManipulator.Filter(CompareMethod.EqualTo, 0, chart.Series["Alleles of Best Known Solution"]); 118 119 if (invisibleSeries.Contains(chart.Series["Other Alleles"])) 120 chart.Series["Other Alleles"].Points.Clear(); 121 chart.DataManipulator.Filter(CompareMethod.EqualTo, 0, chart.Series["Other Alleles"]); 122 123 if (invisibleSeries.Contains(chart.Series["Average Solution Qualities"])) 124 chart.Series["Average Solution Qualities"].Points.Clear(); 125 chart.DataManipulator.Filter(CompareMethod.EqualTo, 0, chart.Series["Average Solution Qualities"]); 126 127 if (invisibleSeries.Contains(chart.Series["Average Impact"])) 128 chart.Series["Average Impact"].Points.Clear(); 129 chart.DataManipulator.Filter(CompareMethod.EqualTo, 0, chart.Series["Average Impact"]); 130 } 131 132 #region Chart Events 133 protected virtual void chart_MouseDown(object sender, MouseEventArgs e) { 134 HitTestResult result = chart.HitTest(e.X, e.Y); 135 if (result.ChartElementType == ChartElementType.LegendItem) { 136 ToggleSeriesVisible(result.Series); 137 } 138 } 139 140 protected virtual void ToggleSeriesVisible(Series series) { 141 if (!invisibleSeries.Contains(series)) 142 invisibleSeries.Add(series); 143 else 144 invisibleSeries.Remove(series); 145 UpdateSeries(); 146 } 147 148 protected virtual void chart_MouseMove(object sender, MouseEventArgs e) { 149 HitTestResult result = chart.HitTest(e.X, e.Y); 150 if (result.ChartElementType == ChartElementType.LegendItem) 151 this.Cursor = Cursors.Hand; 152 else 153 this.Cursor = Cursors.Default; 154 } 155 156 protected virtual void chart_CustomizeLegend(object sender, CustomizeLegendEventArgs e) { 157 foreach (LegendItem legendItem in e.LegendItems) { 158 var series = chart.Series[legendItem.SeriesName]; 159 if (series != null) { 160 bool seriesIsInvisible = invisibleSeries.Contains(series); 161 foreach (LegendCell cell in legendItem.Cells) { 162 cell.ForeColor = seriesIsInvisible ? Color.Gray : Color.Black; 163 } 164 } 165 } 166 } 167 #endregion 86 168 } 87 169 } -
trunk/sources/HeuristicLab.Analysis.Views/3.3/HeuristicLab.Analysis.Views-3.3.csproj
r4623 r4631 94 94 </PropertyGroup> 95 95 <ItemGroup> 96 <Reference Include="HeuristicLab.Common.Resources-3.3, Version=3.2.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL" /> 97 <Reference Include="HeuristicLab.Data.Views-3.3"> 98 <HintPath>..\..\HeuristicLab.Data.Views\3.3\bin\Debug\HeuristicLab.Data.Views-3.3.dll</HintPath> 99 </Reference> 100 <Reference Include="HeuristicLab.Optimization-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL" /> 96 101 <Reference Include="System" /> 97 102 <Reference Include="System.Core"> … … 170 175 <Name>HeuristicLab.MainForm-3.3</Name> 171 176 </ProjectReference> 177 <ProjectReference Include="..\..\HeuristicLab.Optimization.Views\3.3\HeuristicLab.Optimization.Views-3.3.csproj"> 178 <Project>{662B4B15-8F4D-4AE5-B3EB-D91C215F5AF2}</Project> 179 <Name>HeuristicLab.Optimization.Views-3.3</Name> 180 </ProjectReference> 172 181 <ProjectReference Include="..\..\HeuristicLab.PluginInfrastructure\3.3\HeuristicLab.PluginInfrastructure-3.3.csproj"> 173 182 <Project>{94186A6A-5176-4402-AE83-886557B53CCA}</Project> 174 183 <Name>HeuristicLab.PluginInfrastructure-3.3</Name> 184 </ProjectReference> 185 <ProjectReference Include="..\..\HeuristicLab.Visualization.ChartControlsExtensions\3.3\HeuristicLab.Visualization.ChartControlsExtensions-3.3.csproj"> 186 <Project>{315BDA09-3F4F-49B3-9790-B37CFC1C5750}</Project> 187 <Name>HeuristicLab.Visualization.ChartControlsExtensions-3.3</Name> 175 188 </ProjectReference> 176 189 </ItemGroup> -
trunk/sources/HeuristicLab.Analysis.Views/3.3/HeuristicLabAnalysisViewsPlugin.cs.frame
r4623 r4631 36 36 [PluginDependency("HeuristicLab.MainForm", "3.3")] 37 37 [PluginDependency("HeuristicLab.MainForm.WindowsForms", "3.3")] 38 [PluginDependency("HeuristicLab.Visualization.ChartControlsExtensions", "3.3")] 38 39 public class HeuristicLabAnalysisViewsPlugin : PluginBase { 39 40 } -
trunk/sources/HeuristicLab.Analysis/3.3/AlleleFrequencyAnalyzer.cs
r4623 r4631 44 44 get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; } 45 45 } 46 public LookupParameter<T> BestKnownSolutionParameter { 47 get { return (LookupParameter<T>)Parameters["BestKnownSolution"]; } 48 } 46 49 public ValueLookupParameter<ResultCollection> ResultsParameter { 47 50 get { return (ValueLookupParameter<ResultCollection>)Parameters["Results"]; } 48 51 } 49 public LookupParameter<T> BestKnownSolutionParameter {50 get { return ( LookupParameter<T>)Parameters["BestKnownSolution"]; }52 public ValueParameter<BoolValue> StoreAlleleFrequenciesHistoryParameter { 53 get { return (ValueParameter<BoolValue>)Parameters["StoreAlleleFrequenciesHistory"]; } 51 54 } 52 public LookupParameter<AlleleFrequencyArray> AlleleFrequenciesParameter { 53 get { return (LookupParameter<AlleleFrequencyArray>)Parameters["AlleleFrequencies"]; } 55 public ValueParameter<IntValue> UpdateIntervalParameter { 56 get { return (ValueParameter<IntValue>)Parameters["UpdateInterval"]; } 57 } 58 public LookupParameter<IntValue> UpdateCounterParameter { 59 get { return (LookupParameter<IntValue>)Parameters["UpdateCounter"]; } 54 60 } 55 61 … … 59 65 Parameters.Add(new ScopeTreeLookupParameter<T>("Solution", "The solutions whose alleles should be analyzed.")); 60 66 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The qualities of the solutions which should be analyzed.")); 67 Parameters.Add(new LookupParameter<T>("BestKnownSolution", "The best known solution.")); 61 68 Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the allele frequency analysis results should be stored.")); 62 Parameters.Add(new LookupParameter<T>("BestKnownSolution", "The best known solution.")); 63 Parameters.Add(new LookupParameter<AlleleFrequencyArray>("AlleleFrequencies", "The frequencies of the alleles in the current iteration.")); 69 Parameters.Add(new ValueParameter<BoolValue>("StoreAlleleFrequenciesHistory", "True if the history of all allele frequencies should be stored.", new BoolValue(false))); 70 Parameters.Add(new ValueParameter<IntValue>("UpdateInterval", "The interval in which the allele frequency analysis should be applied.", new IntValue(1))); 71 Parameters.Add(new LookupParameter<IntValue>("UpdateCounter", "The value which counts how many times the operator was called since the last update.")); 64 72 } 65 73 66 74 public override IOperation Apply() { 67 bool max = MaximizationParameter.ActualValue.Value; 68 ItemArray<T> solutions = SolutionParameter.ActualValue; 69 ItemArray<DoubleValue> qualities = QualityParameter.ActualValue; 70 ResultCollection results = ResultsParameter.ActualValue; 71 T bestKnownSolution = BestKnownSolutionParameter.ActualValue; 75 int updateInterval = UpdateIntervalParameter.Value.Value; 76 IntValue updateCounter = UpdateCounterParameter.ActualValue; 77 if (updateCounter == null) { 78 updateCounter = new IntValue(updateInterval); 79 UpdateCounterParameter.ActualValue = updateCounter; 80 } else updateCounter.Value++; 72 81 73 int bestIndex = -1; 74 if (!max) bestIndex = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index; 75 else bestIndex = qualities.Select((x, index) => new { index, x.Value }).OrderByDescending(x => x.Value).First().index; 82 if (updateCounter.Value == updateInterval) { 83 updateCounter.Value = 0; 76 84 77 Allele[] bestAlleles = CalculateAlleles(solutions[bestIndex]); 78 Allele[] bestKnownAlleles = null; 79 if (bestKnownSolution != null) { 80 bestKnownAlleles = CalculateAlleles(bestKnownSolution); 85 bool max = MaximizationParameter.ActualValue.Value; 86 ItemArray<T> solutions = SolutionParameter.ActualValue; 87 ItemArray<DoubleValue> qualities = QualityParameter.ActualValue; 88 T bestKnownSolution = BestKnownSolutionParameter.ActualValue; 89 bool storeHistory = StoreAlleleFrequenciesHistoryParameter.Value.Value; 90 91 // calculate index of current best solution 92 int bestIndex = -1; 93 if (!max) bestIndex = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index; 94 else bestIndex = qualities.Select((x, index) => new { index, x.Value }).OrderByDescending(x => x.Value).First().index; 95 96 // calculate allels of current best and (if available) best known solution 97 Allele[] bestAlleles = CalculateAlleles(solutions[bestIndex]); 98 Allele[] bestKnownAlleles = null; 99 if (bestKnownSolution != null) 100 bestKnownAlleles = CalculateAlleles(bestKnownSolution); 101 102 // calculate allele frequencies 103 var frequencies = solutions.SelectMany((s, index) => CalculateAlleles(s).Select(a => new { Allele = a, Quality = qualities[index] })). 104 GroupBy(x => x.Allele.Id). 105 Select(x => new AlleleFrequency(x.Key, 106 x.Count() / ((double)solutions.Length), 107 x.Average(a => a.Allele.Impact), 108 x.Average(a => a.Quality.Value), 109 bestKnownAlleles == null ? false : bestKnownAlleles.Any(a => a.Id == x.Key), 110 bestAlleles.Any(a => a.Id == x.Key))); 111 112 // fetch results collection 113 ResultCollection results; 114 if (!ResultsParameter.ActualValue.ContainsKey("Allele Frequency Analysis Results")) { 115 results = new ResultCollection(); 116 ResultsParameter.ActualValue.Add(new Result("Allele Frequency Analysis Results", results)); 117 } else { 118 results = (ResultCollection)ResultsParameter.ActualValue["Allele Frequency Analysis Results"].Value; 119 } 120 121 // store allele frequencies 122 AlleleFrequencyArray frequenciesArray = new AlleleFrequencyArray(frequencies); 123 if (!results.ContainsKey("Allele Frequencies")) 124 results.Add(new Result("Allele Frequencies", frequenciesArray)); 125 else 126 results["Allele Frequencies"].Value = frequenciesArray; 127 128 // store allele frequencies history 129 if (storeHistory) { 130 if (!results.ContainsKey("Allele Frequencies History")) { 131 ItemCollection<AlleleFrequencyArray> history = new ItemCollection<AlleleFrequencyArray>(); 132 history.Add(frequenciesArray); 133 results.Add(new Result("Allele Frequencies History", history)); 134 } else { 135 ((ItemCollection<AlleleFrequencyArray>)results["Allele Frequencies History"].Value).Add(frequenciesArray); 136 } 137 } 138 139 // store alleles data table 140 DataTable allelesTable; 141 if (!results.ContainsKey("Alleles")) { 142 allelesTable = new DataTable("Alleles"); 143 results.Add(new Result("Alleles", allelesTable)); 144 allelesTable.Rows.Add(new DataRow("Unique Alleles")); 145 } else { 146 allelesTable = (DataTable)results["Alleles"].Value; 147 } 148 allelesTable.Rows["Unique Alleles"].Values.Add(frequenciesArray.Length); 81 149 } 82 83 var frequencies = solutions.SelectMany((s, index) => CalculateAlleles(s).Select(a => new { Allele = a, Quality = qualities[index] })).84 GroupBy(x => x.Allele.Id).85 Select(x => new AlleleFrequency(x.Key,86 x.Count() / ((double)solutions.Length),87 x.Average(a => a.Allele.Impact),88 x.Average(a => a.Quality.Value),89 bestKnownAlleles == null ? false : bestKnownAlleles.Any(a => a.Id == x.Key),90 bestAlleles.Any(a => a.Id == x.Key)));91 92 AlleleFrequencyArray frequenciesArray = new AlleleFrequencyArray(frequencies.OrderBy(x => x.AverageImpact));93 AlleleFrequenciesParameter.ActualValue = frequenciesArray;94 if (results.ContainsKey("Allele Frequencies"))95 results["Allele Frequencies"].Value = frequenciesArray;96 else97 results.Add(new Result("Allele Frequencies", frequenciesArray));98 99 150 return base.Apply(); 100 151 }
Note: See TracChangeset
for help on using the changeset viewer.