Changeset 12706 for stable/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators
- Timestamp:
- 07/10/15 12:02:20 (9 years ago)
- Location:
- stable
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk/sources merged: 12422,12424,12480-12482
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/ArgumentCreater.cs
r12009 r12706 28 28 using HeuristicLab.Parameters; 29 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 using HeuristicLab.Random; 30 31 31 32 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { … … 84 85 ISymbolicExpressionTree clonedTree = (ISymbolicExpressionTree)symbolicExpressionTree.Clone(); 85 86 86 var functionDefiningBranches = clonedTree.IterateNodesPrefix().OfType<DefunTreeNode>() ;87 if ( functionDefiningBranches.Count() == 0)87 var functionDefiningBranches = clonedTree.IterateNodesPrefix().OfType<DefunTreeNode>().ToList(); 88 if (!functionDefiningBranches.Any()) 88 89 // no function defining branch found => abort 89 90 return false; 90 91 91 92 // select a random function defining branch 92 var selectedDefunBranch = functionDefiningBranches.SelectRandom(random); 93 var selectedDefunBranch = functionDefiningBranches.SampleRandom(random); 94 93 95 var definedArguments = (from symbol in selectedDefunBranch.Grammar.Symbols.OfType<Argument>() 94 96 select symbol.ArgumentIndex).Distinct(); -
stable/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/ArgumentDeleter.cs
r12009 r12706 25 25 using HeuristicLab.Data; 26 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 using HeuristicLab.Random; 27 28 28 29 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { … … 54 55 int maxFunctionDefinitions, int maxFunctionArguments) { 55 56 56 var functionDefiningBranches = symbolicExpressionTree.IterateNodesPrefix().OfType<DefunTreeNode>() ;57 if ( functionDefiningBranches.Count() == 0)57 var functionDefiningBranches = symbolicExpressionTree.IterateNodesPrefix().OfType<DefunTreeNode>().ToList(); 58 if (!functionDefiningBranches.Any()) 58 59 // no function defining branch => abort 59 60 return false; 60 var selectedDefunBranch = functionDefiningBranches.SelectRandom(random); 61 62 var selectedDefunBranch = functionDefiningBranches.SampleRandom(random); 61 63 if (selectedDefunBranch.NumberOfArguments <= 1) 62 64 // argument deletion by consolidation is not possible => abort … … 77 79 78 80 // delete the dynamic argument symbol that matches the argument to be removed 79 var matchingSymbol = selectedDefunBranch.Grammar.Symbols.OfType<Argument>(). Where(s => s.ArgumentIndex == removedArgument).Single();81 var matchingSymbol = selectedDefunBranch.Grammar.Symbols.OfType<Argument>().Single(s => s.ArgumentIndex == removedArgument); 80 82 selectedDefunBranch.Grammar.RemoveSymbol(matchingSymbol); 81 83 selectedDefunBranch.NumberOfArguments--; 82 84 // reduce arity in known functions of all root branches 83 85 foreach (var subtree in symbolicExpressionTree.Root.Subtrees) { 84 var matchingInvokeSymbol = subtree.Grammar.Symbols.OfType<InvokeFunction>(). Where(s => s.FunctionName == selectedDefunBranch.FunctionName).SingleOrDefault();86 var matchingInvokeSymbol = subtree.Grammar.Symbols.OfType<InvokeFunction>().SingleOrDefault(s => s.FunctionName == selectedDefunBranch.FunctionName); 85 87 if (matchingInvokeSymbol != null) { 86 88 subtree.Grammar.SetSubtreeCount(matchingInvokeSymbol, selectedDefunBranch.NumberOfArguments, selectedDefunBranch.NumberOfArguments); … … 99 101 select node; 100 102 foreach (var argNode in argNodes) { 101 var replacementSymbol = possibleArgumentSymbols.S electRandom(random);103 var replacementSymbol = possibleArgumentSymbols.SampleRandom(random); 102 104 argNode.Symbol = replacementSymbol; 103 105 } -
stable/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/ArgumentDuplicater.cs
r12009 r12706 27 27 using HeuristicLab.Data; 28 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 using HeuristicLab.Random; 29 30 30 31 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { … … 56 57 ISymbolicExpressionTree symbolicExpressionTree, 57 58 int maxFunctionDefinitions, int maxFunctionArguments) { 58 var functionDefiningBranches = symbolicExpressionTree.IterateNodesPrefix().OfType<DefunTreeNode>() ;59 var functionDefiningBranches = symbolicExpressionTree.IterateNodesPrefix().OfType<DefunTreeNode>().ToList(); 59 60 60 61 var allowedArgumentIndexes = Enumerable.Range(0, maxFunctionArguments); 61 if ( functionDefiningBranches.Count() == 0)62 if (!functionDefiningBranches.Any()) 62 63 // no function defining branches => abort 63 64 return false; 64 65 65 var selectedDefunBranch = functionDefiningBranches.SelectRandom(random); 66 var argumentSymbols = selectedDefunBranch.Grammar.Symbols.OfType<Argument>(); 67 if (argumentSymbols.Count() == 0 || argumentSymbols.Count() >= maxFunctionArguments) 66 var selectedDefunBranch = functionDefiningBranches.SampleRandom(random); 67 68 var argumentSymbols = selectedDefunBranch.Grammar.Symbols.OfType<Argument>().ToList(); 69 if (!argumentSymbols.Any() || argumentSymbols.Count() >= maxFunctionArguments) 68 70 // when no argument or number of arguments is already at max allowed value => abort 69 71 return false; 70 var selectedArgumentSymbol = argumentSymbols.SelectRandom(random); 72 73 var selectedArgumentSymbol = argumentSymbols.SampleRandom(random); 71 74 var takenIndexes = argumentSymbols.Select(s => s.ArgumentIndex); 72 75 var newArgumentIndex = allowedArgumentIndexes.Except(takenIndexes).First(); -
stable/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/SubroutineCreater.cs
r12009 r12706 29 29 using HeuristicLab.Parameters; 30 30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 31 using HeuristicLab.Random; 31 32 32 33 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { … … 113 114 from subtree in parent.Subtrees 114 115 select new CutPoint(parent, subtree)).ToList(); 115 if ( allCutPoints.Count() == 0)116 if (!allCutPoints.Any()) 116 117 // no cut points => abort 117 118 return false; 118 119 string newFunctionName = allowedFunctionNames.Except(functionDefiningBranches.Select(x => x.FunctionName)).First(); 119 var selectedCutPoint = allCutPoints.SelectRandom(random); 120 var selectedCutPoint = allCutPoints.SampleRandom(random); 121 120 122 // select random branches as argument cut-off points (replaced by argument terminal nodes in the function) 121 123 List<CutPoint> argumentCutPoints = SelectRandomArgumentBranches(selectedCutPoint.Child, random, ARGUMENT_CUTOFF_PROBABILITY, maxFunctionArguments); -
stable/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/SubroutineDeleter.cs
r12009 r12706 26 26 using HeuristicLab.Data; 27 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 using HeuristicLab.Random; 28 29 29 30 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { … … 55 56 ISymbolicExpressionTree symbolicExpressionTree, 56 57 int maxFunctionDefinitions, int maxFunctionArguments) { 57 var functionDefiningBranches = symbolicExpressionTree.IterateNodesPrefix().OfType<DefunTreeNode>() ;58 var functionDefiningBranches = symbolicExpressionTree.IterateNodesPrefix().OfType<DefunTreeNode>().ToList(); 58 59 59 if ( functionDefiningBranches.Count() == 0)60 if (!functionDefiningBranches.Any()) 60 61 // no ADF to delete => abort 61 62 return false; 62 var selectedDefunBranch = functionDefiningBranches.SelectRandom(random); 63 64 var selectedDefunBranch = functionDefiningBranches.SampleRandom(random); 63 65 // remove the selected defun 64 66 int defunSubtreeIndex = symbolicExpressionTree.Root.IndexOfSubtree(selectedDefunBranch); … … 92 94 var allowedSymbolsList = invocationCutPoint.Parent.Grammar.GetAllowedChildSymbols(invocationCutPoint.Parent.Symbol, invocationCutPoint.ChildIndex).ToList(); 93 95 var weights = allowedSymbolsList.Select(s => s.InitialFrequency); 96 97 #pragma warning disable 612, 618 94 98 var selectedSymbol = allowedSymbolsList.SelectRandom(weights, random); 99 #pragma warning restore 612, 618 100 95 101 96 102 int minPossibleLength = invocationCutPoint.Parent.Grammar.GetMinimumExpressionLength(selectedSymbol); -
stable/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/SubroutineDuplicater.cs
r12009 r12706 28 28 using HeuristicLab.Data; 29 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 using HeuristicLab.Random; 30 31 31 32 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { … … 59 60 ISymbolicExpressionTree symbolicExpressionTree, 60 61 int maxFunctionDefinitions, int maxFunctionArguments) { 61 var functionDefiningBranches = symbolicExpressionTree.IterateNodesPrefix().OfType<DefunTreeNode>() ;62 if ( functionDefiningBranches.Count() == 0|| functionDefiningBranches.Count() == maxFunctionDefinitions)62 var functionDefiningBranches = symbolicExpressionTree.IterateNodesPrefix().OfType<DefunTreeNode>().ToList(); 63 if (!functionDefiningBranches.Any() || functionDefiningBranches.Count() == maxFunctionDefinitions) 63 64 // no function defining branches to duplicate or already reached the max number of ADFs 64 65 return false; … … 67 68 var allowedFunctionNames = from index in Enumerable.Range(0, maxFunctionDefinitions) 68 69 select "ADF" + index.ToString(formatString); 69 var selectedBranch = functionDefiningBranches.SelectRandom(random); 70 71 var selectedBranch = functionDefiningBranches.SampleRandom(random); 70 72 var duplicatedDefunBranch = (DefunTreeNode)selectedBranch.Clone(); 71 73 string newFunctionName = allowedFunctionNames.Except(UsedFunctionNames(symbolicExpressionTree)).First();
Note: See TracChangeset
for help on using the changeset viewer.