Free cookie consent management tool by TermsFeed Policy Generator

Changeset 18082 for branches


Ignore:
Timestamp:
11/15/21 16:18:39 (3 years ago)
Author:
pfleck
Message:

#3040: Added the ISymbolicDataAnalysisExpressionManipulator and necessary code analogously to the ISymbolicDataAnalysisExpressionCrossover.

Location:
branches/3040_VectorBasedGP
Files:
4 added
12 edited

Legend:

Unmodified
Added
Removed
  • branches/3040_VectorBasedGP/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/MultiSymbolicExpressionTreeArchitectureManipulator.cs

    r17180 r18082  
    114114    }
    115115
     116    public void Manipulate(IRandom random, ISymbolicExpressionTree symbolicExpressionTree) {
     117      double sum = Operators.CheckedItems.Sum(o => Probabilities[o.Index]);
     118      if (sum.IsAlmost(0)) throw new InvalidOperationException(Name + ": All selected operators have zero probability.");
     119      double r = random.NextDouble() * sum;
     120      sum = 0;
     121      int index = -1;
     122      foreach (var indexedItem in Operators.CheckedItems) {
     123        sum += Probabilities[indexedItem.Index];
     124        if (sum > r) {
     125          index = indexedItem.Index;
     126          break;
     127        }
     128      }
     129      Operators[index].Manipulate(random, symbolicExpressionTree);
     130    }
     131
    116132    protected override void Operators_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IndexedItem<ISymbolicExpressionTreeManipulator>> e) {
    117133      base.Operators_ItemsReplaced(sender, e);
  • branches/3040_VectorBasedGP/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/SymbolicExpressionTreeArchitectureManipulator.cs

    r17180 r18082  
    6262    }
    6363
    64     protected override sealed void Manipulate(IRandom random, ISymbolicExpressionTree symbolicExpressionTree) {
     64    public sealed override void Manipulate(IRandom random, ISymbolicExpressionTree symbolicExpressionTree) {
    6565      ModifyArchitecture(random, symbolicExpressionTree, MaximumFunctionDefinitions, MaximumFunctionArguments);
    6666    }
  • branches/3040_VectorBasedGP/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Interfaces/Operators/ISymbolicExpressionTreeManipulator.cs

    r17180 r18082  
    2222using HeuristicLab.Optimization;
    2323using HEAL.Attic;
     24using HeuristicLab.Core;
    2425
    2526namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
     
    2930  /// </summary>
    3031  public interface ISymbolicExpressionTreeManipulator : ISymbolicExpressionTreeOperator, IManipulator {
     32    //ILookupParameter<ISymbolicExpressionTree> ParentParameter { get; }
     33    void Manipulate(IRandom random, ISymbolicExpressionTree symbolicExpressionTree);
    3134  }
    3235}
  • branches/3040_VectorBasedGP/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Manipulators/ChangeNodeTypeManipulation.cs

    r17180 r18082  
    4141    }
    4242
    43     protected override void Manipulate(IRandom random, ISymbolicExpressionTree symbolicExpressionTree) {
     43    public override void Manipulate(IRandom random, ISymbolicExpressionTree symbolicExpressionTree) {
    4444      ChangeNodeType(random, symbolicExpressionTree);
    4545    }
  • branches/3040_VectorBasedGP/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Manipulators/FullTreeShaker.cs

    r17180 r18082  
    5454    }
    5555
    56     protected override void Manipulate(IRandom random, ISymbolicExpressionTree tree) {
     56    public override void Manipulate(IRandom random, ISymbolicExpressionTree tree) {
    5757      tree.Root.ForEachNodePostfix(node => {
    5858        if (node.HasLocalParameters) {
  • branches/3040_VectorBasedGP/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Manipulators/MultiSymbolicExpressionTreeManipulator.cs

    r17180 r18082  
    8181      CheckedItemList<ISymbolicExpressionTreeManipulator> checkedItemList = new CheckedItemList<ISymbolicExpressionTreeManipulator>();
    8282      checkedItemList.AddRange(list.OrderBy(op => op.Name));
    83       Operators = checkedItemList.AsReadOnly();
     83      //Operators = checkedItemList.AsReadOnly();
     84      Operators = checkedItemList;
    8485      Operators_ItemsAdded(this, new CollectionItemsChangedEventArgs<IndexedItem<ISymbolicExpressionTreeManipulator>>(Operators.CheckedItems));
    8586
     
    8990    public override IDeepCloneable Clone(Cloner cloner) {
    9091      return new MultiSymbolicExpressionTreeManipulator(this, cloner);
     92    }
     93
     94    public void Manipulate(IRandom random, ISymbolicExpressionTree symbolicExpressionTree) {
     95      double sum = Operators.CheckedItems.Sum(o => Probabilities[o.Index]);
     96      if (sum.IsAlmost(0)) throw new InvalidOperationException(Name + ": All selected operators have zero probability.");
     97      double r = random.NextDouble() * sum;
     98      sum = 0;
     99      int index = -1;
     100      foreach (var indexedItem in Operators.CheckedItems) {
     101        sum += Probabilities[indexedItem.Index];
     102        if (sum > r) {
     103          index = indexedItem.Index;
     104          break;
     105        }
     106      }
     107      Operators[index].Manipulate(random, symbolicExpressionTree);
    91108    }
    92109
  • branches/3040_VectorBasedGP/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Manipulators/OnePointShaker.cs

    r17180 r18082  
    5656    }
    5757
    58     protected override void Manipulate(IRandom random, ISymbolicExpressionTree tree) {
     58    public override void Manipulate(IRandom random, ISymbolicExpressionTree tree) {
    5959      OnePointShaker.Shake(random, tree, ShakingFactor);
    6060    }
  • branches/3040_VectorBasedGP/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Manipulators/RemoveBranchManipulation.cs

    r17180 r18082  
    6666    }
    6767
    68     protected override void Manipulate(IRandom random, ISymbolicExpressionTree symbolicExpressionTree) {
     68    public override void Manipulate(IRandom random, ISymbolicExpressionTree symbolicExpressionTree) {
    6969      RemoveRandomBranch(random, symbolicExpressionTree, MaximumSymbolicExpressionTreeLength.Value, MaximumSymbolicExpressionTreeDepth.Value);
    7070    }
  • branches/3040_VectorBasedGP/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Manipulators/ReplaceBranchManipulation.cs

    r17180 r18082  
    6565    }
    6666
    67     protected override void Manipulate(IRandom random, ISymbolicExpressionTree symbolicExpressionTree) {
     67    public override void Manipulate(IRandom random, ISymbolicExpressionTree symbolicExpressionTree) {
    6868      ReplaceRandomBranch(random, symbolicExpressionTree, MaximumSymbolicExpressionTreeLength.Value, MaximumSymbolicExpressionTreeDepth.Value);
    6969    }
  • branches/3040_VectorBasedGP/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Manipulators/SymbolicExpressionTreeManipulator.cs

    r17180 r18082  
    4646    }
    4747
    48     protected abstract void Manipulate(IRandom random, ISymbolicExpressionTree symbolicExpressionTree);
     48    public abstract void Manipulate(IRandom random, ISymbolicExpressionTree symbolicExpressionTree);
    4949  }
    5050}
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj

    r17930 r18082  
    174174    <Compile Include="Converters\TreeToAutoDiffTermConverter.cs" />
    175175    <Compile Include="Creators\SymbolicDataAnalysisExpressionBalancedTreeCreator.cs" />
     176    <Compile Include="Mutators\MultiSymbolicDataAnalysisExpressionManipulator.cs" />
     177    <Compile Include="Interfaces\ISymbolicDataAnalysisExpressionManipulator.cs" />
     178    <Compile Include="Mutators\SymbolicDataAnalysisExpressionManipulator.cs" />
    176179    <Compile Include="Crossovers\SymbolicDataAnalysisExpressionDiversityPreservingCrossover.cs" />
    177180    <Compile Include="Formatters\InfixExpressionFormatter.cs" />
     
    201204    <Compile Include="Interpreter\SymbolicDataAnalysisExpressionTreeVectorInterpreter.cs" />
    202205    <Compile Include="Interpreter\SymbolicDataAnalysisExpressionTreeNativeInterpreter.cs" />
     206    <Compile Include="Mutators\SubVectorImprovementManipulator.cs" />
    203207    <Compile Include="Selectors\DiversitySelector.cs" />
    204208    <Compile Include="SymbolicDataAnalysisExpressionTreeAverageSimilarityCalculator.cs" />
     
    454458    </ProjectReference>
    455459  </ItemGroup>
     460  <ItemGroup />
    456461  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
    457462  <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisProblem.cs

    r17456 r18082  
    229229      foreach (var op in ApplicationManager.Manager.GetInstances<ISymbolicDataAnalysisExpressionCrossover<T>>())
    230230        operators.Add(op);
     231      foreach (var op in ApplicationManager.Manager.GetInstances<ISymbolicDataAnalysisExpressionManipulator<T>>())
     232        operators.Add(op);
    231233
    232234      operators.Add(new SymbolicExpressionSymbolFrequencyAnalyzer());
     
    357359        op.EvaluatorParameter.ActualName = EvaluatorParameter.Name;
    358360      }
     361      foreach (var op in operators.OfType<ISymbolicDataAnalysisExpressionManipulator<T>>()) {
     362        op.EvaluationPartitionParameter.ActualName = FitnessCalculationPartitionParameter.Name;
     363        op.ProblemDataParameter.ActualName = ProblemDataParameter.Name;
     364        op.EvaluationPartitionParameter.ActualName = FitnessCalculationPartitionParameter.Name;
     365        op.RelativeNumberOfEvaluatedSamplesParameter.ActualName = RelativeNumberOfEvaluatedSamplesParameter.Name;
     366        op.EvaluatorParameter.ActualName = EvaluatorParameter.Name;
     367      }
    359368    }
    360369
Note: See TracChangeset for help on using the changeset viewer.