Changeset 5499
- Timestamp:
- 02/16/11 19:01:00 (14 years ago)
- Location:
- branches/DataAnalysis Refactoring
- Files:
-
- 3 added
- 50 edited
- 3 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4
- Property svn:ignore
-
old new 2 2 obj 3 3 HeuristicLabEncodingsSymbolicExpressionTreeEncodingPlugin.cs 4 *.user
-
- Property svn:ignore
-
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Analyzers/MinAverageMaxSymbolicExpressionTreeLengthAnalyzer.cs
r5494 r5499 25 25 using HeuristicLab.Core; 26 26 using HeuristicLab.Data; 27 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Interfaces;28 27 using HeuristicLab.Operators; 29 28 using HeuristicLab.Parameters; 30 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 31 30 32 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding .Analyzers{31 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 33 32 /// <summary> 34 /// An operator that tracks the min average and max tree size.33 /// An operator that tracks the min average and max length of symbolic expression trees. 35 34 /// </summary> 36 [Item("MinAverageMaxSymbolicExpressionTree SizeAnalyzer", "An operator that tracks the min avgerage and max tree size.")]35 [Item("MinAverageMaxSymbolicExpressionTreeLengthAnalyzer", "An operator that tracks the min avgerage and max length of symbolic expression trees.")] 37 36 [StorableClass] 38 public sealed class MinAverageMaxSymbolicExpressionTree SizeAnalyzer : AlgorithmOperator, ISymbolicExpressionTreeAnalyzer {37 public sealed class MinAverageMaxSymbolicExpressionTreeLengthAnalyzer : AlgorithmOperator, ISymbolicExpressionTreeAnalyzer { 39 38 private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree"; 40 private const string SymbolicExpressionTree SizeParameterName = "SymbolicExpressionTreeSize";41 private const string SymbolicExpressionTree SizesParameterName = "Symbolic expression tree size";42 private const string MinTree SizeParameterName = "Min tree size";43 private const string AverageTree SizeParameterName = "Average tree size";44 private const string MaxTree SizeParameterName = "Max tree size";39 private const string SymbolicExpressionTreeLengthParameterName = "SymbolicExpressionTreeLength"; 40 private const string SymbolicExpressionTreeLengthsParameterName = "Symbolic expression tree length"; 41 private const string MinTreeLengthParameterName = "Minimal symbolic expression tree length"; 42 private const string AverageTreeLengthParameterName = "Average symbolic expression tree length"; 43 private const string MaxTreeLengthParameterName = "Maximal symbolic expression tree length"; 45 44 private const string ResultsParameterName = "Results"; 46 45 … … 49 48 get { return (ScopeTreeLookupParameter<SymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; } 50 49 } 51 public ScopeTreeLookupParameter<DoubleValue> SymbolicExpressionTree SizeParameter {52 get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters[SymbolicExpressionTree SizeParameterName]; }50 public ScopeTreeLookupParameter<DoubleValue> SymbolicExpressionTreeLengthParameter { 51 get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters[SymbolicExpressionTreeLengthParameterName]; } 53 52 } 54 public ValueLookupParameter<DataTable> SymbolicExpressionTree SizesParameter {55 get { return (ValueLookupParameter<DataTable>)Parameters[SymbolicExpressionTree SizesParameterName]; }53 public ValueLookupParameter<DataTable> SymbolicExpressionTreeLengthsParameter { 54 get { return (ValueLookupParameter<DataTable>)Parameters[SymbolicExpressionTreeLengthsParameterName]; } 56 55 } 57 56 public ValueLookupParameter<VariableCollection> ResultsParameter { … … 65 64 66 65 #endregion 66 67 67 [StorableConstructor] 68 private MinAverageMaxSymbolicExpressionTree SizeAnalyzer(bool deserializing) : base() { }69 private MinAverageMaxSymbolicExpressionTree SizeAnalyzer(MinAverageMaxSymbolicExpressionTreeSizeAnalyzer original, Cloner cloner)68 private MinAverageMaxSymbolicExpressionTreeLengthAnalyzer(bool deserializing) : base() { } 69 private MinAverageMaxSymbolicExpressionTreeLengthAnalyzer(MinAverageMaxSymbolicExpressionTreeLengthAnalyzer original, Cloner cloner) 70 70 : base(original, cloner) { 71 71 AfterDeserialization(); 72 72 } 73 public MinAverageMaxSymbolicExpressionTree SizeAnalyzer()73 public MinAverageMaxSymbolicExpressionTreeLengthAnalyzer() 74 74 : base() { 75 Parameters.Add(new ScopeTreeLookupParameter<SymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression tree whose sizeshould be calculated."));76 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>(SymbolicExpressionTree SizeParameterName, "The tree sizeof the symbolic expression tree."));77 Parameters.Add(new ValueLookupParameter<DataTable>(SymbolicExpressionTree SizesParameterName, "The data table to store the tree sizes."));75 Parameters.Add(new ScopeTreeLookupParameter<SymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression tree whose length should be calculated.")); 76 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>(SymbolicExpressionTreeLengthParameterName, "The length of the symbolic expression tree.")); 77 Parameters.Add(new ValueLookupParameter<DataTable>(SymbolicExpressionTreeLengthsParameterName, "The data table to store the symbolic expression tree lengths.")); 78 78 Parameters.Add(new ValueLookupParameter<VariableCollection>(ResultsParameterName, "The results collection where the analysis values should be stored.")); 79 79 80 80 subScopesProcessor = new UniformSubScopesProcessor(); 81 SymbolicExpressionTree SizeCalculator sizeCalculator = new SymbolicExpressionTreeSizeCalculator();81 SymbolicExpressionTreeLengthCalculator lengthCalculator = new SymbolicExpressionTreeLengthCalculator(); 82 82 valueAnalyzer = new MinAverageMaxValueAnalyzer(); 83 83 84 84 subScopesProcessor.Depth.Value = SymbolicExpressionTreeParameter.Depth; 85 sizeCalculator.SymbolicExpressionTreeParameter.ActualName = SymbolicExpressionTreeParameter.Name;86 sizeCalculator.SymbolicExpressionTreeSizeParameter.ActualName = SymbolicExpressionTreeSizeParameter.Name;87 valueAnalyzer.ValueParameter.ActualName = sizeCalculator.SymbolicExpressionTreeSizeParameter.Name;88 valueAnalyzer.ValueParameter.Depth = SymbolicExpressionTree SizeParameter.Depth;89 valueAnalyzer.AverageValueParameter.ActualName = AverageTree SizeParameterName;85 lengthCalculator.SymbolicExpressionTreeParameter.ActualName = SymbolicExpressionTreeParameter.Name; 86 lengthCalculator.SymbolicExpressionTreeLengthParameter.ActualName = SymbolicExpressionTreeLengthParameter.Name; 87 valueAnalyzer.ValueParameter.ActualName = lengthCalculator.SymbolicExpressionTreeLengthParameter.Name; 88 valueAnalyzer.ValueParameter.Depth = SymbolicExpressionTreeLengthParameter.Depth; 89 valueAnalyzer.AverageValueParameter.ActualName = AverageTreeLengthParameterName; 90 90 valueAnalyzer.CollectAverageValueInResultsParameter.Value = new BoolValue(false); 91 valueAnalyzer.MaxValueParameter.ActualName = MaxTree SizeParameterName;91 valueAnalyzer.MaxValueParameter.ActualName = MaxTreeLengthParameterName; 92 92 valueAnalyzer.CollectMaxValueInResultsParameter.Value = new BoolValue(false); 93 valueAnalyzer.MinValueParameter.ActualName = MinTree SizeParameterName;93 valueAnalyzer.MinValueParameter.ActualName = MinTreeLengthParameterName; 94 94 valueAnalyzer.CollectMinValueInResultsParameter.Value = new BoolValue(false); 95 valueAnalyzer.ValuesParameter.ActualName = SymbolicExpressionTree SizesParameter.Name;95 valueAnalyzer.ValuesParameter.ActualName = SymbolicExpressionTreeLengthsParameter.Name; 96 96 97 97 OperatorGraph.InitialOperator = subScopesProcessor; 98 subScopesProcessor.Operator = sizeCalculator;99 sizeCalculator.Successor = null;98 subScopesProcessor.Operator = lengthCalculator; 99 lengthCalculator.Successor = null; 100 100 subScopesProcessor.Successor = valueAnalyzer; 101 101 valueAnalyzer.Successor = null; … … 108 108 private void AfterDeserialization() { 109 109 SymbolicExpressionTreeParameter.DepthChanged += new EventHandler(SymbolicExpressionTreeParameter_DepthChanged); 110 SymbolicExpressionTree SizeParameter.DepthChanged += new EventHandler(SymbolicExpressionTreeSizeParameter_DepthChanged);110 SymbolicExpressionTreeLengthParameter.DepthChanged += new EventHandler(SymbolicExpressionTreeSizeParameter_DepthChanged); 111 111 } 112 112 113 113 public override IDeepCloneable Clone(Cloner cloner) { 114 return new MinAverageMaxSymbolicExpressionTree SizeAnalyzer(this, cloner);114 return new MinAverageMaxSymbolicExpressionTreeLengthAnalyzer(this, cloner); 115 115 } 116 116 -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Analyzers/SymbolicExpressionSymbolFrequencyAnalyzer.cs
r5445 r5499 25 25 using HeuristicLab.Common; 26 26 using HeuristicLab.Core; 27 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Interfaces;28 27 using HeuristicLab.Operators; 29 28 using HeuristicLab.Optimization; … … 31 30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 32 31 33 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding .Analyzers{32 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 34 33 /// <summary> 35 /// An operator that tracks the frequencies of distinc symbols.34 /// An operator that tracks the frequencies of distinct symbols in symbolic expression trees. 36 35 /// </summary> 37 [Item("SymbolicExpressionSymbolFrequencyAnalyzer", "An operator that tracks frequencies of symbols .")]36 [Item("SymbolicExpressionSymbolFrequencyAnalyzer", "An operator that tracks frequencies of symbols in symbolic expression trees.")] 38 37 [StorableClass] 39 38 public class SymbolicExpressionSymbolFrequencyAnalyzer : SingleSuccessorOperator, ISymbolicExpressionTreeAnalyzer { … … 67 66 Parameters.Add(new ScopeTreeLookupParameter<SymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression trees to analyze.")); 68 67 Parameters.Add(new ValueLookupParameter<DataTable>(SymbolFrequenciesParameterName, "The data table to store the symbol frequencies.")); 69 Parameters.Add(new LookupParameter<ResultCollection>(ResultsParameterName, "The result collection where the best symbolic regression solutionshould be stored."));68 Parameters.Add(new LookupParameter<ResultCollection>(ResultsParameterName, "The result collection where the symbol frequencies should be stored.")); 70 69 } 71 70 public override IDeepCloneable Clone(Cloner cloner) { -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Analyzers/SymbolicExpressionTreeLengthCalculator.cs
r5494 r5499 27 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 28 29 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding .Analyzers{29 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 30 30 /// <summary> 31 /// An operator that outputs the tree sizeof a symbolic expression tree.31 /// An operator that outputs the length of a symbolic expression tree. 32 32 /// </summary> 33 [Item("SymbolicExpressionTree SizeCalculator", "An operator that outputs the tree sizeof a symbolic expression tree.")]33 [Item("SymbolicExpressionTreeLengthCalculator", "An operator that outputs the length of a symbolic expression tree.")] 34 34 [StorableClass] 35 public sealed class SymbolicExpressionTree SizeCalculator : SingleSuccessorOperator {35 public sealed class SymbolicExpressionTreeLengthCalculator : SingleSuccessorOperator { 36 36 private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree"; 37 private const string SymbolicExpressionTree SizeParameterName = "SymbolicExpressionTreeSize";37 private const string SymbolicExpressionTreeLengthParameterName = "SymbolicExpressionTreeLength"; 38 38 39 39 #region parameter properties … … 41 41 get { return (ILookupParameter<SymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; } 42 42 } 43 public ILookupParameter<DoubleValue> SymbolicExpressionTree SizeParameter {44 get { return (ILookupParameter<DoubleValue>)Parameters[SymbolicExpressionTree SizeParameterName]; }43 public ILookupParameter<DoubleValue> SymbolicExpressionTreeLengthParameter { 44 get { return (ILookupParameter<DoubleValue>)Parameters[SymbolicExpressionTreeLengthParameterName]; } 45 45 } 46 46 #endregion … … 50 50 get { return SymbolicExpressionTreeParameter.ActualValue; } 51 51 } 52 public DoubleValue SymbolicExpressionTree Size{53 get { return SymbolicExpressionTree SizeParameter.ActualValue; }54 set { SymbolicExpressionTree SizeParameter.ActualValue = value; }52 public DoubleValue SymbolicExpressionTreeLength { 53 get { return SymbolicExpressionTreeLengthParameter.ActualValue; } 54 set { SymbolicExpressionTreeLengthParameter.ActualValue = value; } 55 55 } 56 56 #endregion 57 57 58 58 [StorableConstructor] 59 private SymbolicExpressionTree SizeCalculator(bool deserializing) : base(deserializing) { }60 private SymbolicExpressionTree SizeCalculator(SymbolicExpressionTreeSizeCalculator original, Cloner cloner) : base(original, cloner) { }61 public SymbolicExpressionTree SizeCalculator()59 private SymbolicExpressionTreeLengthCalculator(bool deserializing) : base(deserializing) { } 60 private SymbolicExpressionTreeLengthCalculator(SymbolicExpressionTreeLengthCalculator original, Cloner cloner) : base(original, cloner) { } 61 public SymbolicExpressionTreeLengthCalculator() 62 62 : base() { 63 Parameters.Add(new LookupParameter<SymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression tree whose sizeshould be calculated."));64 Parameters.Add(new LookupParameter<DoubleValue>(SymbolicExpressionTree SizeParameterName, "The tree sizeof the symbolic expression tree."));63 Parameters.Add(new LookupParameter<SymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression tree whose length should be calculated.")); 64 Parameters.Add(new LookupParameter<DoubleValue>(SymbolicExpressionTreeLengthParameterName, "The length of the symbolic expression tree.")); 65 65 } 66 66 67 67 public override IOperation Apply() { 68 SymbolicExpressionTree tree = SymbolicExpressionTree; 69 SymbolicExpressionTreeSize = new DoubleValue(tree.Size); 68 SymbolicExpressionTreeLength = new DoubleValue(SymbolicExpressionTree.Size); 70 69 return base.Apply(); 71 70 } 72 71 73 72 public override IDeepCloneable Clone(Cloner cloner) { 74 return new SymbolicExpressionTree SizeCalculator(this, cloner);73 return new SymbolicExpressionTreeLengthCalculator(this, cloner); 75 74 } 76 75 } -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/ArgumentCreater.cs
r5445 r5499 26 26 using HeuristicLab.Core; 27 27 using HeuristicLab.Data; 28 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;29 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 29 31 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding .ArchitectureManipulators{30 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 32 31 /// <summary> 33 32 /// Creates a new argument within one function-defining branch of a symbolic expression tree. -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/ArgumentDeleter.cs
r5445 r5499 24 24 using HeuristicLab.Core; 25 25 using HeuristicLab.Data; 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;27 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 27 29 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding .ArchitectureManipulators{28 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 30 29 /// <summary> 31 30 /// As described in Koza, Bennett, Andre, Keane, Genetic Programming III - Darwinian Invention and Problem Solving, 1999, pp. 112 -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/ArgumentDuplicater.cs
r5445 r5499 26 26 using HeuristicLab.Core; 27 27 using HeuristicLab.Data; 28 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;29 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 29 31 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding .ArchitectureManipulators{30 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 32 31 /// <summary> 33 32 /// Manipulates a symbolic expression by duplicating an existing argument node of a function-defining branch. -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/GrammarModifier.cs
r5445 r5499 21 21 22 22 using System.Collections.Generic; 23 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;24 23 25 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding .ArchitectureManipulators{24 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 26 25 public static class GrammarModifier { 27 public static void AddDynamicSymbol(ISymbolicExpression Grammar grammar,Symbol classRepresentative, string symbolName, int nArgs) {26 public static void AddDynamicSymbol(ISymbolicExpressionTreeGrammar grammar, ISymbol classRepresentative, string symbolName, int nArgs) { 28 27 var invokeSym = new InvokeFunction(symbolName); 29 28 grammar.AddSymbol(invokeSym); … … 34 33 35 34 36 public static void AddDynamicArguments(ISymbolicExpression Grammar grammar,Symbol classRepresentative, IEnumerable<int> argumentIndexes) {35 public static void AddDynamicArguments(ISymbolicExpressionTreeGrammar grammar, ISymbol classRepresentative, IEnumerable<int> argumentIndexes) { 37 36 foreach (int argIndex in argumentIndexes) { 38 37 var argSymbol = new Argument(argIndex); … … 44 43 } 45 44 46 private static void SetSyntaxConstraints(ISymbolicExpression Grammar grammar,Symbol classRepresentative, Symbol newSymbol) {45 private static void SetSyntaxConstraints(ISymbolicExpressionTreeGrammar grammar, ISymbol classRepresentative, Symbol newSymbol) { 47 46 // allow symbol as child of the representative first to make sure that the symbol 48 47 // is in the list of parents and children -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/MultiSymbolicExpressionTreeArchitectureManipulator.cs
r5445 r5499 26 26 using HeuristicLab.Core; 27 27 using HeuristicLab.Data; 28 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Interfaces;29 28 using HeuristicLab.Operators; 30 29 using HeuristicLab.Optimization; … … 33 32 using HeuristicLab.PluginInfrastructure; 34 33 35 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding .ArchitectureManipulators{34 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 36 35 [Item("MultiSymbolicExpressionTreeArchitectureManipulator", "Randomly selects and applies one of its architecture manipulators every time it is called.")] 37 36 [StorableClass] -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/SubroutineCreater.cs
r5445 r5499 27 27 using HeuristicLab.Core; 28 28 using HeuristicLab.Data; 29 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;30 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 31 30 32 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding .ArchitectureManipulators{31 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 33 32 /// <summary> 34 33 /// Manipulates a symbolic expression by adding one new function-defining branch containing -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/SubroutineDeleter.cs
r5445 r5499 25 25 using HeuristicLab.Core; 26 26 using HeuristicLab.Data; 27 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Creators;28 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;29 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 28 using System.Collections.Generic; 31 29 32 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding .ArchitectureManipulators{30 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 33 31 /// <summary> 34 32 /// Manipulates a symbolic expression by deleting a preexisting function-defining branch. -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/SubroutineDuplicater.cs
r5445 r5499 27 27 using HeuristicLab.Core; 28 28 using HeuristicLab.Data; 29 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;30 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 31 30 32 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding .ArchitectureManipulators{31 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 33 32 /// <summary> 34 33 /// Manipulates a symbolic expression by duplicating a preexisting function-defining branch. -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/SymbolicExpressionTreeArchitectureManipulator.cs
r5445 r5499 23 23 using HeuristicLab.Core; 24 24 using HeuristicLab.Data; 25 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Interfaces;26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Manipulators;27 25 using HeuristicLab.Parameters; 28 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 27 30 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding .ArchitectureManipulators{28 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 31 29 /// <summary> 32 30 /// Base class for architecture altering operators for symbolic expression trees. … … 34 32 [StorableClass] 35 33 public abstract class SymbolicExpressionTreeArchitectureManipulator : SymbolicExpressionTreeManipulator, ISymbolicExpressionTreeArchitectureManipulator { 36 private const string Max FunctionArgumentsParameterName = "MaxFunctionArguments";37 private const string Max FunctionDefiningBranchesParameterName = "MaxFunctionDefiningBranches";34 private const string MaximumFunctionArgumentsParameterName = "MaximumFunctionArguments"; 35 private const string MaximumFunctionDefinitionsParameterName = "MaximumFunctionDefinitions"; 38 36 public override bool CanChangeName { 39 37 get { return false; } 40 38 } 41 42 public IValueLookupParameter<IntValue> Max FunctionDefinitionsParameter {43 get { return (IValueLookupParameter<IntValue>)Parameters[Max FunctionDefiningBranchesParameterName]; }39 #region parameter properties 40 public IValueLookupParameter<IntValue> MaximumFunctionDefinitionsParameter { 41 get { return (IValueLookupParameter<IntValue>)Parameters[MaximumFunctionDefinitionsParameterName]; } 44 42 } 45 public IValueLookupParameter<IntValue> Max FunctionArgumentsParameter {46 get { return (IValueLookupParameter<IntValue>)Parameters[Max FunctionArgumentsParameterName]; }43 public IValueLookupParameter<IntValue> MaximumFunctionArgumentsParameter { 44 get { return (IValueLookupParameter<IntValue>)Parameters[MaximumFunctionArgumentsParameterName]; } 47 45 } 48 public IntValue MaxFunctionDefiningBranches { 49 get { return MaxFunctionDefinitionsParameter.ActualValue; } 46 #endregion 47 #region properties 48 public IntValue MaximumFunctionDefinitions { 49 get { return MaximumFunctionDefinitionsParameter.ActualValue; } 50 50 } 51 public IntValue Max FunctionArguments {52 get { return Max FunctionArgumentsParameter.ActualValue; }51 public IntValue MaximumFunctionArguments { 52 get { return MaximumFunctionArgumentsParameter.ActualValue; } 53 53 } 54 #endregion 54 55 [StorableConstructor] 55 56 protected SymbolicExpressionTreeArchitectureManipulator(bool deserializing) : base(deserializing) { } … … 57 58 public SymbolicExpressionTreeArchitectureManipulator() 58 59 : base() { 59 Parameters.Add(new ValueLookupParameter<IntValue>(Max FunctionDefiningBranchesParameterName, "The maximal allowed number of function defining branches."));60 Parameters.Add(new ValueLookupParameter<IntValue>(Max FunctionArgumentsParameterName, "The maximal allowed number of arguments of a newly created function."));60 Parameters.Add(new ValueLookupParameter<IntValue>(MaximumFunctionDefinitionsParameterName, "The maximal allowed number of automatically defined functions.")); 61 Parameters.Add(new ValueLookupParameter<IntValue>(MaximumFunctionArgumentsParameterName, "The maximal allowed number of arguments of a automatically defined functions.")); 61 62 } 62 63 63 protected override sealed void Manipulate(IRandom random, SymbolicExpressionTree symbolicExpressionTree , ISymbolicExpressionGrammar grammar, IntValue maxTreeSize, IntValue maxTreeHeight, out bool success) {64 ModifyArchitecture(random, symbolicExpressionTree, grammar, maxTreeSize, maxTreeHeight, MaxFunctionDefiningBranches, MaxFunctionArguments, out success);64 protected override sealed void Manipulate(IRandom random, SymbolicExpressionTree symbolicExpressionTree) { 65 ModifyArchitecture(random, symbolicExpressionTree, MaximumFunctionDefinitions, MaximumFunctionArguments); 65 66 } 66 67 … … 68 69 IRandom random, 69 70 SymbolicExpressionTree tree, 70 ISymbolicExpressionGrammar grammar,71 IntValue maxTreeSize,72 IntValue maxTreeHeight,73 71 IntValue maxFunctionDefinitions, 74 IntValue maxFunctionArguments, 75 out bool success 76 ); 72 IntValue maxFunctionArguments); 77 73 } 78 74 } -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Compiler/Instruction.cs
r5445 r5499 21 21 22 22 23 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Compiler { 24 // total size of this struct should be small to improve cache access while executing the code 25 // should be aligned to 8/16/32 byte 26 // size = 4(8) + 1 + 1 + 2 = 8 (12) 23 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 24 // total size of this class should be small to improve cache access while executing the code 27 25 public class Instruction { 28 26 // the tree node can hold additional data that is necessary for the execution of this instruction 29 public SymbolicExpressionTreeNode dynamicNode;27 public ISymbolicExpressionTreeNode dynamicNode; 30 28 // op code of the function that determines what operation should be executed 31 29 public byte opCode; -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Compiler/SymbolicExpressionTreeCompiler.cs
r5445 r5499 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;26 25 27 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding .Compiler{26 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 28 27 public class SymbolicExpressionTreeCompiler { 29 28 private Dictionary<string, ushort> entryPoint = new Dictionary<string, ushort>(); 30 29 private List<Func<Instruction, Instruction>> postInstructionCompiledHooks = new List<Func<Instruction, Instruction>>(); 31 30 32 public Instruction[] Compile(SymbolicExpressionTree tree, Func< SymbolicExpressionTreeNode, byte> opCodeMapper) {31 public Instruction[] Compile(SymbolicExpressionTree tree, Func<ISymbolicExpressionTreeNode, byte> opCodeMapper) { 33 32 List<Instruction> code = new List<Instruction>(); 34 33 entryPoint.Clear(); 35 34 // compile main body branches 36 foreach (var branch in tree.Root. SubTrees[0].SubTrees) {35 foreach (var branch in tree.Root.GetSubTree(0).SubTrees) { 37 36 code.AddRange(Compile(branch, opCodeMapper)); 38 37 } … … 60 59 } 61 60 62 private IEnumerable<Instruction> Compile( SymbolicExpressionTreeNode branch, Func<SymbolicExpressionTreeNode, byte> opCodeMapper) {61 private IEnumerable<Instruction> Compile(ISymbolicExpressionTreeNode branch, Func<ISymbolicExpressionTreeNode, byte> opCodeMapper) { 63 62 foreach (var node in branch.IterateNodesPrefix()) { 64 63 Instruction instr = new Instruction(); 65 if (node.SubTrees.Count > 255) throw new ArgumentException("Number of subtrees is too big (>255)"); 66 instr.nArguments = (byte)node.SubTrees.Count; 64 int subTreesCount = node.SubTrees.Count(); 65 if (subTreesCount > 255) throw new ArgumentException("Number of subtrees is too big (>255)"); 66 instr.nArguments = (byte)subTreesCount; 67 67 instr.opCode = opCodeMapper(node); 68 68 if (node.Symbol is Argument) { -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/ProbabilisticTreeCreator.cs
r5445 r5499 27 27 using HeuristicLab.Core; 28 28 using HeuristicLab.Data; 29 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ArchitectureManipulators;30 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;31 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 32 33 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Creators { 30 using HeuristicLab.Parameters; 31 32 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 34 33 [StorableClass] 35 34 [Item("ProbabilisticTreeCreator", "An operator that creates new symbolic expression trees with uniformly distributed size")] 36 public sealed class ProbabilisticTreeCreator : SymbolicExpressionTreeCreator { 35 public sealed class ProbabilisticTreeCreator : SymbolicExpressionTreeCreator, 36 ISymbolicExpressionTreeSizeConstraintOperator, ISymbolicExpressionTreeGrammarBasedOperator, ISymbolicExpressionTreeArchitectureAlteringOperator { 37 37 private const int MAX_TRIES = 100; 38 private const string MaximumSymbolicExpressionTreeLengthParameterName = "MaximumSymbolicExpressionTreeLength"; 39 private const string MaximumSymbolicExpressionTreeDepthParameterName = "MaximumSymbolicExpressionTreeDepth"; 40 private const string MaximumFunctionDefinitionsParameterName = "MaximumFunctionDefinitions"; 41 private const string MaximumFunctionArgumentsParameterName = "MaximumFunctionArguments"; 42 private const string SymbolicExpressionTreeGrammarParameterName = "SymbolicExpressionTreeGrammar"; 43 #region Parameter Properties 44 public IValueLookupParameter<IntValue> MaximumSymbolicExpressionTreeLengthParameter { 45 get { return (IValueLookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeLengthParameterName]; } 46 } 47 public IValueLookupParameter<IntValue> MaximumSymbolicExpressionTreeDepthParameter { 48 get { return (IValueLookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeDepthParameterName]; } 49 } 50 public IValueLookupParameter<IntValue> MaximumFunctionDefinitionsParameter { 51 get { return (IValueLookupParameter<IntValue>)Parameters[MaximumFunctionDefinitionsParameterName]; } 52 } 53 public IValueLookupParameter<IntValue> MaximumFunctionArgumentsParameter { 54 get { return (IValueLookupParameter<IntValue>)Parameters[MaximumFunctionArgumentsParameterName]; } 55 } 56 public IValueLookupParameter<ISymbolicExpressionTreeGrammar> SymbolicExpressionTreeGrammarParameter { 57 get { return (IValueLookupParameter<ISymbolicExpressionTreeGrammar>)Parameters[SymbolicExpressionTreeGrammarParameterName]; } 58 } 59 #endregion 60 #region Properties 61 public IntValue MaximumSymbolicExpressionTreeLength { 62 get { return MaximumSymbolicExpressionTreeLengthParameter.ActualValue; } 63 } 64 public IntValue MaximumSymbolicExpressionTreeDepth { 65 get { return MaximumSymbolicExpressionTreeDepthParameter.ActualValue; } 66 } 67 public IntValue MaximumFunctionDefinitions { 68 get { return MaximumFunctionDefinitionsParameter.ActualValue; } 69 } 70 public IntValue MaximumFunctionArguments { 71 get { return MaximumFunctionArgumentsParameter.ActualValue; } 72 } 73 public ISymbolicExpressionTreeGrammar SymbolicExpressionTreeGrammar { 74 get { return SymbolicExpressionTreeGrammarParameter.ActualValue; } 75 } 76 #endregion 77 38 78 [StorableConstructor] 39 79 private ProbabilisticTreeCreator(bool deserializing) : base(deserializing) { } 40 80 private ProbabilisticTreeCreator(ProbabilisticTreeCreator original, Cloner cloner) : base(original, cloner) { } 41 public ProbabilisticTreeCreator() : base() { } 81 public ProbabilisticTreeCreator() 82 : base() { 83 Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeLengthParameterName, "The maximal length (number of nodes) of the symbolic expression tree.")); 84 Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeDepthParameterName, "The maximal depth of the symbolic expression tree (a tree with one node has depth = 0).")); 85 Parameters.Add(new ValueLookupParameter<IntValue>(MaximumFunctionDefinitionsParameterName, "The maximum allowed number of automatically defined functions.")); 86 Parameters.Add(new ValueLookupParameter<IntValue>(MaximumFunctionArgumentsParameterName, "The maximum allowed number of arguments of automatically defined functions.")); 87 Parameters.Add(new ValueLookupParameter<SymbolicExpressionTreeGrammar>(SymbolicExpressionTreeGrammarParameterName, "The tree grammar that defines the correct syntax of symbolic expression trees that should be created.")); 88 } 42 89 43 90 public override IDeepCloneable Clone(Cloner cloner) { … … 45 92 } 46 93 47 protected override SymbolicExpressionTree Create( 48 IRandom random, 49 ISymbolicExpressionGrammar grammar, 50 IntValue maxTreeSize, IntValue maxTreeHeight, 51 IntValue maxFunctionDefinitions, IntValue maxFunctionArguments) { 52 return Create(random, grammar, maxTreeSize.Value, maxTreeHeight.Value, maxFunctionDefinitions.Value, maxFunctionArguments.Value); 53 } 54 55 public static SymbolicExpressionTree Create(IRandom random, ISymbolicExpressionGrammar grammar, 94 protected override SymbolicExpressionTree Create(IRandom random) { 95 return Create(random, SymbolicExpressionTreeGrammar, MaximumSymbolicExpressionTreeLength.Value, MaximumSymbolicExpressionTreeDepth.Value, 96 MaximumFunctionDefinitions.Value, MaximumFunctionArguments.Value); 97 } 98 99 public static SymbolicExpressionTree Create(IRandom random, ISymbolicExpressionTreeGrammar grammar, 56 100 int maxTreeSize, int maxTreeHeight, 57 101 int maxFunctionDefinitions, int maxFunctionArguments … … 66 110 67 111 private class TreeExtensionPoint { 68 public SymbolicExpressionTreeNode Parent { get; set; }112 public ISymbolicExpressionTreeNode Parent { get; set; } 69 113 public int ChildIndex { get; set; } 70 114 public int ExtensionPointDepth { get; set; } 71 115 } 72 116 73 public static SymbolicExpressionTreeNode PTC2(IRandom random,SymbolicExpressionTreeNode seedNode,117 public static ISymbolicExpressionTreeNode PTC2(IRandom random, ISymbolicExpressionTreeNode seedNode, 74 118 int maxTreeSize, int maxDepth, int maxFunctionDefinitions, int maxFunctionArguments) { 75 119 // tree size is limited by the grammar and by the explicit size constraints … … 79 123 while (tries++ < MAX_TRIES) { 80 124 // select a target tree size uniformly in the possible range (as determined by explicit limits and limits of the grammar) 81 int treeSize = random.Next(allowedMinSize, allowedMaxSize + 1); 125 int treeSize; 126 treeSize = random.Next(allowedMinSize, allowedMaxSize + 1); 82 127 if (treeSize <= 1 || maxDepth <= 1) return seedNode; 83 128 … … 89 134 } else { 90 135 // clean seedNode 91 while (seedNode.SubTrees.Count > 0) seedNode.RemoveSubTree(0);136 while (seedNode.SubTrees.Count() > 0) seedNode.RemoveSubTree(0); 92 137 } 93 138 // try a different size MAX_TRIES times … … 96 141 } 97 142 98 private static bool CreateFullTreeFromSeed(IRandom random, SymbolicExpressionTreeNode root, ISymbolicExpressionGrammar globalGrammar,143 private static bool CreateFullTreeFromSeed(IRandom random, ISymbolicExpressionTreeNode root, ISymbolicExpressionTreeGrammar globalGrammar, 99 144 int size, int maxDepth, int maxFunctionDefinitions, int maxFunctionArguments) { 100 145 try { … … 105 150 } 106 151 107 private static void TryCreateFullTreeFromSeed(IRandom random, SymbolicExpressionTreeNode root, ISymbolicExpressionGrammar globalGrammar,152 private static void TryCreateFullTreeFromSeed(IRandom random, ISymbolicExpressionTreeNode root, ISymbolicExpressionTreeGrammar globalGrammar, 108 153 int size, int maxDepth, int maxFunctionDefinitions, int maxFunctionArguments) { 109 154 List<TreeExtensionPoint> extensionPoints = new List<TreeExtensionPoint>(); … … 122 167 TreeExtensionPoint nextExtension = extensionPoints[randomIndex]; 123 168 extensionPoints.RemoveAt(randomIndex); 124 SymbolicExpressionTreeNode parent = nextExtension.Parent;169 ISymbolicExpressionTreeNode parent = nextExtension.Parent; 125 170 int argumentIndex = nextExtension.ChildIndex; 126 171 int extensionDepth = nextExtension.ExtensionPointDepth; … … 128 173 ReplaceWithMinimalTree(random, root, parent, argumentIndex, maxFunctionDefinitions, maxFunctionArguments); 129 174 } else { 130 var allowedSymbols = from s in parent.Grammar.Symbols 131 where parent.Grammar.IsAllowedChild(parent.Symbol, s, argumentIndex) 132 where parent.Grammar.GetMinExpressionDepth(s) + extensionDepth - 1 < maxDepth 133 where parent.Grammar.GetMaxExpressionLength(s) > size - totalListMinSize - currentSize 134 select s; 135 Symbol selectedSymbol = SelectRandomSymbol(random, allowedSymbols); 136 SymbolicExpressionTreeNode newTree = selectedSymbol.CreateTreeNode(); 175 var allowedSymbols = (from s in parent.Grammar.Symbols 176 where parent.Grammar.IsAllowedChild(parent.Symbol, s, argumentIndex) 177 where parent.Grammar.GetMinExpressionDepth(s) + extensionDepth - 1 < maxDepth 178 where parent.Grammar.GetMaxExpressionLength(s) > size - totalListMinSize - currentSize 179 select s) 180 .ToList(); 181 var weights = allowedSymbols.Select(x => x.InitialFrequency).ToList(); 182 var selectedSymbol = allowedSymbols.SelectRandom(weights, random); 183 ISymbolicExpressionTreeNode newTree = selectedSymbol.CreateTreeNode(); 137 184 if (newTree.HasLocalParameters) newTree.ResetLocalParameters(random); 138 185 parent.RemoveSubTree(argumentIndex); … … 159 206 TreeExtensionPoint nextExtension = extensionPoints[randomIndex]; 160 207 extensionPoints.RemoveAt(randomIndex); 161 SymbolicExpressionTreeNode parent = nextExtension.Parent;208 ISymbolicExpressionTreeNode parent = nextExtension.Parent; 162 209 int a = nextExtension.ChildIndex; 163 210 int d = nextExtension.ExtensionPointDepth; … … 166 213 } 167 214 168 private static void ReplaceWithMinimalTree(IRandom random, SymbolicExpressionTreeNode root, SymbolicExpressionTreeNode parent, int argumentIndex, int maxFunctionDefinitions, int maxFunctionArguments) { 215 private static void ReplaceWithMinimalTree(IRandom random, ISymbolicExpressionTreeNode root, ISymbolicExpressionTreeNode parent, 216 int argumentIndex, int maxFunctionDefinitions, int maxFunctionArguments) { 169 217 // determine possible symbols that will lead to the smallest possible tree 170 218 var possibleSymbols = (from s in parent.GetAllowedSymbols(argumentIndex) 171 219 group s by parent.Grammar.GetMinExpressionLength(s) into g 172 220 orderby g.Key 173 select g).First(); 174 var selectedSymbol = SelectRandomSymbol(random, possibleSymbols); 221 select g).First().ToList(); 222 var weights = possibleSymbols.Select(x => x.InitialFrequency).ToList(); 223 var selectedSymbol = possibleSymbols.SelectRandom(weights, random); 175 224 var tree = selectedSymbol.CreateTreeNode(); 176 225 if (tree.HasLocalParameters) tree.ResetLocalParameters(random); … … 187 236 } 188 237 189 private static void InitializeNewTreeNode(IRandom random, SymbolicExpressionTreeNode root,SymbolicExpressionTreeNode newTree, int maxFunctionDefinitions, int maxFunctionArguments) {238 private static void InitializeNewTreeNode(IRandom random, ISymbolicExpressionTreeNode root, ISymbolicExpressionTreeNode newTree, int maxFunctionDefinitions, int maxFunctionArguments) { 190 239 // NB it is assumed that defuns are only allowed as children of root and nowhere else 191 240 // also assumes that newTree is already attached to root somewhere 192 241 if (IsTopLevelBranch(root, newTree)) { 193 ((SymbolicExpressionTreeTopLevelNode)newTree).SetGrammar((ISymbolicExpression Grammar)root.Grammar.Clone());242 ((SymbolicExpressionTreeTopLevelNode)newTree).SetGrammar((ISymbolicExpressionTreeGrammar)root.Grammar.Clone()); 194 243 195 244 // allow invokes of existing ADFs with higher index 196 int argIndex = root. SubTrees.IndexOf(newTree);197 for (int i = argIndex + 1; i < root.SubTrees.Count ; i++) {198 var otherDefunNode = root. SubTrees[i]as DefunTreeNode;245 int argIndex = root.IndexOfSubTree(newTree); 246 for (int i = argIndex + 1; i < root.SubTrees.Count(); i++) { 247 var otherDefunNode = root.GetSubTree(i) as DefunTreeNode; 199 248 if (otherDefunNode != null) { 200 249 GrammarModifier.AddDynamicSymbol(newTree.Grammar, newTree.Symbol, otherDefunNode.FunctionName, otherDefunNode.NumberOfArguments); … … 219 268 } 220 269 // in existing branches with smaller index allow invoke of current function 221 int argIndex = root. SubTrees.IndexOf(newTree);270 int argIndex = root.IndexOfSubTree(newTree); 222 271 for (int i = 0; i < argIndex; i++) { 223 272 // if not dummy node 224 if (root. SubTrees[i].Symbol != null) {225 var existingBranch = root. SubTrees[i];273 if (root.GetSubTree(i).Symbol != null) { 274 var existingBranch = root.GetSubTree(i); 226 275 GrammarModifier.AddDynamicSymbol(existingBranch.Grammar, existingBranch.Symbol, functionName, nArgs); 227 276 } … … 230 279 } 231 280 232 private static bool IsTopLevelBranch( SymbolicExpressionTreeNode root,SymbolicExpressionTreeNode branch) {281 private static bool IsTopLevelBranch(ISymbolicExpressionTreeNode root, ISymbolicExpressionTreeNode branch) { 233 282 return branch is SymbolicExpressionTreeTopLevelNode; 234 283 } 235 284 236 private static Symbol SelectRandomSymbol(IRandom random, IEnumerable<Symbol> symbols) { 237 var symbolList = symbols.ToList(); 238 var ticketsSum = symbolList.Select(x => x.InitialFrequency).Sum(); 239 if (ticketsSum == 0.0) throw new ArgumentException("The initial frequency of all allowed symbols is zero."); 240 var r = random.NextDouble() * ticketsSum; 241 double aggregatedTickets = 0; 242 for (int i = 0; i < symbolList.Count; i++) { 243 aggregatedTickets += symbolList[i].InitialFrequency; 244 if (aggregatedTickets > r) { 245 return symbolList[i]; 246 } 247 } 248 // this should never happen 249 throw new ArgumentException("There is a problem with the initial frequency setting of allowed symbols."); 250 } 251 252 private static int SampleArity(IRandom random, SymbolicExpressionTreeNode node, int targetSize) { 285 private static int SampleArity(IRandom random, ISymbolicExpressionTreeNode node, int targetSize) { 253 286 // select actualArity randomly with the constraint that the sub-trees in the minimal arity can become large enough 254 287 int minArity = node.GetMinSubtreeCount(); -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/SymbolicExpressionTreeCreator.cs
r5445 r5499 23 23 using HeuristicLab.Core; 24 24 using HeuristicLab.Data; 25 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Interfaces;26 25 using HeuristicLab.Parameters; 27 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 27 29 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding .Creators{28 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 30 29 /// <summary> 31 30 /// A base class for operators creating symbolic expression trees. … … 34 33 [StorableClass] 35 34 public abstract class SymbolicExpressionTreeCreator : SymbolicExpressionTreeOperator, ISymbolicExpressionTreeCreator { 36 private const string MaxFunctionDefinitionsParameterName = "MaxFunctionDefinitions";37 private const string MaxFunctionArgumentsParameterName = "MaxFunctionArguments";38 35 private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree"; 39 36 #region Parameter Properties 40 public IValueLookupParameter<IntValue> MaxFunctionDefinitionsParameter {41 get { return (IValueLookupParameter<IntValue>)Parameters[MaxFunctionDefinitionsParameterName]; }42 }43 public IValueLookupParameter<IntValue> MaxFunctionArgumentsParameter {44 get { return (IValueLookupParameter<IntValue>)Parameters[MaxFunctionArgumentsParameterName]; }45 }46 37 public ILookupParameter<SymbolicExpressionTree> SymbolicExpressionTreeParameter { 47 38 get { return (ILookupParameter<SymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; } … … 50 41 51 42 #region Propeties 52 public IntValue MaxFunctionDefinitions {53 get { return MaxFunctionDefinitionsParameter.ActualValue; }54 }55 public IntValue MaxFunctionArguments {56 get { return MaxFunctionArgumentsParameter.ActualValue; }57 }58 43 public SymbolicExpressionTree SymbolicExpressionTree { 59 44 get { return SymbolicExpressionTreeParameter.ActualValue; } … … 67 52 protected SymbolicExpressionTreeCreator() 68 53 : base() { 69 Parameters.Add(new ValueLookupParameter<IntValue>(MaxFunctionDefinitionsParameterName, "Maximal number of function definitions in the symbolic expression tree."));70 Parameters.Add(new ValueLookupParameter<IntValue>(MaxFunctionArgumentsParameterName, "Maximal number of arguments of automatically defined functions in the symbolic expression tree."));71 54 Parameters.Add(new LookupParameter<SymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression tree that should be created.")); 72 55 } 73 56 74 57 public sealed override IOperation Apply() { 75 SymbolicExpressionTree = Create(Random, SymbolicExpressionGrammar, 76 MaxTreeSize, MaxTreeHeight, MaxFunctionDefinitions, MaxFunctionArguments); 58 SymbolicExpressionTree = Create(Random); 77 59 return base.Apply(); 78 60 } 79 61 80 protected abstract SymbolicExpressionTree Create( 81 IRandom random, 82 ISymbolicExpressionGrammar grammar, 83 IntValue maxTreeSize, IntValue maxTreeHeight, 84 IntValue maxFunctionDefinitions, IntValue maxFunctionArguments 85 ); 62 protected abstract SymbolicExpressionTree Create(IRandom random); 86 63 } 87 64 } -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Crossovers/CrossoverPoint.cs
r5445 r5499 21 21 22 22 23 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding .Crossovers{24 publicclass CrossoverPoint {23 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 24 internal class CrossoverPoint { 25 25 public SymbolicExpressionTreeNode Parent { get; set; } 26 26 public SymbolicExpressionTreeNode Child { get; set; } -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Crossovers/SubtreeCrossover.cs
r5445 r5499 29 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 30 31 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding .Crossovers{31 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 32 32 /// <summary> 33 33 /// Takes two parent individuals P0 and P1 each. Selects a random node N0 of P0 and a random node N1 of P1. … … 38 38 [Item("SubtreeCrossover", "An operator which performs subtree swapping crossover.")] 39 39 [StorableClass] 40 public sealed class SubtreeCrossover : SymbolicExpressionTreeCrossover { 40 public sealed class SubtreeCrossover : SymbolicExpressionTreeCrossover, ISymbolicExpressionTreeSizeConstraintOperator { 41 private const string InternalCrossoverPointProbabilityParameterName = "InternalCrossoverPointProbability"; 42 private const string MaximumSymbolicExpressionTreeLengthParameterName = "MaximumSymbolicExpressionTreeLength"; 43 private const string MaximumSymbolicExpressionTreeDepthParameterName = "MaximumSymbolicExpressionTreeDepth"; 44 #region Parameter Properties 41 45 public IValueLookupParameter<PercentValue> InternalCrossoverPointProbabilityParameter { 42 get { return (IValueLookupParameter<PercentValue>)Parameters["InternalCrossoverPointProbability"]; } 43 } 46 get { return (IValueLookupParameter<PercentValue>)Parameters[InternalCrossoverPointProbabilityParameterName]; } 47 } 48 public IValueLookupParameter<IntValue> MaximumSymbolicExpressionTreeLengthParameter { 49 get { return (IValueLookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeLengthParameterName]; } 50 } 51 public IValueLookupParameter<IntValue> MaximumSymbolicExpressionTreeDepthParameter { 52 get { return (IValueLookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeDepthParameterName]; } 53 } 54 #endregion 55 #region Properties 56 public PercentValue InternalCrossoverPointProbability { 57 get { return InternalCrossoverPointProbabilityParameter.ActualValue; } 58 } 59 public IntValue MaximumSymbolicExpressionTreeLength { 60 get { return MaximumSymbolicExpressionTreeLengthParameter.ActualValue; } 61 } 62 public IntValue MaximumSymbolicExpressionTreeDepth { 63 get { return MaximumSymbolicExpressionTreeDepthParameter.ActualValue; } 64 } 65 #endregion 44 66 [StorableConstructor] 45 67 private SubtreeCrossover(bool deserializing) : base(deserializing) { } … … 47 69 public SubtreeCrossover() 48 70 : base() { 49 Parameters.Add(new ValueLookupParameter<PercentValue>("InternalCrossoverPointProbability", "The probability to select an internal crossover point (instead of a leaf node).", new PercentValue(0.9))); 71 Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeLengthParameterName, "The maximal length (number of nodes) of the symbolic expression tree.")); 72 Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeDepthParameterName, "The maximal depth of the symbolic expression tree (a tree with one node has depth = 0).")); 73 Parameters.Add(new ValueLookupParameter<PercentValue>(InternalCrossoverPointProbabilityParameterName, "The probability to select an internal crossover point (instead of a leaf node).", new PercentValue(0.9))); 50 74 } 51 75 … … 55 79 56 80 protected override SymbolicExpressionTree Cross(IRandom random, 57 SymbolicExpressionTree parent0, SymbolicExpressionTree parent1 ,58 IntValue maxTreeSize, IntValue maxTreeHeight, out bool success) {59 return Cross(random, parent0, parent1, InternalCrossoverPointProbabilityParameter.ActualValue.Value, maxTreeSize.Value, maxTreeHeight.Value, out success);81 SymbolicExpressionTree parent0, SymbolicExpressionTree parent1) { 82 return Cross(random, parent0, parent1, InternalCrossoverPointProbability.Value, 83 MaximumSymbolicExpressionTreeLength.Value, MaximumSymbolicExpressionTreeDepth.Value); 60 84 } 61 85 62 86 public static SymbolicExpressionTree Cross(IRandom random, 63 87 SymbolicExpressionTree parent0, SymbolicExpressionTree parent1, 64 double internalCrossoverPointProbability, int maxTreeSize, int maxTreeHeight , out bool success) {88 double internalCrossoverPointProbability, int maxTreeSize, int maxTreeHeight) { 65 89 // select a random crossover point in the first parent 66 90 SymbolicExpressionTreeNode crossoverPoint0; … … 81 105 82 106 if (allowedBranches.Count == 0) { 83 success = false;84 107 return parent0; 85 108 } else { … … 90 113 crossoverPoint0.RemoveSubTree(replacedSubtreeIndex); 91 114 crossoverPoint0.InsertSubTree(replacedSubtreeIndex, selectedBranch); 92 success = true;93 115 return parent0; 94 116 } … … 190 212 } 191 213 192 private static int GetBranchLevel( SymbolicExpressionTreeNode root,SymbolicExpressionTreeNode point) {214 private static int GetBranchLevel(ISymbolicExpressionTreeNode root, ISymbolicExpressionTreeNode point) { 193 215 if (root == point) return 0; 194 216 foreach (var subtree in root.SubTrees) { -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Crossovers/SymbolicExpressionTreeCrossover.cs
r5445 r5499 24 24 using HeuristicLab.Core; 25 25 using HeuristicLab.Data; 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Interfaces;27 26 using HeuristicLab.Parameters; 28 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 28 30 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding .Crossovers{29 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 31 30 /// <summary> 32 31 /// A base class for operators that perform a crossover of symbolic expression trees. … … 37 36 private const string ParentsParameterName = "Parents"; 38 37 private const string ChildParameterName = "Child"; 39 private const string FailedCrossoverEventsParameterName = "FailedCrossoverEvents";38 #region Parameter Properties 40 39 public ILookupParameter<ItemArray<SymbolicExpressionTree>> ParentsParameter { 41 40 get { return (ScopeTreeLookupParameter<SymbolicExpressionTree>)Parameters[ParentsParameterName]; } … … 44 43 get { return (ILookupParameter<SymbolicExpressionTree>)Parameters[ChildParameterName]; } 45 44 } 46 public IValueParameter<IntValue> FailedCrossoverEventsParameter { 47 get { return (ValueParameter<IntValue>)Parameters[FailedCrossoverEventsParameterName]; } 45 #endregion 46 #region Properties 47 public ItemArray<SymbolicExpressionTree> Parents { 48 get { return ParentsParameter.ActualValue; } 48 49 } 49 50 public IntValue FailedCrossoverEvents {51 get { return FailedCrossoverEventsParameter.Value; }50 public SymbolicExpressionTree Child { 51 get { return ChildParameter.ActualValue; } 52 set { ChildParameter.ActualValue = value; } 52 53 } 54 #endregion 53 55 [StorableConstructor] 54 56 protected SymbolicExpressionTreeCrossover(bool deserializing) : base(deserializing) { } … … 58 60 Parameters.Add(new ScopeTreeLookupParameter<SymbolicExpressionTree>(ParentsParameterName, "The parent symbolic expression trees which should be crossed.")); 59 61 Parameters.Add(new LookupParameter<SymbolicExpressionTree>(ChildParameterName, "The child symbolic expression tree resulting from the crossover.")); 60 Parameters.Add(new ValueParameter<IntValue>(FailedCrossoverEventsParameterName, "The number of failed crossover events (child is an exact copy of a parent)", new IntValue()));61 62 } 62 63 63 64 public sealed override IOperation Apply() { 64 if (Parents Parameter.ActualValue.Length != 2)65 if (Parents.Length != 2) 65 66 throw new ArgumentException("Number of parents must be exactly two for symbolic expression tree crossover operators."); 66 67 67 SymbolicExpressionTree parent0 = ParentsParameter.ActualValue[0]; 68 SymbolicExpressionTree parent1 = ParentsParameter.ActualValue[1]; 68 SymbolicExpressionTree result = Cross(Random, Parents[0], Parents[1]); 69 69 70 IRandom random = RandomParameter.ActualValue; 71 72 bool success; 73 SymbolicExpressionTree result = Cross(random, parent0, parent1, 74 MaxTreeSizeParameter.ActualValue, MaxTreeHeightParameter.ActualValue, out success); 75 76 if (!success) FailedCrossoverEvents.Value++; 77 78 ChildParameter.ActualValue = result; 70 Child = result; 79 71 return base.Apply(); 80 72 } 81 73 82 74 protected abstract SymbolicExpressionTree Cross(IRandom random, 83 SymbolicExpressionTree parent0, SymbolicExpressionTree parent1, 84 IntValue maxTreeSize, IntValue maxTreeHeight, out bool success); 75 SymbolicExpressionTree parent0, SymbolicExpressionTree parent1); 85 76 } 86 77 } -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/DefaultSymbolicExpressionGrammar.cs
r5473 r5499 25 25 using HeuristicLab.Common; 26 26 using HeuristicLab.Core; 27 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;28 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 28 … … 37 36 [StorableClass] 38 37 [Item("DefaultSymbolicExpressionGrammar", "Represents a grammar that defines the syntax of symbolic expression trees.")] 39 public abstract class DefaultSymbolicExpressionGrammar : Item, ISymbolicExpression Grammar {38 public abstract class DefaultSymbolicExpressionGrammar : Item, ISymbolicExpressionTreeGrammar { 40 39 41 40 #region properties for separation between implementation and persistence … … 133 132 } 134 133 135 protected DefaultSymbolicExpressionGrammar(ISymbolicExpression Grammar grammar)134 protected DefaultSymbolicExpressionGrammar(ISymbolicExpressionTreeGrammar grammar) 136 135 : base() { 137 136 Cloner cloner = new Cloner(); -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Formatters/SymbolicExpressionTreeStringFormatter.cs
r5445 r5499 21 21 22 22 using System.Text; 23 using System.Linq; 23 24 using HeuristicLab.Core; 24 25 using HeuristicLab.Common; 25 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 27 27 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding .Formatters{28 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 28 29 29 30 [Item("SymbolicExpressionTreeStringFormatter", "The default string formatter for symbolic expression trees.")] … … 49 50 } 50 51 51 private string FormatRecursively( SymbolicExpressionTreeNode node, int indentLength) {52 private string FormatRecursively(ISymbolicExpressionTreeNode node, int indentLength) { 52 53 StringBuilder strBuilder = new StringBuilder(); 53 54 if (Indent) strBuilder.Append(' ', indentLength); 54 55 strBuilder.Append("("); 55 56 // internal nodes or leaf nodes? 56 if (node.SubTrees.Count > 0) {57 if (node.SubTrees.Count() > 0) { 57 58 // symbol on same line as '(' 58 59 strBuilder.AppendLine(node.ToString()); … … 75 76 return new SymbolicExpressionTreeStringFormatter(this, cloner); 76 77 } 77 78 78 } 79 80 79 } -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/GlobalSymbolicExpressionGrammar.cs
r5473 r5499 24 24 using HeuristicLab.Common; 25 25 using HeuristicLab.Core; 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;27 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 27 -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4.csproj
r5494 r5499 123 123 <Compile Include="Compiler\Instruction.cs" /> 124 124 <Compile Include="Compiler\SymbolicExpressionTreeCompiler.cs" /> 125 <Compile Include="Interfaces\ISymbolicExpressionTreeGrammar.cs" /> 126 <Compile Include="Interfaces\Operators\ISymbolicExpressionTreeArchitectureAlteringOperator.cs" /> 127 <Compile Include="Interfaces\Operators\ISymbolicExpressionTreeGrammarBasedOperator.cs" /> 128 <Compile Include="SymbolicExpressionTreeSizeConstraintOperator.cs" /> 125 129 <Compile Include="Creators\SymbolicExpressionTreeCreator.cs" /> 126 130 <Compile Include="Crossovers\CrossoverPoint.cs" /> … … 155 159 <Compile Include="SymbolicExpressionTreeOperator.cs" /> 156 160 <Compile Include="SymbolicExpressionTreeTerminalNode.cs" /> 157 <Compile Include="Interfaces\ISymbolicExpressionGrammar.cs" />158 161 <Compile Include="Creators\ProbabilisticTreeCreator.cs" /> 159 162 <Compile Include="HeuristicLabEncodingsSymbolicExpressionTreeEncodingPlugin.cs" /> -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Interfaces/ISymbol.cs
r5494 r5499 25 25 public interface ISymbol : INamedItem { 26 26 ISymbolicExpressionTreeNode CreateTreeNode(); 27 double InitialFrequency; 27 28 } 28 29 } -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Interfaces/ISymbolicExpressionTree.cs
r5494 r5499 26 26 public interface ISymbolicExpressionTree : IItem { 27 27 ISymbolicExpressionTreeNode Root { get; } 28 uint Size { get; }29 uint Height { get; }28 int Size { get; } 29 int Height { get; } 30 30 31 31 IEnumerable<ISymbolicExpressionTreeNode> IterateNodesPrefix(); -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Interfaces/ISymbolicExpressionTreeGrammar.cs
r5494 r5499 24 24 25 25 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 26 public interface ISymbolicExpression Grammar : IItem {26 public interface ISymbolicExpressionTreeGrammar : IItem { 27 27 ISymbol StartSymbol { get; } 28 28 void AddSymbol(ISymbol symbol); 29 29 void RemoveSymbol(ISymbol symbol); 30 IEnumerable<ISymbol> ISymbol{ get; }30 IEnumerable<ISymbol> Symbols { get; } 31 31 bool ContainsSymbol(ISymbol symbol); 32 32 void SetAllowedChild(ISymbol parent, ISymbol child, int argumentIndex); -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Interfaces/ISymbolicExpressionTreeNode.cs
r5494 r5499 21 21 using System.Collections.Generic; 22 22 using HeuristicLab.Core; 23 using System; 23 24 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 24 25 public interface ISymbolicExpressionTreeNode : IItem { 25 ISymbolicExpression Grammar Grammar { get; }26 ISymbolicExpressionTreeGrammar Grammar { get; } 26 27 27 28 ISymbol Symbol { get; } … … 36 37 IEnumerable<ISymbolicExpressionTreeNode> IterateNodesPostfix(); 37 38 IEnumerable<ISymbolicExpressionTreeNode> IterateNodesPrefix(); 39 void ForEachNodePostfix(Action<SymbolicExpressionTreeNode> a); 40 void ForEachNodePrefix(Action<SymbolicExpressionTreeNode> a); 38 41 39 IEnumerable<SymbolicExpressionTreeNode> SubTrees { get; } 42 IEnumerable<ISymbolicExpressionTreeNode> SubTrees { get; } 43 ISymbolicExpressionTreeNode GetSubTree(int index); 44 int IndexOfSubTree(ISymbolicExpressionTreeNode tree); 40 45 void AddSubTree(ISymbolicExpressionTreeNode tree); 41 46 void InsertSubTree(int index, ISymbolicExpressionTreeNode tree); -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Interfaces/Operators/ISymbolicExpressionTreeArchitectureManipulator.cs
r5494 r5499 27 27 /// Interface for operators that manipulate symbolic expression trees. 28 28 /// </summary> 29 public interface ISymbolicExpressionTreeArchitectureManipulator : ISymbolicExpressionTreeManipulator { 30 IValueLookupParameter<IntValue> MaxFunctionDefinitionsParameter { get; } 31 IValueLookupParameter<IntValue> MaxFunctionArgumentsParameter { get; } 29 public interface ISymbolicExpressionTreeArchitectureManipulator : ISymbolicExpressionTreeManipulator, ISymbolicExpressionTreeArchitectureAlteringOperator { 32 30 } 33 31 } -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Interfaces/Operators/ISymbolicExpressionTreeSizeConstraintOperator.cs
r5494 r5499 25 25 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 26 26 public interface ISymbolicExpressionTreeSizeConstraintOperator : ISymbolicExpressionTreeOperator { 27 IValueLookupParameter<IntValue> MaximumSymbolicExpressionTreeDepth { get; }28 IValueLookupParameter<IntValue> MaximumSymbolicExpressionTreeLength { get; }27 IValueLookupParameter<IntValue> MaximumSymbolicExpressionTreeDepthParameter { get; } 28 IValueLookupParameter<IntValue> MaximumSymbolicExpressionTreeLengthParameter { get; } 29 29 } 30 30 } -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Manipulators/ChangeNodeTypeManipulation.cs
r5445 r5499 26 26 using HeuristicLab.Core; 27 27 using HeuristicLab.Data; 28 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;29 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 29 31 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding .Manipulators{30 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 32 31 [StorableClass] 33 32 [Item("ChangeNodeTypeManipulation", "Selects a random tree node and changes the symbol.")] 34 33 public sealed class ChangeNodeTypeManipulation : SymbolicExpressionTreeManipulator { 35 36 34 [StorableConstructor] 37 35 private ChangeNodeTypeManipulation(bool deserializing) : base(deserializing) { } … … 43 41 } 44 42 45 protected override void Manipulate(IRandom random, SymbolicExpressionTree symbolicExpressionTree , ISymbolicExpressionGrammar grammar, IntValue maxTreeSize, IntValue maxTreeHeight, out bool success) {46 ChangeNodeType(random, symbolicExpressionTree , grammar, maxTreeSize.Value, maxTreeHeight.Value, out success);43 protected override void Manipulate(IRandom random, SymbolicExpressionTree symbolicExpressionTree) { 44 ChangeNodeType(random, symbolicExpressionTree); 47 45 } 48 46 49 public static void ChangeNodeType(IRandom random, SymbolicExpressionTree symbolicExpressionTree , ISymbolicExpressionGrammar grammar, int maxTreeSize, int maxTreeHeight, out bool success) {47 public static void ChangeNodeType(IRandom random, SymbolicExpressionTree symbolicExpressionTree) { 50 48 51 49 // select any node as parent (except the root node) 52 50 var manipulationPoint = (from parent in symbolicExpressionTree.Root.IterateNodesPrefix().Skip(1) 53 51 from subtree in parent.SubTrees 54 select new { Parent = parent, Node = subtree, Index = parent.SubTrees.IndexOf(subtree) }).SelectRandom(random); 52 select new { Parent = parent, Node = subtree, Index = parent.IndexOfSubTree(subtree) }) 53 .SelectRandom(random); 54 int subTreeCount = manipulationPoint.Node.SubTrees.Count(); 55 55 // find possible symbols for the node (also considering the existing branches below it) 56 56 var allowedSymbols = from symbol in manipulationPoint.Parent.GetAllowedSymbols(manipulationPoint.Index) 57 where manipulationPoint.Node.SubTrees.Count <= manipulationPoint.Node.Grammar.GetMaxSubtreeCount(symbol)58 where manipulationPoint.Node.SubTrees.Count >= manipulationPoint.Node.Grammar.GetMinSubtreeCount(symbol)57 where subTreeCount <= manipulationPoint.Node.Grammar.GetMaxSubtreeCount(symbol) 58 where subTreeCount >= manipulationPoint.Node.Grammar.GetMinSubtreeCount(symbol) 59 59 select symbol; 60 60 61 61 if (allowedSymbols.Count() == 0) { 62 success = false;63 62 return; 64 63 } 65 64 var node = manipulationPoint.Node; 66 65 // keep only symbols that are still possible considering the existing sub-trees 67 var constrainedSymbols = from symbol in allowedSymbols 68 let disallowedSubtrees = 69 from subtree in node.SubTrees 70 where !node.Grammar.IsAllowedChild(symbol, subtree.Symbol, node.SubTrees.IndexOf(subtree)) 71 select subtree 72 where disallowedSubtrees.Count() == 0 73 select symbol; 66 var constrainedSymbols = (from symbol in allowedSymbols 67 let disallowedSubtrees = 68 from subtree in node.SubTrees 69 where !node.Grammar.IsAllowedChild(symbol, subtree.Symbol, node.IndexOfSubTree(subtree)) 70 select subtree 71 where disallowedSubtrees.Count() == 0 72 select symbol) 73 .ToList(); 74 74 if (constrainedSymbols.Count() == 0) { 75 success = false;76 75 return; 77 76 } 78 var newSymbol = SelectRandomSymbol(random, constrainedSymbols); 77 var weights = constrainedSymbols.Select(s => s.InitialFrequency).ToList(); 78 var newSymbol = constrainedSymbols.SelectRandom(weights, random); 79 79 80 80 // replace the old node with the new node … … 86 86 manipulationPoint.Parent.RemoveSubTree(manipulationPoint.Index); 87 87 manipulationPoint.Parent.InsertSubTree(manipulationPoint.Index, newNode); 88 success = true;89 }90 91 private static Symbol SelectRandomSymbol(IRandom random, IEnumerable<Symbol> symbols) {92 var symbolList = symbols.ToList();93 var ticketsSum = symbolList.Select(x => x.InitialFrequency).Sum();94 if (ticketsSum == 0.0) throw new ArgumentException("The initial frequency of all allowed symbols is zero.");95 var r = random.NextDouble() * ticketsSum;96 double aggregatedTickets = 0;97 for (int i = 0; i < symbolList.Count; i++) {98 aggregatedTickets += symbolList[i].InitialFrequency;99 if (aggregatedTickets > r) {100 return symbolList[i];101 }102 }103 // this should never happen104 throw new ArgumentException("There is a problem with the initial frequency setting of allowed symbols.");105 88 } 106 89 } -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Manipulators/FullTreeShaker.cs
r5445 r5499 24 24 using HeuristicLab.Data; 25 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 using HeuristicLab.Parameters; 26 27 27 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding .Manipulators{28 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 28 29 [StorableClass] 29 30 [Item("FullTreeShaker", "Manipulates all nodes that have local parameters.")] 30 31 public sealed class FullTreeShaker : SymbolicExpressionTreeManipulator { 32 private const string ShakingFactorParameterName = "ShakingFactor"; 33 #region parameter properties 34 public IValueLookupParameter<DoubleValue> ShakingFactorParameter { 35 get { return (IValueLookupParameter<DoubleValue>)Parameters[ShakingFactorParameterName]; } 36 } 37 #endregion 38 #region properties 39 public DoubleValue ShakingFactor { 40 get { return ShakingFactorParameter.ActualValue; } 41 } 42 #endregion 31 43 32 44 [StorableConstructor] 33 45 private FullTreeShaker(bool deserializing) : base(deserializing) { } 34 46 private FullTreeShaker(FullTreeShaker original, Cloner cloner) : base(original, cloner) { } 35 public FullTreeShaker() : base() { } 47 public FullTreeShaker() 48 : base() { 49 Parameters.Add(new ValueLookupParameter<DoubleValue>(ShakingFactorParameterName, "The shaking factor that should be used for the manipulation of constants (default=1.0).", new DoubleValue(1.0))); 50 } 36 51 37 52 public override IDeepCloneable Clone(Cloner cloner) { … … 39 54 } 40 55 41 protected override void Manipulate(IRandom random, SymbolicExpressionTree symbolicExpressionTree, ISymbolicExpressionGrammar grammar, IntValue maxTreeSize, IntValue maxTreeHeight, out bool success) {42 foreach (var node in symbolicExpressionTree.IterateNodesPrefix()){56 protected override void Manipulate(IRandom random, SymbolicExpressionTree tree) { 57 tree.Root.ForEachNodePostfix(node => { 43 58 if (node.HasLocalParameters) { 44 node.ShakeLocalParameters(random, 1.0);59 node.ShakeLocalParameters(random, ShakingFactor.Value); 45 60 } 46 } 47 success = true; 61 }); 48 62 } 49 63 } -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Manipulators/MultiSymbolicExpressionTreeManipulator.cs
r5445 r5499 26 26 using HeuristicLab.Core; 27 27 using HeuristicLab.Data; 28 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Interfaces;29 28 using HeuristicLab.Operators; 30 29 using HeuristicLab.Optimization; … … 33 32 using HeuristicLab.PluginInfrastructure; 34 33 35 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding .Manipulators{34 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 36 35 [Item("MultiSymbolicExpressionTreeManipulator", "Randomly selects and applies one of its manipulators every time it is called.")] 37 36 [StorableClass] 38 public sealed class MultiSymbolicExpressionTreeManipulator : StochasticMultiBranch<ISymbolicExpressionTreeManipulator>, ISymbolicExpressionTreeManipulator, IStochasticOperator {39 private const string MaxTreeSizeParameterName = "MaxTreeSize";40 private const string MaxTreeHeightParameterName = "MaxTreeHeight";41 private const string SymbolicExpressionGrammarParameterName = "SymbolicExpressionGrammar";37 public sealed class MultiSymbolicExpressionTreeManipulator : StochasticMultiBranch<ISymbolicExpressionTreeManipulator>, 38 ISymbolicExpressionTreeManipulator, 39 IStochasticOperator, 40 ISymbolicExpressionTreeSizeConstraintOperator { 42 41 private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree"; 42 private const string MaximumSymbolicExpressionTreeLengthParameterName = "MaximumSymbolicExpressionTreeLength"; 43 private const string MaximumSymbolicExpressionTreeDepthParameterName = "MaximumSymbolicExpressionTreeDepth"; 43 44 44 45 public override bool CanChangeName { … … 49 50 } 50 51 51 #region ISymbolicExpressionTreeManipulator Members52 public I LookupParameter<SymbolicExpressionTree> SymbolicExpressionTreeParameter {53 get { return (I LookupParameter<SymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; }52 #region Parameter Properties 53 public IValueLookupParameter<IntValue> MaximumSymbolicExpressionTreeLengthParameter { 54 get { return (IValueLookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeLengthParameterName]; } 54 55 } 55 #endregion 56 57 #region ISymbolicExpressionTreeOperator Members 58 public IValueLookupParameter<IntValue> MaxTreeSizeParameter { 59 get { return (IValueLookupParameter<IntValue>)Parameters[MaxTreeSizeParameterName]; } 56 public IValueLookupParameter<IntValue> MaximumSymbolicExpressionTreeDepthParameter { 57 get { return (IValueLookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeDepthParameterName]; } 60 58 } 61 public IValueLookupParameter<IntValue> MaxTreeHeightParameter { 62 get { return (IValueLookupParameter<IntValue>)Parameters[MaxTreeHeightParameterName]; } 63 } 64 public ILookupParameter<ISymbolicExpressionGrammar> SymbolicExpressionGrammarParameter { 65 get { return (ILookupParameter<ISymbolicExpressionGrammar>)Parameters[SymbolicExpressionGrammarParameterName]; } 59 public ILookupParameter<ISymbolicExpressionTree> SymbolicExpressionTreeParameter { 60 get { return (ILookupParameter<ISymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; } 66 61 } 67 62 #endregion … … 72 67 public MultiSymbolicExpressionTreeManipulator() 73 68 : base() { 74 Parameters.Add(new LookupParameter<SymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression tree on which the operator should be applied.")); 75 Parameters.Add(new ValueLookupParameter<IntValue>(MaxTreeSizeParameterName, "The maximal size (number of nodes) of the symbolic expression tree.")); 76 Parameters.Add(new ValueLookupParameter<IntValue>(MaxTreeHeightParameterName, "The maximal height of the symbolic expression tree (a tree with one node has height = 0).")); 77 Parameters.Add(new LookupParameter<ISymbolicExpressionGrammar>(SymbolicExpressionGrammarParameterName, "The grammar that defines the allowed symbols and syntax of the symbolic expression trees.")); 69 Parameters.Add(new LookupParameter<ISymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression tree on which the operator should be applied.")); 70 Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeLengthParameterName, "The maximal length (number of nodes) of the symbolic expression tree.")); 71 Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeDepthParameterName, "The maximal depth of the symbolic expression tree (a tree with one node has depth = 0).")); 78 72 79 73 foreach (Type type in ApplicationManager.Manager.GetTypes(typeof(ISymbolicExpressionTreeManipulator))) { … … 98 92 99 93 private void ParameterizeManipulators() { 94 foreach (IStochasticOperator manipulator in Operators.OfType<IStochasticOperator>()) { 95 manipulator.RandomParameter.ActualName = RandomParameter.Name; 96 } 100 97 foreach (ISymbolicExpressionTreeManipulator manipulator in Operators.OfType<ISymbolicExpressionTreeManipulator>()) { 101 manipulator.MaxTreeSizeParameter.ActualName = MaxTreeSizeParameter.Name;102 manipulator.MaxTreeHeightParameter.ActualName = MaxTreeHeightParameter.Name;103 manipulator.SymbolicExpressionGrammarParameter.ActualName = SymbolicExpressionGrammarParameter.Name;104 98 manipulator.SymbolicExpressionTreeParameter.ActualName = SymbolicExpressionTreeParameter.Name; 105 99 } 106 107 foreach (IStochasticOperator manipulator in Operators.OfType<IStochasticOperator>()) {108 manipulator. RandomParameter.ActualName = RandomParameter.Name;100 foreach (ISymbolicExpressionTreeSizeConstraintOperator manipulator in Operators.OfType<ISymbolicExpressionTreeSizeConstraintOperator>()) { 101 manipulator.MaximumSymbolicExpressionTreeDepthParameter.ActualName = MaximumSymbolicExpressionTreeDepthParameter.Name; 102 manipulator.MaximumSymbolicExpressionTreeLengthParameter.ActualName = MaximumSymbolicExpressionTreeLengthParameter.Name; 109 103 } 110 104 } -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Manipulators/OnePointShaker.cs
r5445 r5499 25 25 using HeuristicLab.Data; 26 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 using HeuristicLab.Parameters; 27 28 28 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding .Manipulators{29 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 29 30 [StorableClass] 30 31 [Item("OnePointShaker", "Selects a random node with local parameters and manipulates the selected node.")] 31 32 public sealed class OnePointShaker : SymbolicExpressionTreeManipulator { 33 private const string ShakingFactorParameterName = "ShakingFactor"; 34 #region parameter properties 35 public IValueLookupParameter<DoubleValue> ShakingFactorParameter { 36 get { return (IValueLookupParameter<DoubleValue>)Parameters[ShakingFactorParameterName]; } 37 } 38 #endregion 39 #region properties 40 public DoubleValue ShakingFactor { 41 get { return ShakingFactorParameter.ActualValue; } 42 } 43 #endregion 32 44 [StorableConstructor] 33 45 private OnePointShaker(bool deserializing) : base(deserializing) { } 34 46 private OnePointShaker(OnePointShaker original, Cloner cloner) : base(original, cloner) { } 35 public OnePointShaker() : base() { } 47 public OnePointShaker() 48 : base() { 49 Parameters.Add(new ValueLookupParameter<DoubleValue>(ShakingFactorParameterName, "The shaking factor that should be used for the manipulation of constants (default=1.0).", new DoubleValue(1.0))); 50 } 36 51 37 52 public override IDeepCloneable Clone(Cloner cloner) { … … 39 54 } 40 55 41 protected override void Manipulate(IRandom random, SymbolicExpressionTree symbolicExpressionTree, ISymbolicExpressionGrammar grammar, IntValue maxTreeSize, IntValue maxTreeHeight, out bool success) {42 var parametricNodes = from node in symbolicExpressionTree.IterateNodesPrefix()56 protected override void Manipulate(IRandom random, SymbolicExpressionTree tree) { 57 var parametricNodes = from node in tree.IterateNodesPrefix() 43 58 where node.HasLocalParameters 44 59 select node; 45 60 if (parametricNodes.Count() > 0) { 46 SymbolicExpressionTreeNodeselectedPoint = parametricNodes.SelectRandom(random);61 var selectedPoint = parametricNodes.SelectRandom(random); 47 62 48 selectedPoint.ShakeLocalParameters(random, 1.0); 49 success = true; 50 } else { 51 success = false; 63 selectedPoint.ShakeLocalParameters(random, ShakingFactor.Value); 52 64 } 53 65 } -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Manipulators/ReplaceBranchManipulation.cs
r5445 r5499 26 26 using HeuristicLab.Core; 27 27 using HeuristicLab.Data; 28 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Creators;29 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;30 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 using HeuristicLab.Parameters; 31 30 32 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding .Manipulators{31 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 33 32 [StorableClass] 34 33 [Item("ReplaceBranchManipulation", "Selects a branch of the tree randomly and replaces it with a newly initialized branch (using PTC2).")] 35 public sealed class ReplaceBranchManipulation : SymbolicExpressionTreeManipulator { 34 public sealed class ReplaceBranchManipulation : SymbolicExpressionTreeManipulator, ISymbolicExpressionTreeSizeConstraintOperator { 35 private const string MaximumSymbolicExpressionTreeLengthParameterName = "MaximumSymbolicExpressionTreeLength"; 36 private const string MaximumSymbolicExpressionTreeDepthParameterName = "MaximumSymbolicExpressionTreeDepth"; 37 #region Parameter Properties 38 public IValueLookupParameter<IntValue> MaximumSymbolicExpressionTreeLengthParameter { 39 get { return (IValueLookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeLengthParameterName]; } 40 } 41 public IValueLookupParameter<IntValue> MaximumSymbolicExpressionTreeDepthParameter { 42 get { return (IValueLookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeDepthParameterName]; } 43 } 44 #endregion 45 #region Properties 46 public IntValue MaximumSymbolicExpressionTreeLength { 47 get { return MaximumSymbolicExpressionTreeLengthParameter.ActualValue; } 48 } 49 public IntValue MaximumSymbolicExpressionTreeDepth { 50 get { return MaximumSymbolicExpressionTreeDepthParameter.ActualValue; } 51 } 52 #endregion 53 36 54 [StorableConstructor] 37 55 private ReplaceBranchManipulation(bool deserializing) : base(deserializing) { } 38 56 private ReplaceBranchManipulation(ReplaceBranchManipulation original, Cloner cloner) : base(original, cloner) { } 39 public ReplaceBranchManipulation() : base() { } 57 public ReplaceBranchManipulation() 58 : base() { 59 Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeLengthParameterName, "The maximal length (number of nodes) of the symbolic expression tree.")); 60 Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeDepthParameterName, "The maximal depth of the symbolic expression tree (a tree with one node has depth = 0).")); 61 } 40 62 41 63 public override IDeepCloneable Clone(Cloner cloner) { … … 43 65 } 44 66 45 protected override void Manipulate(IRandom random, SymbolicExpressionTree symbolicExpressionTree, ISymbolicExpressionGrammar grammar, IntValue maxTreeSize, IntValue maxTreeHeight, out bool success) {46 ReplaceRandomBranch(random, symbolicExpressionTree, grammar, maxTreeSize.Value, maxTreeHeight.Value, out success);67 protected override void Manipulate(IRandom random, ISymbolicExpressionTree symbolicExpressionTree) { 68 ReplaceRandomBranch(random, symbolicExpressionTree, MaximumSymbolicExpressionTreeLength.Value, MaximumSymbolicExpressionTreeDepth.Value); 47 69 } 48 70 49 public static void ReplaceRandomBranch(IRandom random, SymbolicExpressionTree symbolicExpressionTree, ISymbolicExpressionGrammar grammar, int maxTreeSize, int maxTreeHeight, out bool success) { 50 success = false; 71 public static void ReplaceRandomBranch(IRandom random, ISymbolicExpressionTree symbolicExpressionTree, int maxTreeLength, int maxTreeDepth) { 51 72 // select any node as parent (except the root node) 52 73 var manipulationPoint = (from parent in symbolicExpressionTree.Root.IterateNodesPrefix().Skip(1) 53 74 from subtree in parent.SubTrees 54 select new { Parent = parent, Node = subtree, Index = parent.SubTrees.IndexOf(subtree) }).SelectRandom(random); 75 select new { Parent = parent, Node = subtree, Index = parent.IndexOfSubTree(subtree) }) 76 .SelectRandom(random); 55 77 56 int max Size = maxTreeSize- symbolicExpressionTree.Size + manipulationPoint.Node.GetSize();57 int max Height = maxTreeHeight- symbolicExpressionTree.Height + manipulationPoint.Node.GetHeight();78 int maxLength = maxTreeLength - symbolicExpressionTree.Size + manipulationPoint.Node.GetSize(); 79 int maxDepth = maxTreeDepth - symbolicExpressionTree.Height + manipulationPoint.Node.GetHeight(); 58 80 // find possible symbols for the node (also considering the existing branches below it) 59 var allowedSymbols = from symbol in manipulationPoint.Parent.GetAllowedSymbols(manipulationPoint.Index)60 where manipulationPoint.Node.Grammar.GetMinExpressionDepth(symbol) <= maxHeight61 where manipulationPoint.Node.Grammar.GetMinExpressionLength(symbol) <= maxSize62 select symbol;81 var allowedSymbols = (from symbol in manipulationPoint.Parent.GetAllowedSymbols(manipulationPoint.Index) 82 where manipulationPoint.Node.Grammar.GetMinExpressionDepth(symbol) <= maxDepth 83 where manipulationPoint.Node.Grammar.GetMinExpressionLength(symbol) <= maxLength 84 select symbol).ToList(); 63 85 if (allowedSymbols.Count() == 0) return; 64 65 var seedSymbol = SelectRandomSymbol(random, allowedSymbols); // replace the old node with the new node 86 var weights = allowedSymbols.Select(s => s.InitialFrequency).ToList(); 87 var seedSymbol = allowedSymbols.SelectRandom(weights, random); 88 // replace the old node with the new node 66 89 var seedNode = seedSymbol.CreateTreeNode(); 67 90 if (seedNode.HasLocalParameters) … … 70 93 manipulationPoint.Parent.RemoveSubTree(manipulationPoint.Index); 71 94 manipulationPoint.Parent.InsertSubTree(manipulationPoint.Index, seedNode); 72 seedNode = ProbabilisticTreeCreator.PTC2(random, seedNode, maxSize, maxHeight, 0, 0); 73 success = true; 74 } 75 76 private static Symbol SelectRandomSymbol(IRandom random, IEnumerable<Symbol> symbols) { 77 var symbolList = symbols.ToList(); 78 var ticketsSum = symbolList.Select(x => x.InitialFrequency).Sum(); 79 if (ticketsSum == 0.0) throw new ArgumentException("The initial frequency of all allowed symbols is zero."); 80 var r = random.NextDouble() * ticketsSum; 81 double aggregatedTickets = 0; 82 for (int i = 0; i < symbolList.Count; i++) { 83 aggregatedTickets += symbolList[i].InitialFrequency; 84 if (aggregatedTickets > r) { 85 return symbolList[i]; 86 } 87 } 88 // this should never happen 89 throw new ArgumentException("There is a problem with the initial frequency setting of allowed symbols."); 95 seedNode = ProbabilisticTreeCreator.PTC2(random, seedNode, maxLength, maxDepth, 0, 0); 90 96 } 91 97 } -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Manipulators/SymbolicExpressionTreeManipulator.cs
r5494 r5499 33 33 [StorableClass] 34 34 public abstract class SymbolicExpressionTreeManipulator : SymbolicExpressionTreeOperator, ISymbolicExpressionTreeManipulator { 35 private const string FailedManipulationEventsParameterName = "FailedManipulationEvents";36 35 private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree"; 37 36 38 37 #region Parameter Properties 39 public IValueParameter<IntValue> FailedManipulationEventsParameter {40 get { return (IValueParameter<IntValue>)Parameters[FailedManipulationEventsParameterName]; }41 }42 38 public ILookupParameter<SymbolicExpressionTree> SymbolicExpressionTreeParameter { 43 39 get { return (ILookupParameter<SymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; } … … 46 42 47 43 #region Properties 48 public IntValue FailedManipulationEvents {49 get { return FailedManipulationEventsParameter.Value; }50 }51 44 public SymbolicExpressionTree SymbolicExpressionTree { 52 45 get { return SymbolicExpressionTreeParameter.ActualValue; } … … 59 52 public SymbolicExpressionTreeManipulator() 60 53 : base() { 61 Parameters.Add(new ValueParameter<IntValue>(FailedManipulationEventsParameterName, "The number of failed manipulation events.", new IntValue()));62 54 Parameters.Add(new LookupParameter<SymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression tree on which the operator should be applied.")); 63 55 } … … 65 57 public sealed override IOperation Apply() { 66 58 SymbolicExpressionTree tree = SymbolicExpressionTreeParameter.ActualValue; 67 bool success; 68 Manipulate(RandomParameter.ActualValue, tree, SymbolicExpressionGrammarParameter.ActualValue, 69 MaxTreeSizeParameter.ActualValue, MaxTreeHeightParameter.ActualValue, out success); 59 Manipulate(RandomParameter.ActualValue, tree); 70 60 71 if (!success) FailedManipulationEvents.Value++;72 61 return base.Apply(); 73 62 } 74 63 75 protected abstract void Manipulate(IRandom random, SymbolicExpressionTree symbolicExpressionTree, ISymbolicExpressionGrammar grammar, 76 IntValue maxTreeSize, IntValue maxTreeHeight, out bool success); 64 protected abstract void Manipulate(IRandom random, SymbolicExpressionTree symbolicExpressionTree); 77 65 } 78 66 } -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTree.cs
r5473 r5499 30 30 [StorableClass] 31 31 [Item("SymbolicExpressionTree", "Represents a symbolic expression tree.")] 32 public class SymbolicExpressionTree : Item {32 public class SymbolicExpressionTree : Item, ISymbolicExpressionTree { 33 33 public override Image ItemImage { 34 34 get { return HeuristicLab.Common.Resources.VSImageLibrary.Function; } 35 35 } 36 36 [Storable] 37 private SymbolicExpressionTreeNode root;38 public SymbolicExpressionTreeNode Root {37 private ISymbolicExpressionTreeNode root; 38 public ISymbolicExpressionTreeNode Root { 39 39 get { return root; } 40 40 set { … … 75 75 } 76 76 77 public IEnumerable< SymbolicExpressionTreeNode> IterateNodesPrefix() {77 public IEnumerable<ISymbolicExpressionTreeNode> IterateNodesPrefix() { 78 78 if (root == null) 79 79 return new SymbolicExpressionTreeNode[0]; 80 80 return root.IterateNodesPrefix(); 81 81 } 82 public IEnumerable< SymbolicExpressionTreeNode> IterateNodesPostfix() {82 public IEnumerable<ISymbolicExpressionTreeNode> IterateNodesPostfix() { 83 83 if (root == null) 84 84 return new SymbolicExpressionTreeNode[0]; -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTreeGrammar.cs
r5473 r5499 25 25 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 26 26 public sealed class SymbolicExpressionTreeGrammar : DefaultSymbolicExpressionGrammar { 27 public SymbolicExpressionTreeGrammar(ISymbolicExpression Grammar grammar)27 public SymbolicExpressionTreeGrammar(ISymbolicExpressionTreeGrammar grammar) 28 28 : base(grammar) { 29 29 } -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTreeNode.cs
r5473 r5499 25 25 using HeuristicLab.Common; 26 26 using HeuristicLab.Core; 27 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;28 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 28 30 29 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 31 30 [StorableClass] 32 public class SymbolicExpressionTreeNode : DeepCloneable {31 public class SymbolicExpressionTreeNode : DeepCloneable, ISymbolicExpressionTreeNode { 33 32 [Storable] 34 33 private IList<SymbolicExpressionTreeNode> subTrees; … … 96 95 } 97 96 98 public virtual ISymbolicExpression Grammar Grammar {97 public virtual ISymbolicExpressionTreeGrammar Grammar { 99 98 get { return parent.Grammar; } 100 99 } … … 175 174 } 176 175 177 public IEnumerable< Symbol> GetAllowedSymbols(int argumentIndex) {176 public IEnumerable<ISymbol> GetAllowedSymbols(int argumentIndex) { 178 177 return Grammar.Symbols.Where(s => Grammar.IsAllowedChild(Symbol, s, argumentIndex)); 179 178 } -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTreeOperator.cs
r5473 r5499 23 23 using HeuristicLab.Core; 24 24 using HeuristicLab.Data; 25 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Interfaces;26 25 using HeuristicLab.Operators; 27 26 using HeuristicLab.Optimization; … … 37 36 public abstract class SymbolicExpressionTreeOperator : SingleSuccessorOperator, IStochasticOperator, ISymbolicExpressionTreeOperator { 38 37 private const string RandomParameterName = "Random"; 39 private const string MaxTreeSizeParameterName = "MaxTreeSize";40 private const string MaxTreeHeightParameterName = "MaxTreeHeight";41 private const string SymbolicExpressionGrammarParameterName = "SymbolicExpressionGrammar";42 38 43 39 public override bool CanChangeName { … … 49 45 get { return (LookupParameter<IRandom>)Parameters[RandomParameterName]; } 50 46 } 51 public IValueLookupParameter<IntValue> MaxTreeSizeParameter {52 get { return (IValueLookupParameter<IntValue>)Parameters[MaxTreeSizeParameterName]; }53 }54 public IValueLookupParameter<IntValue> MaxTreeHeightParameter {55 get { return (IValueLookupParameter<IntValue>)Parameters[MaxTreeHeightParameterName]; }56 }57 public ILookupParameter<ISymbolicExpressionGrammar> SymbolicExpressionGrammarParameter {58 get { return (ILookupParameter<ISymbolicExpressionGrammar>)Parameters[SymbolicExpressionGrammarParameterName]; }59 }60 47 #endregion 61 48 … … 63 50 public IRandom Random { 64 51 get { return RandomParameter.ActualValue; } 65 }66 public IntValue MaxTreeSize {67 get { return MaxTreeSizeParameter.ActualValue; }68 }69 public IntValue MaxTreeHeight {70 get { return MaxTreeHeightParameter.ActualValue; }71 }72 public ISymbolicExpressionGrammar SymbolicExpressionGrammar {73 get { return SymbolicExpressionGrammarParameter.ActualValue; }74 52 } 75 53 #endregion … … 81 59 : base() { 82 60 Parameters.Add(new LookupParameter<IRandom>(RandomParameterName, "The pseudo random number generator which should be used for symbolic expression tree operators.")); 83 Parameters.Add(new ValueLookupParameter<IntValue>(MaxTreeSizeParameterName, "The maximal size (number of nodes) of the symbolic expression tree."));84 Parameters.Add(new ValueLookupParameter<IntValue>(MaxTreeHeightParameterName, "The maximal height of the symbolic expression tree (a tree with one node has height = 0)."));85 Parameters.Add(new LookupParameter<ISymbolicExpressionGrammar>(SymbolicExpressionGrammarParameterName, "The grammar that defines the allowed symbols and syntax of the symbolic expression trees."));86 61 } 87 62 } -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTreeTerminalNode.cs
r5473 r5499 23 23 using System.Collections.Generic; 24 24 using HeuristicLab.Common; 25 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;26 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 26 -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTreeTopLevelNode.cs
r5473 r5499 21 21 22 22 using HeuristicLab.Common; 23 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;24 23 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 25 24 … … 28 27 public class SymbolicExpressionTreeTopLevelNode : SymbolicExpressionTreeNode { 29 28 [Storable] 30 private ISymbolicExpression Grammar grammar;31 public override ISymbolicExpression Grammar Grammar {29 private ISymbolicExpressionTreeGrammar grammar; 30 public override ISymbolicExpressionTreeGrammar Grammar { 32 31 get { return grammar; } 33 32 } 34 public void SetGrammar(ISymbolicExpression Grammar grammar) {33 public void SetGrammar(ISymbolicExpressionTreeGrammar grammar) { 35 34 this.grammar = grammar; 36 35 } -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Symbols/Argument.cs
r5445 r5499 23 23 using HeuristicLab.Core; 24 24 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 25 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding .Symbols{25 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 26 26 /// <summary> 27 27 /// Symbol for function arguments -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Symbols/ArgumentTreeNode.cs
r5445 r5499 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 25 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding .Symbols{25 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 26 26 [StorableClass] 27 27 public sealed class ArgumentTreeNode : SymbolicExpressionTreeTerminalNode { -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Symbols/Defun.cs
r5445 r5499 23 23 using HeuristicLab.Core; 24 24 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 25 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding .Symbols{25 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 26 26 /// <summary> 27 27 /// Symbol for function defining branches -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Symbols/DefunTreeNode.cs
r5445 r5499 22 22 using HeuristicLab.Common; 23 23 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 24 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding .Symbols{24 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 25 25 [StorableClass] 26 26 public sealed class DefunTreeNode : SymbolicExpressionTreeTopLevelNode { -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Symbols/InvokeFunction.cs
r5445 r5499 24 24 using HeuristicLab.Core; 25 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding .Symbols{26 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 27 27 /// <summary> 28 28 /// Symbol for invoking automatically defined functions -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Symbols/InvokeFunctionTreeNode.cs
r5445 r5499 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 25 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding .Symbols{25 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 26 26 [StorableClass] 27 27 public sealed class InvokeFunctionTreeNode : SymbolicExpressionTreeNode { -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Symbols/ProgramRootSymbol.cs
r5445 r5499 23 23 using HeuristicLab.Core; 24 24 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 25 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding .Symbols{25 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 26 26 [StorableClass] 27 27 [Item(ProgramRootSymbol.ProgramRootSymbolName, ProgramRootSymbol.ProgramRootSymbolDescription)] -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Symbols/ReadOnlySymbol.cs
r5445 r5499 24 24 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 25 25 26 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding .Symbols{26 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 27 27 [StorableClass] 28 28 [Item("ReadOnlySymbol", "Represents a symbol in a symbolic function tree that cannot be modified.")] -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Symbols/StartSymbol.cs
r5445 r5499 23 23 using HeuristicLab.Core; 24 24 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 25 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding .Symbols{25 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 26 26 [StorableClass] 27 27 [Item(StartSymbol.StartSymbolName, StartSymbol.StartSymbolDescription)] -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Symbols/Symbol.cs
r5445 r5499 25 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 26 27 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding .Symbols{27 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 28 28 [StorableClass] 29 29 [Item("Symbol", "Represents a symbol in a symbolic function tree.")] 30 public abstract class Symbol : NamedItem {30 public abstract class Symbol : NamedItem, ISymbol { 31 31 #region Properties 32 32 [Storable] -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.ArtificialAnt/3.4/ArtificialAntProblem.cs
r5473 r5499 311 311 operators.AddRange(ApplicationManager.Manager.GetInstances<ISymbolicExpressionTreeOperator>().OfType<IOperator>()); 312 312 operators.Add(new BestAntTrailAnalyzer()); 313 operators.Add(new MinAverageMaxSymbolicExpressionTree SizeAnalyzer());313 operators.Add(new MinAverageMaxSymbolicExpressionTreeLengthAnalyzer()); 314 314 operators.Add(new SymbolicExpressionSymbolFrequencyAnalyzer()); 315 315 ParameterizeAnalyzers();
Note: See TracChangeset
for help on using the changeset viewer.