- Timestamp:
- 08/27/15 16:55:07 (9 years ago)
- Location:
- branches/HeuristicLab.Algorithms.IteratedSentenceConstruction
- Files:
-
- 4 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Algorithms.IteratedSentenceConstruction/HeuristicLab.Algorithms.IteratedSymbolicExpressionConstruction/3.3/HeuristicLab.Algorithms.IteratedSymbolicExpressionConstruction-3.3.csproj
r12909 r12922 161 161 <Compile Include="Plugin.cs" /> 162 162 <Compile Include="Policies\BoltzmannExplorationSymbolicExpressionConstructionPolicy.cs" /> 163 <Compile Include="Policies\UcbTunedSymbolicExpressionConstructionPolicy.cs" /> 163 164 <Compile Include="Policies\EpsGreedySymbolicExpressionConstructionPolicy.cs" /> 164 165 <Compile Include="Policies\SymbolicExpressionConstructionPolicyBase.cs" /> … … 168 169 </Compile> 169 170 <Compile Include="Properties\AssemblyInfo.cs" /> 171 <Compile Include="QualityFunctions\TabularQualityFunctionBase.cs" /> 170 172 <Compile Include="QualityFunctions\TabularAvgQualityFunction.cs" /> 171 173 <Compile Include="QualityFunctions\TabularMaxQualityFunction.cs" /> -
branches/HeuristicLab.Algorithms.IteratedSentenceConstruction/HeuristicLab.Algorithms.IteratedSymbolicExpressionConstruction/3.3/Interfaces/ITabularQualityFunction.cs
r12909 r12922 9 9 // represents quality functions that use a table representation for states & actions and can therefore return the number of tries for each state/action pair 10 10 public interface ITabularQualityFunction : IQualityFunction { 11 double QVariance(object state, int action); // estimate for the variance of observed rewards 11 12 int Tries(object state, int action); 12 13 } -
branches/HeuristicLab.Algorithms.IteratedSentenceConstruction/HeuristicLab.Algorithms.IteratedSymbolicExpressionConstruction/3.3/Policies/SymbolicExpressionConstructionPolicyBase.cs
r12909 r12922 46 46 47 47 protected SymbolicExpressionConstructionPolicyBase() { 48 48 49 } 49 50 … … 106 107 // and add child node to parent 107 108 var childNode = alts[selectedIdx].CreateTreeNode(); 108 if (childNode.HasLocalParameters) childNode.ResetLocalParameters(Random); 109 if (childNode.HasLocalParameters) { 110 throw new NotSupportedException("Symbols with parameters are not supported by construction policies for symbolic expressions. Try to reformulate the problem so that only discrete actions are necessary"); 111 // childNode.ResetLocalParameters(Random); 112 } 109 113 110 114 Contract.Assert(parent.SubtreeCount == childIdx); … … 113 117 114 118 // push new slots 115 for (int chIdx = childNode.Symbol.MinimumArity- 1; chIdx >= 0; chIdx--) {119 for (int chIdx = g.GetMinimumSubtreeCount(childNode.Symbol) - 1; chIdx >= 0; chIdx--) { 116 120 int minForChild = g.GetAllowedChildSymbols(childNode.Symbol, chIdx).Min(a => g.GetMinimumExpressionLength(a)); // min length of all possible alts for the slot 117 121 openSlots.Push(new Slot() { parent = childNode, childIdx = chIdx, minSize = minForChild }); -
branches/HeuristicLab.Algorithms.IteratedSentenceConstruction/HeuristicLab.Algorithms.IteratedSymbolicExpressionConstruction/3.3/QualityFunctions/TabularAvgQualityFunction.cs
r12909 r12922 9 9 [StorableClass] 10 10 [Item("TabularAvgQualityFunction", "")] 11 internal class TabularAvgQualityFunction : ParameterizedNamedItem, ITabularQualityFunction { 12 [Storable] 13 private readonly Dictionary<object, Dictionary<int, double>> q = new Dictionary<object, Dictionary<int, double>>(); 14 [Storable] 15 private readonly Dictionary<object, Dictionary<int, int>> tries = new Dictionary<object, Dictionary<int, int>>(); 11 internal class TabularAvgQualityFunction : TabularQualityFunctionBase { 16 12 17 public IStateFunction StateFunction { 18 get { 19 return ((IValueParameter<IStateFunction>)Parameters["State function"]).Value; 20 } 21 set { ((IValueParameter<IStateFunction>)Parameters["State function"]).Value = value; } 22 } 23 24 public TabularAvgQualityFunction() { 25 Parameters.Add(new ValueParameter<IStateFunction>("State function", "The function that is used to map partial trees to states", new DefaultStateFunction())); 26 } 27 28 public double Q(object state, int action) { 29 // an action that has never been tried has q == infinity 30 Dictionary<int, double> stateActionQualities; 31 if (!q.TryGetValue(state, out stateActionQualities)) return double.PositiveInfinity; 32 double quality; 33 if (!stateActionQualities.TryGetValue(action, out quality)) return double.PositiveInfinity; 34 return quality; 35 } 36 37 public void Update(object state, int action, double observedQuality) { 38 Dictionary<int, int> stateActionTries; 39 if (!tries.TryGetValue(state, out stateActionTries)) { 40 stateActionTries = new Dictionary<int, int>(); 41 tries.Add(state, stateActionTries); 42 } 43 Dictionary<int, double> stateActionQualities = null; 44 if (!q.TryGetValue(state, out stateActionQualities)) { 45 stateActionQualities = new Dictionary<int, double>(); 46 q.Add(state, stateActionQualities); 47 } 48 int t; 49 if (!stateActionTries.TryGetValue(action, out t)) { 50 t = 0; 51 stateActionTries.Add(action, t + 1); 52 stateActionQualities.Add(action, observedQuality); 53 } else { 54 stateActionTries[action] = t + 1; 55 var delta = observedQuality - stateActionQualities[action]; 56 stateActionQualities[action] = stateActionQualities[action] + (1.0 / (t + 1)) * delta; // incremental calculation of average 57 } 58 } 59 60 public int Tries(object state, int action) { 61 Dictionary<int, int> stateTries; 62 if (!tries.TryGetValue(state, out stateTries)) return 0; 63 int stateActionTries; 64 if (!stateTries.TryGetValue(action, out stateActionTries)) return 0; 65 return stateActionTries; 13 public TabularAvgQualityFunction() 14 : base() { 66 15 } 67 16 … … 71 20 protected TabularAvgQualityFunction(TabularAvgQualityFunction original, Cloner cloner) 72 21 : base(original, cloner) { 73 this.q = new Dictionary<object, Dictionary<int, double>>(original.q);74 this.tries = new Dictionary<object, Dictionary<int, int>>(original.tries);75 22 } 76 23 public override IDeepCloneable Clone(Cloner cloner) { … … 79 26 #endregion 80 27 81 public void InitializeState() { 82 ClearState(); 83 } 84 85 public void ClearState() { 86 q.Clear(); 87 tries.Clear(); 28 protected override double CalculateNewQ(object state, int action, double observedQuality) { 29 var delta = observedQuality - Q(state, action); 30 return Q(state, action) + (1.0 / Tries(state, action)) * delta; // iterative calculation of mean 88 31 } 89 32 } -
branches/HeuristicLab.Algorithms.IteratedSentenceConstruction/HeuristicLab.Algorithms.IteratedSymbolicExpressionConstruction/3.3/QualityFunctions/TabularMaxQualityFunction.cs
r12909 r12922 9 9 [StorableClass] 10 10 [Item("TabularMaxQualityFunction", "")] 11 internal class TabularMaxQualityFunction : ParameterizedNamedItem, ITabularQualityFunction { 12 [Storable] 13 private readonly Dictionary<object, Dictionary<int, double>> q = new Dictionary<object, Dictionary<int, double>>(); 14 [Storable] 15 private readonly Dictionary<object, Dictionary<int, int>> tries = new Dictionary<object, Dictionary<int, int>>(); 11 internal class TabularMaxQualityFunction : TabularQualityFunctionBase { 16 12 17 public IStateFunction StateFunction { 18 get { 19 return ((IValueParameter<IStateFunction>)Parameters["State function"]).Value; 20 } 21 set { ((IValueParameter<IStateFunction>)Parameters["State function"]).Value = value; } 22 } 23 24 public TabularMaxQualityFunction() { 25 Parameters.Add(new ValueParameter<IStateFunction>("State function", "The function that is used to map partial trees to states", new DefaultStateFunction())); 26 } 27 28 public double Q(object state, int action) { 29 // an action that has never been tried has q == infinity 30 Dictionary<int, double> stateActionQualities; 31 if (!q.TryGetValue(state, out stateActionQualities)) return double.PositiveInfinity; 32 double quality; 33 if (!stateActionQualities.TryGetValue(action, out quality)) return double.PositiveInfinity; 34 return quality; 35 } 36 37 public void Update(object state, int action, double observedQuality) { 38 Dictionary<int, int> stateActionTries; 39 if (!tries.TryGetValue(state, out stateActionTries)) { 40 stateActionTries = new Dictionary<int, int>(); 41 tries.Add(state, stateActionTries); 42 } 43 Dictionary<int, double> stateActionQualities = null; 44 if (!q.TryGetValue(state, out stateActionQualities)) { 45 stateActionQualities = new Dictionary<int, double>(); 46 q.Add(state, stateActionQualities); 47 } 48 int t; 49 if (!stateActionTries.TryGetValue(action, out t)) { 50 t = 0; 51 stateActionTries.Add(action, t + 1); 52 stateActionQualities.Add(action, observedQuality); 53 } else { 54 stateActionTries[action] = t + 1; 55 stateActionQualities[action] = Math.Max(stateActionQualities[action], observedQuality); 56 } 57 } 58 59 public int Tries(object state, int action) { 60 Dictionary<int, int> stateTries; 61 if (!tries.TryGetValue(state, out stateTries)) return 0; 62 int stateActionTries; 63 if (!stateTries.TryGetValue(action, out stateActionTries)) return 0; 64 return stateActionTries; 13 public TabularMaxQualityFunction() 14 : base() { 65 15 } 66 16 … … 70 20 protected TabularMaxQualityFunction(TabularMaxQualityFunction original, Cloner cloner) 71 21 : base(original, cloner) { 72 this.q = new Dictionary<object, Dictionary<int, double>>(original.q);73 this.tries = new Dictionary<object, Dictionary<int, int>>(original.tries);74 22 } 75 23 public override IDeepCloneable Clone(Cloner cloner) { … … 78 26 #endregion 79 27 80 public void InitializeState() { 81 ClearState(); 82 } 83 84 public void ClearState() { 85 q.Clear(); 86 tries.Clear(); 28 protected override double CalculateNewQ(object state, int action, double observedQuality) { 29 return Math.Max(Q(state, action), observedQuality); 87 30 } 88 31 } -
branches/HeuristicLab.Algorithms.IteratedSentenceConstruction/HeuristicLab.Algorithms.IteratedSymbolicExpressionConstruction/3.3/SearchTree.cs
r12909 r12922 62 62 63 63 private void RemoveRecursively(Node node) { 64 if (node == null) return;65 64 // when the last child has been removed we must remove the current node from it's parent 66 if (node.children.All(ch => ch == null) && node.parent != null) {65 while (node.parent != null && node.children.All(ch => ch == null)) { 67 66 node.parent.children[Array.IndexOf(node.parent.children, node)] = null; 68 RemoveRecursively(node.parent);67 node = node.parent; 69 68 } 70 69 } -
branches/HeuristicLab.Algorithms.IteratedSentenceConstruction/HeuristicLab.Problems.GeneticProgramming.Views/3.3
-
Property
svn:ignore
set to
obj
Plugin.cs
-
Property
svn:ignore
set to
-
branches/HeuristicLab.Algorithms.IteratedSentenceConstruction/HeuristicLab.Problems.GeneticProgramming.Views/3.3/Properties
-
Property
svn:ignore
set to
AssemblyInfo.cs
-
Property
svn:ignore
set to
-
branches/HeuristicLab.Algorithms.IteratedSentenceConstruction/HeuristicLab.Problems.GeneticProgramming/3.3
-
Property
svn:ignore
set to
obj
Plugin.cs
-
Property
svn:ignore
set to
-
branches/HeuristicLab.Algorithms.IteratedSentenceConstruction/HeuristicLab.Problems.GeneticProgramming/3.3/HeuristicLab.Problems.GeneticProgramming-3.3.csproj
r12919 r12922 141 141 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.PluginInfrastructure-3.3.dll</HintPath> 142 142 </Reference> 143 <Reference Include="HeuristicLab.Problems.DataAnalysis-3.4, Version=3.4.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 144 <SpecificVersion>False</SpecificVersion> 145 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Problems.DataAnalysis-3.4.dll</HintPath> 146 </Reference> 147 <Reference Include="HeuristicLab.Problems.Instances-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 148 <SpecificVersion>False</SpecificVersion> 149 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Problems.Instances-3.3.dll</HintPath> 150 </Reference> 143 151 <Reference Include="HeuristicLab.Random-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 144 152 <SpecificVersion>False</SpecificVersion> … … 155 163 <Compile Include="ArtificialAnt\Problem.cs" /> 156 164 <Compile Include="ArtificialAnt\Trail.cs" /> 165 <Compile Include="BasicSymbolicRegression\Problem.cs" /> 157 166 <Compile Include="LawnMower\Interpreter.cs" /> 158 167 <Compile Include="LawnMower\Problem.cs" /> -
branches/HeuristicLab.Algorithms.IteratedSentenceConstruction/HeuristicLab.Problems.GeneticProgramming/3.3/Properties
-
Property
svn:ignore
set to
AssemblyInfo.cs
-
Property
svn:ignore
set to
Note: See TracChangeset
for help on using the changeset viewer.