Changeset 5686 for branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/SubroutineDeleter.cs
- Timestamp:
- 03/15/11 13:34:38 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/SubroutineDeleter.cs
r5549 r5686 26 26 using HeuristicLab.Data; 27 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 using System.Collections.Generic;29 28 30 29 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { … … 87 86 from subtree in node.SubTrees.OfType<InvokeFunctionTreeNode>() 88 87 where subtree.Symbol.FunctionName == selectedDefunBranch.FunctionName 89 select new { Parent = node, ReplacedChildIndex = node.IndexOfSubTree(subtree), ReplacedChild = subtree }).FirstOrDefault();88 select new CutPoint(node, subtree)).FirstOrDefault(); 90 89 while (invocationCutPoint != null) { 91 90 // deletion by random regeneration 92 91 ISymbolicExpressionTreeNode replacementTree = null; 93 var allowedSymbolsList = invocationCutPoint.Parent.Grammar.GetAllowed Symbols(invocationCutPoint.Parent.Symbol, invocationCutPoint.ReplacedChildIndex).ToList();92 var allowedSymbolsList = invocationCutPoint.Parent.Grammar.GetAllowedChildSymbols(invocationCutPoint.Parent.Symbol, invocationCutPoint.ChildIndex).ToList(); 94 93 var weights = allowedSymbolsList.Select(s => s.InitialFrequency); 95 94 var selectedSymbol = allowedSymbolsList.SelectRandom(weights, random); 96 95 97 int minPossibleLength = invocationCutPoint.Parent.Grammar.GetMin ExpressionLength(selectedSymbol);98 int maxLength = Math.Max(minPossibleLength, invocationCutPoint. ReplacedChild.GetLength());99 int minPossibleDepth = invocationCutPoint.Parent.Grammar.GetMin ExpressionDepth(selectedSymbol);100 int maxDepth = Math.Max(minPossibleDepth, invocationCutPoint. ReplacedChild.GetDepth());96 int minPossibleLength = invocationCutPoint.Parent.Grammar.GetMinimumExpressionLength(selectedSymbol); 97 int maxLength = Math.Max(minPossibleLength, invocationCutPoint.Child.GetLength()); 98 int minPossibleDepth = invocationCutPoint.Parent.Grammar.GetMinimumExpressionDepth(selectedSymbol); 99 int maxDepth = Math.Max(minPossibleDepth, invocationCutPoint.Child.GetDepth()); 101 100 replacementTree = selectedSymbol.CreateTreeNode(); 102 101 if (replacementTree.HasLocalParameters) 103 102 replacementTree.ResetLocalParameters(random); 104 invocationCutPoint.Parent.RemoveSubTree(invocationCutPoint. ReplacedChildIndex);105 invocationCutPoint.Parent.InsertSubTree(invocationCutPoint. ReplacedChildIndex, replacementTree);103 invocationCutPoint.Parent.RemoveSubTree(invocationCutPoint.ChildIndex); 104 invocationCutPoint.Parent.InsertSubTree(invocationCutPoint.ChildIndex, replacementTree); 106 105 107 ProbabilisticTreeCreator.PTC2(random, replacementTree, maxLength, maxDepth , 0, 0);106 ProbabilisticTreeCreator.PTC2(random, replacementTree, maxLength, maxDepth); 108 107 109 108 invocationCutPoint = (from node in symbolicExpressionTree.IterateNodesPrefix() 110 109 from subtree in node.SubTrees.OfType<InvokeFunctionTreeNode>() 111 110 where subtree.Symbol.FunctionName == selectedDefunBranch.FunctionName 112 select new { Parent = node, ReplacedChildIndex = node.IndexOfSubTree(subtree), ReplacedChild = subtree }).FirstOrDefault();111 select new CutPoint(node, subtree)).FirstOrDefault(); 113 112 } 114 113 }
Note: See TracChangeset
for help on using the changeset viewer.