source:
branches/2988_ModelsOfModels2/HeuristicLab.Problems.DataAnalysis.Symbolic/new-analyzers.patch
@
17300
Last change on this file since 17300 was 17134, checked in by msemenki, 5 years ago | |
---|---|
File size: 14.6 KB |
-
3.4/Analyzers/MinAverageMaxSymbolicExpressionNeastedTreeSyzeAnalyzer.cs
1  2 #region License Information 3 /* HeuristicLab 4 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 5 * 6 * This file is part of HeuristicLab. 7 * 8 * HeuristicLab is free software: you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation, either version 3 of the License, or 11 * (at your option) any later version. 12 * 13 * HeuristicLab is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 20 */ 21 #endregion 22 23 using System; 24 using HeuristicLab.Analysis; 25 using HeuristicLab.Common; 26 using HeuristicLab.Core; 27 using HeuristicLab.Data; 28 using HeuristicLab.Operators; 29 using HeuristicLab.Parameters; 30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 31 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 32 using HeuristicLab.Problems.DataAnalysis.Symbolic; 33 using System.Collections.Generic; 34 using System.Linq; 35 using HeuristicLab.Optimization; 36 37 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 38 /// <summary> 39 /// An operator that tracks the min average and max length of symbolic expression trees. 40 /// </summary> 41 [Item("MinAverageMaxSymbolicExpressionNeastedTreeSizeAnalyzer", "An operator that tracks the min avgerage and max Neasted Tree Size of symbolic expression trees.")] 42 [StorableClass] 43 public sealed class MinAverageMaxSymbolicExpressionNeastedTreeSizeAnalyzer : SymbolicDataAnalysisAnalyzer, ISymbolicExpressionTreeAnalyzer { 44 private const string ResultsParameterName = "Results"; 45 private const string MinMaxAvgNeastedTreeSizeResultName = "MinMaxAvgNeastedTreeSize"; 46 47 #region parameter properties 48 public ValueLookupParameter<VariableCollection> ResultsParameter { 49 get { return (ValueLookupParameter<VariableCollection>)Parameters[ResultsParameterName]; } 50 } 51 #endregion 52 53 [StorableConstructor] 54 private MinAverageMaxSymbolicExpressionNeastedTreeSizeAnalyzer(bool deserializing) : base() { } 55 private MinAverageMaxSymbolicExpressionNeastedTreeSizeAnalyzer(MinAverageMaxSymbolicExpressionNeastedTreeSizeAnalyzer original, Cloner cloner) 56 : base(original, cloner) { 57 AfterDeserialization(); 58 } 59 public MinAverageMaxSymbolicExpressionNeastedTreeSizeAnalyzer() 60 : base() { 61 } 62 63 [StorableHook(HookType.AfterDeserialization)] 64 private void AfterDeserialization() { } 65 66 public override IDeepCloneable Clone(Cloner cloner) { 67 return new MinAverageMaxSymbolicExpressionNeastedTreeSizeAnalyzer(this, cloner); 68 } 69 70 public override IOperation Apply() { 71 var trees = SymbolicExpressionTreeParameter.ActualValue; 72 //var variablesNumber = new DoubleArray(trees.Length); 73 var variablesNumber = trees.Select(tree => tree.IterateNodesPostfix().Sum(n => n.GetLength())).ToArray(); 74 var min = variablesNumber.Min(); 75 var max = variablesNumber.Max(); 76 var avg = variablesNumber.Average(); 77 78 DataTable table; 79 if (ResultCollection.ContainsKey(MinMaxAvgNeastedTreeSizeResultName)) { 80 table = (DataTable)ResultCollection[MinMaxAvgNeastedTreeSizeResultName].Value; 81 } else { 82 table = new DataTable("Tree Variables Number"); 83 ResultCollection.Add(new Result(MinMaxAvgNeastedTreeSizeResultName, table)); 84 table.Rows.Add(new DataRow("Min") { VisualProperties = { StartIndexZero = true } }); 85 table.Rows.Add(new DataRow("Max") { VisualProperties = { StartIndexZero = true } }); 86 table.Rows.Add(new DataRow("Avg") { VisualProperties = { StartIndexZero = true } }); 87 } 88 table.Rows["Min"].Values.Add(min); 89 table.Rows["Max"].Values.Add(max); 90 table.Rows["Avg"].Values.Add(avg); 91 92 return base.Apply(); 93 } 94 } 95 } -
3.4/Analyzers/MinAverageMaxSymbolicExpressionTreeComplexcityAnalyzer.cs
1  2 #region License Information 3 /* HeuristicLab 4 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 5 * 6 * This file is part of HeuristicLab. 7 * 8 * HeuristicLab is free software: you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation, either version 3 of the License, or 11 * (at your option) any later version. 12 * 13 * HeuristicLab is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 20 */ 21 #endregion 22 23 using System; 24 using HeuristicLab.Analysis; 25 using HeuristicLab.Common; 26 using HeuristicLab.Core; 27 using HeuristicLab.Data; 28 using HeuristicLab.Operators; 29 using HeuristicLab.Parameters; 30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 31 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 32 using HeuristicLab.Problems.DataAnalysis.Symbolic; 33 using System.Collections.Generic; 34 using System.Linq; 35 using HeuristicLab.Optimization; 36 37 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 38 /// <summary> 39 /// An operator that tracks the min average and max length of symbolic expression trees. 40 /// </summary> 41 [Item("MinAverageMaxSymbolicExpressionTreeComplexityAnalyzer", "An operator that tracks the min avgerage and max Complexity of symbolic expression trees.")] 42 [StorableClass] 43 public sealed class MinAverageMaxSymbolicExpressionTreeComplexityAnalyzer : SymbolicDataAnalysisAnalyzer, ISymbolicExpressionTreeAnalyzer { 44 private const string ResultsParameterName = "Results"; 45 private const string MinMaxAvgComplexityResultName = "MinMaxAvgTreeComplexity"; 46 47 #region parameter properties 48 public ValueLookupParameter<VariableCollection> ResultsParameter { 49 get { return (ValueLookupParameter<VariableCollection>)Parameters[ResultsParameterName]; } 50 } 51 #endregion 52 53 [StorableConstructor] 54 private MinAverageMaxSymbolicExpressionTreeComplexityAnalyzer(bool deserializing) : base() { } 55 private MinAverageMaxSymbolicExpressionTreeComplexityAnalyzer(MinAverageMaxSymbolicExpressionTreeComplexityAnalyzer original, Cloner cloner) 56 : base(original, cloner) { 57 AfterDeserialization(); 58 } 59 public MinAverageMaxSymbolicExpressionTreeComplexityAnalyzer() 60 : base() { 61 } 62 63 [StorableHook(HookType.AfterDeserialization)] 64 private void AfterDeserialization() {} 65 66 public override IDeepCloneable Clone(Cloner cloner) { 67 return new MinAverageMaxSymbolicExpressionTreeComplexityAnalyzer(this, cloner); 68 } 69 70 public override IOperation Apply() { 71 var trees = SymbolicExpressionTreeParameter.ActualValue; 72 var complexities = trees.Select(SymbolicDataAnalysisModelComplexityCalculator.CalculateComplexity).ToArray(); 73 74 var min = complexities.Min(); 75 var max = complexities.Max(); 76 var avg = complexities.Average(); 77 78 //double min = complexities[0], max = complexities[0], avg = 0; 79 80 //foreach (var c in complexities) { 81 // if (min > c) { 82 // min = c; 83 // } 84 // if (max < c) { 85 // max = c; 86 // } 87 // avg += c; 88 //} 89 //avg /= complexities.Length; 90 91 DataTable table; 92 if (ResultCollection.ContainsKey(MinMaxAvgComplexityResultName)) { 93 table = (DataTable)ResultCollection[MinMaxAvgComplexityResultName].Value; 94 } else { 95 table = new DataTable("Tree Complexity"); 96 ResultCollection.Add(new Result(MinMaxAvgComplexityResultName, table)); 97 table.Rows.Add(new DataRow("Min") { VisualProperties = { StartIndexZero = true } }); 98 table.Rows.Add(new DataRow("Max") { VisualProperties = { StartIndexZero = true } }); 99 table.Rows.Add(new DataRow("Avg") { VisualProperties = { StartIndexZero = true } }); 100 } 101 table.Rows["Min"].Values.Add(min); 102 table.Rows["Max"].Values.Add(max); 103 table.Rows["Avg"].Values.Add(avg); 104 105 return base.Apply(); 106 } 107 } 108 } -
3.4/Analyzers/MinAverageMaxSymbolicExpressionTreeVariablesNumberAnalyzer.cs
1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 * 5 * This file is part of HeuristicLab. 6 * 7 * HeuristicLab is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * HeuristicLab is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 #endregion 21 22 using System; 23 using HeuristicLab.Analysis; 24 using HeuristicLab.Common; 25 using HeuristicLab.Core; 26 using HeuristicLab.Data; 27 using HeuristicLab.Operators; 28 using HeuristicLab.Parameters; 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 31 using HeuristicLab.Problems.DataAnalysis.Symbolic; 32 using System.Collections.Generic; 33 using System.Linq; 34 using HeuristicLab.Optimization; 35 36 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 37 /// <summary> 38 /// An operator that tracks the min average and max length of symbolic expression trees. 39 /// </summary> 40 [Item("MinAverageMaxSymbolicExpressionTreeVariablesNumberAnalyzer", "An operator that tracks the min avgerage and max VariablesNumber of symbolic expression trees.")] 41 [StorableClass] 42 public sealed class MinAverageMaxSymbolicExpressionTreeVariablesNumberAnalyzer : SymbolicDataAnalysisAnalyzer, ISymbolicExpressionTreeAnalyzer { 43 private const string ResultsParameterName = "Results"; 44 private const string MinMaxAvgVariablesNumberResultName = "MinMaxAvgTreeVariablesNumber"; 45 46 #region parameter properties 47 public ValueLookupParameter<VariableCollection> ResultsParameter { 48 get { return (ValueLookupParameter<VariableCollection>)Parameters[ResultsParameterName]; } 49 } 50 #endregion 51 52 [StorableConstructor] 53 private MinAverageMaxSymbolicExpressionTreeVariablesNumberAnalyzer(bool deserializing) : base() { } 54 private MinAverageMaxSymbolicExpressionTreeVariablesNumberAnalyzer(MinAverageMaxSymbolicExpressionTreeVariablesNumberAnalyzer original, Cloner cloner) 55 : base(original, cloner) { 56 AfterDeserialization(); 57 } 58 public MinAverageMaxSymbolicExpressionTreeVariablesNumberAnalyzer() 59 : base() { 60 } 61 62 [StorableHook(HookType.AfterDeserialization)] 63 private void AfterDeserialization() { } 64 65 public override IDeepCloneable Clone(Cloner cloner) { 66 return new MinAverageMaxSymbolicExpressionTreeVariablesNumberAnalyzer(this, cloner); 67 } 68 69 public override IOperation Apply() { 70 var trees = SymbolicExpressionTreeParameter.ActualValue; 71 //var variablesNumber = new DoubleArray(trees.Length); 72 var variablesNumber = trees.Select(tree => tree.IterateNodesPostfix().OfType<IVariableTreeNode>().Count()).ToArray(); 73 var min = variablesNumber.Min(); 74 var max = variablesNumber.Max(); 75 var avg = variablesNumber.Average(); 76 77 DataTable table; 78 if (ResultCollection.ContainsKey(MinMaxAvgVariablesNumberResultName)) { 79 table = (DataTable)ResultCollection[MinMaxAvgVariablesNumberResultName].Value; 80 } else { 81 table = new DataTable("Tree Variables Number"); 82 ResultCollection.Add(new Result(MinMaxAvgVariablesNumberResultName, table)); 83 table.Rows.Add(new DataRow("Min") { VisualProperties = { StartIndexZero = true } }); 84 table.Rows.Add(new DataRow("Max") { VisualProperties = { StartIndexZero = true } }); 85 table.Rows.Add(new DataRow("Avg") { VisualProperties = { StartIndexZero = true } }); 86 } 87 table.Rows["Min"].Values.Add(min); 88 table.Rows["Max"].Values.Add(max); 89 table.Rows["Avg"].Values.Add(avg); 90 91 return base.Apply(); 92 } 93 } 94 } -
3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj
126 126 <Reference Include="System.Xml" /> 127 127 </ItemGroup> 128 128 <ItemGroup> 129 <Compile Include="Analyzers\MinAverageMaxSymbolicExpressionNeastedTreeSyzeAnalyzer.cs" /> 130 <Compile Include="Analyzers\MinAverageMaxSymbolicExpressionTreeVariablesNumberAnalyzer.cs" /> 131 <Compile Include="Analyzers\MinAverageMaxSymbolicExpressionTreeComplexcityAnalyzer.cs" /> 129 132 <Compile Include="Analyzers\SymbolicDataAnalysisBottomUpDiversityAnalyzer.cs" /> 130 133 <Compile Include="Analyzers\SymbolicDataAnalysisBuildingBlockAnalyzer.cs" /> 131 134 <Compile Include="Analyzers\SymbolicDataAnalysisSingleObjectivePruningAnalyzer.cs" />
Note: See TracBrowser
for help on using the repository browser.