Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/29/09 18:28:45 (15 years ago)
Author:
gkronber
Message:

GP Refactoring #713

  • introduced a plugin for GP interfaces
  • created a new interface IGeneticProgrammingModel which represents GP models in HL scopes instead of IFunctionTree
  • changed interfaces IFunction and IFunctionTree
  • moved some files to new directories (general housekeeping)
  • changed all GP operators and engines to work with IGeneticProgrammingModels
  • removed parameters TreeSize and TreeHeight in all GP operators
  • changed parameter OperatorLibrary to FunctionLibrary in all GP operators
Location:
branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3
Files:
2 added
1 deleted
16 edited

Legend:

Unmodified
Added
Removed
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/AlgorithmBase.cs

    r2161 r2210  
    3636using HeuristicLab.Evolutionary;
    3737using HeuristicLab.Modeling;
     38using HeuristicLab.GP.Interfaces;
    3839
    3940namespace HeuristicLab.GP.StructureIdentification {
     
    419420      Model model = new Model();
    420421      Dataset ds = bestModelScope.GetVariableValue<Dataset>("Dataset", true);
    421       model.Data = bestModelScope.GetVariableValue<IFunctionTree>("FunctionTree", false);
     422      model.Data = bestModelScope.GetVariableValue<IGeneticProgrammingModel>("FunctionTree", false);
    422423      model.Dataset = ds;
    423424      model.TargetVariable = ds.GetVariableName(bestModelScope.GetVariableValue<IntData>("TargetVariable", true).Data);
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Constant.cs

    r2202 r2210  
    3030using HeuristicLab.Operators;
    3131using HeuristicLab.Random;
     32using HeuristicLab.GP.Interfaces;
    3233
    3334namespace HeuristicLab.GP.StructureIdentification {
    3435  public sealed class Constant : Terminal {
    3536    public const string VALUE = "Value";
    36     private BakedFunctionTree constantNodeTemplate;
    3737
    3838    public override string Description {
     
    4848    public Constant()
    4949      : base() {
    50       DoubleData valueData = new DoubleData();
    51       constantNodeTemplate = new BakedFunctionTree(this);
    52       constantNodeTemplate.AddVariable(new HeuristicLab.Core.Variable(VALUE, valueData));
    53 
    5450      SetupInitialization();
    5551      SetupManipulation();
     
    5753
    5854    public override IFunctionTree GetTreeNode() {
    59       return (IFunctionTree)constantNodeTemplate.Clone();
     55      return new ConstantFunctionTree(this);
    6056    }
    6157
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Evaluators/GPEvaluatorBase.cs

    r2130 r2210  
    2828using HeuristicLab.Operators;
    2929using HeuristicLab.DataAnalysis;
     30using HeuristicLab.GP.Interfaces;
    3031
    3132namespace HeuristicLab.GP.StructureIdentification {
     
    3435      : base() {
    3536      AddVariableInfo(new VariableInfo("TreeEvaluator", "The evaluator that should be used to evaluate the expression tree", typeof(ITreeEvaluator), VariableKind.In));
    36       AddVariableInfo(new VariableInfo("FunctionTree", "The function tree that should be evaluated", typeof(IFunctionTree), VariableKind.In));
    37       AddVariableInfo(new VariableInfo("TreeSize", "Size (number of nodes) of the tree to evaluate", typeof(IntData), VariableKind.In));
     37      AddVariableInfo(new VariableInfo("FunctionTree", "The function tree that should be evaluated", typeof(IGeneticProgrammingModel), VariableKind.In));
    3838      AddVariableInfo(new VariableInfo("Dataset", "Dataset with all samples on which to apply the function", typeof(Dataset), VariableKind.In));
    3939      AddVariableInfo(new VariableInfo("TargetVariable", "Index of the column of the dataset that holds the target variable", typeof(IntData), VariableKind.In));
     
    5151      int targetVariable = GetVariableValue<IntData>("TargetVariable", scope, true).Data;
    5252      Dataset dataset = GetVariableValue<Dataset>("Dataset", scope, true);
    53       IFunctionTree functionTree = GetVariableValue<IFunctionTree>("FunctionTree", scope, true);
     53      IGeneticProgrammingModel gpModel = GetVariableValue<IGeneticProgrammingModel>("FunctionTree", scope, true);
    5454      double punishmentFactor = GetVariableValue<DoubleData>("PunishmentFactor", scope, true).Data;
    55       int treeSize = scope.GetVariableValue<IntData>("TreeSize", true).Data;
    5655      double totalEvaluatedNodes = scope.GetVariableValue<DoubleData>("TotalEvaluatedNodes", true).Data;
    5756      int trainingStart = GetVariableValue<IntData>("TrainingSamplesStart", scope, true).Data;
     
    6160      bool useEstimatedValues = GetVariableValue<BoolData>("UseEstimatedTargetValue", scope, true).Data;
    6261      ITreeEvaluator evaluator = GetVariableValue<ITreeEvaluator>("TreeEvaluator", scope, true);
    63       evaluator.PrepareForEvaluation(dataset, targetVariable, trainingStart, trainingEnd, punishmentFactor, functionTree);
     62      evaluator.PrepareForEvaluation(dataset, targetVariable, trainingStart, trainingEnd, punishmentFactor, gpModel.FunctionTree);
    6463
    6564      double[] backupValues = null;
     
    8685
    8786      // update the value of total evaluated nodes
    88       scope.GetVariableValue<DoubleData>("TotalEvaluatedNodes", true).Data = totalEvaluatedNodes + treeSize * (end - start);
     87      scope.GetVariableValue<DoubleData>("TotalEvaluatedNodes", true).Data = totalEvaluatedNodes + gpModel.Size * (end - start);
    8988      return null;
    9089    }
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Evaluators/VariableEvaluationImpactCalculator.cs

    r2165 r2210  
    2828using HeuristicLab.DataAnalysis;
    2929using System.Linq;
     30using HeuristicLab.GP.Interfaces;
    3031
    3132namespace HeuristicLab.GP.StructureIdentification {
     
    3536      : base() {
    3637      AddVariableInfo(new VariableInfo("TreeEvaluator", "The evaluator that should be used to evaluate the expression tree", typeof(ITreeEvaluator), VariableKind.In));
    37       AddVariableInfo(new VariableInfo("FunctionTree", "The function tree that should be evaluated", typeof(IFunctionTree), VariableKind.In));
     38      AddVariableInfo(new VariableInfo("FunctionTree", "The function tree that should be evaluated", typeof(IGeneticProgrammingModel), VariableKind.In));
    3839      AddVariableInfo(new VariableInfo("TreeSize", "Size (number of nodes) of the tree to evaluate", typeof(IntData), VariableKind.In));
    3940      AddVariableInfo(new VariableInfo("PunishmentFactor", "Punishment factor for invalid estimations", typeof(DoubleData), VariableKind.In));
     
    4344    protected override double[] GetOutputs(IScope scope, Dataset dataset, int targetVariable, int start, int end) {
    4445      ITreeEvaluator evaluator = GetVariableValue<ITreeEvaluator>("TreeEvaluator", scope, true);
    45       IFunctionTree tree = GetVariableValue<IFunctionTree>("FunctionTree", scope, true);
     46      IGeneticProgrammingModel gpModel = GetVariableValue<IGeneticProgrammingModel>("FunctionTree", scope, true);
    4647      double punishmentFactor = GetVariableValue<DoubleData>("PunishmentFactor", scope, true).Data;
    47       evaluator.PrepareForEvaluation(dataset, targetVariable, start, end, punishmentFactor, tree);
     48      evaluator.PrepareForEvaluation(dataset, targetVariable, start, end, punishmentFactor, gpModel.FunctionTree);
    4849
    4950      double[] result = new double[end - start];
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Evaluators/VariableQualityImpactCalculator.cs

    r2165 r2210  
    2828using HeuristicLab.DataAnalysis;
    2929using System.Linq;
     30using HeuristicLab.GP.Interfaces;
    3031
    3132namespace HeuristicLab.GP.StructureIdentification {
     
    3536      : base() {
    3637      AddVariableInfo(new VariableInfo("TreeEvaluator", "The evaluator that should be used to evaluate the expression tree", typeof(ITreeEvaluator), VariableKind.In));
    37       AddVariableInfo(new VariableInfo("FunctionTree", "The function tree that should be evaluated", typeof(IFunctionTree), VariableKind.In));
     38      AddVariableInfo(new VariableInfo("FunctionTree", "The function tree that should be evaluated", typeof(IGeneticProgrammingModel), VariableKind.In));
    3839      AddVariableInfo(new VariableInfo("TreeSize", "Size (number of nodes) of the tree to evaluate", typeof(IntData), VariableKind.In));
    3940      AddVariableInfo(new VariableInfo("PunishmentFactor", "Punishment factor for invalid estimations", typeof(DoubleData), VariableKind.In));
     
    4243    protected override double CalculateQuality(IScope scope, Dataset dataset, int targetVariable, int start, int end) {
    4344      ITreeEvaluator evaluator = GetVariableValue<ITreeEvaluator>("TreeEvaluator", scope, true);
    44       IFunctionTree tree = GetVariableValue<IFunctionTree>("FunctionTree", scope, true);
     45      IGeneticProgrammingModel gpModel = GetVariableValue<IGeneticProgrammingModel>("FunctionTree", scope, true);
    4546      double punishmentFactor = GetVariableValue<DoubleData>("PunishmentFactor", scope, true).Data;
    46       evaluator.PrepareForEvaluation(dataset, targetVariable, start, end, punishmentFactor, tree);
     47      evaluator.PrepareForEvaluation(dataset, targetVariable, start, end, punishmentFactor, gpModel.FunctionTree);
    4748
    4849      double[,] result = new double[end - start, 2];
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/FunctionLibraryInjector.cs

    r2202 r2210  
    2929using HeuristicLab.Constraints;
    3030using StructId = HeuristicLab.GP.StructureIdentification;
     31using HeuristicLab.GP.Interfaces;
    3132
    3233namespace HeuristicLab.GP.StructureIdentification {
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/GreaterThan.cs

    r2202 r2210  
    3535
    3636    public GreaterThan() : base() { }
     37
    3738  }
    3839}
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/HeuristicLab.GP.StructureIdentification-3.3.csproj

    r2202 r2210  
    8686    <Compile Include="Average.cs" />
    8787    <Compile Include="BakedTreeEvaluator.cs" />
    88     <Compile Include="BaseClasses\BinaryFunction.cs" />
    89     <Compile Include="BaseClasses\Terminal.cs" />
    90     <Compile Include="BaseClasses\UnaryFunction.cs" />
    9188    <Compile Include="Constant.cs" />
    9289    <Compile Include="AlgorithmBase.cs" />
     90    <Compile Include="ConstantFunctionTree.cs" />
    9391    <Compile Include="Evaluators\SimpleGPEvaluatorBase.cs" />
     92    <Compile Include="VariableFunctionTree.cs" />
    9493    <Compile Include="TreeEvaluatorBase.cs" />
    9594    <Compile Include="HL2TreeEvaluator.cs" />
     
    168167      <Name>HeuristicLab.Evolutionary-3.2</Name>
    169168    </ProjectReference>
     169    <ProjectReference Include="..\..\HeuristicLab.GP.Interfaces\3.3\HeuristicLab.GP.Interfaces-3.3.csproj">
     170      <Project>{924B6BEA-9A99-40FE-9334-5C01E8D540EC}</Project>
     171      <Name>HeuristicLab.GP.Interfaces-3.3</Name>
     172    </ProjectReference>
    170173    <ProjectReference Include="..\..\HeuristicLab.GP\3.3\HeuristicLab.GP-3.3.csproj">
    171174      <Project>{1F1CF3ED-374C-4288-995B-93F6B872F571}</Project>
     
    221224    <None Include="HeuristicLab.snk" />
    222225    <None Include="Properties\AssemblyInfo.frame" />
     226  </ItemGroup>
     227  <ItemGroup>
     228    <Folder Include="BaseClasses\" />
    223229  </ItemGroup>
    224230  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/HeuristicLabGPStructureIdentificationPlugin.cs

    r1927 r2210  
    3434  [Dependency(Dependency = "HeuristicLab.Evolutionary-3.2")]
    3535  [Dependency(Dependency = "HeuristicLab.GP-3.3")]
     36  [Dependency(Dependency = "HeuristicLab.GP.Interfaces-3.3")]
    3637  [Dependency(Dependency = "HeuristicLab.Logging-3.2")]
    3738  [Dependency(Dependency = "HeuristicLab.Modeling-3.2")]
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/ITreeEvaluator.cs

    r2034 r2210  
    2828using System.Diagnostics;
    2929using HeuristicLab.DataAnalysis;
     30using HeuristicLab.GP.Interfaces;
    3031
    3132namespace HeuristicLab.GP.StructureIdentification {
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/ModelAnalyzerExporter.cs

    r2174 r2210  
    2525using System.Text;
    2626using HeuristicLab.Data;
     27using HeuristicLab.GP.Interfaces;
    2728
    2829namespace HeuristicLab.GP.StructureIdentification {
     
    120121
    121122    public static string ExportToHL2(this Constant constant, IFunctionTree tree) {
    122       HeuristicLab.Core.IItem constantItem = tree.GetLocalVariable(Constant.VALUE).Value;
    123       double value;
    124       if (constantItem is ConstrainedDoubleData) {
    125         value = ((ConstrainedDoubleData)constantItem).Data;
    126       } else {
    127         value = ((DoubleData)constantItem).Data;
    128       }
     123      double value = ((ConstantFunctionTree)tree).Value;
    129124      return "[T]Constant(" + value.ToString("r") + ";0;0)";
    130125    }
     
    135130
    136131    public static string ExportToHL2(this Differential differential, IFunctionTree tree) {
    137       HeuristicLab.Core.IItem weightItem = tree.GetLocalVariable(Differential.WEIGHT).Value;
    138       double weight;
    139       if (weightItem is ConstrainedDoubleData) {
    140         weight = ((ConstrainedDoubleData)weightItem).Data;
    141       } else {
    142         weight = ((DoubleData)weightItem).Data;
    143       }
    144       var index = tree.GetLocalVariable(Differential.INDEX).Value;
    145       var offset = ((ConstrainedDoubleData)tree.GetLocalVariable(Differential.OFFSET).Value).Data;
    146 
    147       return "[T]Differential(" + weight.ToString("r") + ";" + index + ";" + -offset + ")";
     132      var varTree = (VariableFunctionTree)tree;
     133      return "[T]Differential(" + varTree.Weight.ToString("r") + ";" + varTree.VariableName + ";" + -varTree.SampleOffset + ")";
    148134    }
    149135
     
    189175
    190176    public static string ExportToHL2(this Variable variable, IFunctionTree tree) {
    191       HeuristicLab.Core.IItem weightItem = tree.GetLocalVariable(Differential.WEIGHT).Value;
    192       double weight;
    193       if (weightItem is ConstrainedDoubleData) {
    194         weight = ((ConstrainedDoubleData)weightItem).Data;
    195       } else {
    196         weight = ((DoubleData)weightItem).Data;
    197       }
    198       string index = ((StringData)tree.GetLocalVariable(Variable.INDEX).Value).Data;
    199       double offset = ((ConstrainedIntData)tree.GetLocalVariable(Variable.OFFSET).Value).Data;
    200 
    201       return "[T]Variable(" + weight.ToString("r") + ";" + index + ";" + -offset + ")";
     177      var varTree = (VariableFunctionTree)tree;
     178      return "[T]Variable(" + varTree.Weight.ToString("r") + ";" + varTree.VariableName + ";" + -varTree.SampleOffset + ")";
    202179    }
    203180
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/StandardGP.cs

    r2161 r2210  
    159159      StandardCrossOver crossover = new StandardCrossOver();
    160160      crossover.Name = "Crossover";
    161       crossover.GetVariableInfo("OperatorLibrary").ActualName = "FunctionLibrary";
    162161      return crossover;
    163162    }
     
    166165      ProbabilisticTreeCreator treeCreator = new ProbabilisticTreeCreator();
    167166      treeCreator.Name = "Tree generator";
    168       treeCreator.GetVariableInfo("OperatorLibrary").ActualName = "FunctionLibrary";
    169167      treeCreator.GetVariableInfo("MinTreeSize").ActualName = "MinInitialTreeSize";
    170168      return treeCreator;
     
    183181      StochasticMultiBranch multibranch = new StochasticMultiBranch();
    184182      FullTreeShaker fullTreeShaker = new FullTreeShaker();
    185       fullTreeShaker.GetVariableInfo("OperatorLibrary").ActualName = "FunctionLibrary";
    186183      fullTreeShaker.GetVariableInfo("ShakingFactor").ActualName = "FullTreeShakingFactor";
    187184
    188185      OnePointShaker onepointShaker = new OnePointShaker();
    189       onepointShaker.GetVariableInfo("OperatorLibrary").ActualName = "FunctionLibrary";
    190186      onepointShaker.GetVariableInfo("ShakingFactor").ActualName = "OnePointShakingFactor";
    191187      ChangeNodeTypeManipulation changeNodeTypeManipulation = new ChangeNodeTypeManipulation();
    192       changeNodeTypeManipulation.GetVariableInfo("OperatorLibrary").ActualName = "FunctionLibrary";
    193188      CutOutNodeManipulation cutOutNodeManipulation = new CutOutNodeManipulation();
    194       cutOutNodeManipulation.GetVariableInfo("OperatorLibrary").ActualName = "FunctionLibrary";
    195189      DeleteSubTreeManipulation deleteSubTreeManipulation = new DeleteSubTreeManipulation();
    196       deleteSubTreeManipulation.GetVariableInfo("OperatorLibrary").ActualName = "FunctionLibrary";
    197190      SubstituteSubTreeManipulation substituteSubTreeManipulation = new SubstituteSubTreeManipulation();
    198       substituteSubTreeManipulation.GetVariableInfo("OperatorLibrary").ActualName = "FunctionLibrary";
    199191
    200192      IOperator[] manipulators = new IOperator[] {
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/SymbolTable.cs

    r1529 r2210  
    2626using HeuristicLab.Core;
    2727using System.Xml;
     28using HeuristicLab.GP.Interfaces;
    2829
    2930namespace HeuristicLab.GP.StructureIdentification {
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/SymbolicExpressionExporter.cs

    r1529 r2210  
    2525using System.Text;
    2626using HeuristicLab.Data;
     27using HeuristicLab.GP.Interfaces;
    2728
    2829namespace HeuristicLab.GP.StructureIdentification {
     
    125126
    126127    public static string ExportToScheme(this Constant constant, IFunctionTree tree) {
    127       return tree.GetLocalVariable(Constant.VALUE).Value.ToString();
     128      return ((ConstantFunctionTree)tree).Value.ToString("r");
    128129    }
    129130
     
    173174
    174175    public static string ExportToScheme(this Variable variable, IFunctionTree tree) {
    175       return "(variable " + tree.GetLocalVariable(Variable.WEIGHT).Value + " " +
    176         tree.GetLocalVariable(Variable.INDEX).Value + " " + tree.GetLocalVariable(Variable.OFFSET).Value + ")";
     176      var varTree = (VariableFunctionTree)tree;
     177      return "(variable " + varTree.Weight.ToString("r") + " " +
     178        varTree.VariableName + " " + varTree.SampleOffset + ")";
    177179    }
    178180    public static string ExportToScheme(this Differential differential, IFunctionTree tree) {
    179       return "(differential " + tree.GetLocalVariable(Differential.WEIGHT).Value + " " +
    180         tree.GetLocalVariable(Differential.INDEX).Value + " " + tree.GetLocalVariable(Differential.OFFSET).Value + ")";
     181      var varTree = (VariableFunctionTree)tree;
     182      return "(differential " + varTree.Weight.ToString("r") + " " +
     183        varTree.VariableName + " " + varTree.SampleOffset + ")";
    181184    }
    182185
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/TreeEvaluatorBase.cs

    r2202 r2210  
    2929using HeuristicLab.DataAnalysis;
    3030using HeuristicLab.Data;
     31using HeuristicLab.GP.Interfaces;
    3132
    3233namespace HeuristicLab.GP.StructureIdentification {
     
    4546      public byte arity;
    4647      public byte symbol;
    47       public IFunction function;
    4848    }
    4949
     
    6161      minValue = mean - punishmentFactor * range;
    6262
    63       BakedFunctionTree bakedTree = functionTree as BakedFunctionTree;
    64       if (bakedTree == null) throw new ArgumentException("TreeEvaluators can only evaluate BakedFunctionTrees");
    65 
    66       List<LightWeightFunction> linearRepresentation = bakedTree.LinearRepresentation;
    67       codeArr = new Instr[linearRepresentation.Count];
     63      codeArr = new Instr[functionTree.GetSize()];
    6864      int i = 0;
    69       foreach (LightWeightFunction f in linearRepresentation) {
    70         codeArr[i++] = TranslateToInstr(f);
     65      foreach (IFunctionTree tree in IteratePrefix(functionTree)) {
     66        codeArr[i++] = TranslateToInstr(tree);
    7167      }
    7268    }
    7369
    74     private Instr TranslateToInstr(LightWeightFunction f) {
     70    private IEnumerable<IFunctionTree> IteratePrefix(IFunctionTree functionTree) {
     71      List<IFunctionTree> prefixForm = new List<IFunctionTree>();
     72      prefixForm.Add(functionTree);
     73      foreach (IFunctionTree subTree in functionTree.SubTrees) {
     74        prefixForm.AddRange(IteratePrefix(subTree));
     75      }
     76      return prefixForm;
     77    }
     78
     79    private Instr TranslateToInstr(IFunctionTree tree) {
    7580      Instr instr = new Instr();
    76       instr.arity = f.arity;
    77       instr.symbol = EvaluatorSymbolTable.MapFunction(f.functionType);
     81      instr.arity = (byte)tree.SubTrees.Count;
     82      instr.symbol = EvaluatorSymbolTable.MapFunction(tree.Function);
    7883      switch (instr.symbol) {
    7984        case EvaluatorSymbolTable.DIFFERENTIAL:
    8085        case EvaluatorSymbolTable.VARIABLE: {
    81             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
     86            VariableFunctionTree varTree = (VariableFunctionTree)tree;
     87            instr.i_arg0 = (short)dataset.GetVariableIndex(varTree.VariableName);
     88            instr.d_arg0 = varTree.Weight;
     89            instr.i_arg1 = (short)varTree.SampleOffset;
    8490            break;
    8591          }
    8692        case EvaluatorSymbolTable.CONSTANT: {
    87             instr.d_arg0 = ((DoubleData)f.localData[0].Value).Data; // value
     93            ConstantFunctionTree constTree = (ConstantFunctionTree)tree;
     94            instr.d_arg0 = constTree.Value;
    8895            break;
    8996          }
    9097        case EvaluatorSymbolTable.UNKNOWN: {
    91             instr.function = f.functionType;
    92             break;
     98            throw new NotSupportedException("Unknown function symbol: " + instr.symbol);
    9399          }
    94100      }
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Variable.cs

    r2202 r2210  
    3030using HeuristicLab.Random;
    3131using HeuristicLab.Operators;
     32using HeuristicLab.GP.Interfaces;
    3233
    3334namespace HeuristicLab.GP.StructureIdentification {
     
    3536    public const string WEIGHT = "Weight";
    3637    public const string OFFSET = "SampleOffset";
    37     public const string INDEX = "Variable";
    38 
    39     private BakedFunctionTree variableNodeTemplate;
     38    public const string VARIABLENAME = "Variable";
    4039
    4140    private int minOffset;
     
    5049    }
    5150
    52     public override IEnumerable<string> LocalParameterNames {
    53       get {
    54         return new string[] { WEIGHT, OFFSET, INDEX };
    55       }
    56     }
    57 
    5851    public override IFunctionTree GetTreeNode() {
    59       return (IFunctionTree)variableNodeTemplate.Clone();
     52      return new VariableFunctionTree(this);
    6053    }
    6154
    6255    public Variable()
    6356      : base() {
    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);
    71 
    72       DoubleData weight = new DoubleData();
    73       variableNodeTemplate.AddVariable(new HeuristicLab.Core.Variable(WEIGHT, weight));
    74 
    75       StringData variable = new StringData();
    76       variableNodeTemplate.AddVariable(new HeuristicLab.Core.Variable(INDEX, variable));
    77 
    78       ConstrainedIntData sampleOffset = new ConstrainedIntData();
    79       variableNodeTemplate.AddVariable(new HeuristicLab.Core.Variable(OFFSET, sampleOffset));
    80 
    8157      SetupInitialization();
    8258      SetupManipulation();
     
    8763      SequentialProcessor seq = new SequentialProcessor();
    8864      UniformItemChooser variableRandomizer = new UniformItemChooser();
    89       variableRandomizer.GetVariableInfo("Value").ActualName = INDEX;
     65      variableRandomizer.GetVariableInfo("Value").ActualName = VARIABLENAME;
    9066      variableRandomizer.GetVariableInfo("Values").ActualName = "InputVariables";
    9167      variableRandomizer.Name = "Variable randomizer";
     
    11793      SequentialProcessor seq = new SequentialProcessor();
    11894      UniformItemChooser variableRandomizer = new UniformItemChooser();
    119       variableRandomizer.GetVariableInfo("Value").ActualName = INDEX;
     95      variableRandomizer.GetVariableInfo("Value").ActualName = VARIABLENAME;
    12096      variableRandomizer.GetVariableInfo("Values").ActualName = "InputVariables";
    12197      variableRandomizer.Name = "Variable randomizer";
     
    143119
    144120    public void SetConstraints(int minSampleOffset, int maxSampleOffset) {
    145       ConstrainedIntData offset = (ConstrainedIntData)variableNodeTemplate.GetLocalVariable(OFFSET).Value;
    146       IntBoundedConstraint offsetConstraint = new IntBoundedConstraint();
    147121      this.minOffset = minSampleOffset;
    148122      this.maxOffset = maxSampleOffset;
    149       offsetConstraint.LowerBound = minSampleOffset;
    150       offsetConstraint.LowerBoundEnabled = true;
    151       offsetConstraint.LowerBoundIncluded = true;
    152       offsetConstraint.UpperBound = maxSampleOffset;
    153       offsetConstraint.UpperBoundEnabled = true;
    154       offsetConstraint.UpperBoundIncluded = true;
    155       offset.AddConstraint(offsetConstraint);
    156 
    157       //ConstrainedIntData index = GetVariableValue<ConstrainedIntData>(INDEX, null, false);
    158       //IntBoundedConstraint indexConstraint = new IntBoundedConstraint();
    159       //minIndex = minInputIndex;
    160       //maxIndex = maxInputIndex;
    161       //indexConstraint.LowerBound = minInputIndex;
    162       //indexConstraint.LowerBoundEnabled = true;
    163       //indexConstraint.LowerBoundIncluded = true;
    164       //indexConstraint.UpperBound = maxInputIndex;
    165       //indexConstraint.UpperBoundEnabled = true;
    166       //indexConstraint.UpperBoundIncluded = true;
    167       //index.AddConstraint(indexConstraint);
    168 
    169123      SetupInitialization();
    170124      SetupManipulation();
Note: See TracChangeset for help on using the changeset viewer.