- Timestamp:
- 05/27/09 13:46:46 (15 years ago)
- Location:
- trunk/sources
- Files:
-
- 2 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.GP.StructureIdentification.TimeSeries/3.3/HeuristicLab.GP.StructureIdentification.TimeSeries-3.3.csproj
r1856 r1908 83 83 <ItemGroup> 84 84 <Compile Include="AveragePercentageChangeEvaluator.cs" /> 85 <Compile Include="FunctionLibraryInjector.cs">86 <SubType>Code</SubType>87 </Compile>88 85 <Compile Include="HeuristicLabGPTimeSeriesPlugin.cs" /> 89 86 <Compile Include="OffspringSelectionGP.cs" /> -
trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/FunctionLibraryInjector.cs
r1540 r1908 32 32 namespace HeuristicLab.GP.StructureIdentification { 33 33 public class FunctionLibraryInjector : OperatorBase { 34 private const string FUNCTIONLIBRARY = "FunctionLibrary"; 34 35 private const string TARGETVARIABLE = "TargetVariable"; 35 36 private const string ALLOWEDFEATURES = "AllowedFeatures"; 36 protected const string FUNCTIONLIBRARY = "FunctionLibrary"; 37 private const string AUTOREGRESSIVE = "Autoregressive"; 38 private const string MINTIMEOFFSET = "MinTimeOffset"; 39 private const string MAXTIMEOFFSET = "MaxTimeOffset"; 40 41 private const string DIFFERENTIALS_ALLOWED = "Differentials"; 42 private const string VARIABLES_ALLOWED = "Variables"; 43 private const string CONSTANTS_ALLOWED = "Constants"; 44 private const string ADDITION_ALLOWED = "Addition"; 45 private const string AVERAGE_ALLOWED = "Average"; 46 private const string AND_ALLOWED = "And"; 47 private const string COSINUS_ALLOWED = "Cosinus"; 48 private const string DIVISION_ALLOWED = "Division"; 49 private const string EQUAL_ALLOWED = "Equal"; 50 private const string EXPONENTIAL_ALLOWED = "Exponential"; 51 private const string GREATERTHAN_ALLOWED = "GreaterThan"; 52 private const string IFTHENELSE_ALLOWED = "IfThenElse"; 53 private const string LESSTHAN_ALLOWED = "LessThan"; 54 private const string LOGARTIHM_ALLOWED = "Logarithm"; 55 private const string MULTIPLICATION_ALLOWED = "Multiplication"; 56 private const string NOT_ALLOWED = "Not"; 57 private const string POWER_ALLOWED = "Power"; 58 private const string OR_ALLOWED = "Or"; 59 private const string SIGNUM_ALLOWED = "Signum"; 60 private const string SINUS_ALLOWED = "Sinus"; 61 private const string SQRT_ALLOWED = "SquareRoot"; 62 private const string SUBTRACTION_ALLOWED = "Subtraction"; 63 private const string TANGENS_ALLOWED = "Tangens"; 64 private const string XOR_ALLOWED = "Xor"; 65 37 66 38 67 public override string Description { 39 get { return @"Injects a defaultfunction library for regression and classification problems."; }68 get { return @"Injects a configurable function library for regression and classification problems."; } 40 69 } 41 70 … … 44 73 AddVariableInfo(new VariableInfo(TARGETVARIABLE, "The target variable", typeof(IntData), VariableKind.In)); 45 74 AddVariableInfo(new VariableInfo(ALLOWEDFEATURES, "List of indexes of allowed features", typeof(ItemList<IntData>), VariableKind.In)); 75 AddVariableInfo(new Core.VariableInfo(AUTOREGRESSIVE, "Switch to turn on/off autoregressive modeling (wether to allow the target variable as input)", typeof(BoolData), Core.VariableKind.In)); 76 AddVariableInfo(new Core.VariableInfo(MINTIMEOFFSET, "Minimal time offset for all features", typeof(IntData), Core.VariableKind.In)); 77 AddVariableInfo(new Core.VariableInfo(MAXTIMEOFFSET, "Maximal time offset for all feature", typeof(IntData), Core.VariableKind.In)); 46 78 AddVariableInfo(new VariableInfo(FUNCTIONLIBRARY, "Preconfigured default operator library", typeof(GPOperatorLibrary), VariableKind.New)); 79 80 AddVariable(DIFFERENTIALS_ALLOWED, false); 81 AddVariable(VARIABLES_ALLOWED, true); 82 AddVariable(CONSTANTS_ALLOWED, true); 83 AddVariable(ADDITION_ALLOWED, true); 84 AddVariable(AVERAGE_ALLOWED, false); 85 AddVariable(AND_ALLOWED, true); 86 AddVariable(COSINUS_ALLOWED, true); 87 AddVariable(DIVISION_ALLOWED, true); 88 AddVariable(EQUAL_ALLOWED, true); 89 AddVariable(EXPONENTIAL_ALLOWED, true); 90 AddVariable(GREATERTHAN_ALLOWED, true); 91 AddVariable(IFTHENELSE_ALLOWED, true); 92 AddVariable(LESSTHAN_ALLOWED, true); 93 AddVariable(LOGARTIHM_ALLOWED, true); 94 AddVariable(MULTIPLICATION_ALLOWED, true); 95 AddVariable(NOT_ALLOWED, true); 96 AddVariable(POWER_ALLOWED, true); 97 AddVariable(OR_ALLOWED, true); 98 AddVariable(SIGNUM_ALLOWED, true); 99 AddVariable(SINUS_ALLOWED, true); 100 AddVariable(SQRT_ALLOWED, true); 101 AddVariable(SUBTRACTION_ALLOWED, true); 102 AddVariable(TANGENS_ALLOWED, true); 103 AddVariable(XOR_ALLOWED, false); 104 } 105 106 private void AddVariable(string name, bool allowed) { 107 AddVariableInfo(new VariableInfo(name, name + " allowed", typeof(BoolData), Core.VariableKind.New)); 108 GetVariableInfo(name).Local = true; 109 AddVariable(new Core.Variable(name, new BoolData(allowed))); 47 110 } 48 111 … … 53 116 ItemList<IntData> allowedFeatures = GetVariableValue<ItemList<IntData>>(ALLOWEDFEATURES, scope, true); 54 117 int targetVariable = GetVariableValue<IntData>(TARGETVARIABLE, scope, true).Data; 55 56 // remove the target-variable in case it occures in allowed features 57 List<IntData> ts = allowedFeatures.FindAll(d => d.Data == targetVariable); 58 foreach (IntData t in ts) allowedFeatures.Remove(t); 118 int minTimeOffset = GetVariableValue<IntData>(MINTIMEOFFSET, scope, true).Data; 119 int maxTimeOffset = GetVariableValue<IntData>(MAXTIMEOFFSET, scope, true).Data; 120 bool autoregressive = GetVariableValue<BoolData>(AUTOREGRESSIVE, scope, true).Data; 121 122 if (autoregressive) { 123 // make sure the target-variable occures in list of allowed features 124 if (!allowedFeatures.Exists(d => d.Data == targetVariable)) allowedFeatures.Add(new IntData(targetVariable)); 125 } else { 126 // remove the target-variable in case it occures in allowed features 127 List<IntData> ts = allowedFeatures.FindAll(d => d.Data == targetVariable); 128 foreach (IntData t in ts) allowedFeatures.Remove(t); 129 } 59 130 60 131 variable = new StructId.Variable(); 61 132 StructId.Constant constant = new StructId.Constant(); 62 133 StructId.Differential differential = new Differential(); 63 134 StructId.Addition addition = new StructId.Addition(); 64 135 StructId.And and = new StructId.And(); … … 93 164 }; 94 165 IFunction[] doubleFunctions = new IFunction[] { 166 differential, 95 167 variable, 96 168 constant, … … 136 208 137 209 operatorLibrary = new GPOperatorLibrary(); 138 operatorLibrary.GPOperatorGroup.AddOperator(variable); 139 operatorLibrary.GPOperatorGroup.AddOperator(constant); 140 operatorLibrary.GPOperatorGroup.AddOperator(addition); 141 operatorLibrary.GPOperatorGroup.AddOperator(average); 142 operatorLibrary.GPOperatorGroup.AddOperator(and); 143 operatorLibrary.GPOperatorGroup.AddOperator(cosinus); 144 operatorLibrary.GPOperatorGroup.AddOperator(division); 145 operatorLibrary.GPOperatorGroup.AddOperator(equal); 146 operatorLibrary.GPOperatorGroup.AddOperator(exponential); 147 operatorLibrary.GPOperatorGroup.AddOperator(greaterThan); 148 operatorLibrary.GPOperatorGroup.AddOperator(ifThenElse); 149 operatorLibrary.GPOperatorGroup.AddOperator(lessThan); 150 operatorLibrary.GPOperatorGroup.AddOperator(logarithm); 151 operatorLibrary.GPOperatorGroup.AddOperator(multiplication); 152 operatorLibrary.GPOperatorGroup.AddOperator(not); 153 operatorLibrary.GPOperatorGroup.AddOperator(power); 154 operatorLibrary.GPOperatorGroup.AddOperator(or); 155 operatorLibrary.GPOperatorGroup.AddOperator(signum); 156 operatorLibrary.GPOperatorGroup.AddOperator(sinus); 157 operatorLibrary.GPOperatorGroup.AddOperator(sqrt); 158 operatorLibrary.GPOperatorGroup.AddOperator(subtraction); 159 operatorLibrary.GPOperatorGroup.AddOperator(tangens); 160 operatorLibrary.GPOperatorGroup.AddOperator(xor); 210 ConditionalAddOperator(DIFFERENTIALS_ALLOWED, operatorLibrary, differential); 211 ConditionalAddOperator(VARIABLES_ALLOWED, operatorLibrary, variable); 212 ConditionalAddOperator(CONSTANTS_ALLOWED, operatorLibrary, constant); 213 ConditionalAddOperator(ADDITION_ALLOWED, operatorLibrary, addition); 214 ConditionalAddOperator(AVERAGE_ALLOWED, operatorLibrary, average); 215 ConditionalAddOperator(AND_ALLOWED, operatorLibrary, and); 216 ConditionalAddOperator(COSINUS_ALLOWED, operatorLibrary, cosinus); 217 ConditionalAddOperator(DIVISION_ALLOWED, operatorLibrary, division); 218 ConditionalAddOperator(EQUAL_ALLOWED, operatorLibrary, equal); 219 ConditionalAddOperator(EXPONENTIAL_ALLOWED, operatorLibrary, exponential); 220 ConditionalAddOperator(GREATERTHAN_ALLOWED, operatorLibrary, greaterThan); 221 ConditionalAddOperator(IFTHENELSE_ALLOWED, operatorLibrary, ifThenElse); 222 ConditionalAddOperator(LESSTHAN_ALLOWED, operatorLibrary, lessThan); 223 ConditionalAddOperator(LOGARTIHM_ALLOWED, operatorLibrary, logarithm); 224 ConditionalAddOperator(MULTIPLICATION_ALLOWED, operatorLibrary, multiplication); 225 ConditionalAddOperator(NOT_ALLOWED, operatorLibrary, not); 226 ConditionalAddOperator(POWER_ALLOWED, operatorLibrary, power); 227 ConditionalAddOperator(OR_ALLOWED, operatorLibrary, or); 228 ConditionalAddOperator(SIGNUM_ALLOWED, operatorLibrary, signum); 229 ConditionalAddOperator(SINUS_ALLOWED, operatorLibrary, sinus); 230 ConditionalAddOperator(SQRT_ALLOWED, operatorLibrary, sqrt); 231 ConditionalAddOperator(SUBTRACTION_ALLOWED, operatorLibrary, subtraction); 232 ConditionalAddOperator(TANGENS_ALLOWED, operatorLibrary, tangens); 233 ConditionalAddOperator(XOR_ALLOWED, operatorLibrary, xor); 161 234 162 235 int[] allowedIndexes = new int[allowedFeatures.Count]; … … 165 238 } 166 239 167 variable.SetConstraints(allowedIndexes, 0, 0); 240 variable.SetConstraints(allowedIndexes, minTimeOffset, maxTimeOffset); 241 differential.SetConstraints(allowedIndexes, minTimeOffset, maxTimeOffset); 168 242 169 243 scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName(FUNCTIONLIBRARY), operatorLibrary)); 244 170 245 return null; 246 } 247 248 private void ConditionalAddOperator(string condName, GPOperatorLibrary operatorLibrary, IOperator op) { 249 if (GetVariableValue<BoolData>(condName, null, false).Data) operatorLibrary.GPOperatorGroup.AddOperator(op); 171 250 } 172 251 -
trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/HeuristicLab.GP.StructureIdentification-3.3.csproj
r1894 r1908 86 86 <Compile Include="Average.cs" /> 87 87 <Compile Include="BakedTreeEvaluator.cs" /> 88 <Compile Include="ConfigurableFunctionLibraryInjector.cs" />89 88 <Compile Include="Constant.cs" /> 90 89 <Compile Include="AlgorithmBase.cs" /> -
trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/StandardGP.cs
r1906 r1908 142 142 143 143 protected internal override IOperator CreateFunctionLibraryInjector() { 144 ConfigurableFunctionLibraryInjector funLibInjector = new ConfigurableFunctionLibraryInjector();144 FunctionLibraryInjector funLibInjector = new FunctionLibraryInjector(); 145 145 funLibInjector.GetVariableValue<BoolData>("Xor", null, false).Data = false; 146 146 funLibInjector.GetVariableValue<BoolData>("Average", null, false).Data = false;
Note: See TracChangeset
for help on using the changeset viewer.