Changeset 7506
- Timestamp:
- 02/23/12 16:05:57 (13 years ago)
- Location:
- trunk/sources
- Files:
-
- 10 edited
- 9 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Crossovers
-
Property
svn:ignore
set to
*.bak
-
Property
svn:ignore
set to
-
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Crossovers/SubtreeCrossover.cs
r7259 r7506 36 36 /// until a valid configuration is found. 37 37 /// </summary> 38 [Item("Subtree Crossover", "An operator which performs subtree swapping crossover.")]38 [Item("SubtreeSwappingCrossover", "An operator which performs subtree swapping crossover.")] 39 39 [StorableClass] 40 public sealedclass SubtreeCrossover : SymbolicExpressionTreeCrossover, ISymbolicExpressionTreeSizeConstraintOperator {40 public class SubtreeCrossover : SymbolicExpressionTreeCrossover, ISymbolicExpressionTreeSizeConstraintOperator { 41 41 private const string InternalCrossoverPointProbabilityParameterName = "InternalCrossoverPointProbability"; 42 42 private const string MaximumSymbolicExpressionTreeLengthParameterName = "MaximumSymbolicExpressionTreeLength"; 43 43 private const string MaximumSymbolicExpressionTreeDepthParameterName = "MaximumSymbolicExpressionTreeDepth"; 44 44 45 #region Parameter Properties 45 46 public IValueLookupParameter<PercentValue> InternalCrossoverPointProbabilityParameter { … … 65 66 #endregion 66 67 [StorableConstructor] 67 pr ivateSubtreeCrossover(bool deserializing) : base(deserializing) { }68 pr ivateSubtreeCrossover(SubtreeCrossover original, Cloner cloner) : base(original, cloner) { }68 protected SubtreeCrossover(bool deserializing) : base(deserializing) { } 69 protected SubtreeCrossover(SubtreeCrossover original, Cloner cloner) : base(original, cloner) { } 69 70 public SubtreeCrossover() 70 71 : base() { … … 78 79 } 79 80 80 p rotected override ISymbolicExpressionTree Cross(IRandom random,81 public override ISymbolicExpressionTree Crossover(IRandom random, 81 82 ISymbolicExpressionTree parent0, ISymbolicExpressionTree parent1) { 82 83 return Cross(random, parent0, parent1, InternalCrossoverPointProbability.Value, … … 94 95 // calculate the max length and depth that the inserted branch can have 95 96 int maxInsertedBranchLength = maxTreeLength - (parent0.Length - childLength); 96 int maxInsertedBranchDepth = maxTreeDepth - GetBranchLevel(parent0.Root,crossoverPoint0.Parent);97 int maxInsertedBranchDepth = maxTreeDepth - parent0.Root.GetBranchLevel(crossoverPoint0.Parent); 97 98 98 99 List<ISymbolicExpressionTreeNode> allowedBranches = new List<ISymbolicExpressionTreeNode>(); 99 100 parent1.Root.ForEachNodePostfix((n) => { 100 101 if (n.GetLength() <= maxInsertedBranchLength && 101 n.GetDepth() <= maxInsertedBranchDepth && 102 IsMatchingPointType(crossoverPoint0, n)) 102 n.GetDepth() <= maxInsertedBranchDepth && crossoverPoint0.IsMatchingPointType(n)) 103 103 allowedBranches.Add(n); 104 104 }); 105 105 // empty branch 106 if ( IsMatchingPointType(crossoverPoint0,null)) allowedBranches.Add(null);106 if (crossoverPoint0.IsMatchingPointType(null)) allowedBranches.Add(null); 107 107 108 108 if (allowedBranches.Count == 0) { … … 128 128 } 129 129 130 private static bool IsMatchingPointType(CutPoint cutPoint, ISymbolicExpressionTreeNode newChild) {131 var parent = cutPoint.Parent;132 if (newChild == null) {133 // make sure that one subtree can be removed and that only the last subtree is removed134 return parent.Grammar.GetMinimumSubtreeCount(parent.Symbol) < parent.SubtreeCount &&135 cutPoint.ChildIndex == parent.SubtreeCount - 1;136 } else {137 // check syntax constraints of direct parent - child relation138 if (!parent.Grammar.ContainsSymbol(newChild.Symbol) ||139 !parent.Grammar.IsAllowedChildSymbol(parent.Symbol, newChild.Symbol, cutPoint.ChildIndex)) return false;140 141 bool result = true;142 // check point type for the whole branch143 newChild.ForEachNodePostfix((n) => {144 result =145 result &&146 parent.Grammar.ContainsSymbol(n.Symbol) &&147 n.SubtreeCount >= parent.Grammar.GetMinimumSubtreeCount(n.Symbol) &&148 n.SubtreeCount <= parent.Grammar.GetMaximumSubtreeCount(n.Symbol);149 });150 return result;151 }152 }153 154 130 private static void SelectCrossoverPoint(IRandom random, ISymbolicExpressionTree parent0, double internalNodeProbability, int maxBranchLength, int maxBranchDepth, out CutPoint crossoverPoint) { 155 131 if (internalNodeProbability < 0.0 || internalNodeProbability > 1.0) throw new ArgumentException("internalNodeProbability"); … … 157 133 List<CutPoint> leafCrossoverPoints = new List<CutPoint>(); 158 134 parent0.Root.ForEachNodePostfix((n) => { 159 if (n.Subtree s.Any()&& n != parent0.Root) {135 if (n.SubtreeCount > 0 && n != parent0.Root) { 160 136 foreach (var child in n.Subtrees) { 161 137 if (child.GetLength() <= maxBranchLength && 162 138 child.GetDepth() <= maxBranchDepth) { 163 if (child.Subtree s.Any())139 if (child.SubtreeCount > 0) 164 140 internalCrossoverPoints.Add(new CutPoint(n, child)); 165 141 else … … 167 143 } 168 144 } 145 169 146 // add one additional extension point if the number of sub trees for the symbol is not full 170 147 if (n.SubtreeCount < n.Grammar.GetMaximumSubtreeCount(n.Symbol)) { … … 173 150 } 174 151 } 175 }); 152 } 153 ); 176 154 177 155 if (random.NextDouble() < internalNodeProbability) { … … 200 178 // select internal node if possible 201 179 allowedInternalBranches = (from branch in branches 202 where branch != null && branch.Subtree s.Any()180 where branch != null && branch.SubtreeCount > 0 203 181 select branch).ToList(); 204 182 if (allowedInternalBranches.Count > 0) { … … 207 185 // no internal nodes allowed => select leaf nodes 208 186 allowedLeafBranches = (from branch in branches 209 where branch == null || !branch.Subtrees.Any()187 where branch == null || branch.SubtreeCount == 0 210 188 select branch).ToList(); 211 189 return allowedLeafBranches.SelectRandom(random); … … 214 192 // select leaf node if possible 215 193 allowedLeafBranches = (from branch in branches 216 where branch == null || !branch.Subtrees.Any()194 where branch == null || branch.SubtreeCount == 0 217 195 select branch).ToList(); 218 196 if (allowedLeafBranches.Count > 0) { … … 220 198 } else { 221 199 allowedInternalBranches = (from branch in branches 222 where branch != null && branch.Subtree s.Any()200 where branch != null && branch.SubtreeCount > 0 223 201 select branch).ToList(); 224 202 return allowedInternalBranches.SelectRandom(random); … … 226 204 } 227 205 } 228 229 private static int GetBranchLevel(ISymbolicExpressionTreeNode root, ISymbolicExpressionTreeNode point) {230 if (root == point) return 0;231 foreach (var subtree in root.Subtrees) {232 int branchLevel = GetBranchLevel(subtree, point);233 if (branchLevel < int.MaxValue) return 1 + branchLevel;234 }235 return int.MaxValue;236 }237 206 } 238 207 } -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Crossovers/SymbolicExpressionTreeCrossover.cs
r7259 r7506 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Core; 25 using HeuristicLab.Data;26 25 using HeuristicLab.Parameters; 27 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 66 65 throw new ArgumentException("Number of parents must be exactly two for symbolic expression tree crossover operators."); 67 66 68 ISymbolicExpressionTree result = Cross (Random, Parents[0], Parents[1]);67 ISymbolicExpressionTree result = Crossover(Random, Parents[0], Parents[1]); 69 68 70 69 Child = result; … … 72 71 } 73 72 74 protected abstract ISymbolicExpressionTree Cross(IRandom random, 75 ISymbolicExpressionTree parent0, ISymbolicExpressionTree parent1); 73 public abstract ISymbolicExpressionTree Crossover(IRandom random, ISymbolicExpressionTree parent0, ISymbolicExpressionTree parent1); 76 74 } 77 75 } -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/CutPoint.cs
r7259 r7506 22 22 23 23 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 24 internalclass CutPoint {24 public class CutPoint { 25 25 public ISymbolicExpressionTreeNode Parent { get; set; } 26 26 public ISymbolicExpressionTreeNode Child { get; set; } … … 39 39 this.Child = null; 40 40 } 41 42 public bool IsMatchingPointType(ISymbolicExpressionTreeNode newChild) { 43 var parent = this.Parent; 44 if (newChild == null) { 45 // make sure that one subtree can be removed and that only the last subtree is removed 46 return parent.Grammar.GetMinimumSubtreeCount(parent.Symbol) < parent.SubtreeCount && 47 this.ChildIndex == parent.SubtreeCount - 1; 48 } else { 49 // check syntax constraints of direct parent - child relation 50 if (!parent.Grammar.ContainsSymbol(newChild.Symbol) || 51 !parent.Grammar.IsAllowedChildSymbol(parent.Symbol, newChild.Symbol, this.ChildIndex)) 52 return false; 53 54 bool result = true; 55 // check point type for the whole branch 56 newChild.ForEachNodePostfix((n) => { 57 result = 58 result && 59 parent.Grammar.ContainsSymbol(n.Symbol) && 60 n.SubtreeCount >= parent.Grammar.GetMinimumSubtreeCount(n.Symbol) && 61 n.SubtreeCount <= parent.Grammar.GetMaximumSubtreeCount(n.Symbol); 62 }); 63 return result; 64 } 65 } 41 66 } 42 67 } -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTreeNode.cs
r7259 r7506 125 125 } 126 126 127 public int GetBranchLevel(ISymbolicExpressionTreeNode child) { 128 return GetBranchLevel(this, child); 129 } 130 131 private static int GetBranchLevel(ISymbolicExpressionTreeNode root, ISymbolicExpressionTreeNode point) { 132 if (root == point) 133 return 0; 134 foreach (var subtree in root.Subtrees) { 135 int branchLevel = GetBranchLevel(subtree, point); 136 if (branchLevel < int.MaxValue) 137 return 1 + branchLevel; 138 } 139 return int.MaxValue; 140 } 141 127 142 public virtual void ResetLocalParameters(IRandom random) { } 128 143 public virtual void ShakeLocalParameters(IRandom random, double shakingFactor) { } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Crossovers/MultiSymbolicDataAnalysisExpressionCrossover.cs
r7503 r7506 33 33 using HeuristicLab.PluginInfrastructure; 34 34 35 namespace HeuristicLab.Problems.DataAnalysis.Symbolic .Crossovers{35 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 36 36 [Item("MultiSymbolicDataAnalysisExpressionCrossover", "Randomly selects and applies one of its crossovers every time it is called.")] 37 37 public class MultiSymbolicDataAnalysisExpressionCrossover<T> : StochasticMultiBranch<ISymbolicExpressionTreeCrossover>, 38 ISymbolicDataAnalysisExpressionCrossover<T> ,39 ISymbolicExpressionTreeSizeConstraintOperator,40 ISymbolicExpressionTreeGrammarBasedOperator where T : class, IDataAnalysisProblemData {38 ISymbolicDataAnalysisExpressionCrossover<T> where T : class, IDataAnalysisProblemData { 39 private const string ParentsParameterName = "Parents"; 40 private const string ChildParameterName = "Child"; 41 41 private const string MaximumSymbolicExpressionTreeLengthParameterName = "MaximumSymbolicExpressionTreeLength"; 42 42 private const string MaximumSymbolicExpressionTreeDepthParameterName = "MaximumSymbolicExpressionTreeDepth"; 43 private const string SymbolicExpressionTreeGrammarParameterName = "SymbolicExpressionTreeGrammar"; 44 private const string ClonedSymbolicExpressionTreeGrammarParameterName = "ClonedSymbolicExpressionTreeGrammar"; 43 private const string SymbolicDataAnalysisTreeInterpreterParameterName = "SymbolicExpressionTreeInterpreter"; 45 44 private const string EvaluatorParameterName = "Evaluator"; 46 45 private const string SymbolicDataAnalysisEvaluationPartitionParameterName = "EvaluationPartition"; 47 private const string ParentsParameterName = "Parents"; 48 private const string ChildParameterName = "Child"; 46 private const string RelativeNumberOfEvaluatedSamplesParameterName = "RelativeNumberOfEvaluatedSamples"; 47 private const string ProblemDataParameterName = "ProblemData"; 48 49 49 50 50 public override bool CanChangeName { … … 56 56 57 57 #region parameter properties 58 public ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter> SymbolicDataAnalysisTreeInterpreterParameter { 59 get { return (ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>)Parameters[SymbolicDataAnalysisTreeInterpreterParameterName]; } 60 } 58 61 public ILookupParameter<ItemArray<ISymbolicExpressionTree>> ParentsParameter { 59 62 get { return (ScopeTreeLookupParameter<ISymbolicExpressionTree>)Parameters[ParentsParameterName]; } … … 68 71 get { return (IValueLookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeDepthParameterName]; } 69 72 } 70 public IValueLookupParameter<ISymbolicExpressionGrammar> SymbolicExpressionTreeGrammarParameter {71 get { return (IValueLookupParameter<ISymbolicExpressionGrammar>)Parameters[SymbolicExpressionTreeGrammarParameterName]; }72 }73 public ILookupParameter<ISymbolicExpressionGrammar> ClonedSymbolicExpressionTreeGrammarParameter {74 get { return (ILookupParameter<ISymbolicExpressionGrammar>)Parameters[ClonedSymbolicExpressionTreeGrammarParameterName]; }75 }76 73 public ILookupParameter<ISymbolicDataAnalysisSingleObjectiveEvaluator<T>> EvaluatorParameter { 77 74 get { return (ILookupParameter<ISymbolicDataAnalysisSingleObjectiveEvaluator<T>>)Parameters[EvaluatorParameterName]; } 78 75 } 79 public IValueLookupParameter<IntRange> SymbolicDataAnalysisEvaluationPartitionParameter {76 public IValueLookupParameter<IntRange> EvaluationPartitionParameter { 80 77 get { return (IValueLookupParameter<IntRange>)Parameters[SymbolicDataAnalysisEvaluationPartitionParameterName]; } 78 } 79 public IValueLookupParameter<PercentValue> RelativeNumberOfEvaluatedSamplesParameter { 80 get { return (IValueLookupParameter<PercentValue>)Parameters[RelativeNumberOfEvaluatedSamplesParameterName]; } 81 } 82 public IValueLookupParameter<T> ProblemDataParameter { 83 get { return (IValueLookupParameter<T>)Parameters[ProblemDataParameterName]; } 81 84 } 82 85 #endregion … … 88 91 public MultiSymbolicDataAnalysisExpressionCrossover() 89 92 : base() { 93 Parameters.Add(new ValueLookupParameter<PercentValue>(RelativeNumberOfEvaluatedSamplesParameterName, "The relative number of samples of the dataset partition, which should be randomly chosen for evaluation between the start and end index.")); 94 Parameters.Add(new ValueLookupParameter<T>(ProblemDataParameterName, "The problem data on which the symbolic data analysis solution should be evaluated.")); 95 Parameters.Add(new LookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(SymbolicDataAnalysisTreeInterpreterParameterName, "The interpreter that should be used to calculate the output values of the symbolic data analysis tree.")); 90 96 Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeLengthParameterName, "The maximal length (number of nodes) of the symbolic expression tree.")); 91 97 Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeDepthParameterName, "The maximal depth of the symbolic expression tree (a tree with one node has depth = 0).")); 92 Parameters.Add(new ValueLookupParameter<ISymbolicExpressionGrammar>(SymbolicExpressionTreeGrammarParameterName, "The tree grammar that defines the correct syntax of symbolic expression trees that should be created."));93 Parameters.Add(new LookupParameter<ISymbolicExpressionGrammar>(ClonedSymbolicExpressionTreeGrammarParameterName, "An immutable clone of the concrete grammar that is actually used to create and manipulate trees."));94 98 Parameters.Add(new LookupParameter<ISymbolicDataAnalysisSingleObjectiveEvaluator<T>>(EvaluatorParameterName, "The single objective solution evaluator")); 95 99 Parameters.Add(new ValueLookupParameter<IntRange>(SymbolicDataAnalysisEvaluationPartitionParameterName, "The start index of the dataset partition on which the symbolic data analysis solution should be evaluated.")); … … 97 101 Parameters.Add(new LookupParameter<ISymbolicExpressionTree>(ChildParameterName, "The child symbolic expression tree resulting from the crossover.")); 98 102 103 EvaluatorParameter.Hidden = true; 104 EvaluationPartitionParameter.Hidden = true; 105 SymbolicDataAnalysisTreeInterpreterParameter.Hidden = true; 106 ProblemDataParameter.Hidden = true; 107 RelativeNumberOfEvaluatedSamplesParameter.Hidden = true; 108 109 InitializeOperators(); 110 Name = "MultiSymbolicDataAnalysisExpressionCrossover"; 111 } 112 113 private void InitializeOperators() { 99 114 var list = ApplicationManager.Manager.GetInstances<ISymbolicExpressionTreeCrossover>().ToList(); 100 115 var dataAnalysisCrossovers = from type in ApplicationManager.Manager.GetTypes(typeof(ISymbolicDataAnalysisExpressionCrossover<T>)) … … 108 123 Operators = checkedItemList; 109 124 Operators_ItemsAdded(this, new CollectionItemsChangedEventArgs<IndexedItem<ISymbolicExpressionTreeCrossover>>(Operators.CheckedItems)); 110 Name = "MultiSymbolicDataAnalysisExpressionCrossover";111 }112 113 public override IOperation Apply() {114 if (ClonedSymbolicExpressionTreeGrammarParameter.ActualValue == null) {115 SymbolicExpressionTreeGrammarParameter.ActualValue.ReadOnly = true;116 IScope globalScope = ExecutionContext.Scope;117 while (globalScope.Parent != null)118 globalScope = globalScope.Parent;119 120 globalScope.Variables.Add(new Core.Variable(ClonedSymbolicExpressionTreeGrammarParameterName, (ISymbolicExpressionGrammar)SymbolicExpressionTreeGrammarParameter.ActualValue.Clone()));121 }122 return base.Apply();123 125 } 124 126 … … 150 152 151 153 private void ParameterizeCrossovers() { 154 foreach (ISymbolicExpressionTreeCrossover op in Operators) { 155 op.ChildParameter.ActualName = ChildParameter.Name; 156 op.ParentsParameter.ActualName = ParentsParameter.Name; 157 } 152 158 foreach (IStochasticOperator op in Operators.OfType<IStochasticOperator>()) { 153 159 op.RandomParameter.ActualName = RandomParameter.Name; … … 157 163 op.MaximumSymbolicExpressionTreeLengthParameter.ActualName = MaximumSymbolicExpressionTreeLengthParameter.Name; 158 164 } 159 foreach (ISymbolicExpressionTreeGrammarBasedOperator op in Operators.OfType<ISymbolicExpressionTreeGrammarBasedOperator>()) { 160 op.SymbolicExpressionTreeGrammarParameter.ActualName = SymbolicExpressionTreeGrammarParameter.Name; 165 166 foreach (ISymbolicDataAnalysisInterpreterOperator op in Operators.OfType<ISymbolicDataAnalysisInterpreterOperator>()) { 167 op.SymbolicDataAnalysisTreeInterpreterParameter.ActualName = SymbolicDataAnalysisTreeInterpreterParameter.Name; 168 } 169 foreach (var op in Operators.OfType<ISymbolicDataAnalysisExpressionCrossover<T>>()) { 170 op.ProblemDataParameter.ActualName = ProblemDataParameter.Name; 171 op.EvaluationPartitionParameter.ActualName = EvaluationPartitionParameter.Name; 172 op.RelativeNumberOfEvaluatedSamplesParameter.ActualName = RelativeNumberOfEvaluatedSamplesParameter.Name; 173 op.EvaluatorParameter.ActualName = EvaluatorParameter.Name; 161 174 } 162 175 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Crossovers/SymbolicDataAnalysisExpressionContextAwareCrossover.cs
r7503 r7506 29 29 30 30 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 31 32 31 [Item("ContextAwareCrossover", "An operator which deterministically choses the best insertion point for a randomly selected node:\n" + 33 32 "- Take two parent individuals P0 and P1\n" + … … 92 91 // perform a swap and check the quality of the solution 93 92 Swap(crossoverPoint, selectedChild); 94 double quality = evaluator.Evaluate(context, parent0, problemData, rows); 93 IExecutionContext childContext = new ExecutionContext(context, evaluator, context.Scope); 94 double quality = evaluator.Evaluate(childContext, parent0, problemData, rows); 95 95 qualities.Add(new Tuple<CutPoint, double>(crossoverPoint, quality)); 96 96 // restore the correct parent -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Crossovers/SymbolicDataAnalysisExpressionCrossover.cs
r7503 r7506 35 35 private const string SymbolicDataAnalysisTreeInterpreterParameterName = "SymbolicExpressionTreeInterpreter"; 36 36 private const string ProblemDataParameterName = "ProblemData"; 37 private const string EstimationLimitsParameterName = "EstimationLimits";38 37 private const string EvaluatorParameterName = "Evaluator"; 39 private const string SymbolicDataAnalysisEvaluationPartitionParameterName = "EvaluationPartition";38 private const string EvaluationPartitionParameterName = "EvaluationPartition"; 40 39 private const string RelativeNumberOfEvaluatedSamplesParameterName = "RelativeNumberOfEvaluatedSamples"; 41 40 private const string MaximumSymbolicExpressionTreeLengthParameterName = "MaximumSymbolicExpressionTreeLength"; … … 54 53 get { return (ILookupParameter<ISymbolicDataAnalysisSingleObjectiveEvaluator<T>>)Parameters[EvaluatorParameterName]; } 55 54 } 56 public IValueLookupParameter<IntRange> SymbolicDataAnalysisEvaluationPartitionParameter { 57 get { return (IValueLookupParameter<IntRange>)Parameters[SymbolicDataAnalysisEvaluationPartitionParameterName]; } 58 } 59 public IValueLookupParameter<DoubleLimit> EstimationLimitsParameter { 60 get { return (IValueLookupParameter<DoubleLimit>)Parameters[EstimationLimitsParameterName]; } 55 public IValueLookupParameter<IntRange> EvaluationPartitionParameter { 56 get { return (IValueLookupParameter<IntRange>)Parameters[EvaluationPartitionParameterName]; } 61 57 } 62 58 public IValueLookupParameter<PercentValue> RelativeNumberOfEvaluatedSamplesParameter { … … 90 86 Parameters.Add(new LookupParameter<ISymbolicDataAnalysisSingleObjectiveEvaluator<T>>(EvaluatorParameterName, "The single objective solution evaluator")); 91 87 Parameters.Add(new ValueLookupParameter<T>(ProblemDataParameterName, "The problem data on which the symbolic data analysis solution should be evaluated.")); 92 Parameters.Add(new ValueLookupParameter<IntRange>(SymbolicDataAnalysisEvaluationPartitionParameterName, "The start index of the dataset partition on which the symbolic data analysis solution should be evaluated.")); 93 Parameters.Add(new ValueLookupParameter<DoubleLimit>(EstimationLimitsParameterName, "The upper and lower limit that should be used as cut off value for the output values of symbolic data analysis trees.")); 88 Parameters.Add(new ValueLookupParameter<IntRange>(EvaluationPartitionParameterName, "The start index of the dataset partition on which the symbolic data analysis solution should be evaluated.")); 94 89 Parameters.Add(new ValueLookupParameter<PercentValue>(RelativeNumberOfEvaluatedSamplesParameterName, "The relative number of samples of the dataset partition, which should be randomly chosen for evaluation between the start and end index.")); 95 90 Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeDepthParameterName, "The maximum tree depth.")); … … 97 92 98 93 EvaluatorParameter.Hidden = true; 99 EstimationLimitsParameter.Hidden = true; 100 SymbolicDataAnalysisEvaluationPartitionParameter.Hidden = true; 94 EvaluationPartitionParameter.Hidden = true; 101 95 SymbolicDataAnalysisTreeInterpreterParameter.Hidden = true; 102 96 ProblemDataParameter.Hidden = true; … … 131 125 protected IEnumerable<int> GenerateRowsToEvaluate(double percentageOfRows) { 132 126 IEnumerable<int> rows; 133 int samplesStart = SymbolicDataAnalysisEvaluationPartitionParameter.ActualValue.Start;134 int samplesEnd = SymbolicDataAnalysisEvaluationPartitionParameter.ActualValue.End;127 int samplesStart = EvaluationPartitionParameter.ActualValue.Start; 128 int samplesEnd = EvaluationPartitionParameter.ActualValue.End; 135 129 int testPartitionStart = ProblemDataParameter.ActualValue.TestPartition.Start; 136 130 int testPartitionEnd = ProblemDataParameter.ActualValue.TestPartition.End; -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Crossovers/SymbolicDataAnalysisExpressionDepthConstrainedCrossover.cs
r7503 r7506 31 31 32 32 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 33 34 33 [Item("DepthConstrainedCrossover", "An operator which performs subtree swapping within a specific depth range. The range parameter controls the crossover behavior:\n" + 35 34 "- HighLevel (upper 25% of the tree)\n" + -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Crossovers/SymbolicDataAnalysisExpressionDeterministicBestCrossover.cs
r7503 r7506 29 29 30 30 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 31 32 31 [Item("DeterministicBestCrossover", "An operator which performs subtree swapping by choosing the best subtree to be swapped in a certain position:\n" + 33 32 "- Take two parent individuals P0 and P1\n" + … … 85 84 // create symbols in order to improvize an ad-hoc tree so that the child can be evaluated 86 85 ISymbolicExpressionTreeNode selectedBranch = null; 87 88 86 var nodeQualities = new List<Tuple<ISymbolicExpressionTreeNode, double>>(); 89 90 87 var originalChild = crossoverPoint0.Child; 91 88 … … 93 90 var parent = node.Parent; 94 91 Swap(crossoverPoint0, node); // the swap will set the nodes parent to crossoverPoint0.Parent 95 double quality = evaluator.Evaluate(context, parent0, problemData, rows); 92 IExecutionContext childContext = new ExecutionContext(context, evaluator, context.Scope); 93 double quality = evaluator.Evaluate(childContext, parent0, problemData, rows); 96 94 Swap(crossoverPoint0, originalChild); // swap the child back (so that the next swap will not affect the currently swapped node from parent1) 97 95 nodeQualities.Add(new Tuple<ISymbolicExpressionTreeNode, double>(node, quality)); … … 99 97 } 100 98 101 nodeQualities.Sort((a, b) => a.Item2.CompareTo(b.Item2)); // assuming this sorts the list in ascending order99 nodeQualities.Sort((a, b) => a.Item2.CompareTo(b.Item2)); 102 100 selectedBranch = evaluator.Maximization ? nodeQualities.Last().Item1 : nodeQualities.First().Item1; 103 104 105 if (selectedBranch == null)106 throw new Exception("Selected branch is null");107 108 if (selectedBranch.Parent == null)109 throw new Exception("Parent is null");110 111 101 112 102 // swap the node that would create the best offspring -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Crossovers/SymbolicDataAnalysisExpressionProbabilisticFunctionalCrossover.cs
r7503 r7506 29 29 30 30 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 31 32 31 [Item("ProbabilisticFunctionalCrossover", "An operator which performs subtree swapping based on the behavioral similarity between subtrees:\n" + 33 32 "- Take two parent individuals P0 and P1\n" + -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj
r7037 r7506 126 126 <Compile Include="Creators\SymbolicDataAnalysisExpressionRampedHalfAndHalfTreeCreator.cs" /> 127 127 <Compile Include="Creators\SymbolicDataAnalysisExpressionTreeCreator.cs" /> 128 <Compile Include="Crossovers\MultiSymbolicDataAnalysisExpressionCrossover.cs" /> 129 <Compile Include="Crossovers\SymbolicDataAnalysisExpressionContextAwareCrossover.cs" /> 130 <Compile Include="Crossovers\SymbolicDataAnalysisExpressionCrossover.cs" /> 131 <Compile Include="Crossovers\SymbolicDataAnalysisExpressionDepthConstrainedCrossover.cs" /> 132 <Compile Include="Crossovers\SymbolicDataAnalysisExpressionDeterministicBestCrossover.cs" /> 133 <Compile Include="Crossovers\SymbolicDataAnalysisExpressionProbabilisticFunctionalCrossover.cs" /> 134 <Compile Include="Crossovers\SymbolicDataAnalysisExpressionSemanticSimilarityCrossover.cs" /> 135 <Compile Include="Interfaces\ISymbolicDataAnalysisExpressionCrossover.cs" /> 128 136 <Compile Include="Plugin.cs" /> 129 137 <Compile Include="SymbolicDataAnalysisExpressionTreeILEmittingInterpreter.cs" /> -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interfaces/ISymbolicDataAnalysisExpressionCrossover.cs
r7503 r7506 25 25 26 26 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 27 public interface ISymbolicDataAnalysisExpressionCrossover<T> : ISymbolicExpressionTreeCrossover { 28 IValueLookupParameter<IntRange> SymbolicDataAnalysisEvaluationPartitionParameter { get; } 27 public interface ISymbolicDataAnalysisExpressionCrossover<T> : ISymbolicExpressionTreeCrossover, 28 ISymbolicExpressionTreeSizeConstraintOperator, ISymbolicDataAnalysisInterpreterOperator 29 where T : class, IDataAnalysisProblemData { 30 IValueLookupParameter<T> ProblemDataParameter { get; } 31 ILookupParameter<ISymbolicDataAnalysisSingleObjectiveEvaluator<T>> EvaluatorParameter { get; } 32 IValueLookupParameter<IntRange> EvaluationPartitionParameter { get; } 33 IValueLookupParameter<PercentValue> RelativeNumberOfEvaluatedSamplesParameter { get; } 29 34 } 30 35 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interfaces/ISymbolicDataAnalysisExpressionTreeInterpreter.cs
r7259 r7506 22 22 using System.Collections.Generic; 23 23 using HeuristicLab.Core; 24 using HeuristicLab.Data; 24 25 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 25 26 26 27 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 27 public interface ISymbolicDataAnalysisExpressionTreeInterpreter : INamedItem {28 public interface ISymbolicDataAnalysisExpressionTreeInterpreter : INamedItem, IStatefulItem { 28 29 IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, Dataset dataset, IEnumerable<int> rows); 30 IntValue EvaluatedSolutions { get; set; } 29 31 } 30 32 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisExpressionTreeILEmittingInterpreter.cs
r7259 r7506 21 21 22 22 using System; 23 using System.Collections. ObjectModel;23 using System.Collections.Generic; 24 24 using System.Linq; 25 using System.Collections.Generic;26 25 using System.Reflection; 27 26 using System.Reflection.Emit; … … 48 47 internal delegate double CompiledFunction(int sampleIndex, IList<double>[] columns); 49 48 private const string CheckExpressionsWithIntervalArithmeticParameterName = "CheckExpressionsWithIntervalArithmetic"; 49 private const string EvaluatedSolutionsParameterName = "EvaluatedSolutions"; 50 50 #region private classes 51 51 private class InterpreterState { … … 156 156 get { return (IValueParameter<BoolValue>)Parameters[CheckExpressionsWithIntervalArithmeticParameterName]; } 157 157 } 158 159 public IValueParameter<IntValue> EvaluatedSolutionsParameter { 160 get { return (IValueParameter<IntValue>)Parameters[EvaluatedSolutionsParameterName]; } 161 } 158 162 #endregion 159 163 … … 162 166 get { return CheckExpressionsWithIntervalArithmeticParameter.Value; } 163 167 set { CheckExpressionsWithIntervalArithmeticParameter.Value = value; } 168 } 169 170 public IntValue EvaluatedSolutions { 171 get { return EvaluatedSolutionsParameter.Value; } 172 set { EvaluatedSolutionsParameter.Value = value; } 164 173 } 165 174 #endregion … … 176 185 : base("SymbolicDataAnalysisExpressionTreeILEmittingInterpreter", "Interpreter for symbolic expression trees.") { 177 186 Parameters.Add(new ValueParameter<BoolValue>(CheckExpressionsWithIntervalArithmeticParameterName, "Switch that determines if the interpreter checks the validity of expressions with interval arithmetic before evaluating the expression.", new BoolValue(false))); 178 } 187 Parameters.Add(new ValueParameter<IntValue>(EvaluatedSolutionsParameterName, "A counter for the total number of solutions the interpreter has evaluated", new IntValue(0))); 188 } 189 190 [StorableHook(HookType.AfterDeserialization)] 191 private void AfterDeserialization() { 192 if (!Parameters.ContainsKey(EvaluatedSolutionsParameterName)) 193 Parameters.Add(new ValueParameter<IntValue>(EvaluatedSolutionsParameterName, "A counter for the total number of solutions the interpreter has evaluated", new IntValue(0))); 194 } 195 196 #region IStatefulItem 197 public void InitializeState() { 198 EvaluatedSolutions.Value = 0; 199 } 200 201 public void ClearState() { 202 EvaluatedSolutions.Value = 0; 203 } 204 #endregion 179 205 180 206 public IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, Dataset dataset, IEnumerable<int> rows) { 181 207 if (CheckExpressionsWithIntervalArithmetic.Value) 182 208 throw new NotSupportedException("Interval arithmetic is not yet supported in the symbolic data analysis interpreter."); 209 EvaluatedSolutions.Value++; // increment the evaluated solutions counter 183 210 var compiler = new SymbolicExpressionTreeCompiler(); 184 211 Instruction[] code = compiler.Compile(tree, MapSymbolToOpCode); -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisExpressionTreeInterpreter.cs
r7259 r7506 34 34 public sealed class SymbolicDataAnalysisExpressionTreeInterpreter : ParameterizedNamedItem, ISymbolicDataAnalysisExpressionTreeInterpreter { 35 35 private const string CheckExpressionsWithIntervalArithmeticParameterName = "CheckExpressionsWithIntervalArithmetic"; 36 private const string EvaluatedSolutionsParameterName = "EvaluatedSolutions"; 36 37 #region private classes 37 38 private class InterpreterState { … … 176 177 get { return (IValueParameter<BoolValue>)Parameters[CheckExpressionsWithIntervalArithmeticParameterName]; } 177 178 } 179 180 public IValueParameter<IntValue> EvaluatedSolutionsParameter { 181 get { return (IValueParameter<IntValue>)Parameters[EvaluatedSolutionsParameterName]; } 182 } 178 183 #endregion 179 184 … … 183 188 set { CheckExpressionsWithIntervalArithmeticParameter.Value = value; } 184 189 } 190 191 public IntValue EvaluatedSolutions { 192 get { return EvaluatedSolutionsParameter.Value; } 193 set { EvaluatedSolutionsParameter.Value = value; } 194 } 185 195 #endregion 186 187 196 188 197 [StorableConstructor] … … 196 205 : base("SymbolicDataAnalysisExpressionTreeInterpreter", "Interpreter for symbolic expression trees including automatically defined functions.") { 197 206 Parameters.Add(new ValueParameter<BoolValue>(CheckExpressionsWithIntervalArithmeticParameterName, "Switch that determines if the interpreter checks the validity of expressions with interval arithmetic before evaluating the expression.", new BoolValue(false))); 198 } 207 Parameters.Add(new ValueParameter<IntValue>(EvaluatedSolutionsParameterName, "A counter for the total number of solutions the interpreter has evaluated", new IntValue(0))); 208 } 209 210 [StorableHook(HookType.AfterDeserialization)] 211 private void AfterDeserialization() { 212 if (!Parameters.ContainsKey(EvaluatedSolutionsParameterName)) 213 Parameters.Add(new ValueParameter<IntValue>(EvaluatedSolutionsParameterName, "A counter for the total number of solutions the interpreter has evaluated", new IntValue(0))); 214 } 215 216 #region IStatefulItem 217 public void InitializeState() { 218 EvaluatedSolutions.Value = 0; 219 } 220 221 public void ClearState() { 222 } 223 #endregion 199 224 200 225 public IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, Dataset dataset, IEnumerable<int> rows) { 201 226 if (CheckExpressionsWithIntervalArithmetic.Value) 202 227 throw new NotSupportedException("Interval arithmetic is not yet supported in the symbolic data analysis interpreter."); 228 EvaluatedSolutions.Value++; // increment the evaluated solutions counter 203 229 var compiler = new SymbolicExpressionTreeCompiler(); 204 230 Instruction[] code = compiler.Compile(tree, MapSymbolToOpCode); -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisProblem.cs
r7259 r7506 198 198 private void InitializeOperators() { 199 199 Operators.AddRange(ApplicationManager.Manager.GetInstances<ISymbolicExpressionTreeOperator>()); 200 Operators.AddRange(ApplicationManager.Manager.GetInstances<ISymbolicDataAnalysisExpressionCrossover<T>>()); 200 201 Operators.Add(new SymbolicExpressionSymbolFrequencyAnalyzer()); 201 202 Operators.Add(new SymbolicDataAnalysisVariableFrequencyAnalyzer()); … … 268 269 269 270 protected virtual void ParameterizeOperators() { 270 var operators = Parameters.OfType<IValueParameter>().Select(p => p.Value).OfType<IOperator>().Union(Operators) ;271 var operators = Parameters.OfType<IValueParameter>().Select(p => p.Value).OfType<IOperator>().Union(Operators).ToList(); 271 272 272 273 foreach (var op in operators.OfType<ISymbolicExpressionTreeGrammarBasedOperator>()) { … … 307 308 op.SymbolicDataAnalysisTreeInterpreterParameter.ActualName = SymbolicExpressionTreeInterpreterParameterName; 308 309 } 310 foreach (var op in operators.OfType<ISymbolicDataAnalysisExpressionCrossover<T>>()) { 311 op.EvaluationPartitionParameter.ActualName = FitnessCalculationPartitionParameterName; 312 } 313 foreach (var op in operators.OfType<ISymbolicDataAnalysisExpressionCrossover<T>>()) { 314 op.ProblemDataParameter.ActualName = ProblemDataParameter.Name; 315 op.EvaluationPartitionParameter.ActualName = FitnessCalculationPartitionParameter.Name; 316 op.RelativeNumberOfEvaluatedSamplesParameter.ActualName = RelativeNumberOfEvaluatedSamplesParameter.Name; 317 op.EvaluatorParameter.ActualName = EvaluatorParameter.Name; 318 } 309 319 } 310 320
Note: See TracChangeset
for help on using the changeset viewer.