- Timestamp:
- 02/23/12 16:05:57 (13 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Crossovers
- Files:
-
- 8 copied
Legend:
- Unmodified
- Added
- Removed
-
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" +
Note: See TracChangeset
for help on using the changeset viewer.