Changeset 7832
- Timestamp:
- 05/15/12 19:09:09 (13 years ago)
- Location:
- branches/GP-MoveOperators
- Files:
-
- 11 added
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GP-MoveOperators/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4.csproj
r7802 r7832 162 162 <Compile Include="Moves\ChangeNodeTypeMove.cs" /> 163 163 <Compile Include="Moves\ChangeNodeTypeMoveMaker.cs" /> 164 <Compile Include="Moves\ChangeNodeTypeMoveSoftTabuCriterion.cs"> 165 <SubType>Code</SubType> 166 </Compile> 164 167 <Compile Include="Moves\ChangeNodeTypeMultiMoveGenerator.cs" /> 168 <Compile Include="Moves\ReplaceBranchMoveTabuMaker.cs" /> 169 <Compile Include="Moves\ReplaceBranchMoveSoftTabuCriterion.cs" /> 170 <Compile Include="Moves\ReplaceBranchMoveMaker.cs" /> 171 <Compile Include="Moves\ReplaceBranchMove.cs" /> 172 <Compile Include="Moves\SymbolicExpressionTreeMoveAttribute.cs" /> 165 173 <Compile Include="Moves\ShakeMultiMoveGenerator.cs" /> 166 174 <Compile Include="Moves\ShakeMoveGenerator.cs" /> 175 <Compile Include="Moves\ChangeNodeTypeMoveHardTabuCriterion.cs" /> 176 <Compile Include="Moves\ChangeNodeTypeMoveTabuMaker.cs" /> 177 <Compile Include="Moves\ChangeNodeTypeMoveAbsoluteAttribute.cs" /> 167 178 <Compile Include="Plugin.cs" /> 168 179 <Compile Include="SymbolicExpressionGrammarBase.cs" /> -
branches/GP-MoveOperators/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Interfaces/Operators/ISymbolicExpressionTreeMoveOperator.cs
r7802 r7832 25 25 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 26 26 public interface ISymbolicExpressionTreeMoveOperator : ISymbolicExpressionTreeOperator, IMoveOperator { 27 ILookupParameter< SymbolicExpressionTree> SymbolicExpressionTreeParameter { get; }27 ILookupParameter<ISymbolicExpressionTree> SymbolicExpressionTreeParameter { get; } 28 28 } 29 29 } -
branches/GP-MoveOperators/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Moves/ChangeNodeTypeMoveGenerator.cs
r7802 r7832 30 30 31 31 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 32 [Item("ChangeNodeType MoveGenerator", "Operator that generates moves for changing the symbol of a single symbolic expression tree node.")]32 [Item("ChangeNodeTypeExhaustiveMoveGenerator", "Operator that generates moves for changing the symbol of a single symbolic expression tree node.")] 33 33 [StorableClass] 34 public class ChangeNodeTypeMoveGenerator : SingleSuccessorOperator, ISymbolicExpressionTreeMoveOperator, I MoveGenerator, IStochasticOperator {34 public class ChangeNodeTypeMoveGenerator : SingleSuccessorOperator, ISymbolicExpressionTreeMoveOperator, IExhaustiveMoveGenerator, IStochasticOperator { 35 35 public override bool CanChangeName { 36 36 get { return false; } … … 39 39 get { return (ILookupParameter<IRandom>)Parameters["Random"]; } 40 40 } 41 public ILookupParameter< SymbolicExpressionTree> SymbolicExpressionTreeParameter {42 get { return (ILookupParameter< SymbolicExpressionTree>)Parameters["SymbolicExpressionTree"]; }41 public ILookupParameter<ISymbolicExpressionTree> SymbolicExpressionTreeParameter { 42 get { return (ILookupParameter<ISymbolicExpressionTree>)Parameters["SymbolicExpressionTree"]; } 43 43 } 44 44 public ILookupParameter<ChangeNodeTypeMove> ChangeNodeTypeMoveParameter { … … 55 55 : base() { 56 56 Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator.")); 57 Parameters.Add(new LookupParameter< SymbolicExpressionTree>("SymbolicExpressionTree", "The symbolic expression tree for which moves should be generated."));57 Parameters.Add(new LookupParameter<ISymbolicExpressionTree>("SymbolicExpressionTree", "The symbolic expression tree for which moves should be generated.")); 58 58 Parameters.Add(new LookupParameter<ChangeNodeTypeMove>("ChangeNodeTypeMove", "The moves that should be generated in subscopes.")); 59 59 Parameters.Add(new ScopeParameter("CurrentScope", "The current scope where the moves should be added as subscopes.")); … … 66 66 67 67 public override IOperation Apply() { 68 SymbolicExpressionTreetree = SymbolicExpressionTreeParameter.ActualValue;68 var tree = SymbolicExpressionTreeParameter.ActualValue; 69 69 var moves = GenerateMoves(tree); 70 70 string moveParameterName = ChangeNodeTypeMoveParameter.ActualName; … … 82 82 } 83 83 84 public static IEnumerable<ChangeNodeTypeMove> GenerateMoves( SymbolicExpressionTree tree) {84 public static IEnumerable<ChangeNodeTypeMove> GenerateMoves(ISymbolicExpressionTree tree) { 85 85 var g = tree.Root.Grammar; 86 86 return (from parent in tree.Root.GetSubtree(0).IterateNodesPrefix() -
branches/GP-MoveOperators/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Moves/ChangeNodeTypeMoveMaker.cs
r7802 r7832 45 45 get { return (ILookupParameter<ChangeNodeTypeMove>)Parameters["ChangeNodeTypeMove"]; } 46 46 } 47 public ILookupParameter< SymbolicExpressionTree> SymbolicExpressionTreeParameter {48 get { return (ILookupParameter< SymbolicExpressionTree>)Parameters["SymbolicExpressionTree"]; }47 public ILookupParameter<ISymbolicExpressionTree> SymbolicExpressionTreeParameter { 48 get { return (ILookupParameter<ISymbolicExpressionTree>)Parameters["SymbolicExpressionTree"]; } 49 49 } 50 50 … … 57 57 Parameters.Add(new LookupParameter<ChangeNodeTypeMove>("ChangeNodeTypeMove", "The move to evaluate.")); 58 58 Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "The relative quality of the move.")); 59 Parameters.Add(new LookupParameter< SymbolicExpressionTree>("SymbolicExpressionTree", "The symbolic expression tree on which the move should be applied."));59 Parameters.Add(new LookupParameter<ISymbolicExpressionTree>("SymbolicExpressionTree", "The symbolic expression tree on which the move should be applied.")); 60 60 } 61 61 … … 66 66 public override IOperation Apply() { 67 67 ChangeNodeTypeMove move = ChangeNodeTypeMoveParameter.ActualValue; 68 SymbolicExpressionTreetree = SymbolicExpressionTreeParameter.ActualValue;68 var tree = SymbolicExpressionTreeParameter.ActualValue; 69 69 DoubleValue moveQuality = MoveQualityParameter.ActualValue; 70 70 DoubleValue quality = QualityParameter.ActualValue; -
branches/GP-MoveOperators/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Moves/ChangeNodeTypeMultiMoveGenerator.cs
r7802 r7832 20 20 #endregion 21 21 22 using System;23 22 using System.Collections.Generic; 24 23 using System.Linq; … … 46 45 set { SampleSizeParameter.Value = value; } 47 46 } 48 public ILookupParameter< SymbolicExpressionTree> SymbolicExpressionTreeParameter {49 get { return (ILookupParameter< SymbolicExpressionTree>)Parameters["SymbolicExpressionTree"]; }47 public ILookupParameter<ISymbolicExpressionTree> SymbolicExpressionTreeParameter { 48 get { return (ILookupParameter<ISymbolicExpressionTree>)Parameters["SymbolicExpressionTree"]; } 50 49 } 51 50 public ILookupParameter<ChangeNodeTypeMove> ChangeNodeTypeMoveParameter { … … 64 63 Parameters.Add(new ValueLookupParameter<IntValue>("SampleSize", "The number of moves to generate.")); 65 64 66 Parameters.Add(new LookupParameter< SymbolicExpressionTree>("SymbolicExpressionTree", "The symbolic expression tree for which moves should be generated."));65 Parameters.Add(new LookupParameter<ISymbolicExpressionTree>("SymbolicExpressionTree", "The symbolic expression tree for which moves should be generated.")); 67 66 Parameters.Add(new LookupParameter<ChangeNodeTypeMove>("ChangeNodeTypeMove", "The moves that should be generated in subscopes.")); 68 67 Parameters.Add(new ScopeParameter("CurrentScope", "The current scope where the moves should be added as subscopes.")); … … 75 74 76 75 public override IOperation Apply() { 77 SymbolicExpressionTree tree = SymbolicExpressionTreeParameter.ActualValue; 78 var moves = ChangeNodeTypeMoveGenerator.GenerateMoves(tree).ToArray(); 76 var tree = SymbolicExpressionTreeParameter.ActualValue; 77 78 79 79 string moveParameterName = ChangeNodeTypeMoveParameter.ActualName; 80 80 var moveScopes = new List<Scope>(); … … 82 82 int n = SampleSizeParameter.ActualValue.Value; 83 83 84 var rand = Enumerable.Range(0, moves.Length).Select(i => random.NextDouble()).ToArray(); 85 Array.Sort(rand, moves); 86 n = Math.Min(n, moves.Length); 84 var moves = GenerateMoves(tree, random, n); 87 85 88 foreach (var m in moves .Take(n)) {86 foreach (var m in moves) { 89 87 if (m.NewChild.HasLocalParameters) 90 88 m.NewChild.ResetLocalParameters(random); … … 96 94 return base.Apply(); 97 95 } 96 97 public static IEnumerable<ChangeNodeTypeMove> GenerateMoves(ISymbolicExpressionTree tree, IRandom random, int n) { 98 int count = 0; 99 var g = tree.Root.Grammar; 100 var possibleChildren = (from parent in tree.Root.GetSubtree(0).IterateNodesPrefix() 101 from i in Enumerable.Range(0, parent.SubtreeCount) 102 from s in g.GetAllowedChildSymbols(parent.Symbol, i) 103 where s.Enabled 104 where s.InitialFrequency > 0.0 105 let currentChild = parent.GetSubtree(i) 106 where s.MinimumArity >= currentChild.SubtreeCount 107 where s.MaximumArity <= currentChild.SubtreeCount 108 where (from j in Enumerable.Range(0, currentChild.SubtreeCount) 109 let childOfChild = currentChild.GetSubtree(j) 110 select g.IsAllowedChildSymbol(s, childOfChild.Symbol, j)).All(p => p) 111 select new { parent, i, s }).ToArray(); 112 if (possibleChildren.Length < n) n = possibleChildren.Length; 113 while (count < n) { 114 var selected = possibleChildren[random.Next(possibleChildren.Length)]; 115 yield return new ChangeNodeTypeMove(tree, selected.parent, selected.i, selected.s.CreateTreeNode()); 116 count++; 117 } 118 } 98 119 } 99 120 } -
branches/GP-MoveOperators/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Moves/ShakeMoveGenerator.cs
r7802 r7832 30 30 31 31 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 32 [Item("Shake MoveGenerator", "Operator that generates moves for shaking a single symbolic expression tree node.")]32 [Item("ShakeExhaustiveMoveGenerator", "Operator that generates moves for shaking a single symbolic expression tree node.")] 33 33 [StorableClass] 34 public class ShakeMoveGenerator : SingleSuccessorOperator, ISymbolicExpressionTreeMoveOperator, I MoveGenerator, IStochasticOperator {34 public class ShakeMoveGenerator : SingleSuccessorOperator, ISymbolicExpressionTreeMoveOperator, IExhaustiveMoveGenerator, IStochasticOperator { 35 35 public override bool CanChangeName { 36 36 get { return false; } … … 39 39 get { return (ILookupParameter<IRandom>)Parameters["Random"]; } 40 40 } 41 public ILookupParameter< SymbolicExpressionTree> SymbolicExpressionTreeParameter {42 get { return (ILookupParameter< SymbolicExpressionTree>)Parameters["SymbolicExpressionTree"]; }41 public ILookupParameter<ISymbolicExpressionTree> SymbolicExpressionTreeParameter { 42 get { return (ILookupParameter<ISymbolicExpressionTree>)Parameters["SymbolicExpressionTree"]; } 43 43 } 44 44 public ILookupParameter<ChangeNodeTypeMove> ChangeNodeTypeMoveParameter { … … 55 55 : base() { 56 56 Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator.")); 57 Parameters.Add(new LookupParameter< SymbolicExpressionTree>("SymbolicExpressionTree", "The symbolic expression tree for which moves should be generated."));57 Parameters.Add(new LookupParameter<ISymbolicExpressionTree>("SymbolicExpressionTree", "The symbolic expression tree for which moves should be generated.")); 58 58 Parameters.Add(new LookupParameter<ChangeNodeTypeMove>("ChangeNodeTypeMove", "The moves that should be generated in subscopes.")); 59 59 Parameters.Add(new ScopeParameter("CurrentScope", "The current scope where the moves should be added as subscopes.")); … … 66 66 67 67 public override IOperation Apply() { 68 SymbolicExpressionTreetree = SymbolicExpressionTreeParameter.ActualValue;68 var tree = SymbolicExpressionTreeParameter.ActualValue; 69 69 var moves = GenerateMoves(tree); 70 70 string moveParameterName = ChangeNodeTypeMoveParameter.ActualName; … … 81 81 } 82 82 83 public static IEnumerable<ChangeNodeTypeMove> GenerateMoves(SymbolicExpressionTree tree) { 84 var g = tree.Root.Grammar; 83 public static IEnumerable<ChangeNodeTypeMove> GenerateMoves(ISymbolicExpressionTree tree) { 85 84 return (from parent in tree.Root.GetSubtree(0).IterateNodesPrefix() 86 85 from i in Enumerable.Range(0, parent.SubtreeCount) -
branches/GP-MoveOperators/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Moves/ShakeMultiMoveGenerator.cs
r7802 r7832 20 20 #endregion 21 21 22 using System;23 22 using System.Collections.Generic; 24 23 using System.Linq; … … 46 45 set { SampleSizeParameter.Value = value; } 47 46 } 48 public ILookupParameter< SymbolicExpressionTree> SymbolicExpressionTreeParameter {49 get { return (ILookupParameter< SymbolicExpressionTree>)Parameters["SymbolicExpressionTree"]; }47 public ILookupParameter<ISymbolicExpressionTree> SymbolicExpressionTreeParameter { 48 get { return (ILookupParameter<ISymbolicExpressionTree>)Parameters["SymbolicExpressionTree"]; } 50 49 } 51 50 public ILookupParameter<ChangeNodeTypeMove> ChangeNodeTypeMoveParameter { … … 64 63 Parameters.Add(new ValueLookupParameter<IntValue>("SampleSize", "The number of moves to generate.")); 65 64 66 Parameters.Add(new LookupParameter< SymbolicExpressionTree>("SymbolicExpressionTree", "The symbolic expression tree for which moves should be generated."));65 Parameters.Add(new LookupParameter<ISymbolicExpressionTree>("SymbolicExpressionTree", "The symbolic expression tree for which moves should be generated.")); 67 66 Parameters.Add(new LookupParameter<ChangeNodeTypeMove>("ChangeNodeTypeMove", "The moves that should be generated in subscopes.")); 68 67 Parameters.Add(new ScopeParameter("CurrentScope", "The current scope where the moves should be added as subscopes.")); … … 75 74 76 75 public override IOperation Apply() { 77 SymbolicExpressionTree tree = SymbolicExpressionTreeParameter.ActualValue; 78 var moves = ChangeNodeTypeMoveGenerator.GenerateMoves(tree).ToArray(); 76 var tree = SymbolicExpressionTreeParameter.ActualValue; 77 var random = RandomParameter.ActualValue; 78 int n = SampleSizeParameter.ActualValue.Value; 79 var moves = ChangeNodeTypeMultiMoveGenerator.GenerateMoves(tree, random, n); 79 80 string moveParameterName = ChangeNodeTypeMoveParameter.ActualName; 80 81 var moveScopes = new List<Scope>(); 81 var random = RandomParameter.ActualValue;82 int n = SampleSizeParameter.ActualValue.Value;83 82 84 var rand = Enumerable.Range(0, moves.Length).Select(i => random.NextDouble()).ToArray(); 85 Array.Sort(rand, moves); 86 n = Math.Min(n, moves.Length); 87 88 foreach (var m in moves.Take(n)) { 83 foreach (var m in moves) { 89 84 m.NewChild.ShakeLocalParameters(random, 1); 90 85 var moveScope = new Scope(moveScopes.Count.ToString()); … … 95 90 return base.Apply(); 96 91 } 92 93 public static IEnumerable<ChangeNodeTypeMove> GenerateMoves(ISymbolicExpressionTree tree, IRandom random, int n) { 94 int count = 0; 95 var g = tree.Root.Grammar; 96 var possibleChildren = (from parent in tree.Root.GetSubtree(0).IterateNodesPrefix() 97 from i in Enumerable.Range(0, parent.SubtreeCount) 98 let currentChild = parent.GetSubtree(i) 99 where currentChild.HasLocalParameters 100 select new { parent, i, currentChild }).ToArray(); 101 if (possibleChildren.Length < n) n = possibleChildren.Length; 102 while (count < n) { 103 var selected = possibleChildren[random.Next(possibleChildren.Length)]; 104 yield return new ChangeNodeTypeMove(tree, selected.parent, selected.i, (ISymbolicExpressionTreeNode)selected.currentChild.Clone()); 105 count++; 106 } 107 } 97 108 } 98 109 } -
branches/GP-MoveOperators/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTreeNode.cs
r7795 r7832 53 53 protected SymbolicExpressionTreeNode(bool deserializing) { } 54 54 protected SymbolicExpressionTreeNode(SymbolicExpressionTreeNode original, Cloner cloner) 55 : base( ) {55 : base(original, cloner) { 56 56 symbol = original.symbol; // symbols are reused 57 57 length = original.length; -
branches/GP-MoveOperators/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression-3.4.csproj
r7802 r7832 112 112 </ItemGroup> 113 113 <ItemGroup> 114 <Compile Include="ReplaceBranchMoveEvaluator.cs" /> 114 115 <Compile Include="Interfaces\ISymbolicRegressionMoveEvaluator.cs" /> 115 116 <Compile Include="MultiObjective\SymbolicRegressionMultiObjectiveValidationBestSolutionAnalyzer.cs" /> 116 117 <Compile Include="Plugin.cs" /> 118 <Compile Include="ReplaceBranchMultiMoveGenerator.cs" /> 117 119 <Compile Include="SingleObjective\SymbolicRegressionSingleObjectiveValidationParetoBestSolutionAnalyzer.cs" /> 118 120 <Compile Include="SingleObjective\SymbolicRegressionSingleObjectiveTrainingParetoBestSolutionAnalyzer.cs" /> -
branches/GP-MoveOperators/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionMoveEvaluator.cs
r7802 r7832 60 60 } 61 61 62 public ILookupParameter< SymbolicExpressionTree> SymbolicExpressionTreeParameter {63 get { return (ILookupParameter< SymbolicExpressionTree>)Parameters["SymbolicExpressionTree"]; }62 public ILookupParameter<ISymbolicExpressionTree> SymbolicExpressionTreeParameter { 63 get { return (ILookupParameter<ISymbolicExpressionTree>)Parameters["SymbolicExpressionTree"]; } 64 64 } 65 65 [StorableConstructor] … … 74 74 Parameters.Add(new LookupParameter<IRegressionProblemData>("ProblemData", "")); 75 75 Parameters.Add(new LookupParameter<IntRange>("FitnessCalculationPartition", "")); 76 Parameters.Add(new LookupParameter< SymbolicExpressionTree>("SymbolicExpressionTree", ""));76 Parameters.Add(new LookupParameter<ISymbolicExpressionTree>("SymbolicExpressionTree", "")); 77 77 } 78 78 -
branches/GP-MoveOperators/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisProblem.cs
r7802 r7832 197 197 198 198 private void InitializeOperators() { 199 Operators.AddRange(ApplicationManager.Manager.GetInstances<ISymbolicExpressionTreeMoveOperator>());200 199 Operators.AddRange(ApplicationManager.Manager.GetInstances<ISymbolicExpressionTreeOperator>()); 201 200 Operators.AddRange(ApplicationManager.Manager.GetInstances<ISymbolicDataAnalysisExpressionCrossover<T>>()); -
branches/GP-MoveOperators/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionEnsembleSolution.cs
r7738 r7832 218 218 219 219 private double AggregateEstimatedValues(IEnumerable<double> estimatedValues) { 220 return estimatedValues.DefaultIfEmpty(double.NaN).Average(); 220 // return trimean 221 var orderdValues = estimatedValues 222 .Where(x => !double.IsNaN(x)) 223 .DefaultIfEmpty(0.0) 224 .OrderBy(x => x) 225 .ToArray(); 226 return (orderdValues[(int)Math.Floor(orderdValues.Length * 0.25)] + 227 orderdValues[(int)Math.Floor(orderdValues.Length * 0.75)]) / 2.0; 221 228 } 222 229 #endregion
Note: See TracChangeset
for help on using the changeset viewer.