- Timestamp:
- 07/28/09 19:24:23 (15 years ago)
- Location:
- branches/GP-Refactoring-713
- Files:
-
- 4 added
- 28 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Addition.cs
r1529 r2202 42 42 : base() { 43 43 // 2 - 3 seems like an reasonable defaut (used for +,-,*,/) (discussion with swinkler and maffenze) 44 AddConstraint(new NumberOfSubOperatorsConstraint(2, 3)); 45 AddConstraint(new SubOperatorTypeConstraint(0)); 46 AddConstraint(new SubOperatorTypeConstraint(1)); 47 AddConstraint(new SubOperatorTypeConstraint(2)); 44 MinArity = 2; 45 MaxArity = 3; 48 46 } 49 47 } -
branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/And.cs
r1529 r2202 38 38 public And() 39 39 : base() { 40 AddConstraint(new NumberOfSubOperatorsConstraint(2, 3)); 41 AddConstraint(new SubOperatorTypeConstraint(0)); 42 AddConstraint(new SubOperatorTypeConstraint(1)); 43 AddConstraint(new SubOperatorTypeConstraint(2)); 40 MinArity = 2; MaxArity = 3; 44 41 } 45 42 } -
branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Average.cs
r1529 r2202 36 36 public Average() 37 37 : base() { 38 AddConstraint(new NumberOfSubOperatorsConstraint(2, 3)); 39 AddConstraint(new SubOperatorTypeConstraint(0)); 40 AddConstraint(new SubOperatorTypeConstraint(1)); 41 AddConstraint(new SubOperatorTypeConstraint(2)); 38 MinArity = 2; MaxArity = 3; 42 39 } 43 40 } -
branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/BakedTreeEvaluator.cs
r1836 r2202 183 183 return Math.Abs(x - y); 184 184 } 185 case EvaluatorSymbolTable.UNKNOWN: { // evaluate functions which are not statically defined directly186 return currInstr.function.Apply();187 }188 185 default: { 189 186 throw new NotImplementedException(); -
branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Constant.cs
r2174 r2202 32 32 33 33 namespace HeuristicLab.GP.StructureIdentification { 34 public sealed class Constant : FunctionBase{34 public sealed class Constant : Terminal { 35 35 public const string VALUE = "Value"; 36 private BakedFunctionTree constantNodeTemplate; 36 37 37 38 public override string Description { … … 39 40 } 40 41 42 public override IEnumerable<string> LocalParameterNames { 43 get { 44 return new string[] { VALUE }; 45 } 46 } 47 41 48 public Constant() 42 49 : base() { 43 AddVariableInfo(new VariableInfo(VALUE, "The constant value", typeof(DoubleData), VariableKind.None));44 GetVariableInfo(VALUE).Local = true;45 46 50 DoubleData valueData = new DoubleData(); 47 // initialize a default range for the contant value 48 HeuristicLab.Core.Variable value = new HeuristicLab.Core.Variable(VALUE, valueData); 49 AddVariable(value); 51 constantNodeTemplate = new BakedFunctionTree(this); 52 constantNodeTemplate.AddVariable(new HeuristicLab.Core.Variable(VALUE, valueData)); 50 53 51 54 SetupInitialization(); 52 55 SetupManipulation(); 56 } 53 57 54 // constant can't have suboperators55 AddConstraint(new NumberOfSubOperatorsConstraint(0, 0));58 public override IFunctionTree GetTreeNode() { 59 return (IFunctionTree)constantNodeTemplate.Clone(); 56 60 } 57 61 58 62 private void SetupInitialization() { 59 63 // initialization operator 60 AddVariableInfo(new VariableInfo(INITIALIZATION, "Initialization operator-graph for constants", typeof(IOperatorGraph), VariableKind.None));61 GetVariableInfo(INITIALIZATION).Local = false;62 64 CombinedOperator combinedOp = new CombinedOperator(); 63 65 SequentialProcessor initSeq = new SequentialProcessor(); … … 70 72 combinedOp.OperatorGraph.InitialOperator = initSeq; 71 73 initSeq.AddSubOperator(randomizer); 72 AddVariable(new HeuristicLab.Core.Variable(INITIALIZATION, combinedOp));74 Initializer = combinedOp; 73 75 } 74 76 75 77 private void SetupManipulation() { 76 78 // manipulation operator 77 AddVariableInfo(new VariableInfo(MANIPULATION, "Manipulation operator-graph for constants", typeof(IOperatorGraph), VariableKind.None));78 GetVariableInfo(MANIPULATION).Local = false;79 79 CombinedOperator combinedOp = new CombinedOperator(); 80 80 SequentialProcessor manipulationSeq = new SequentialProcessor(); … … 87 87 combinedOp.OperatorGraph.InitialOperator = manipulationSeq; 88 88 manipulationSeq.AddSubOperator(valueAdder); 89 AddVariable(new HeuristicLab.Core.Variable(MANIPULATION, combinedOp));89 Manipulator = combinedOp; 90 90 } 91 91 } -
branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Cosinus.cs
r1529 r2202 29 29 30 30 namespace HeuristicLab.GP.StructureIdentification { 31 public sealed class Cosinus : FunctionBase{31 public sealed class Cosinus : UnaryFunction { 32 32 public override string Description { 33 33 get { return "Returns the cosinus of the first sub-tree."; } … … 36 36 public Cosinus() 37 37 : base() { 38 // must have exactly one subfunction39 AddConstraint(new NumberOfSubOperatorsConstraint(1, 1));40 AddConstraint(new SubOperatorTypeConstraint(0));41 38 } 42 39 } -
branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Differential.cs
r1529 r2202 40 40 } 41 41 42 public Differential() 43 : base() { 44 } 42 public Differential() : base() { } 45 43 } 46 44 } -
branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Division.cs
r2054 r2202 30 30 31 31 namespace HeuristicLab.GP.StructureIdentification { 32 public sealed class Division : FunctionBase { 33 private const double EPSILON = 10.0E-20; // if any divisor is < EPSILON return 0 34 32 public sealed class Division : BinaryFunction { 35 33 public override string Description { 36 34 get { … … 46 44 } 47 45 48 public Division() 49 : base() { 50 // 2 - 3 seems like an reasonable defaut (used for +,-,*,/) (discussion with swinkler and maffenze) 51 //MK changed to only 2 allowed suboperators to be compliant with HL2 52 AddConstraint(new NumberOfSubOperatorsConstraint(2, 2)); 53 AddConstraint(new SubOperatorTypeConstraint(0)); 54 AddConstraint(new SubOperatorTypeConstraint(1)); 55 } 46 public Division() : base() { } 56 47 } 57 48 } -
branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Equal.cs
r1529 r2202 28 28 29 29 namespace HeuristicLab.GP.StructureIdentification { 30 public sealed class Equal : FunctionBase{30 public sealed class Equal : BinaryFunction { 31 31 public override string Description { 32 32 get { … … 35 35 } 36 36 37 public Equal() 38 : base() { 39 AddConstraint(new NumberOfSubOperatorsConstraint(2, 2)); 40 AddConstraint(new SubOperatorTypeConstraint(0)); 41 AddConstraint(new SubOperatorTypeConstraint(1)); 42 } 37 public Equal() : base() { } 43 38 } 44 39 } -
branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Exponential.cs
r1529 r2202 29 29 30 30 namespace HeuristicLab.GP.StructureIdentification { 31 public sealed class Exponential : FunctionBase{31 public sealed class Exponential : UnaryFunction { 32 32 public override string Description { 33 33 get { return "Returns returns exponential of the first sub-tree (power(e, x))."; } 34 34 } 35 35 36 public Exponential() 37 : base() { 38 // must have exactly one sub-operator 39 AddConstraint(new NumberOfSubOperatorsConstraint(1, 1)); 40 AddConstraint(new SubOperatorTypeConstraint(0)); 41 } 36 public Exponential() : base() { } 42 37 } 43 38 } -
branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/FunctionLibraryInjector.cs
r2174 r2202 72 72 AddVariableInfo(new VariableInfo(MINTIMEOFFSET, "Minimal time offset for all features", typeof(IntData), VariableKind.In)); 73 73 AddVariableInfo(new VariableInfo(MAXTIMEOFFSET, "Maximal time offset for all feature", typeof(IntData), VariableKind.In)); 74 AddVariableInfo(new VariableInfo(FUNCTIONLIBRARY, "Preconfigured default operator library", typeof(GPOperatorLibrary), VariableKind.New));74 AddVariableInfo(new VariableInfo(FUNCTIONLIBRARY, "Preconfigured default function library", typeof(FunctionLibrary), VariableKind.New)); 75 75 76 76 AddVariable(DIFFERENTIALS_ALLOWED, false); … … 107 107 108 108 public override IOperation Apply(IScope scope) { 109 StructId.Variable variable; 110 GPOperatorLibrary operatorLibrary; 109 FunctionLibrary functionLibrary = new FunctionLibrary(); 111 110 int targetVariable = GetVariableValue<IntData>(TARGETVARIABLE, scope, true).Data; 112 111 … … 118 117 int maxTimeOffset = maxTimeOffsetItem == null ? 0 : ((IntData)maxTimeOffsetItem).Data; 119 118 120 variable = new StructId.Variable();121 StructId.Constant constant = new StructId.Constant();122 StructId.Differential differential = new Differential();123 StructId.Addition addition = new StructId.Addition();124 StructId.And and = new StructId.And();125 StructId.Average average = new StructId.Average();126 StructId.Cosinus cosinus = new StructId.Cosinus();127 StructId.Division division = new StructId.Division();128 StructId.Equal equal = new StructId.Equal();129 StructId.Exponential exponential = new StructId.Exponential();130 StructId.GreaterThan greaterThan = new StructId.GreaterThan();131 StructId.IfThenElse ifThenElse = new StructId.IfThenElse();132 StructId.LessThan lessThan = new StructId.LessThan();133 StructId.Logarithm logarithm = new StructId.Logarithm();134 StructId.Multiplication multiplication = new StructId.Multiplication();135 StructId.Not not = new StructId.Not();136 StructId.Or or = new StructId.Or();137 StructId.Power power = new StructId.Power();138 S tructId.Signum signum = new StructId.Signum();139 S tructId.Sinus sinus = new StructId.Sinus();140 S tructId.Sqrt sqrt = new StructId.Sqrt();141 S tructId.Subtraction subtraction = new StructId.Subtraction();142 StructId.Tangens tangens = new StructId.Tangens();143 StructId.Xor xor = new StructId.Xor();144 145 146 List<I Operator> booleanFunctions = new List<IOperator>();147 ConditionalAdd Operator(AND_ALLOWED, and, booleanFunctions);148 ConditionalAdd Operator(EQUAL_ALLOWED, equal, booleanFunctions);149 ConditionalAdd Operator(GREATERTHAN_ALLOWED, greaterThan, booleanFunctions);150 ConditionalAdd Operator(LESSTHAN_ALLOWED, lessThan, booleanFunctions);151 ConditionalAdd Operator(NOT_ALLOWED, not, booleanFunctions);152 ConditionalAdd Operator(OR_ALLOWED, or, booleanFunctions);153 ConditionalAdd Operator(XOR_ALLOWED, xor, booleanFunctions);154 155 List<I Operator> doubleFunctions = new List<IOperator>();156 ConditionalAdd Operator(DIFFERENTIALS_ALLOWED, differential, doubleFunctions);157 ConditionalAdd Operator(VARIABLES_ALLOWED, variable, doubleFunctions);158 ConditionalAdd Operator(CONSTANTS_ALLOWED, constant, doubleFunctions);159 ConditionalAdd Operator(ADDITION_ALLOWED, addition, doubleFunctions);160 ConditionalAdd Operator(AVERAGE_ALLOWED, average, doubleFunctions);161 ConditionalAdd Operator(COSINUS_ALLOWED, cosinus, doubleFunctions);162 ConditionalAdd Operator(DIVISION_ALLOWED, division, doubleFunctions);163 ConditionalAdd Operator(EXPONENTIAL_ALLOWED, exponential, doubleFunctions);164 ConditionalAdd Operator(IFTHENELSE_ALLOWED, ifThenElse, doubleFunctions);165 ConditionalAdd Operator(LOGARTIHM_ALLOWED, logarithm, doubleFunctions);166 ConditionalAdd Operator(MULTIPLICATION_ALLOWED, multiplication, doubleFunctions);167 ConditionalAdd Operator(POWER_ALLOWED, power, doubleFunctions);168 ConditionalAdd Operator(SIGNUM_ALLOWED, signum, doubleFunctions);169 ConditionalAdd Operator(SINUS_ALLOWED, sinus, doubleFunctions);170 ConditionalAdd Operator(SQRT_ALLOWED, sqrt, doubleFunctions);171 ConditionalAdd Operator(SUBTRACTION_ALLOWED, subtraction, doubleFunctions);172 ConditionalAdd Operator(TANGENS_ALLOWED, tangens, doubleFunctions);119 Variable variable = new Variable(); 120 Constant constant = new Constant(); 121 Differential differential = new Differential(); 122 Addition addition = new Addition(); 123 And and = new And(); 124 Average average = new Average(); 125 Cosinus cosinus = new Cosinus(); 126 Division division = new Division(); 127 Equal equal = new Equal(); 128 Exponential exponential = new Exponential(); 129 GreaterThan greaterThan = new GreaterThan(); 130 IfThenElse ifThenElse = new IfThenElse(); 131 LessThan lessThan = new LessThan(); 132 Logarithm logarithm = new Logarithm(); 133 Multiplication multiplication = new Multiplication(); 134 Not not = new Not(); 135 Or or = new Or(); 136 Power power = new Power(); 137 Signum signum = new Signum(); 138 Sinus sinus = new Sinus(); 139 Sqrt sqrt = new Sqrt(); 140 Subtraction subtraction = new Subtraction(); 141 Tangens tangens = new Tangens(); 142 Xor xor = new Xor(); 143 144 145 List<IFunction> booleanFunctions = new List<IFunction>(); 146 ConditionalAddFunction(AND_ALLOWED, and, booleanFunctions); 147 ConditionalAddFunction(EQUAL_ALLOWED, equal, booleanFunctions); 148 ConditionalAddFunction(GREATERTHAN_ALLOWED, greaterThan, booleanFunctions); 149 ConditionalAddFunction(LESSTHAN_ALLOWED, lessThan, booleanFunctions); 150 ConditionalAddFunction(NOT_ALLOWED, not, booleanFunctions); 151 ConditionalAddFunction(OR_ALLOWED, or, booleanFunctions); 152 ConditionalAddFunction(XOR_ALLOWED, xor, booleanFunctions); 153 154 List<IFunction> doubleFunctions = new List<IFunction>(); 155 ConditionalAddFunction(DIFFERENTIALS_ALLOWED, differential, doubleFunctions); 156 ConditionalAddFunction(VARIABLES_ALLOWED, variable, doubleFunctions); 157 ConditionalAddFunction(CONSTANTS_ALLOWED, constant, doubleFunctions); 158 ConditionalAddFunction(ADDITION_ALLOWED, addition, doubleFunctions); 159 ConditionalAddFunction(AVERAGE_ALLOWED, average, doubleFunctions); 160 ConditionalAddFunction(COSINUS_ALLOWED, cosinus, doubleFunctions); 161 ConditionalAddFunction(DIVISION_ALLOWED, division, doubleFunctions); 162 ConditionalAddFunction(EXPONENTIAL_ALLOWED, exponential, doubleFunctions); 163 ConditionalAddFunction(IFTHENELSE_ALLOWED, ifThenElse, doubleFunctions); 164 ConditionalAddFunction(LOGARTIHM_ALLOWED, logarithm, doubleFunctions); 165 ConditionalAddFunction(MULTIPLICATION_ALLOWED, multiplication, doubleFunctions); 166 ConditionalAddFunction(POWER_ALLOWED, power, doubleFunctions); 167 ConditionalAddFunction(SIGNUM_ALLOWED, signum, doubleFunctions); 168 ConditionalAddFunction(SINUS_ALLOWED, sinus, doubleFunctions); 169 ConditionalAddFunction(SQRT_ALLOWED, sqrt, doubleFunctions); 170 ConditionalAddFunction(SUBTRACTION_ALLOWED, subtraction, doubleFunctions); 171 ConditionalAddFunction(TANGENS_ALLOWED, tangens, doubleFunctions); 173 172 174 173 SetAllowedSubOperators(and, booleanFunctions); … … 196 195 SetAllowedSubOperators(tangens, doubleFunctions); 197 196 198 operatorLibrary = new GPOperatorLibrary(); 199 ConditionalAddOperator(DIFFERENTIALS_ALLOWED, operatorLibrary, differential); 200 ConditionalAddOperator(VARIABLES_ALLOWED, operatorLibrary, variable); 201 ConditionalAddOperator(CONSTANTS_ALLOWED, operatorLibrary, constant); 202 ConditionalAddOperator(ADDITION_ALLOWED, operatorLibrary, addition); 203 ConditionalAddOperator(AVERAGE_ALLOWED, operatorLibrary, average); 204 ConditionalAddOperator(AND_ALLOWED, operatorLibrary, and); 205 ConditionalAddOperator(COSINUS_ALLOWED, operatorLibrary, cosinus); 206 ConditionalAddOperator(DIVISION_ALLOWED, operatorLibrary, division); 207 ConditionalAddOperator(EQUAL_ALLOWED, operatorLibrary, equal); 208 ConditionalAddOperator(EXPONENTIAL_ALLOWED, operatorLibrary, exponential); 209 ConditionalAddOperator(GREATERTHAN_ALLOWED, operatorLibrary, greaterThan); 210 ConditionalAddOperator(IFTHENELSE_ALLOWED, operatorLibrary, ifThenElse); 211 ConditionalAddOperator(LESSTHAN_ALLOWED, operatorLibrary, lessThan); 212 ConditionalAddOperator(LOGARTIHM_ALLOWED, operatorLibrary, logarithm); 213 ConditionalAddOperator(MULTIPLICATION_ALLOWED, operatorLibrary, multiplication); 214 ConditionalAddOperator(NOT_ALLOWED, operatorLibrary, not); 215 ConditionalAddOperator(POWER_ALLOWED, operatorLibrary, power); 216 ConditionalAddOperator(OR_ALLOWED, operatorLibrary, or); 217 ConditionalAddOperator(SIGNUM_ALLOWED, operatorLibrary, signum); 218 ConditionalAddOperator(SINUS_ALLOWED, operatorLibrary, sinus); 219 ConditionalAddOperator(SQRT_ALLOWED, operatorLibrary, sqrt); 220 ConditionalAddOperator(SUBTRACTION_ALLOWED, operatorLibrary, subtraction); 221 ConditionalAddOperator(TANGENS_ALLOWED, operatorLibrary, tangens); 222 ConditionalAddOperator(XOR_ALLOWED, operatorLibrary, xor); 197 ConditionalAddOperator(DIFFERENTIALS_ALLOWED, functionLibrary, differential); 198 ConditionalAddOperator(VARIABLES_ALLOWED, functionLibrary, variable); 199 ConditionalAddOperator(CONSTANTS_ALLOWED, functionLibrary, constant); 200 ConditionalAddOperator(ADDITION_ALLOWED, functionLibrary, addition); 201 ConditionalAddOperator(AVERAGE_ALLOWED, functionLibrary, average); 202 ConditionalAddOperator(AND_ALLOWED, functionLibrary, and); 203 ConditionalAddOperator(COSINUS_ALLOWED, functionLibrary, cosinus); 204 ConditionalAddOperator(DIVISION_ALLOWED, functionLibrary, division); 205 ConditionalAddOperator(EQUAL_ALLOWED, functionLibrary, equal); 206 ConditionalAddOperator(EXPONENTIAL_ALLOWED, functionLibrary, exponential); 207 ConditionalAddOperator(GREATERTHAN_ALLOWED, functionLibrary, greaterThan); 208 ConditionalAddOperator(IFTHENELSE_ALLOWED, functionLibrary, ifThenElse); 209 ConditionalAddOperator(LESSTHAN_ALLOWED, functionLibrary, lessThan); 210 ConditionalAddOperator(LOGARTIHM_ALLOWED, functionLibrary, logarithm); 211 ConditionalAddOperator(MULTIPLICATION_ALLOWED, functionLibrary, multiplication); 212 ConditionalAddOperator(NOT_ALLOWED, functionLibrary, not); 213 ConditionalAddOperator(POWER_ALLOWED, functionLibrary, power); 214 ConditionalAddOperator(OR_ALLOWED, functionLibrary, or); 215 ConditionalAddOperator(SIGNUM_ALLOWED, functionLibrary, signum); 216 ConditionalAddOperator(SINUS_ALLOWED, functionLibrary, sinus); 217 ConditionalAddOperator(SQRT_ALLOWED, functionLibrary, sqrt); 218 ConditionalAddOperator(SUBTRACTION_ALLOWED, functionLibrary, subtraction); 219 ConditionalAddOperator(TANGENS_ALLOWED, functionLibrary, tangens); 220 ConditionalAddOperator(XOR_ALLOWED, functionLibrary, xor); 223 221 224 222 variable.SetConstraints(minTimeOffset, maxTimeOffset); 225 223 differential.SetConstraints(minTimeOffset, maxTimeOffset); 226 224 227 scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName(FUNCTIONLIBRARY), operatorLibrary));225 scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName(FUNCTIONLIBRARY), functionLibrary)); 228 226 229 227 return null; 230 228 } 231 229 232 private void ConditionalAddOperator(string condName, IOperator op, List<IOperator> list) { 233 if (GetVariableValue<BoolData>(condName, null, false).Data) list.Add(op); 234 } 235 236 private void ConditionalAddOperator(string condName, GPOperatorLibrary operatorLibrary, IOperator op) { 237 if (GetVariableValue<BoolData>(condName, null, false).Data) operatorLibrary.GPOperatorGroup.AddOperator(op); 238 } 239 240 private void SetAllowedSubOperators(IFunction f, List<IOperator> gs) { 241 foreach (IConstraint c in f.Constraints) { 242 if (c is SubOperatorTypeConstraint) { 243 SubOperatorTypeConstraint typeConstraint = c as SubOperatorTypeConstraint; 244 typeConstraint.Clear(); 245 foreach (IOperator g in gs) { 246 typeConstraint.AddOperator(g); 247 } 248 } else if (c is AllSubOperatorsTypeConstraint) { 249 AllSubOperatorsTypeConstraint typeConstraint = c as AllSubOperatorsTypeConstraint; 250 typeConstraint.Clear(); 251 foreach (IOperator g in gs) { 252 typeConstraint.AddOperator(g); 253 } 254 } 230 private void ConditionalAddFunction(string condName, IFunction fun, List<IFunction> list) { 231 if (GetVariableValue<BoolData>(condName, null, false).Data) list.Add(fun); 232 } 233 234 private void ConditionalAddOperator(string condName, FunctionLibrary functionLib, IFunction op) { 235 if (GetVariableValue<BoolData>(condName, null, false).Data) functionLib.AddFunction(op); 236 } 237 238 private void SetAllowedSubOperators(IFunction f, List<IFunction> gs) { 239 for (int i = 0; i < f.MaxArity; i++) { 240 SetAllowedSubOperators(f, i, gs); 255 241 } 256 242 } 257 243 258 private void SetAllowedSubOperators(IFunction f, int p, List<IOperator> gs) { 259 foreach (IConstraint c in f.Constraints) { 260 if (c is SubOperatorTypeConstraint) { 261 SubOperatorTypeConstraint typeConstraint = c as SubOperatorTypeConstraint; 262 if (typeConstraint.SubOperatorIndex.Data == p) { 263 typeConstraint.Clear(); 264 foreach (IOperator g in gs) { 265 typeConstraint.AddOperator(g); 266 } 267 } 268 } 269 } 244 private void SetAllowedSubOperators(IFunction f, int i, List<IFunction> gs) { 245 gs.ForEach((g) => f.AddAllowedSubFunction(g, i)); 270 246 } 271 247 } -
branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/GreaterThan.cs
r1529 r2202 27 27 28 28 namespace HeuristicLab.GP.StructureIdentification { 29 public sealed class GreaterThan : FunctionBase{29 public sealed class GreaterThan : BinaryFunction { 30 30 public override string Description { 31 31 get { … … 34 34 } 35 35 36 public GreaterThan() 37 : base() { 38 AddConstraint(new NumberOfSubOperatorsConstraint(2, 2)); 39 AddConstraint(new SubOperatorTypeConstraint(0)); 40 AddConstraint(new SubOperatorTypeConstraint(1)); 41 } 36 public GreaterThan() : base() { } 42 37 } 43 38 } -
branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/HeuristicLab.GP.StructureIdentification-3.3.csproj
r2041 r2202 86 86 <Compile Include="Average.cs" /> 87 87 <Compile Include="BakedTreeEvaluator.cs" /> 88 <Compile Include="BaseClasses\BinaryFunction.cs" /> 89 <Compile Include="BaseClasses\Terminal.cs" /> 90 <Compile Include="BaseClasses\UnaryFunction.cs" /> 88 91 <Compile Include="Constant.cs" /> 89 92 <Compile Include="AlgorithmBase.cs" /> -
branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/IfThenElse.cs
r1529 r2202 38 38 public IfThenElse() 39 39 : base() { 40 AddConstraint(new NumberOfSubOperatorsConstraint(3, 3)); 41 AddConstraint(new SubOperatorTypeConstraint(0)); 42 AddConstraint(new SubOperatorTypeConstraint(1)); 43 AddConstraint(new SubOperatorTypeConstraint(2)); 40 MinArity = 3; MaxArity = 3; 44 41 } 45 42 } -
branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/LessThan.cs
r1529 r2202 28 28 29 29 namespace HeuristicLab.GP.StructureIdentification { 30 public sealed class LessThan : FunctionBase{30 public sealed class LessThan : BinaryFunction { 31 31 public override string Description { 32 32 get { … … 37 37 public LessThan() 38 38 : base() { 39 AddConstraint(new NumberOfSubOperatorsConstraint(2, 2));40 AddConstraint(new SubOperatorTypeConstraint(0));41 AddConstraint(new SubOperatorTypeConstraint(1));42 39 } 43 40 } -
branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Logarithm.cs
r1529 r2202 29 29 30 30 namespace HeuristicLab.GP.StructureIdentification { 31 public sealed class Logarithm : FunctionBase{31 public sealed class Logarithm : UnaryFunction { 32 32 public override string Description { 33 33 get { return "Returns the natural (base e) logarithm of the first sub-tree."; } … … 36 36 public Logarithm() 37 37 : base() { 38 // must have exactly 1 suboperator39 AddConstraint(new NumberOfSubOperatorsConstraint(1, 1));40 AddConstraint(new SubOperatorTypeConstraint(0));41 38 } 42 39 } -
branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Multiplication.cs
r1529 r2202 43 43 : base() { 44 44 // 2 - 3 seems like an reasonable defaut (used for +,-,*,/) (discussion with swinkler and maffenze) 45 AddConstraint(new NumberOfSubOperatorsConstraint(2, 3)); 46 AddConstraint(new SubOperatorTypeConstraint(0)); 47 AddConstraint(new SubOperatorTypeConstraint(1)); 48 AddConstraint(new SubOperatorTypeConstraint(2)); 45 MinArity = 2; MaxArity = 3; 49 46 } 50 47 } -
branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Not.cs
r1529 r2202 28 28 29 29 namespace HeuristicLab.GP.StructureIdentification { 30 public sealed class Not : FunctionBase{30 public sealed class Not : UnaryFunction { 31 31 public override string Description { 32 32 get { … … 37 37 public Not() 38 38 : base() { 39 AddConstraint(new NumberOfSubOperatorsConstraint(1, 1));40 AddConstraint(new SubOperatorTypeConstraint(0));41 39 } 42 40 } -
branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Or.cs
r1529 r2202 31 31 public override string Description { 32 32 get { 33 return @"Logical OR operation. Only defined for sub-tree-results 0.0 and 1.0. 34 Special form, evaluation stops at first sub-tree that evaluates to 1.0 (true)."; 33 return @"Logical OR operation. Only defined for sub-tree-results 0.0 and 1.0."; 35 34 } 36 35 } … … 38 37 public Or() 39 38 : base() { 40 AddConstraint(new NumberOfSubOperatorsConstraint(2, 3)); 41 AddConstraint(new SubOperatorTypeConstraint(0)); 42 AddConstraint(new SubOperatorTypeConstraint(1)); 43 AddConstraint(new SubOperatorTypeConstraint(2)); 39 MinArity = 2; MaxArity = 3; 44 40 } 45 41 } -
branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Power.cs
r1529 r2202 29 29 30 30 namespace HeuristicLab.GP.StructureIdentification { 31 public sealed class Power : FunctionBase{31 public sealed class Power : BinaryFunction { 32 32 public override string Description { 33 33 get { return "Returns the result of the first sub-tree to the power of the second sub-tree (power(x, y))."; } … … 36 36 public Power() 37 37 : base() { 38 // must have exactly 2 suboperators base ^ exponent39 AddConstraint(new NumberOfSubOperatorsConstraint(2, 2));40 AddConstraint(new SubOperatorTypeConstraint(0));41 AddConstraint(new SubOperatorTypeConstraint(1));42 38 } 43 39 } -
branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Signum.cs
r1529 r2202 29 29 30 30 namespace HeuristicLab.GP.StructureIdentification { 31 public sealed class Signum : FunctionBase{31 public sealed class Signum : UnaryFunction { 32 32 public override string Description { 33 33 get { return "Returns the signum of the first sub-tree."; } … … 36 36 public Signum() 37 37 : base() { 38 // must have exactly 1 suboperator39 AddConstraint(new NumberOfSubOperatorsConstraint(1, 1));40 AddConstraint(new SubOperatorTypeConstraint(0));41 38 } 42 39 } -
branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Sinus.cs
r1529 r2202 29 29 30 30 namespace HeuristicLab.GP.StructureIdentification { 31 public sealed class Sinus : FunctionBase{31 public sealed class Sinus : UnaryFunction { 32 32 public override string Description { 33 33 get { return "Returns the sinus of the first sub-tree."; } … … 36 36 public Sinus() 37 37 : base() { 38 // must have exactly 1 suboperator39 AddConstraint(new NumberOfSubOperatorsConstraint(1, 1));40 AddConstraint(new SubOperatorTypeConstraint(0));41 38 } 42 39 } -
branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Sqrt.cs
r1529 r2202 29 29 30 30 namespace HeuristicLab.GP.StructureIdentification { 31 public sealed class Sqrt : FunctionBase{31 public sealed class Sqrt : UnaryFunction { 32 32 public override string Description { 33 33 get { return "Returns the square root of the first sub-tree."; } … … 36 36 public Sqrt() 37 37 : base() { 38 // must have exactly 1 suboperator39 AddConstraint(new NumberOfSubOperatorsConstraint(1, 1));40 AddConstraint(new SubOperatorTypeConstraint(0));41 38 } 42 39 } -
branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Subtraction.cs
r2054 r2202 30 30 31 31 namespace HeuristicLab.GP.StructureIdentification { 32 public sealed class Subtraction : FunctionBase{32 public sealed class Subtraction : BinaryFunction { 33 33 public override string Description { 34 34 get { … … 42 42 public Subtraction() 43 43 : base() { 44 // 2 - 3 seems like an reasonable defaut (used for +,-,*,/) (discussion with swinkler and maffenze)45 //MK changed to only 2 allowed suboperators to be compliant with HL246 AddConstraint(new NumberOfSubOperatorsConstraint(2, 2));47 AddConstraint(new SubOperatorTypeConstraint(0));48 AddConstraint(new SubOperatorTypeConstraint(1));49 44 } 50 45 } -
branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Tangens.cs
r1529 r2202 29 29 30 30 namespace HeuristicLab.GP.StructureIdentification { 31 public sealed class Tangens : FunctionBase{31 public sealed class Tangens : UnaryFunction { 32 32 public override string Description { 33 33 get { return "Returns the tangens of the first sub-tree."; } … … 36 36 public Tangens() 37 37 : base() { 38 // must have exactly one suboperator39 AddConstraint(new NumberOfSubOperatorsConstraint(1, 1));40 AddConstraint(new SubOperatorTypeConstraint(0));41 38 } 42 39 } -
branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/TreeEvaluatorBase.cs
r2174 r2202 28 28 using System.Diagnostics; 29 29 using HeuristicLab.DataAnalysis; 30 using HeuristicLab.Data; 30 31 31 32 namespace HeuristicLab.GP.StructureIdentification { … … 78 79 case EvaluatorSymbolTable.DIFFERENTIAL: 79 80 case EvaluatorSymbolTable.VARIABLE: { 80 instr.i_arg0 = (short)dataset.GetVariableIndex(( string)f.localData[0]); // var81 instr.d_arg0 = ( double)f.localData[1]; // weight82 instr.i_arg1 = (short)( int)f.localData[2]; // sample-offset81 instr.i_arg0 = (short)dataset.GetVariableIndex((((StringData)f.localData[1].Value).Data)); // var 82 instr.d_arg0 = ((DoubleData)f.localData[0].Value).Data; // weight 83 instr.i_arg1 = (short)((ConstrainedIntData)f.localData[2].Value).Data; // sample-offset 83 84 break; 84 85 } 85 86 case EvaluatorSymbolTable.CONSTANT: { 86 instr.d_arg0 = ( double)f.localData[0]; // value87 instr.d_arg0 = ((DoubleData)f.localData[0].Value).Data; // value 87 88 break; 88 89 } -
branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Variable.cs
r2174 r2202 32 32 33 33 namespace HeuristicLab.GP.StructureIdentification { 34 public class Variable : FunctionBase { 35 34 public class Variable : Terminal { 36 35 public const string WEIGHT = "Weight"; 37 36 public const string OFFSET = "SampleOffset"; 38 37 public const string INDEX = "Variable"; 38 39 private BakedFunctionTree variableNodeTemplate; 39 40 40 41 private int minOffset; … … 49 50 } 50 51 52 public override IEnumerable<string> LocalParameterNames { 53 get { 54 return new string[] { WEIGHT, OFFSET, INDEX }; 55 } 56 } 57 58 public override IFunctionTree GetTreeNode() { 59 return (IFunctionTree)variableNodeTemplate.Clone(); 60 } 61 51 62 public Variable() 52 63 : base() { 53 AddVariableInfo(new VariableInfo(INDEX, "The variable name", typeof(StringData), VariableKind.None)); 54 GetVariableInfo(INDEX).Local = true; 55 AddVariableInfo(new VariableInfo(WEIGHT, "Weight is multiplied to the feature value", typeof(DoubleData), VariableKind.None)); 56 GetVariableInfo(WEIGHT).Local = true; 57 AddVariableInfo(new VariableInfo(OFFSET, "SampleOffset is added to the sample index", typeof(ConstrainedIntData), VariableKind.None)); 58 GetVariableInfo(OFFSET).Local = true; 59 AddVariableInfo(new VariableInfo(INITIALIZATION, "Initialization operator for variables", typeof(CombinedOperator), VariableKind.None)); 60 GetVariableInfo(INITIALIZATION).Local = false; 61 AddVariableInfo(new VariableInfo(MANIPULATION, "Manipulation operator for variables", typeof(CombinedOperator), VariableKind.None)); 62 GetVariableInfo(MANIPULATION).Local = false; 64 //AddVariableInfo(new VariableInfo(INDEX, "The variable name", typeof(StringData), VariableKind.None)); 65 //GetVariableInfo(INDEX).Local = true; 66 //AddVariableInfo(new VariableInfo(WEIGHT, "Weight is multiplied to the feature value", typeof(DoubleData), VariableKind.None)); 67 //GetVariableInfo(WEIGHT).Local = true; 68 //AddVariableInfo(new VariableInfo(OFFSET, "SampleOffset is added to the sample index", typeof(ConstrainedIntData), VariableKind.None)); 69 //GetVariableInfo(OFFSET).Local = true; 70 variableNodeTemplate = new BakedFunctionTree(this); 63 71 64 72 DoubleData weight = new DoubleData(); 65 AddVariable(new HeuristicLab.Core.Variable(WEIGHT, weight));73 variableNodeTemplate.AddVariable(new HeuristicLab.Core.Variable(WEIGHT, weight)); 66 74 67 75 StringData variable = new StringData(); 68 AddVariable(new HeuristicLab.Core.Variable(INDEX, variable));76 variableNodeTemplate.AddVariable(new HeuristicLab.Core.Variable(INDEX, variable)); 69 77 70 78 ConstrainedIntData sampleOffset = new ConstrainedIntData(); 71 AddVariable(new HeuristicLab.Core.Variable(OFFSET, sampleOffset));79 variableNodeTemplate.AddVariable(new HeuristicLab.Core.Variable(OFFSET, sampleOffset)); 72 80 73 81 SetupInitialization(); 74 82 SetupManipulation(); 75 76 // variable can't have suboperators77 AddConstraint(new NumberOfSubOperatorsConstraint(0, 0));78 83 } 79 84 … … 104 109 seq.AddSubOperator(weightRandomizer); 105 110 seq.AddSubOperator(offsetRandomizer); 106 HeuristicLab.Core.IVariable initOp = GetVariable(INITIALIZATION); 107 if(initOp == null) { 108 AddVariable(new HeuristicLab.Core.Variable(INITIALIZATION, combinedOp)); 109 } else { 110 initOp.Value = combinedOp; 111 } 111 Initializer = combinedOp; 112 112 } 113 113 … … 139 139 seq.AddSubOperator(weightRandomAdder); 140 140 seq.AddSubOperator(offsetRandomAdder); 141 HeuristicLab.Core.IVariable manipulationOp = GetVariable(MANIPULATION); 142 if(manipulationOp == null) { 143 AddVariable(new HeuristicLab.Core.Variable(MANIPULATION, combinedOp)); 144 } else { 145 manipulationOp.Value = combinedOp; 146 } 141 Manipulator = combinedOp; 147 142 } 148 143 149 144 public void SetConstraints(int minSampleOffset, int maxSampleOffset) { 150 ConstrainedIntData offset = GetVariableValue<ConstrainedIntData>(OFFSET, null, false);145 ConstrainedIntData offset = (ConstrainedIntData)variableNodeTemplate.GetLocalVariable(OFFSET).Value; 151 146 IntBoundedConstraint offsetConstraint = new IntBoundedConstraint(); 152 147 this.minOffset = minSampleOffset; -
branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Xor.cs
r1529 r2202 28 28 29 29 namespace HeuristicLab.GP.StructureIdentification { 30 public sealed class Xor : FunctionBase{30 public sealed class Xor : BinaryFunction { 31 31 public override string Description { 32 32 get { … … 37 37 public Xor() 38 38 : base() { 39 AddConstraint(new NumberOfSubOperatorsConstraint(2, 2));40 AddConstraint(new SubOperatorTypeConstraint(0));41 AddConstraint(new SubOperatorTypeConstraint(1));42 39 } 43 40 }
Note: See TracChangeset
for help on using the changeset viewer.