Free cookie consent management tool by TermsFeed Policy Generator

Changeset 425 for trunk


Ignore:
Timestamp:
08/03/08 10:51:50 (16 years ago)
Author:
gkronber
Message:

moved creation of default init and manipulation operators from !GPOperatorGroup into the functions (ticket #225 "Simplify GP infrastructure (GPOperatorLibrary and Functions)")

Location:
trunk/sources
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Functions/Constant.cs

    r229 r425  
    2828using HeuristicLab.Constraints;
    2929using HeuristicLab.DataAnalysis;
     30using HeuristicLab.Operators;
     31using HeuristicLab.Random;
    3032
    3133namespace HeuristicLab.Functions {
     
    4850      AddVariable(value);
    4951
     52      SetupInitialization();
     53      SetupManipulation();
     54
    5055      // constant can't have suboperators
    5156      AddConstraint(new NumberOfSubOperatorsConstraint(0, 0));
    5257    }
     58
     59    private void SetupInitialization() {
     60      // initialization operator
     61      AddVariableInfo(new VariableInfo(INITIALIZATION, "Initialization operator-graph for constants", typeof(IOperatorGraph), VariableKind.None));
     62      GetVariableInfo(INITIALIZATION).Local = false;
     63      CombinedOperator combinedOp = new CombinedOperator();
     64      SequentialProcessor initSeq = new SequentialProcessor();
     65      UniformRandomizer randomizer = new UniformRandomizer();
     66      randomizer.Min = -20.0;
     67      randomizer.Max = 20.0;
     68
     69      combinedOp.OperatorGraph.AddOperator(initSeq);
     70      combinedOp.OperatorGraph.AddOperator(randomizer);
     71      combinedOp.OperatorGraph.InitialOperator = initSeq;
     72      initSeq.AddSubOperator(randomizer);
     73      AddVariable(new HeuristicLab.Core.Variable(INITIALIZATION, combinedOp));
     74    }
     75
     76    private void SetupManipulation() {
     77      // manipulation operator
     78      AddVariableInfo(new VariableInfo(MANIPULATION, "Manipulation operator-graph for constants", typeof(IOperatorGraph), VariableKind.None));
     79      GetVariableInfo(MANIPULATION).Local = false;
     80      CombinedOperator combinedOp = new CombinedOperator();
     81      SequentialProcessor manipulationSeq = new SequentialProcessor();
     82      NormalRandomAdder valueAdder = new NormalRandomAdder();
     83      valueAdder.Mu = 0.0;
     84      valueAdder.Sigma = 0.1;
     85
     86      combinedOp.OperatorGraph.AddOperator(manipulationSeq);
     87      combinedOp.OperatorGraph.AddOperator(valueAdder);
     88      combinedOp.OperatorGraph.InitialOperator = manipulationSeq;
     89      manipulationSeq.AddSubOperator(valueAdder);
     90      AddVariable(new HeuristicLab.Core.Variable(MANIPULATION, combinedOp));
     91    }
     92
    5393    public override void Accept(IFunctionVisitor visitor) {
    5494      visitor.Visit(this);
  • trunk/sources/HeuristicLab.Functions/Differential.cs

    r365 r425  
    2828using HeuristicLab.Constraints;
    2929using HeuristicLab.DataAnalysis;
     30using HeuristicLab.Operators;
     31using HeuristicLab.Random;
    3032
    3133namespace HeuristicLab.Functions {
     
    6062
    6163      ConstrainedIntData sampleOffset = new ConstrainedIntData();
    62       // initialize a totally arbitrary default range for sampleoffset = [-10, 10]
    63       sampleOffset.AddConstraint(new IntBoundedConstraint(0, 0));
     64      // initialize a sample offset for static models
     65      IntBoundedConstraint offsetConstraint = new IntBoundedConstraint(0, 0);
     66      offsetConstraint.LowerBoundIncluded = true;
     67      offsetConstraint.UpperBoundIncluded = true;
     68      sampleOffset.AddConstraint(offsetConstraint);
    6469      AddVariable(new HeuristicLab.Core.Variable(OFFSET, sampleOffset));
     70
     71      SetupInitialization();
     72      SetupManipulation();
    6573
    6674      // variable can't have suboperators
    6775      AddConstraint(new NumberOfSubOperatorsConstraint(0, 0));
     76    }
     77
     78    private void SetupInitialization() {
     79      AddVariableInfo(new VariableInfo(INITIALIZATION, "Initialization operator for differentials", typeof(CombinedOperator), VariableKind.None));
     80      GetVariableInfo(INITIALIZATION).Local = false;
     81      CombinedOperator combinedOp = new CombinedOperator();
     82      SequentialProcessor seq = new SequentialProcessor();
     83      UniformRandomizer indexRandomizer = new UniformRandomizer();
     84      indexRandomizer.Min = 0;
     85      indexRandomizer.Max = 10;
     86      indexRandomizer.GetVariableInfo("Value").ActualName = INDEX;
     87      indexRandomizer.Name = "Index Randomizer";
     88      NormalRandomizer weightRandomizer = new NormalRandomizer();
     89      weightRandomizer.Mu = 1.0;
     90      weightRandomizer.Sigma = 1.0;
     91      weightRandomizer.GetVariableInfo("Value").ActualName = WEIGHT;
     92      weightRandomizer.Name = "Weight Randomizer";
     93      UniformRandomizer offsetRandomizer = new UniformRandomizer();
     94      offsetRandomizer.Min = 0.0;
     95      offsetRandomizer.Max = 1.0;
     96      offsetRandomizer.GetVariableInfo("Value").ActualName = OFFSET;
     97      offsetRandomizer.Name = "Offset Randomizer";
     98
     99      combinedOp.OperatorGraph.AddOperator(seq);
     100      combinedOp.OperatorGraph.AddOperator(indexRandomizer);
     101      combinedOp.OperatorGraph.AddOperator(weightRandomizer);
     102      combinedOp.OperatorGraph.AddOperator(offsetRandomizer);
     103      combinedOp.OperatorGraph.InitialOperator = seq;
     104      seq.AddSubOperator(indexRandomizer);
     105      seq.AddSubOperator(weightRandomizer);
     106      seq.AddSubOperator(offsetRandomizer);
     107      AddVariable(new HeuristicLab.Core.Variable(INITIALIZATION, combinedOp));
     108    }
     109
     110    private void SetupManipulation() {
     111      // manipulation operator
     112      AddVariableInfo(new VariableInfo(MANIPULATION, "Manipulation operator for differentials", typeof(CombinedOperator), VariableKind.None));
     113      GetVariableInfo(MANIPULATION).Local = false;
     114      CombinedOperator combinedOp = new CombinedOperator();
     115      SequentialProcessor seq = new SequentialProcessor();
     116      UniformRandomizer indexRandomizer = new UniformRandomizer();
     117      indexRandomizer.Min = 0;
     118      indexRandomizer.Max = 10;
     119      indexRandomizer.GetVariableInfo("Value").ActualName = INDEX;
     120      indexRandomizer.Name = "Index Randomizer";
     121      NormalRandomAdder weightRandomAdder = new NormalRandomAdder();
     122      weightRandomAdder.Mu = 0.0;
     123      weightRandomAdder.Sigma = 0.1;
     124      weightRandomAdder.GetVariableInfo("Value").ActualName = WEIGHT;
     125      weightRandomAdder.Name = "Weight Adder";
     126      NormalRandomAdder offsetRandomAdder = new NormalRandomAdder();
     127      offsetRandomAdder.Mu = 0.0;
     128      offsetRandomAdder.Sigma = 1.0;
     129      offsetRandomAdder.GetVariableInfo("Value").ActualName = OFFSET;
     130      offsetRandomAdder.Name = "Offset Adder";
     131
     132      combinedOp.OperatorGraph.AddOperator(seq);
     133      combinedOp.OperatorGraph.AddOperator(indexRandomizer);
     134      combinedOp.OperatorGraph.AddOperator(weightRandomAdder);
     135      combinedOp.OperatorGraph.AddOperator(offsetRandomAdder);
     136      combinedOp.OperatorGraph.InitialOperator = seq;
     137      seq.AddSubOperator(indexRandomizer);
     138      seq.AddSubOperator(weightRandomAdder);
     139      seq.AddSubOperator(offsetRandomAdder);
     140      AddVariable(new HeuristicLab.Core.Variable(MANIPULATION, combinedOp));
    68141    }
    69142
  • trunk/sources/HeuristicLab.Functions/FunctionBase.cs

    r229 r425  
    3434  /// </summary>
    3535  public abstract class FunctionBase : OperatorBase, IFunction {
     36    protected const string INITIALIZATION = "Initialization";
     37    protected const string MANIPULATION = "Manipulation";
     38
    3639
    3740    public virtual double Apply(Dataset dataset, int sampleIndex, double[] args) {
  • trunk/sources/HeuristicLab.Functions/HeuristicLab.Functions.csproj

    r396 r425  
    118118      <Name>HeuristicLab.Operators.Programmable</Name>
    119119    </ProjectReference>
     120    <ProjectReference Include="..\HeuristicLab.Operators\HeuristicLab.Operators.csproj">
     121      <Project>{A9983BA2-B3B2-475E-8E2C-62050B71D1C5}</Project>
     122      <Name>HeuristicLab.Operators</Name>
     123    </ProjectReference>
    120124    <ProjectReference Include="..\HeuristicLab.PluginInfrastructure\HeuristicLab.PluginInfrastructure.csproj">
    121125      <Project>{94186A6A-5176-4402-AE83-886557B53CCA}</Project>
    122126      <Name>HeuristicLab.PluginInfrastructure</Name>
     127    </ProjectReference>
     128    <ProjectReference Include="..\HeuristicLab.Random\HeuristicLab.Random.csproj">
     129      <Project>{47019A74-F7F7-482E-83AA-D3F4F777E879}</Project>
     130      <Name>HeuristicLab.Random</Name>
    123131    </ProjectReference>
    124132  </ItemGroup>
  • trunk/sources/HeuristicLab.Functions/HeuristicLabFunctionsPlugin.cs

    r165 r425  
    3232  [Dependency(Dependency = "HeuristicLab.Data")]
    3333  [Dependency(Dependency = "HeuristicLab.DataAnalysis")]
     34  [Dependency(Dependency = "HeuristicLab.Operators")]
    3435  [Dependency(Dependency = "HeuristicLab.Operators.Programmable")]
     36  [Dependency(Dependency = "HeuristicLab.Random")]
    3537  public class HeuristicLabFunctionsPlugin : PluginBase {
    3638  }
  • trunk/sources/HeuristicLab.Functions/Variable.cs

    r229 r425  
    2828using HeuristicLab.Constraints;
    2929using HeuristicLab.DataAnalysis;
     30using HeuristicLab.Random;
     31using HeuristicLab.Operators;
    3032
    3133namespace HeuristicLab.Functions {
     
    6264
    6365      ConstrainedIntData sampleOffset = new ConstrainedIntData();
    64       // initialize a totally arbitrary default range for sampleoffset = [-10, 10]
    65       sampleOffset.AddConstraint(new IntBoundedConstraint(0, 0));
     66      // initialize a sample offset for static models
     67      IntBoundedConstraint offsetConstraint = new IntBoundedConstraint(0, 0);
     68      offsetConstraint.LowerBoundIncluded = true;
     69      offsetConstraint.UpperBoundIncluded = true;
     70      sampleOffset.AddConstraint(offsetConstraint);
    6671      AddVariable(new HeuristicLab.Core.Variable(OFFSET, sampleOffset));
     72
     73      SetupInitialization();
     74      SetupManipulation();
    6775
    6876      // variable can't have suboperators
    6977      AddConstraint(new NumberOfSubOperatorsConstraint(0, 0));
     78    }
     79
     80    private void SetupInitialization() {
     81      AddVariableInfo(new VariableInfo(INITIALIZATION, "Initialization operator for variables", typeof(CombinedOperator), VariableKind.None));
     82      GetVariableInfo(INITIALIZATION).Local = false;
     83      CombinedOperator combinedOp = new CombinedOperator();
     84      SequentialProcessor seq = new SequentialProcessor();
     85      UniformRandomizer indexRandomizer = new UniformRandomizer();
     86      indexRandomizer.Min = 0;
     87      indexRandomizer.Max = 10;
     88      indexRandomizer.GetVariableInfo("Value").ActualName = INDEX;
     89      indexRandomizer.Name = "Index Randomizer";
     90      NormalRandomizer weightRandomizer = new NormalRandomizer();
     91      weightRandomizer.Mu = 1.0;
     92      weightRandomizer.Sigma = 1.0;
     93      weightRandomizer.GetVariableInfo("Value").ActualName = WEIGHT;
     94      weightRandomizer.Name = "Weight Randomizer";
     95      UniformRandomizer offsetRandomizer = new UniformRandomizer();
     96      offsetRandomizer.Min = 0.0;
     97      offsetRandomizer.Max = 1.0;
     98      offsetRandomizer.GetVariableInfo("Value").ActualName = OFFSET;
     99      offsetRandomizer.Name = "Offset Randomizer";
     100
     101      combinedOp.OperatorGraph.AddOperator(seq);
     102      combinedOp.OperatorGraph.AddOperator(indexRandomizer);
     103      combinedOp.OperatorGraph.AddOperator(weightRandomizer);
     104      combinedOp.OperatorGraph.AddOperator(offsetRandomizer);
     105      combinedOp.OperatorGraph.InitialOperator = seq;
     106      seq.AddSubOperator(indexRandomizer);
     107      seq.AddSubOperator(weightRandomizer);
     108      seq.AddSubOperator(offsetRandomizer);
     109      AddVariable(new HeuristicLab.Core.Variable(INITIALIZATION, combinedOp));
     110    }
     111
     112    private void SetupManipulation() {
     113      // manipulation operator
     114      AddVariableInfo(new VariableInfo(MANIPULATION, "Manipulation operator for variables", typeof(CombinedOperator), VariableKind.None));
     115      GetVariableInfo(MANIPULATION).Local = false;
     116      CombinedOperator combinedOp = new CombinedOperator();
     117      SequentialProcessor seq = new SequentialProcessor();
     118      UniformRandomizer indexRandomizer = new UniformRandomizer();
     119      indexRandomizer.Min = 0;
     120      indexRandomizer.Max = 10;
     121      indexRandomizer.GetVariableInfo("Value").ActualName = INDEX;
     122      indexRandomizer.Name = "Index Randomizer";
     123      NormalRandomAdder weightRandomAdder = new NormalRandomAdder();
     124      weightRandomAdder.Mu = 0.0;
     125      weightRandomAdder.Sigma = 0.1;
     126      weightRandomAdder.GetVariableInfo("Value").ActualName = WEIGHT;
     127      weightRandomAdder.Name = "Weight Adder";
     128      NormalRandomAdder offsetRandomAdder = new NormalRandomAdder();
     129      offsetRandomAdder.Mu = 0.0;
     130      offsetRandomAdder.Sigma = 1.0;
     131      offsetRandomAdder.GetVariableInfo("Value").ActualName = OFFSET;
     132      offsetRandomAdder.Name = "Offset Adder";
     133
     134      combinedOp.OperatorGraph.AddOperator(seq);
     135      combinedOp.OperatorGraph.AddOperator(indexRandomizer);
     136      combinedOp.OperatorGraph.AddOperator(weightRandomAdder);
     137      combinedOp.OperatorGraph.AddOperator(offsetRandomAdder);
     138      combinedOp.OperatorGraph.InitialOperator = seq;
     139      seq.AddSubOperator(indexRandomizer);
     140      seq.AddSubOperator(weightRandomAdder);
     141      seq.AddSubOperator(offsetRandomAdder);
     142      AddVariable(new HeuristicLab.Core.Variable(MANIPULATION, combinedOp));
    70143    }
    71144
  • trunk/sources/HeuristicLab.StructureIdentification/GPOperatorGroup.cs

    r423 r425  
    4141      var localVariableInfos = op.VariableInfos.Where(f => f.Local);
    4242
    43       if(op.GetVariable(GPOperatorLibrary.MANIPULATION) == null) {
    44         CombinedOperator manipulationOperator = new CombinedOperator();
    45         SequentialProcessor manipulationSequence = new SequentialProcessor();
    46         foreach(IVariableInfo variableInfo in localVariableInfos) {
    47           IOperator manipulator = GetDefaultManipulationOperator(variableInfo);
    48           if (manipulator != null) {
    49             manipulationSequence.AddSubOperator(manipulator);
    50           }
    51         }
    52         if(manipulationSequence.SubOperators.Count > 0) {
    53           op.AddVariable(new Variable(GPOperatorLibrary.MANIPULATION, manipulationOperator));
    54 
    55           manipulationOperator.OperatorGraph.AddOperator(manipulationSequence);
    56           manipulationOperator.OperatorGraph.InitialOperator = manipulationSequence;
    57           foreach(IOperator subOp in manipulationSequence.SubOperators) {
    58             manipulationOperator.OperatorGraph.AddOperator(subOp);
    59           }
    60         }
    61       }
    62 
    63       if(op.GetVariable(GPOperatorLibrary.INITIALIZATION) == null) {
    64         CombinedOperator initOperator = new CombinedOperator();
    65         SequentialProcessor initSequence = new SequentialProcessor();
    66         foreach(IVariableInfo variableInfo in localVariableInfos) {
    67           IOperator initializer = GetDefaultInitOperator(variableInfo);
    68           if (initializer != null) {
    69             initSequence.AddSubOperator(initializer);
    70           }
    71         }
    72         if(initSequence.SubOperators.Count > 0) {
    73           op.AddVariable(new Variable(GPOperatorLibrary.INITIALIZATION, initOperator));
    74           initOperator.OperatorGraph.AddOperator(initSequence);
    75           initOperator.OperatorGraph.InitialOperator = initSequence;
    76           foreach(IOperator subOp in initSequence.SubOperators) {
    77             initOperator.OperatorGraph.AddOperator(subOp);
    78           }
    79         }
    80       }
     43      //if(op.GetVariable(GPOperatorLibrary.MANIPULATION) == null) {
     44      //  CombinedOperator manipulationOperator = new CombinedOperator();
     45      //  SequentialProcessor manipulationSequence = new SequentialProcessor();
     46      //  foreach(IVariableInfo variableInfo in localVariableInfos) {
     47      //    IOperator manipulator = GetDefaultManipulationOperator(variableInfo);
     48      //    if (manipulator != null) {
     49      //      manipulationSequence.AddSubOperator(manipulator);
     50      //    }
     51      //  }
     52      //  if(manipulationSequence.SubOperators.Count > 0) {
     53      //    op.AddVariable(new Variable(GPOperatorLibrary.MANIPULATION, manipulationOperator));
     54
     55      //    manipulationOperator.OperatorGraph.AddOperator(manipulationSequence);
     56      //    manipulationOperator.OperatorGraph.InitialOperator = manipulationSequence;
     57      //    foreach(IOperator subOp in manipulationSequence.SubOperators) {
     58      //      manipulationOperator.OperatorGraph.AddOperator(subOp);
     59      //    }
     60      //  }
     61      //}
     62
     63      //if(op.GetVariable(GPOperatorLibrary.INITIALIZATION) == null) {
     64      //  CombinedOperator initOperator = new CombinedOperator();
     65      //  SequentialProcessor initSequence = new SequentialProcessor();
     66      //  foreach(IVariableInfo variableInfo in localVariableInfos) {
     67      //    IOperator initializer = GetDefaultInitOperator(variableInfo);
     68      //    if (initializer != null) {
     69      //      initSequence.AddSubOperator(initializer);
     70      //    }
     71      //  }
     72      //  if(initSequence.SubOperators.Count > 0) {
     73      //    op.AddVariable(new Variable(GPOperatorLibrary.INITIALIZATION, initOperator));
     74      //    initOperator.OperatorGraph.AddOperator(initSequence);
     75      //    initOperator.OperatorGraph.InitialOperator = initSequence;
     76      //    foreach(IOperator subOp in initSequence.SubOperators) {
     77      //      initOperator.OperatorGraph.AddOperator(subOp);
     78      //    }
     79      //  }
     80      //}
    8181
    8282      // add a new typeid if necessary
     
    9797        op.AddVariable(new Variable(GPOperatorLibrary.TICKETS, new DoubleData(1.0)));
    9898      }
    99 
    100       //RecalculateAllowedSuboperators();
    101       //RecalculateMinimalTreeBounds();
    102 
    10399      OnOperatorAdded(op);
    104100    }
     
    248244
    249245
    250     private IOperator GetDefaultManipulationOperator(IVariableInfo variableInfo) {
    251       IOperator shaker;
    252       if(variableInfo.DataType == typeof(ConstrainedDoubleData) ||
    253         variableInfo.DataType == typeof(ConstrainedIntData) ||
    254         variableInfo.DataType == typeof(DoubleData) ||
    255         variableInfo.DataType == typeof(IntData)) {
    256         shaker = new NormalRandomAdder();
    257       } else {
    258         return null;
    259       }
    260       shaker.GetVariableInfo("Value").ActualName = variableInfo.FormalName;
    261       shaker.Name = variableInfo.FormalName + " manipulation";
    262       return shaker;
    263     }
    264 
    265     private IOperator GetDefaultInitOperator(IVariableInfo variableInfo) {
    266       IOperator shaker;
    267       if(variableInfo.DataType == typeof(ConstrainedDoubleData) ||
    268         variableInfo.DataType == typeof(ConstrainedIntData) ||
    269         variableInfo.DataType == typeof(DoubleData) ||
    270         variableInfo.DataType == typeof(IntData)) {
    271         shaker = new UniformRandomizer();
    272       } else {
    273         return null;
    274       }
    275       shaker.GetVariableInfo("Value").ActualName = variableInfo.FormalName;
    276       shaker.Name = variableInfo.FormalName + " initialization";
    277       return shaker;
    278     }
     246    //private IOperator GetDefaultManipulationOperator(IVariableInfo variableInfo) {
     247    //  IOperator shaker;
     248    //  if(variableInfo.DataType == typeof(ConstrainedDoubleData) ||
     249    //    variableInfo.DataType == typeof(ConstrainedIntData) ||
     250    //    variableInfo.DataType == typeof(DoubleData) ||
     251    //    variableInfo.DataType == typeof(IntData)) {
     252    //    shaker = new NormalRandomAdder();
     253    //  } else {
     254    //    return null;
     255    //  }
     256    //  shaker.GetVariableInfo("Value").ActualName = variableInfo.FormalName;
     257    //  shaker.Name = variableInfo.FormalName + " manipulation";
     258    //  return shaker;
     259    //}
     260
     261    //private IOperator GetDefaultInitOperator(IVariableInfo variableInfo) {
     262    //  IOperator shaker;
     263    //  if(variableInfo.DataType == typeof(ConstrainedDoubleData) ||
     264    //    variableInfo.DataType == typeof(ConstrainedIntData) ||
     265    //    variableInfo.DataType == typeof(DoubleData) ||
     266    //    variableInfo.DataType == typeof(IntData)) {
     267    //    shaker = new UniformRandomizer();
     268    //  } else {
     269    //    return null;
     270    //  }
     271    //  shaker.GetVariableInfo("Value").ActualName = variableInfo.FormalName;
     272    //  shaker.Name = variableInfo.FormalName + " initialization";
     273    //  return shaker;
     274    //}
    279275
    280276    public override void AddSubGroup(IOperatorGroup group) {
     
    284280    public override void RemoveOperator(IOperator op) {
    285281      base.RemoveOperator(op);
    286       op.RemoveVariable(GPOperatorLibrary.MANIPULATION);
    287       op.RemoveVariable(GPOperatorLibrary.INITIALIZATION);
    288282      op.RemoveVariable(GPOperatorLibrary.TYPE_ID);
    289283      op.RemoveVariable(GPOperatorLibrary.MIN_TREE_SIZE);
Note: See TracChangeset for help on using the changeset viewer.