Free cookie consent management tool by TermsFeed Policy Generator

Changeset 18062


Ignore:
Timestamp:
10/01/21 10:55:19 (3 years ago)
Author:
dpiringe
Message:

#3136

  • added a new Symbol SubFunctionSymbol for sub functions
  • modified InfixExpressionParser to support SubFunctionSymbol (parsing of variableNames still in work)
  • modified StructuredSymbolicRegressionSingleObjectiveProblem to extract sub functions and add them to MultiEncoding
Location:
branches/3136_Structural_GP
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/StructuredSymbolicRegressionSingleObjectiveProblem.cs

    r18061 r18062  
    1111using HeuristicLab.Parameters;
    1212using HeuristicLab.Data;
     13using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    1314
    1415namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.SingleObjective {
     
    2728    public IValueParameter<IRegressionProblemData> ProblemDataParameter => (IValueParameter<IRegressionProblemData>)Parameters[ProblemDataParameterName];
    2829    public IFixedValueParameter<StringValue> StructureDefinitionParameter => (IFixedValueParameter<StringValue>)Parameters[StructureDefinitionParameterName];
    29     public IValueParameter<ISymbolicDataAnalysisGrammar> GrammarParameter => (IValueParameter<ISymbolicDataAnalysisGrammar>)Parameters[GrammarParameterName];
     30    public IValueParameter<ISymbolicDataAnalysisGrammar> GrammarParameter => (IValueParameter<ISymbolicDataAnalysisGrammar>)Parameters[GrammarParameterName]; // könnte auch weg?
    3031    #endregion
    3132
     
    6162    #region Constructors & Cloning
    6263    public StructuredSymbolicRegressionSingleObjectiveProblem() {
    63       Parameters.Add(new ValueParameter<RegressionProblemData>(ProblemDataParameterName, new RegressionProblemData()));
    64       Parameters.Add(new FixedValueParameter<StringValue>(StructureDefinitionParameterName, new StringValue("")));
    65       Parameters.Add(new ValueParameter<ISymbolicDataAnalysisGrammar>(GrammarParameterName, new LinearScalingGrammar()));
     64      var problemData = new ShapeConstrainedRegressionProblemData();
     65      var grammar = new LinearScalingGrammar();
     66      var varSym = (Variable)grammar.GetSymbol("Variable");
     67      varSym.AllVariableNames = problemData.InputVariables.Select(x => x.Value);
     68      varSym.VariableNames = problemData.InputVariables.Select(x => x.Value);
     69      varSym.Enabled = true;
     70
     71      Parameters.Add(new ValueParameter<RegressionProblemData>(ProblemDataParameterName, problemData));
     72      Parameters.Add(new FixedValueParameter<StringValue>(StructureDefinitionParameterName, new StringValue("e^f(x)/F(y)")));
     73      Parameters.Add(new ValueParameter<ISymbolicDataAnalysisGrammar>(GrammarParameterName, grammar));
     74      var parser = new InfixExpressionParser();
     75      var tree = parser.Parse(StructureDefinition);
     76     
     77      GetSubFunctions(tree);
    6678    }
    6779
     
    7789    #endregion
    7890
     91    public void GetSubFunctions(ISymbolicExpressionTree tree) {
     92      int count = 1;
     93      foreach(var node in tree.IterateNodesPrefix())
     94        if(node.Symbol is SubFunctionSymbol)
     95          Encoding.Add(new SymbolicExpressionTreeEncoding($"f{count++}", Grammar/*new LinearScalingGrammar()*/, 25, 8));
     96    }
     97
    7998    public override double Evaluate(Individual individual, IRandom random) {
     99      foreach(var kvp in individual.Values) {
     100        if(kvp.Value is SymbolicExpressionTree tree) {
     101          foreach(var n in tree.IterateNodesPrefix()) {
     102            if(n.Symbol is Variable v) {
     103              var t = v.VariableNames;
     104            }
     105          }
     106          Console.WriteLine(tree);
     107        }
     108      }
    80109      return 0.0;
    81110    }
  • branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj

    r17958 r18062  
    245245    <Compile Include="Symbols\CubeRoot.cs" />
    246246    <Compile Include="Symbols\HyperbolicTangent.cs" />
     247    <Compile Include="Symbols\SubFunctionSymbol.cs" />
    247248    <Compile Include="Symbols\VariableBase.cs" />
    248249    <Compile Include="Symbols\VariableTreeNodeBase.cs" />
  • branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Importer/InfixExpressionParser.cs

    r17902 r18062  
    138138        { "DIFF", new Derivative()},
    139139        { "LAG", new LaggedVariable() },
     140        { "F", new SubFunctionSymbol() }
    140141      };
    141142
Note: See TracChangeset for help on using the changeset viewer.