Changeset 9089 for branches/LearningClassifierSystems/HeuristicLab.Encodings.CombinedIntegerVectorEncoding
- Timestamp:
- 12/27/12 19:14:51 (12 years ago)
- Location:
- branches/LearningClassifierSystems
- Files:
-
- 12 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/LearningClassifierSystems
-
Property
svn:ignore
set to
*.suo
-
Property
svn:ignore
set to
-
branches/LearningClassifierSystems/HeuristicLab.Encodings.CombinedIntegerVectorEncoding/3.3
-
Property
svn:ignore
set to
*.user
Plugin.cs
-
Property
svn:ignore
set to
-
branches/LearningClassifierSystems/HeuristicLab.Encodings.CombinedIntegerVectorEncoding/3.3/CombinedIntegerVector.cs
r8941 r9089 25 25 using HeuristicLab.Common; 26 26 using HeuristicLab.Core; 27 using HeuristicLab.Data; 28 using HeuristicLab.Encodings.ConditionActionEncoding; 27 29 using HeuristicLab.Encodings.IntegerVectorEncoding; 28 30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 31 33 [StorableClass] 32 34 [Item("CombinedIntegerVector", "Represents a combined vector of integer values.")] 33 public class CombinedIntegerVector : IntegerVector, I Matching{35 public class CombinedIntegerVector : IntegerVector, IClassifier { 34 36 35 37 [Storable] 36 protected int actionPart; 38 protected int actionLength; 39 public int ActionLength { get { return actionLength; } } 37 40 38 41 /// <summary> … … 42 45 /// </summary> 43 46 [Storable] 44 protected int[,] bounds; 47 protected IntMatrix bounds; 48 public IntMatrix Bounds { get { return (IntMatrix)bounds.Clone(); } } 45 49 46 50 [StorableConstructor] … … 48 52 public CombinedIntegerVector() : base() { } 49 53 50 public CombinedIntegerVector(int[] elements, int actionPart, int[,]bounds)54 public CombinedIntegerVector(int[] elements, int actionPart, IntMatrix bounds) 51 55 : base(elements) { 52 this.action Part= actionPart;56 this.actionLength = actionPart; 53 57 //check if combinedVector satisfies bounds and if bounds is set correctly (at leats one row with 2 columns) is missing! 54 58 this.bounds = bounds; 55 59 } 56 60 57 public CombinedIntegerVector(IntegerVector combinedVector, int actionPart, int[,]bounds)61 public CombinedIntegerVector(IntegerVector combinedVector, int actionPart, IntMatrix bounds) 58 62 : this(combinedVector.ToArray(), actionPart, bounds) { } 59 63 60 public CombinedIntegerVector(IntegerVector condition, IntegerVector action, int[,]bounds)64 public CombinedIntegerVector(IntegerVector condition, IntegerVector action, IntMatrix bounds) 61 65 : base(condition.Concat(action).ToArray()) { 62 action Part= action.Length;66 actionLength = action.Length; 63 67 //check if combinedVector satisfies bounds and if bounds is set correctly (at leats one row with 2 columns) is missing! 64 68 this.bounds = bounds; 65 69 } 66 70 71 public CombinedIntegerVector(IntegerVector condition, IntMatrix conditionBounds, IntegerVector action, IntMatrix actionBounds) 72 : this(condition, action, CombineBounds(conditionBounds, actionBounds)) { 73 } 74 75 private static IntMatrix CombineBounds(IntMatrix conditionBounds, IntMatrix actionBounds) { 76 int columns = conditionBounds.Columns < actionBounds.Columns ? conditionBounds.Columns : actionBounds.Columns; 77 IntMatrix bounds = new IntMatrix(conditionBounds.Rows + actionBounds.Rows, columns); 78 for (int i = 0; i < conditionBounds.Rows; i++) { 79 for (int j = 0; j < columns; j++) { 80 bounds[i, j] = conditionBounds[i % conditionBounds.Rows, j]; 81 } 82 } 83 84 for (int i = conditionBounds.Rows; i < actionBounds.Rows + conditionBounds.Rows; i++) { 85 for (int j = 0; j < columns; j++) { 86 bounds[i, j] = actionBounds[i % actionBounds.Rows, j]; 87 } 88 } 89 return bounds; 90 } 91 67 92 public CombinedIntegerVector(IRandom random, int length, int min, int max, int actionLenght, int actionMin, int actionMax) : 68 93 this(new IntegerVector(length, random, min, max), new IntegerVector(actionLenght, random, actionMin, actionMax), null) { 69 bounds = new int[length + actionLenght, 2];94 bounds = new IntMatrix(length + actionLenght, 2); 70 95 for (int i = 0; i < length; i++) { 71 96 bounds[i, 0] = min; … … 78 103 } 79 104 80 public CombinedIntegerVector(int length, int actionPart, int[,]bounds)105 public CombinedIntegerVector(int length, int actionPart, IntMatrix bounds) 81 106 : base(length) { 82 this.action Part= actionPart;107 this.actionLength = actionPart; 83 108 this.bounds = bounds; 84 109 } … … 86 111 protected CombinedIntegerVector(CombinedIntegerVector original, Cloner cloner) 87 112 : base(original, cloner) { 88 actionPart = original.actionPart; 89 bounds = (int[,])original.bounds.Clone(); 90 } 113 actionLength = original.actionLength; 114 bounds = (IntMatrix)original.bounds.Clone(); 115 } 116 91 117 public override IDeepCloneable Clone(Cloner cloner) { 92 118 return new CombinedIntegerVector(this, cloner); 93 119 } 94 120 95 public I MatchingCondition {121 public IClassifier Condition { 96 122 get { 97 int[] condition = new int[Length - action Part];98 Array.Copy(this.array, condition, Length - action Part);123 int[] condition = new int[Length - actionLength]; 124 Array.Copy(this.array, condition, Length - actionLength); 99 125 return new CombinedIntegerVector(condition, 0, bounds); 100 126 } 101 127 } 102 128 103 public I MatchingAction {129 public IClassifier Action { 104 130 get { 105 int[] action = new int[actionPart]; 106 Array.Copy(this.array, Length - actionPart, action, 0, actionPart); 107 return new CombinedIntegerVector(action, actionPart, bounds); 108 } 109 } 110 111 public bool MatchCondition(IMatching target) { 131 int[] action = new int[actionLength]; 132 Array.Copy(this.array, Length - actionLength, action, 0, actionLength); 133 134 IntMatrix actionBounds = GetElementsOfBoundsForAction(bounds, Length, actionLength); 135 return new CombinedIntegerVector(action, actionLength, actionBounds); 136 } 137 } 138 139 private IntMatrix GetElementsOfBoundsForAction(IntMatrix bounds, int length, int actionPartLength) { 140 IntMatrix actionBounds = new IntMatrix(actionPartLength, bounds.Columns); 141 int start = length - actionPartLength; 142 for (int i = start; i < length; i++) { 143 int pos = i % bounds.Rows; 144 for (int j = 0; j < bounds.Columns; j++) { 145 actionBounds[i - start, j] = bounds[pos, j]; 146 } 147 } 148 return actionBounds; 149 } 150 151 public bool MatchCondition(IClassifier target) { 112 152 var targetVector = target as CombinedIntegerVector; 113 153 if (targetVector == null) return false; … … 115 155 116 156 int curbounds; 117 for (int i = 0; i < this.Length - this.action Part; i++) {118 curbounds = i % bounds. GetLength(0);157 for (int i = 0; i < this.Length - this.actionLength; i++) { 158 curbounds = i % bounds.Rows; 119 159 //if don't care symbol is matched, next indices can be checked 120 160 if (this[i].Equals(bounds[curbounds, 1] - 1)) { … … 129 169 130 170 // no "don't care" symbols have to be considered 131 public bool MatchAction(I Matchingtarget) {171 public bool MatchAction(IClassifier target) { 132 172 var targetVector = target as CombinedIntegerVector; 133 173 if (targetVector == null) return false; 134 if (targetVector.action Part != this.actionPart) return false;135 136 int curPos = this.Length - this.action Part;137 int curTargetPos = targetVector.Length - targetVector.action Part;138 for (int i = 0; i < this.action Part; i++) {174 if (targetVector.actionLength != this.actionLength) return false; 175 176 int curPos = this.Length - this.actionLength; 177 int curTargetPos = targetVector.Length - targetVector.actionLength; 178 for (int i = 0; i < this.actionLength; i++) { 139 179 if (!this[curPos + i].Equals(targetVector[curTargetPos + i])) { 140 180 return false; … … 149 189 int curbounds; 150 190 for (int i = 0; i < this.Length; i++) { 151 curbounds = i % bounds. GetLength(0);152 if (i >= this.Length - this.action Part|| this[i] < bounds[curbounds, 1] - 1) {191 curbounds = i % bounds.Rows; 192 if (i >= this.Length - this.actionLength || this[i] < bounds[curbounds, 1] - 1) { 153 193 strBuilder.Append(this[i]); 154 194 } else { … … 171 211 } 172 212 173 public bool Equals(I Matchingother) {213 public bool Equals(IClassifier other) { 174 214 return this.MatchAction(other) && this.MatchCondition(other); 175 215 } 176 216 177 217 public override int GetHashCode() { 178 int result = action Part;218 int result = actionLength; 179 219 for (int i = 0; i < array.Length; i++) { 180 220 result ^= array[i]; -
branches/LearningClassifierSystems/HeuristicLab.Encodings.CombinedIntegerVectorEncoding/3.3/CombinedIntegerVectorCreator.cs
r8941 r9089 23 23 using HeuristicLab.Core; 24 24 using HeuristicLab.Data; 25 using HeuristicLab.Encodings.IntegerVectorEncoding; 25 using HeuristicLab.Operators; 26 using HeuristicLab.Optimization; 26 27 using HeuristicLab.Parameters; 27 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 33 34 [Item("CombinedIntegerVectorCreator", "A base class for operators creating combined int-valued vectors.")] 34 35 [StorableClass] 35 public abstract class CombinedIntegerVectorCreator : IntegerVectorCreator, ICombinedIntegerVectorCreator { 36 public abstract class CombinedIntegerVectorCreator : SingleSuccessorOperator, IStochasticOperator, ICombinedIntegerVectorCreator { 37 public override bool CanChangeName { 38 get { return false; } 39 } 40 public ILookupParameter<IRandom> RandomParameter { 41 get { return (LookupParameter<IRandom>)Parameters["Random"]; } 42 } 43 public IValueLookupParameter<IntValue> LengthParameter { 44 get { return (IValueLookupParameter<IntValue>)Parameters["Length"]; } 45 } 46 public IValueLookupParameter<IntMatrix> BoundsParameter { 47 get { return (IValueLookupParameter<IntMatrix>)Parameters["Bounds"]; } 48 } 49 36 50 public IValueLookupParameter<IntValue> ActionPartLengthParameter { 37 51 get { return (IValueLookupParameter<IntValue>)Parameters["ActionPartLength"]; } … … 44 58 [StorableConstructor] 45 59 protected CombinedIntegerVectorCreator(bool deserializing) : base(deserializing) { } 46 protected CombinedIntegerVectorCreator( IntegerVectorCreator original, Cloner cloner) : base(original, cloner) { }60 protected CombinedIntegerVectorCreator(CombinedIntegerVectorCreator original, Cloner cloner) : base(original, cloner) { } 47 61 protected CombinedIntegerVectorCreator() 48 62 : base() { 63 Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used for stochastic manipulation operators.")); 64 Parameters.Add(new ValueLookupParameter<IntValue>("Length", "The length of the vector.")); 65 Parameters.Add(new ValueLookupParameter<IntMatrix>("Bounds", "The bounds matrix can contain one row for each dimension with three columns specifying minimum (inclusive), maximum (exclusive), and step size. If less rows are given the matrix is cycled.")); 49 66 Parameters.Add(new LookupParameter<CombinedIntegerVector>("CombinedIntegerVector", "The vector which should be manipulated.")); 50 67 Parameters.Add(new ValueLookupParameter<IntValue>("ActionPartLength", "The length of the vector.")); 51 68 } 52 69 53 p rotected override IntegerVector Create(IRandom random, IntValue length, IntMatrix bounds) {54 CombinedIntegerVectorParameter.ActualValue = Create( random, length, bounds, ActionPartLengthParameter.ActualValue);55 return CombinedIntegerVectorParameter.ActualValue;70 public sealed override IOperation Apply() { 71 CombinedIntegerVectorParameter.ActualValue = Create(RandomParameter.ActualValue, LengthParameter.ActualValue, BoundsParameter.ActualValue, ActionPartLengthParameter.ActualValue); 72 return base.Apply(); 56 73 } 57 74 -
branches/LearningClassifierSystems/HeuristicLab.Encodings.CombinedIntegerVectorEncoding/3.3/Creators/UniformRandomCombinedIntegerVectorCreator.cs
r8941 r9089 50 50 /// <returns>The newly created integer vector.</returns> 51 51 public static CombinedIntegerVector Apply(IRandom random, int length, IntMatrix bounds, int actionPartLength) { 52 var result = new CombinedIntegerVector(length, actionPartLength, GetElementsOfBounds(bounds));52 var result = new CombinedIntegerVector(length, actionPartLength, bounds); 53 53 result.Randomize(random, bounds); 54 54 return result; 55 }56 57 private static int[,] GetElementsOfBounds(IntMatrix bounds) {58 int[,] realBounds = new int[bounds.Rows, bounds.Columns];59 for (int i = 0; i < bounds.Rows; i++) {60 for (int j = 0; j < bounds.Columns; j++) {61 realBounds[i, j] = bounds[i, j];62 }63 }64 return realBounds;65 55 } 66 56 -
branches/LearningClassifierSystems/HeuristicLab.Encodings.CombinedIntegerVectorEncoding/3.3/HeuristicLab.Encodings.CombinedIntegerVectorEncoding-3.3.csproj
r8941 r9089 104 104 <Compile Include="CombinedIntegerVector.cs" /> 105 105 <Compile Include="CombinedIntegerVectorCreator.cs" /> 106 <Compile Include="CombinedIntegerVectorCrossover.cs" /> 107 <Compile Include="CombinedIntegerVectorManipulator.cs" /> 108 <Compile Include="Covering\CombinedIntegerVectorCoveringCreator.cs" /> 106 109 <Compile Include="Creators\UniformRandomCombinedIntegerVectorCreator.cs" /> 107 <Compile Include="Matching\IMatching.cs" /> 110 <Compile Include="Crossovers\SinglePointCrossover.cs" /> 111 <Compile Include="Interfaces\ICombinedIntegerVectorManipulator.cs" /> 112 <Compile Include="Interfaces\ICombinedIntegerVectorCrossover.cs" /> 108 113 <Compile Include="Interfaces\IBoundedCombinedIntegerVectorOperator.cs" /> 109 114 <Compile Include="Interfaces\ICombinedIntegerVectorCreator.cs" /> 110 115 <Compile Include="Interfaces\ICombinedIntegerVectorOperator.cs" /> 111 <Compile Include="Properties\AssemblyInfo.cs" /> 116 <Compile Include="Manipulator\UniformActionManipulator.cs"> 117 <SubType>Code</SubType> 118 </Compile> 119 <Compile Include="Manipulator\UniformOnePositionInConditionManipulator.cs" /> 120 <Compile Include="Manipulator\UniformSomePositionsManipulator.cs" /> 112 121 <Compile Include="Plugin.cs" /> 113 122 <None Include="Properties\AssemblyInfo.cs.frame" /> 123 <Compile Include="Properties\AssemblyInfo.cs" /> 114 124 </ItemGroup> 115 125 <ItemGroup> 116 126 <None Include="HeuristicLab.snk" /> 117 127 <None Include="Plugin.cs.frame" /> 128 </ItemGroup> 129 <ItemGroup> 130 <ProjectReference Include="..\..\HeuristicLab.Encodings.ConditionActionEncoding\3.3\HeuristicLab.Encodings.ConditionActionEncoding-3.3.csproj"> 131 <Project>{422FB262-0845-4969-8D16-12F057AA90B1}</Project> 132 <Name>HeuristicLab.Encodings.ConditionActionEncoding-3.3</Name> 133 </ProjectReference> 118 134 </ItemGroup> 119 135 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> -
branches/LearningClassifierSystems/HeuristicLab.Encodings.CombinedIntegerVectorEncoding/3.3/Interfaces/IBoundedCombinedIntegerVectorOperator.cs
r8941 r9089 20 20 #endregion 21 21 22 using HeuristicLab.Encodings.IntegerVectorEncoding; 22 using System; 23 using HeuristicLab.Common; 24 using HeuristicLab.Core; 25 using HeuristicLab.Data; 23 26 24 27 namespace HeuristicLab.Encodings.CombinedIntegerVectorEncoding { … … 26 29 /// The bounds parameter must contain at least one row and at least two columns. The first two columns specify min and max values, the last column specifies the step size, but is optional (1 is assumed if omitted). 27 30 /// </summary> 28 public interface IBoundedCombinedIntegerVectorOperator : IBoundedIntegerVectorOperator { } 31 public interface IBoundedCombinedIntegerVectorOperator : ICombinedIntegerVectorOperator, IOperator, IParameterizedNamedItem, INamedItem, IParameterizedItem, IItem, IContent, IDeepCloneable, ICloneable { 32 IValueLookupParameter<IntMatrix> BoundsParameter { get; } 33 } 29 34 } -
branches/LearningClassifierSystems/HeuristicLab.Encodings.CombinedIntegerVectorEncoding/3.3/Interfaces/ICombinedIntegerVectorCreator.cs
r8941 r9089 20 20 #endregion 21 21 22 using System; 23 using HeuristicLab.Common; 22 24 using HeuristicLab.Core; 23 25 using HeuristicLab.Data; 24 using HeuristicLab. Encodings.IntegerVectorEncoding;26 using HeuristicLab.Optimization; 25 27 26 28 namespace HeuristicLab.Encodings.CombinedIntegerVectorEncoding { 27 public interface ICombinedIntegerVectorCreator : IIntegerVectorCreator, IBoundedCombinedIntegerVectorOperator { 29 public interface ICombinedIntegerVectorCreator : ISolutionCreator, IBoundedCombinedIntegerVectorOperator, ICombinedIntegerVectorOperator, IOperator, IParameterizedNamedItem, INamedItem, IParameterizedItem, IItem, IContent, IDeepCloneable, ICloneable { 30 IValueLookupParameter<IntValue> LengthParameter { get; } 28 31 IValueLookupParameter<IntValue> ActionPartLengthParameter { get; } 29 32 ILookupParameter<CombinedIntegerVector> CombinedIntegerVectorParameter { get; } -
branches/LearningClassifierSystems/HeuristicLab.Encodings.CombinedIntegerVectorEncoding/3.3/Interfaces/ICombinedIntegerVectorOperator.cs
r8941 r9089 20 20 #endregion 21 21 22 using System; 23 using HeuristicLab.Common; 22 24 using HeuristicLab.Core; 23 25 24 26 namespace HeuristicLab.Encodings.CombinedIntegerVectorEncoding { 25 public interface ICombinedIntegerVectorOperator : IOperator { } 27 public interface ICombinedIntegerVectorOperator : IOperator, IParameterizedNamedItem, INamedItem, IParameterizedItem, IItem, IContent, IDeepCloneable, ICloneable { 28 } 26 29 } -
branches/LearningClassifierSystems/HeuristicLab.Encodings.CombinedIntegerVectorEncoding/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.