- Timestamp:
- 02/04/13 16:16:38 (12 years ago)
- Location:
- branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3
- Files:
-
- 11 added
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3
-
Property
svn:ignore
set to
obj
-
Property
svn:ignore
set to
-
branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/Crossover/SinglePointCrossover.cs
r9194 r9204 62 62 IList<IVariable> newCondition = new List<IVariable>(parent1Condition.Count); 63 63 64 var keyEnumerator = parent1Condition. Keys.GetEnumerator();64 var keyEnumerator = parent1Condition.Order.GetEnumerator(); 65 65 66 66 int index = 0; -
branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/HeuristicLab.Encodings.VariableVector-3.3.csproj
r9194 r9204 71 71 </ItemGroup> 72 72 <ItemGroup> 73 <Compile Include="Covering\VariableVectorCoveringCreator.cs" /> 73 74 <Compile Include="Crossover\SinglePointCrossover.cs" /> 75 <Compile Include="Interfaces\IVariableVectorCoveringCreator.cs" /> 74 76 <Compile Include="Interfaces\IVariableVectorCrossover.cs" /> 77 <Compile Include="Interfaces\IVariableVectorManipulator.cs" /> 78 <Compile Include="Manipulator\UniformActionManipulator.cs" /> 79 <Compile Include="Manipulator\UniformOnePositionInConditionManipulator.cs" /> 80 <Compile Include="Manipulator\UniformSomePositionManipulator.cs" /> 75 81 <Compile Include="VariableVectorCrossover.cs" /> 82 <Compile Include="VariableVectorManipulator.cs" /> 76 83 <Compile Include="Variable\IActionVariable.cs" /> 77 84 <Compile Include="Variable\IVariable.cs" /> -
branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/Variable/DoubleVariable.cs
r9194 r9204 137 137 public override double GetGenerality() { 138 138 double delta = max - min; 139 double interval Width = 2 * currentSpread;140 double generality = interval Width / delta;139 double intervalInBoundsWidth = Math.Min(max, currentCenter + currentSpread) - Math.Max(min, currentCenter - currentSpread); 140 double generality = intervalInBoundsWidth / delta; 141 141 return generality > 1 ? 1 : generality; 142 142 } … … 159 159 return crossed; 160 160 } 161 162 public override void Manipulate(IRandom random, string stringValue, int pos) { 163 if (pos > 1 || pos < 0) { throw new ArgumentOutOfRangeException(); } 164 Manipulate(random, pos, 10); 165 } 166 167 public void Manipulate(IRandom random, int pos, double percentage) { 168 if (pos > 1 || pos < 0) { throw new ArgumentOutOfRangeException(); } 169 double delta = max - min; 170 double maxChange = delta * (percentage / 100); 171 double actualChange = (random.NextDouble() * maxChange * 2) - maxChange; 172 if (pos == 0) { 173 currentCenter += actualChange; 174 } else if (pos == 1) { 175 currentSpread += actualChange; 176 //otherwise the interval could be corrupt and no input could match the rule. 177 currentSpread = currentSpread > 0 ? currentSpread : 0; 178 } 179 } 180 181 public override void Cover(IRandom random, string stringValue, double changeSymbolProbability) { 182 Cover(random, stringValue, 50); 183 } 184 185 public void CoverWithSpreadPercentage(IRandom random, string stringValue, double spreadPercentage) { 186 currentCenter = double.Parse(stringValue); 187 double delta = max - min; 188 currentSpread = random.NextDouble() * (delta * (spreadPercentage / 100)); 189 } 161 190 } 162 191 } -
branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/Variable/IVariable.cs
r9194 r9204 41 41 42 42 IVariable CrossParentsAtPosition(IVariable parent2, int pos); 43 44 void Manipulate(IRandom random, string stringValue, int pos); 45 46 void Cover(IRandom random, string stringValue, double changeSymbolProbability); 43 47 } 44 48 } -
branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/Variable/IntVariable.cs
r9194 r9204 86 86 87 87 public override string ToString() { 88 return currentValue.ToString();88 return Wildcard ? "#" : currentValue.ToString(); 89 89 } 90 90 … … 145 145 return this.GetSetCopy(); 146 146 } 147 148 public override void Manipulate(IRandom random, string stringValue, int pos) { 149 if (pos != 0) { throw new ArgumentOutOfRangeException(); } 150 Wildcard = !Wildcard; 151 if (!Wildcard) { 152 currentValue = int.Parse(stringValue); 153 } 154 } 155 156 public override void Cover(IRandom random, string stringValue, double changeSymbolProbability) { 157 Wildcard = random.NextDouble() < changeSymbolProbability; 158 if (!Wildcard) { 159 currentValue = int.Parse(stringValue); 160 } 161 } 147 162 } 148 163 } -
branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/Variable/StringVariable.cs
r9194 r9204 134 134 135 135 public override string ToString() { 136 return CurrentStringValue;136 return Wildcard ? "#" : CurrentStringValue; 137 137 } 138 138 … … 197 197 return this.GetSetCopy(); 198 198 } 199 200 public override void Manipulate(IRandom random, string stringValue, int pos) { 201 if (pos != 0) { throw new ArgumentOutOfRangeException(); } 202 Wildcard = !Wildcard; 203 if (!Wildcard) { 204 int newValue = featureMapping.First(x => x.Value.Equals(stringValue)).Key; 205 currentValue = newValue; 206 } 207 } 208 209 public override void Cover(IRandom random, string stringValue, double changeSymbolProbability) { 210 Wildcard = random.NextDouble() < changeSymbolProbability; 211 if (!Wildcard) { 212 int newValue = featureMapping.First(x => x.Value.Equals(stringValue)).Key; 213 currentValue = newValue; 214 } 215 } 199 216 } 200 217 } -
branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/Variable/Variable.cs
r9194 r9204 69 69 70 70 public virtual IVariable CrossParentsAtPosition(IVariable parent2, int pos) { throw new NotSupportedException("This method is not supported."); } 71 72 public abstract void Manipulate(IRandom random, string stringValue, int pos); 73 74 public abstract void Cover(IRandom random, string stringValue, double changeSymbolProbability); 71 75 } 72 76 } -
branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/VariableVector.cs
r9194 r9204 33 33 [Item("VariableVector", "")] 34 34 public class VariableVector : Item, IClassifier { 35 35 36 [Storable] 36 37 protected VariableVectorCondition condition; … … 131 132 return true; 132 133 } 134 135 [StorableClass] 136 [Item("VariableVectorActionComparer", "")] 137 public class VariableVectorActionComparer : Item, IEqualityComparer<VariableVectorAction>, IClassifierComparer { 138 139 [StorableConstructor] 140 protected VariableVectorActionComparer(bool deserializing) : base(deserializing) { } 141 protected VariableVectorActionComparer(VariableVectorActionComparer original, Cloner cloner) 142 : base(original, cloner) { 143 } 144 public override IDeepCloneable Clone(Cloner cloner) { 145 return new VariableVectorActionComparer(this, cloner); 146 } 147 public VariableVectorActionComparer() : base() { } 148 149 public bool Equals(VariableVectorAction x, VariableVectorAction y) { 150 throw new NotImplementedException(); 151 } 152 153 public int GetHashCode(VariableVectorAction obj) { 154 throw new NotImplementedException(); 155 } 156 157 public bool Equals(IAction x, IAction y) { 158 var xCast = x as VariableVectorAction; 159 var yCast = y as VariableVectorAction; 160 return x != null && y != null && Equals(xCast, yCast); 161 } 162 163 public int GetHashCode(IAction obj) { 164 var objCast = obj as VariableVectorAction; 165 return objCast != null ? GetHashCode(objCast) : obj.GetHashCode(); 166 } 167 } 133 168 } 134 169 } -
branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/VariableVectorAction.cs
r9194 r9204 35 35 public class VariableVectorAction : ItemDictionary<StringValue, IActionVariable>, IAction { 36 36 37 public IOrderedEnumerable<StringValue> Order { get { return this.Keys.OrderBy(x => x.Value); } } 38 37 39 public int VirtualLength { get { return this.Values.Sum(x => x.VirtualLength); } } 38 40 … … 61 63 var targetCast = target as VariableVectorAction; 62 64 if (targetCast == null) { return false; } 63 if ( !(this.Keys.Except(targetCast.Keys).Count() == 0 && targetCast.Keys.Except(this.Keys).Count() == 0)) { return false; }65 if (this.Order.SequenceEqual(targetCast.Order)) { return false; } 64 66 foreach (var keyValuePair in targetCast) { 65 67 if (!this[keyValuePair.Key].MatchVariable(keyValuePair.Value)) { … … 97 99 98 100 public bool Identical(VariableVectorCondition target) { 99 if ( !(target.Keys.Except(this.Keys).Count() == 0 && this.Keys.Except(target.Keys).Count() == 0)) { return false; }101 if (this.Order.SequenceEqual(target.Order)) { return false; } 100 102 foreach (var keyValuePair in target) { 101 103 if (!this[keyValuePair.Key].Identical(keyValuePair.Value)) { -
branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/VariableVectorCondition.cs
r9194 r9204 34 34 public class VariableVectorCondition : ItemDictionary<StringValue, IVariable>, ICondition { 35 35 36 public IOrderedEnumerable<StringValue> Order { get { return this.Keys.OrderBy(x => x.Value); } } 37 36 38 public int VirtualLength { get { return this.Values.Sum(x => x.VirtualLength); } } 37 39 … … 51 53 var targetCast = target as VariableVectorInput; 52 54 if (targetCast == null) { return false; } 53 if ( !(targetCast.Keys.Except(this.Keys).Count() == 0 && this.Keys.Except(targetCast.Keys).Count() == 0)) { return false; }55 if (this.Order.SequenceEqual(targetCast.Order)) { return false; } 54 56 foreach (var keyValuePair in targetCast) { 55 57 if (!this[keyValuePair.Key].MatchInput(keyValuePair.Value.Value)) { … … 91 93 92 94 public bool Identical(VariableVectorCondition target) { 93 if ( !(target.Keys.Except(this.Keys).Count() == 0 && this.Keys.Except(target.Keys).Count() == 0)) { return false; }95 if (this.Order.SequenceEqual(target.Order)) { return false; } 94 96 foreach (var keyValuePair in target) { 95 97 if (!this[keyValuePair.Key].Identical(keyValuePair.Value)) { -
branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/VariableVectorInput.cs
r9194 r9204 21 21 22 22 using System.Collections.Generic; 23 using System.Linq; 23 24 using HeuristicLab.Common; 24 25 using HeuristicLab.Core; … … 31 32 [Item("VariableVectorInput", "")] 32 33 public class VariableVectorInput : ItemDictionary<StringValue, StringValue>, IInput { 34 35 public IOrderedEnumerable<StringValue> Order { get { return this.Keys.OrderBy(x => x.Value); } } 33 36 34 37 [StorableConstructor]
Note: See TracChangeset
for help on using the changeset viewer.