Changeset 11792 for branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Algorithms.Bandits/GrammarPolicies
- Timestamp:
- 01/16/15 18:26:35 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Algorithms.Bandits/GrammarPolicies/GenericGrammarPolicy.cs
r11770 r11792 27 27 out ReadonlySequence selectedState) { 28 28 // only select states that are not yet done 29 afterStates = afterStates.Where(a => !done.Contains(CanonicalState(a .ToString()))).ToArray();29 afterStates = afterStates.Where(a => !done.Contains(CanonicalState(a))).ToArray(); 30 30 if (!afterStates.Any()) { 31 31 // fail because all follow states have already been visited => also disable the current state (if we can be sure that it has been fully explored) 32 throw new NotImplementedException(); 33 //var curStateCanonical = CanonicalState(curState.ToString()); 34 //if (curState.ToString().Length == curStateCanonical.Length) 35 done.Add(CanonicalState(curState.ToString())); 32 33 done.Add(CanonicalState(curState)); 36 34 selectedState = null; 37 35 return false; … … 45 43 46 44 private IBanditPolicyActionInfo GetStateInfo(ReadonlySequence state) { 47 var s = CanonicalState(state .ToString());45 var s = CanonicalState(state); 48 46 IBanditPolicyActionInfo info; 49 47 if (!stateInfo.TryGetValue(s, out info)) { … … 57 55 // the last state could be terminal 58 56 var lastState = stateTrajectory.Last(); 59 if (lastState.IsTerminal) done.Add(CanonicalState(lastState .ToString()));57 if (lastState.IsTerminal) done.Add(CanonicalState(lastState)); 60 58 61 59 foreach (var state in stateTrajectory) { … … 70 68 71 69 public int GetTries(ReadonlySequence state) { 72 var s = CanonicalState(state .ToString());70 var s = CanonicalState(state); 73 71 if (stateInfo.ContainsKey(s)) return stateInfo[s].Tries; 74 72 else return 0; … … 76 74 77 75 public double GetValue(ReadonlySequence state) { 78 var s = CanonicalState(state .ToString());76 var s = CanonicalState(state); 79 77 if (stateInfo.ContainsKey(s)) return stateInfo[s].Value; 80 78 else return 0.0; // TODO: check alternatives 81 79 } 82 80 83 protected string CanonicalState(string state) { 84 if (useCanonicalState) return problem.CanonicalRepresentation(state); 85 else return state; 81 protected string CanonicalState(ReadonlySequence state) { 82 if (useCanonicalState) { 83 if (state.IsTerminal) 84 return problem.CanonicalRepresentation(state.ToString()); 85 else { 86 // for non-terminal phrases make sure we don't disable canonical states that have not yet been fully explored 87 // e.g. if for the ant problem we have the phrase lllS (and we are limited to 4 symbols) and lllr as well as llll are explored 88 // then we are not allowed to disable rS (canonical of lllS) because rS might not have been fully explored 89 // solution: we disable the state rS4 90 return problem.CanonicalRepresentation(state.ToString()) + state.Length; 91 } 92 } else 93 return state.ToString(); 86 94 } 87 95 }
Note: See TracChangeset
for help on using the changeset viewer.