Changeset 12924
- Timestamp:
- 08/28/15 17:50:53 (9 years ago)
- Location:
- branches/HeuristicLab.Algorithms.IteratedSentenceConstruction
- Files:
-
- 1 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Algorithms.IteratedSentenceConstruction/HeuristicLab.Algorithms.IteratedSymbolicExpressionConstruction/3.3/HeuristicLab.Algorithms.IteratedSymbolicExpressionConstruction-3.3.csproj
r12923 r12924 99 99 </PropertyGroup> 100 100 <ItemGroup> 101 <Reference Include="HeuristicLab.Algorithms.DataAnalysis-3.4, Version=3.4.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 102 <SpecificVersion>False</SpecificVersion> 103 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Algorithms.DataAnalysis-3.4.dll</HintPath> 104 </Reference> 101 105 <Reference Include="HeuristicLab.Analysis-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 102 106 <SpecificVersion>False</SpecificVersion> … … 142 146 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.PluginInfrastructure-3.3.dll</HintPath> 143 147 <Private>False</Private> 148 </Reference> 149 <Reference Include="HeuristicLab.Problems.DataAnalysis-3.4, Version=3.4.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 150 <SpecificVersion>False</SpecificVersion> 151 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Problems.DataAnalysis-3.4.dll</HintPath> 144 152 </Reference> 145 153 <Reference Include="HeuristicLab.Random-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> … … 169 177 </Compile> 170 178 <Compile Include="Properties\AssemblyInfo.cs" /> 179 <Compile Include="QualityFunctions\GbtApproximateStateValueFunction.cs" /> 171 180 <Compile Include="QualityFunctions\TabularStateValueFunctionBase.cs" /> 172 181 <Compile Include="QualityFunctions\TabularAvgStateValueFunction.cs" /> … … 198 207 </BootstrapperPackage> 199 208 </ItemGroup> 200 <ItemGroup /> 209 <ItemGroup> 210 <Folder Include="FeatureFunctions\" /> 211 </ItemGroup> 201 212 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> 202 213 <!-- To modify your build process, add your task inside one of the targets below and uncomment it. -
branches/HeuristicLab.Algorithms.IteratedSentenceConstruction/HeuristicLab.Algorithms.IteratedSymbolicExpressionConstruction/3.3/Interfaces/IStateValueFunction.cs
r12923 r12924 8 8 namespace HeuristicLab.Algorithms.IteratedSymbolicExpressionConstruction { 9 9 // represents the state value function (V(s)) 10 public interface IStateValueFunction : I StatefulItem {10 public interface IStateValueFunction : IItem { 11 11 double Value(object state); 12 12 void Update(object state, double observedQuality); -
branches/HeuristicLab.Algorithms.IteratedSentenceConstruction/HeuristicLab.Algorithms.IteratedSymbolicExpressionConstruction/3.3/Policies/BoltzmannExplorationSymbolicExpressionConstructionPolicy.cs
r12923 r12924 45 45 var idxs = Enumerable.Range(0, followStates.Count); 46 46 // find best action 47 var bestQuality = double.NegativeInfinity;48 47 if (followStates.Any(s => StateValueFunction.Tries(s) == 0)) { 49 48 return idxs.Where(idx => StateValueFunction.Tries(followStates[idx]) == 0).SampleRandom(random); -
branches/HeuristicLab.Algorithms.IteratedSentenceConstruction/HeuristicLab.Algorithms.IteratedSymbolicExpressionConstruction/3.3/Policies/RandomSymbolicExpressionConstructionPolicy.cs
r12923 r12924 23 23 24 24 public sealed override void Update(IEnumerable<object> stateSequence, double quality) { 25 26 25 // ignore 27 26 } -
branches/HeuristicLab.Algorithms.IteratedSentenceConstruction/HeuristicLab.Algorithms.IteratedSymbolicExpressionConstruction/3.3/QualityFunctions/TabularAvgStateValueFunction.cs
r12923 r12924 9 9 [StorableClass] 10 10 [Item("TabularAvgQualityFunction", "")] 11 internalclass TabularAvgStateValueFunction : TabularStateValueFunctionBase {11 public class TabularAvgStateValueFunction : TabularStateValueFunctionBase { 12 12 13 13 public TabularAvgStateValueFunction() -
branches/HeuristicLab.Algorithms.IteratedSentenceConstruction/HeuristicLab.Algorithms.IteratedSymbolicExpressionConstruction/3.3/QualityFunctions/TabularMaxStateValueFunction.cs
r12923 r12924 9 9 [StorableClass] 10 10 [Item("TabularMaxStateValueFunction", "")] 11 internalclass TabularMaxStateValueFunction : TabularStateValueFunctionBase {11 public class TabularMaxStateValueFunction : TabularStateValueFunctionBase { 12 12 13 13 public TabularMaxStateValueFunction() -
branches/HeuristicLab.Algorithms.IteratedSentenceConstruction/HeuristicLab.Algorithms.IteratedSymbolicExpressionConstruction/3.3/QualityFunctions/TabularStateValueFunctionBase.cs
r12923 r12924 8 8 namespace HeuristicLab.Algorithms.IteratedSymbolicExpressionConstruction { 9 9 [StorableClass] 10 internalabstract class TabularStateValueFunctionBase : ParameterizedNamedItem, ITabularStateValueFunction {10 public abstract class TabularStateValueFunctionBase : ParameterizedNamedItem, ITabularStateValueFunction { 11 11 [Storable] 12 12 private readonly Dictionary<object, double> q = new Dictionary<object, double>(); … … 78 78 #endregion 79 79 80 public void InitializeState() {81 ClearState();82 }83 84 public void ClearState() {85 q.Clear();86 tries.Clear();87 qVariance.Clear();88 }80 //public void InitializeState() { 81 // ClearState(); 82 //} 83 // 84 //public void ClearState() { 85 // q.Clear(); 86 // tries.Clear(); 87 // qVariance.Clear(); 88 //} 89 89 } 90 90 } -
branches/HeuristicLab.Algorithms.IteratedSentenceConstruction/HeuristicLab.Algorithms.IteratedSymbolicExpressionConstruction/3.3/SearchTree.cs
r12923 r12924 8 8 namespace HeuristicLab.Algorithms.IteratedSymbolicExpressionConstruction { 9 9 internal class SearchTree<TValue> { 10 private class Node <TValue>{10 private class Node { 11 11 internal TValue value; 12 internal Node <TValue>parent;13 internal Node <TValue>[] children;12 internal Node parent; 13 internal Node[] children; 14 14 // children == null -> never visited 15 15 // children[i] != null -> visited at least once, still allowed … … 17 17 } 18 18 19 private Node <TValue>root;19 private Node root; 20 20 21 21 // for iteration 22 private Node <TValue>currentNode;22 private Node currentNode; 23 23 24 24 public SearchTree() { 25 root = new Node <TValue>();25 root = new Node(); 26 26 currentNode = root; 27 27 } … … 38 38 Contract.Assert(values.Any()); 39 39 Contract.Assert(currentNode.children == null); 40 currentNode.children = values.Select(val => new Node <TValue>() { value = val, parent = currentNode }).ToArray();40 currentNode.children = values.Select(val => new Node() { value = val, parent = currentNode }).ToArray(); 41 41 } 42 42 … … 71 71 } 72 72 73 private void RemoveRecursively(Node <TValue>node) {73 private void RemoveRecursively(Node node) { 74 74 // when the last child has been removed we must remove the current node from it's parent 75 75 while (node.parent != null && node.children.All(ch => ch == null)) { -
branches/HeuristicLab.Algorithms.IteratedSentenceConstruction/HeuristicLab.Algorithms.IteratedSymbolicExpressionConstruction/3.3/StateFunctions/DefaultStateFunction.cs
r12923 r12924 13 13 [StorableClass] 14 14 [Item("DefaultStateFunction", "")] 15 internalclass DefaultStateFunction : Item, IStateFunction {15 public class DefaultStateFunction : Item, IStateFunction { 16 16 public DefaultStateFunction() 17 17 : base() { … … 19 19 20 20 public object CreateState(ISymbolicExpressionTreeNode root, List<ISymbol> actions, ISymbolicExpressionTreeNode parentNode, int childIdx) { 21 return string.Join(",", actions.Select(a => a.Name)); 21 return string.Join(",", actions.Select(a => a.Name)); // TODO: perf 22 22 } 23 23 -
branches/HeuristicLab.Algorithms.IteratedSentenceConstruction/HeuristicLab.Algorithms.IteratedSymbolicExpressionConstruction/3.3/StateFunctions/ParentChildStateFunction.cs
r12923 r12924 14 14 [StorableClass] 15 15 [Item("ParentChildStateFunction", "")] 16 internalclass ParentChildStateFunction : Item, IStateFunction {16 public class ParentChildStateFunction : Item, IStateFunction { 17 17 public ParentChildStateFunction() 18 18 : base() { … … 20 20 21 21 public object CreateState(ISymbolicExpressionTreeNode root, List<ISymbol> actions, ISymbolicExpressionTreeNode parentNode, int childIdx) { 22 return (parentNode == null ? "" : parentNode.Symbol.Name) + childIdx; 22 if (parentNode == null) return string.Empty; 23 else return parentNode.Symbol.Name + "." + string.Join(".", parentNode.Subtrees.Select(t => t.Symbol.Name)); 23 24 } 24 25 -
branches/HeuristicLab.Algorithms.IteratedSentenceConstruction/Tests/IteratedSymbolicExpressionConstructionTest.cs
r12923 r12924 12 12 13 13 // see Langdon and Poli, "Why Ants are Hard", Table 2 (http://marvin.cs.uidaho.edu/Teaching/CS472/santaFeTrailSpace.pdf) 14 TestAlg(problem: new Problem(), maxLen: 3, expectedEvals: 3, expectedBestQuality: 3);15 TestAlg(problem: new Problem(), maxLen: 4, expectedEvals: 3, expectedBestQuality: 3);16 TestAlg(problem: new Problem(), maxLen: 5, expectedEvals: 21, expectedBestQuality: 11);17 TestAlg(problem: new Problem(), maxLen: 6, expectedEvals: 48, expectedBestQuality: 11);18 TestAlg(problem: new Problem(), maxLen: 10, expectedEvals: 25455, expectedBestQuality: 47);19 TestAlg(problem: new Problem(), maxLen: 13, expectedEvals: 3191259, expectedBestQuality: 89);14 TestAlg(problem: new Problem(), policy: new RandomSymbolicExpressionConstructionPolicy(), maxLen: 3, expectedEvals: 3, expectedBestQuality: 3); 15 TestAlg(problem: new Problem(), policy: new RandomSymbolicExpressionConstructionPolicy(), maxLen: 4, expectedEvals: 3, expectedBestQuality: 3); 16 TestAlg(problem: new Problem(), policy: new RandomSymbolicExpressionConstructionPolicy(), maxLen: 5, expectedEvals: 21, expectedBestQuality: 11); 17 TestAlg(problem: new Problem(), policy: new RandomSymbolicExpressionConstructionPolicy(), maxLen: 6, expectedEvals: 48, expectedBestQuality: 11); 18 TestAlg(problem: new Problem(), policy: new RandomSymbolicExpressionConstructionPolicy(), maxLen: 10, expectedEvals: 25455, expectedBestQuality: 47); 19 TestAlg(problem: new Problem(), policy: new RandomSymbolicExpressionConstructionPolicy(), maxLen: 13, expectedEvals: 3191259, expectedBestQuality: 89); 20 20 21 21 // log of runtimes (28.08.2015), single core, Intel Core i5 @3.2 GHz … … 29 29 } 30 30 31 private void TestAlg(Problem problem, int maxLen, int expectedEvals, double expectedBestQuality) { 31 [TestMethod] 32 public void TestStateAggregation() { 33 var stateValueFunction = new TabularMaxStateValueFunction(); 34 stateValueFunction.StateFunction = new ParentChildStateFunction(); 35 var pol = new UcbSymbolicExpressionConstructionPolicy(); 36 pol.StateValueFunction = stateValueFunction; 37 TestAlg(new Problem(), pol, maxLen: 13, expectedEvals: 3191259, expectedBestQuality: 89); 38 } 39 40 [TestMethod] 41 public void TestStateValueApproximation() { 42 var stateValueFunction = new GbtApproximateStateValueFunction(); 43 var pol = new EpsGreedySymbolicExpressionConstructionPolicy(); 44 pol.StateValueFunction = stateValueFunction; 45 TestAlg(new Problem(), pol, maxLen: 13, expectedEvals: 3191259, expectedBestQuality: 89); 46 } 47 48 private void TestAlg(Problem problem, ISymbolicExpressionConstructionPolicy policy, int maxLen, int expectedEvals, double expectedBestQuality) { 32 49 var alg = new IteratedSymbolicExpressionConstruction(); 33 50 problem.Encoding.TreeLength = maxLen; 34 51 alg.Problem = problem; 35 alg.PolicyParameter.Value = new RandomSymbolicExpressionConstructionPolicy();52 alg.PolicyParameter.Value = policy; 36 53 alg.MaximumEvaluations = 5000000; 37 54
Note: See TracChangeset
for help on using the changeset viewer.