- Timestamp:
- 07/30/09 19:41:58 (15 years ago)
- Location:
- branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/FunctionLibraryInjector.cs
r2212 r2216 24 24 using HeuristicLab.Data; 25 25 using HeuristicLab.GP.Interfaces; 26 using HeuristicLab.GP.SantaFe; 26 27 27 28 namespace HeuristicLab.GP.StructureIdentification { 28 public class FunctionLibraryInjector : OperatorBase { 29 private const string FUNCTIONLIBRARY = "FunctionLibrary"; 30 private const string TARGETVARIABLE = "TargetVariable"; 29 public class FunctionLibraryInjector : FunctionLibraryInjectorBase { 31 30 private const string MINTIMEOFFSET = "MinTimeOffset"; 32 31 private const string MAXTIMEOFFSET = "MaxTimeOffset"; … … 57 56 private const string XOR_ALLOWED = "Xor"; 58 57 58 private int minTimeOffset; 59 private int maxTimeOffset; 59 60 60 61 public override string Description { … … 64 65 public FunctionLibraryInjector() 65 66 : base() { 66 AddVariableInfo(new VariableInfo(TARGETVARIABLE, "The target variable", typeof(IntData), VariableKind.In));67 67 AddVariableInfo(new VariableInfo(MINTIMEOFFSET, "Minimal time offset for all features", typeof(IntData), VariableKind.In)); 68 68 AddVariableInfo(new VariableInfo(MAXTIMEOFFSET, "Maximal time offset for all feature", typeof(IntData), VariableKind.In)); 69 AddVariableInfo(new VariableInfo(FUNCTIONLIBRARY, "Preconfigured default function library", typeof(FunctionLibrary), VariableKind.New));70 69 71 70 AddVariable(DIFFERENTIALS_ALLOWED, false); … … 102 101 103 102 public override IOperation Apply(IScope scope) { 104 FunctionLibrary functionLibrary = new FunctionLibrary();105 int targetVariable = GetVariableValue<IntData>(TARGETVARIABLE, scope, true).Data;106 107 103 // try to get minTimeOffset (use 0 as default if not available) 108 104 IItem minTimeOffsetItem = GetVariableValue(MINTIMEOFFSET, scope, true, false); 109 intminTimeOffset = minTimeOffsetItem == null ? 0 : ((IntData)minTimeOffsetItem).Data;105 minTimeOffset = minTimeOffsetItem == null ? 0 : ((IntData)minTimeOffsetItem).Data; 110 106 // try to get maxTimeOffset (use 0 as default if not available) 111 107 IItem maxTimeOffsetItem = GetVariableValue(MAXTIMEOFFSET, scope, true, false); 112 int maxTimeOffset = maxTimeOffsetItem == null ? 0 : ((IntData)maxTimeOffsetItem).Data; 108 maxTimeOffset = maxTimeOffsetItem == null ? 0 : ((IntData)maxTimeOffsetItem).Data; 109 110 return base.Apply(scope); 111 } 112 113 protected override FunctionLibrary CreateFunctionLibrary() { 114 FunctionLibrary functionLibrary = new FunctionLibrary(); 113 115 114 116 Variable variable = new Variable(); … … 218 220 differential.SetConstraints(minTimeOffset, maxTimeOffset); 219 221 220 scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName(FUNCTIONLIBRARY), functionLibrary)); 221 222 return null; 222 return functionLibrary; 223 223 } 224 224 … … 230 230 if (GetVariableValue<BoolData>(condName, null, false).Data) functionLib.AddFunction(op); 231 231 } 232 233 private void SetAllowedSubOperators(IFunction f, List<IFunction> gs) {234 for (int i = 0; i < f.MaxSubTrees; i++) {235 SetAllowedSubOperators(f, i, gs);236 }237 }238 239 private void SetAllowedSubOperators(IFunction f, int i, List<IFunction> gs) {240 gs.ForEach((g) => f.AddAllowedSubFunction(g, i));241 }242 232 } 243 233 } -
branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/ModelAnalyzerExporter.cs
r2212 r2216 21 21 22 22 using HeuristicLab.GP.Interfaces; 23 using System; 23 24 24 25 namespace HeuristicLab.GP.StructureIdentification { 25 public class ModelAnalyzerExporter : IFunctionTree Exporter, IFunctionTreeNameGenerator {26 public class ModelAnalyzerExporter : IFunctionTreeSerializer, IFunctionTreeNameGenerator { 26 27 #region IFunctionTreeExporter Members 27 28 … … 53 54 if(tree.SubTrees.Count > 0) result += ")"; 54 55 return result; 56 } 57 58 public IFunctionTree Import(string tree) { 59 throw new UnknownFunctionException(tree); 60 } 61 62 public bool TryImport(string tree, out IFunctionTree importedTree) { 63 try { 64 importedTree = Import(tree); 65 return true; 66 } 67 catch (UnknownFunctionException) { 68 importedTree = null; 69 return false; 70 } 55 71 } 56 72 … … 104 120 105 121 #endregion 122 123 106 124 } 107 125 -
branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/SymbolicExpressionExporter.cs
r2212 r2216 22 22 using System.Text; 23 23 using HeuristicLab.GP.Interfaces; 24 using System; 25 using System.Collections.Generic; 24 26 25 27 namespace HeuristicLab.GP.StructureIdentification { 26 public class SymbolicExpressionExporter : IFunctionTree Exporter, IFunctionTreeNameGenerator {28 public class SymbolicExpressionExporter : IFunctionTreeSerializer, IFunctionTreeNameGenerator { 27 29 private StringBuilder builder; 28 30 private string currentIndent; … … 48 50 } catch(UnknownFunctionException) { 49 51 exported = ""; 52 return false; 53 } 54 } 55 56 public IFunctionTree Import(string tree) { 57 Queue<string> tokens = new Queue<string>(tree.Split(' ', '\n', '\t')); 58 return ParseTree(tokens); 59 } 60 61 private IFunctionTree ParseTree(Queue<string> tokens) { 62 Expect("(", tokens); 63 string funSymb = tokens.Peek(); 64 double constValue; 65 if (double.TryParse(funSymb, out constValue)) { 66 throw new UnknownFunctionException(funSymb); 67 } 68 switch (funSymb) { 69 case "variable": return ParseVariable(tokens); 70 case "differential": return ParseDifferential(tokens); 71 default: 72 IFunctionTree fNode = ParseFunction(tokens); 73 Expect(")", tokens); 74 return fNode; 75 } 76 77 } 78 79 private IFunctionTree ParseFunction(Queue<string> tokens) { 80 throw new UnknownFunctionException(tokens.Dequeue()); 81 } 82 83 private IFunctionTree ParseDifferential(Queue<string> tokens) { 84 throw new UnknownFunctionException(tokens.Dequeue()); 85 } 86 87 private IFunctionTree ParseVariable(Queue<string> tokens) { 88 throw new UnknownFunctionException(tokens.Dequeue()); 89 } 90 91 private void Expect(string p, Queue<string> tokens) { 92 throw new NotImplementedException(); 93 } 94 95 public bool TryImport(string tree, out IFunctionTree importedTree) { 96 try { 97 importedTree = Import(tree); 98 return true; 99 } 100 catch (UnknownFunctionException) { 101 importedTree = null; 50 102 return false; 51 103 } -
branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Symbols/Constant.cs
r2212 r2216 31 31 public override string Description { 32 32 get { return "Returns the value of local variable 'Value'."; } 33 }34 35 public override IEnumerable<string> LocalParameterNames {36 get {37 return new string[] { VALUE };38 }39 33 } 40 34 -
branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Symbols/ConstantFunctionTree.cs
r2212 r2216 26 26 27 27 namespace HeuristicLab.GP.StructureIdentification { 28 public class ConstantFunctionTree : FunctionTreeBase { 29 private static readonly IList<IFunctionTree> subTrees = new List<IFunctionTree>().AsReadOnly(); 28 public class ConstantFunctionTree : TerminalTreeNode { 30 29 public double Value { get; set; } 31 30 32 public ConstantFunctionTree(Constant constant) { 33 Function = constant; 31 public ConstantFunctionTree(Constant constant) : base(constant){ 34 32 } 35 33 36 protected ConstantFunctionTree(ConstantFunctionTree original) { 37 Function = original.Function; 34 protected ConstantFunctionTree(ConstantFunctionTree original) : base(original){ 38 35 Value = original.Value; 39 }40 41 public override IList<IFunctionTree> SubTrees {42 get {43 return subTrees;44 }45 36 } 46 37 -
branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Symbols/VariableFunctionTree.cs
r2212 r2216 26 26 27 27 namespace HeuristicLab.GP.StructureIdentification { 28 public class VariableFunctionTree : FunctionTreeBase { 29 private static readonly IList<IFunctionTree> subTrees = new List<IFunctionTree>().AsReadOnly(); 28 public class VariableFunctionTree : TerminalTreeNode { 30 29 public double Weight { get; set; } 31 30 public string VariableName { get; set; } 32 31 public int SampleOffset { get; set; } 33 32 34 public VariableFunctionTree(Variable variable) {35 Function = variable;33 public VariableFunctionTree(Variable variable) 34 : base(variable) { 36 35 } 37 36 38 protected VariableFunctionTree(VariableFunctionTree original) {39 Function = original.Function;37 protected VariableFunctionTree(VariableFunctionTree original) 38 : base(original) { 40 39 Weight = original.Weight; 41 40 VariableName = original.VariableName; 42 41 SampleOffset = original.SampleOffset; 43 }44 45 public override IList<IFunctionTree> SubTrees {46 get {47 return subTrees;48 }49 42 } 50 43 … … 66 59 public override IOperation CreateInitOperation(IScope scope) { 67 60 Scope myVariableScope = new Scope(); 68 scope.AddSubScope(myVariableScope); 61 scope.AddSubScope(myVariableScope); 69 62 myVariableScope.AddVariable(CreateWeightVariable()); 70 63 myVariableScope.AddVariable(CreateVariableNameVariable());
Note: See TracChangeset
for help on using the changeset viewer.